abc/src/base/abci/abcDec.c
/**Function*************************************************************

  Synopsis    [Determine the number of variables by reading the first line.]

  Description [Determine the number of functions by counting the lines.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Determine the number of variables by reading the first line.]

Description [Determine the number of functions by counting the lines.]




Function Synopsis [ Determine the number of variables by reading the first line . ] Description [ Determine the number of functions by counting the lines . ]
void Abc_TruthGetParams( char * pFileName, int * pnVars, int * pnTruths )
{
    char * pContents;
    int i, nVars, nLines;
    if ( pnVars )
        *pnVars = 0;
    if ( pnTruths )
        *pnTruths = 0;
    pContents = Abc_FileRead( pFileName );
    if ( pContents == NULL )
        return;
    for ( i = 0; pContents[i]; i++ )
        if ( pContents[i] == ' ' || pContents[i] == '\n' || pContents[i] == '\r' )
            break;
    if ( pContents[i] == 0 )
        printf( "Strange, the input file does not have spaces and new-lines...\n" );
    if ( pContents[0] == '0' && pContents[1] == 'x' )
        i = i - 2;
    for ( nVars = 0; nVars < 32; nVars++ )
        if ( 4 * i == (1 << nVars) ) 
            break;
    if ( nVars < 2 || nVars > 16 )
    {
        printf( "Does not look like the input file contains truth tables...\n" );
        return;
    }
    if ( pnVars )
        *pnVars = nVars;
    nLines = 0;
    for ( i = 0; pContents[i]; i++ )
        nLines += (pContents[i] == '\n');
    if ( pnTruths )
        *pnTruths = nLines;
    ABC_FREE( pContents );
}
void Abc_TruthGetParams ( char * pFileName , int * pnVars , int * pnTruths ) { char * pContents ; int i , nVars , nLines ; if ( pnVars ) * pnVars = 0 ; if ( pnTruths ) * pnTruths = 0 ; pContents = Abc_FileRead ( pFileName ) ; if ( pContents == NULL ) return ; for ( i = 0 ; pContents [ i ] ; i ++ ) if ( pContents [ i ] == ' ' || pContents [ i ] == ' \n ' || pContents [ i ] == ' \r ' ) break ; if ( pContents [ i ] == 0 ) printf ( " \n " ) ; if ( pContents [ 0 ] == ' ' && pContents [ 1 ] == ' ' ) i = i - 2 ; for ( nVars = 0 ; nVars < 32 ; nVars ++ ) if ( 4 * i == ( 1 << nVars ) ) break ; if ( nVars < 2 || nVars > 16 ) { printf ( " \n " ) ; return ; } if ( pnVars ) * pnVars = nVars ; nLines = 0 ; for ( i = 0 ; pContents [ i ] ; i ++ ) nLines += ( pContents [ i ] == ' \n ' ) ; if ( pnTruths ) * pnTruths = nLines ; ABC_FREE ( pContents ) ; }
Function
Synopsis    [Determine the number of variables by reading the first line.]
Function Synopsis [ Determine the number of variables by reading the first line . ]
// prepare the output  // read data from file // count the number of symbols before the first space or new-line // (note that on Windows symbols '\r' can be inserted before each '\n') // acount for the fact that truth tables may have "0x" at the beginning of each line // determine the number of variables // the number of bits equal to the size of truth table // determine the number of functions by counting the lines