Exemple #1
0
int main( int argc, char *argv[] )
{
    if( argc == 1 ) {
        HCError( ARG_ERR );
    }

    BlockFile   input( argv[1] );
    if( !input ) {
        HCError( FILE_ERR );
    }

    Buffer<char>        block(FILE_BLOCK_SIZE);
    Buffer<int>         pagebreaks( input.size() / FILE_BLOCK_SIZE + 1 );

    unsigned    amount_read = 0;
    unsigned    amount_written = 0;
    CompWriter  trashcan;
    CompReader  compactor( &trashcan );
    int i = 0;

    for( int num_pages = 0 ;; num_pages++ ) {
        amount_read = input.get_block( block );
        if( amount_read == 0 )
            break;
        amount_written += compactor.compress( block, amount_read );
        if( amount_written > FILE_PAGE_SIZE ) {
            pagebreaks[i++] = num_pages;
            compactor.flush();
            amount_written = compactor.compress( block, amount_read );
        }
    }

    input.reset();
    OutFile     output("pagecomp.out");
    if( !output ) {
        HCError( FILE_ERR );
    }
    CompOutFile newwriter( &output );

    compactor.reset( &newwriter );
    i = 0;
    amount_written = 0;
    for( int j=0; j < num_pages; j++ ) {
        if( j == pagebreaks[i] ) {
            compactor.flush();
            while( amount_written < FILE_PAGE_SIZE ) {
                output.write( (uint_8)0 );
                amount_written++;
            }
            amount_written = 0;
            i++;
        } else {
            amount_read = input.get_block( block );
            amount_written += compactor.compress( block, amount_read );
        }
    }
    return 1;
}
Exemple #2
0
void HPJReader::parseFile()
{
    HCStartFile( _scanner.name() );

    int     length = _scanner.getLine();    // Get the first line.
    char    section[15];
    int     i;
    while( length != 0 ){

    // The first line had better be the beginning of a section.
    if( _scanner[0] != '[' ){
        HCWarning( HPJ_NOTSECTION, _scanner.lineNum(), _scanner.name() );
        length = skipSection();
        continue;
    }

    // Read in the name of the section.
    for( i=1; i < length ; i++ ){
        if( _scanner[i] == ']' ) break;
        section[i-1] = (char) toupper( _scanner[i] );
    }

    // If the section name wasn't terminated properly, skip the section.
    if( i == length ){
        HCWarning( HPJ_BADSECTION, _scanner.lineNum(), _scanner.name() );
        length = skipSection();
        continue;
    }
    section[i-1] = '\0';

    // Pass control to the appropriate "section handler".
    if( strcmp( section, SBaggage ) == 0 ){
        length = handleBaggage();
    } else if( strcmp( section, SOptions ) == 0 ){
        length = handleOptions();
    } else if( strcmp( section, SConfig ) == 0 ){
        length = handleConfig();
    } else if( strcmp( section, SFiles ) == 0 ){
        length = handleFiles();
    } else if( strcmp( section, SMap ) == 0 ){
        length = handleMap();
    } else if( strcmp( section, SBitmaps ) == 0 ){
        length = handleBitmaps();
    } else if( strcmp( section, SWindows ) == 0 ){
        length = handleWindows();
    } else {
        HCWarning( HPJ_BADSECTION, _scanner.lineNum(), _scanner.name() );
        length = skipSection();
    }
    }

    if( _rtfFiles == NULL ){
    HCError( HPJ_NOFILES );
    }

    // Now parse individual RTF files.
    StrNode *curfile = _rtfFiles;
    StrNode *curdir;
    InFile  source;

    // First, implement phrase replacement if desired.
    if( _theFiles->_sysFile->isCompressed() ){
    _topFile = _rtfFiles;
    _firstDir = _root;
    _startDir = _homeDir;

    _theFiles->_phrFile = new HFPhrases( _dir, &firstFile, &nextFile );

    char    full_path[_MAX_PATH];
    char    drive[_MAX_DRIVE];
    char    dir[_MAX_DIR];
    char    fname[_MAX_FNAME];
    char    ext[_MAX_EXT];

    _fullpath( full_path, _scanner.name(), _MAX_PATH );
    _splitpath( full_path, drive, dir, fname, ext );
    _makepath( full_path, drive, dir, fname, PhExt );

    if( !_oldPhrases || !_theFiles->_phrFile->oldTable(full_path) ){
        _theFiles->_phrFile->readPhrases();
        _theFiles->_phrFile->createQueue( full_path );
    }
    }

    _theFiles->_topFile = new HFTopic( _dir, _theFiles->_phrFile );

    // For each file, search the ROOT path, and create a RTFparser
    // to deal with it.
    curfile = _rtfFiles;
    while( curfile != NULL ){
    curdir = _root;
    if( curdir == NULL ){
        source.open( curfile->_name );
    } else while( curdir != NULL ){
        chdir( curdir->_name );
        source.open( curfile->_name );
        chdir( _homeDir );
        if( !source.bad() ) break;
        curdir = curdir->_next;
    }
    if( source.bad() ){
        HCWarning( FILE_ERR, curfile->_name );
    } else {
        RTFparser rtfhandler( _theFiles, &source );
        rtfhandler.Go();
        source.close();
    }
    curfile = curfile->_next;
    }
}
void HCMemerr( void )
{
    HCError( MEM_ERR );
}