Exemplo n.º 1
0
void HFSDirectory::dump()
{
    BtreeIter   iterator( _files );
    BtreeData   *current = iterator.data();
    if( current == NULL )
        return;

    uint_32 direct_size = _files.size();
    uint_32 filesize = direct_size + 4*sizeof( uint_32 ) + FILE_HEADER_SIZE;

    HCStartOutput();

    // Calculate the size of the entire .HLP file.
    HFSnode *curnode;
    for( ; current != NULL; current = (++iterator).data() ) {
        curnode = (HFSnode*)current;
        curnode->_offset = filesize;
        filesize += curnode->_pointer->size();
        filesize += FILE_HEADER_SIZE;
    }

    // Write out the .HLP file header.
    static const uint_32    header[3] = {
        0x00035F3F,
        0x00000010,
        0xFFFFFFFF
    };

    _output.write( header, sizeof( uint_32 ), 3 );
    _output.write( filesize );

    // Now dump the directory file itself.
    direct_size += FILE_HEADER_SIZE;
    _output.write( direct_size );
    direct_size -= FILE_HEADER_SIZE;
    _output.write( direct_size );
    _output.write( (uint_8)0x04 );    // WinHelp needs a 0x04 at this point.
    _files.dump( &_output );

    // Now dump the each of the files listed in the b-tree.
    uint_32 cursize;
    iterator.init();
    for( current = iterator.data(); current != NULL; current = (++iterator).data() ) {
        cursize = ((HFSnode*) current)->_pointer->size();
        cursize += FILE_HEADER_SIZE;
        _output.write( cursize );
        cursize -= FILE_HEADER_SIZE;
        _output.write( cursize );
        _output.write( (uint_8)0 );     // Again, keeping WinHelp happy.
        ((HFSnode*)current)->_pointer->dump( &_output );
    }
    HCDoneTick();

    return;
}
Exemplo n.º 2
0
void HPJReader::includeMapFile( char i_str[] )
{
    int i = 0;
    char seek_char;

    // Get the filename.
    while( i_str[i] != '\0' && isspace( i_str[i] ) ){
    ++i;
    }
    switch( i_str[i] ){
    case '"':
    seek_char = '"';
    break;
    case '<':
    seek_char = '>';
    break;
    default:
    HCWarning( HPJ_BADINCLUDE, _scanner.lineNum(), _scanner.name() );
    return;
    }

    ++i;
    int j = i;
    while( i_str[j] != '\0' && i_str[j] != seek_char ){
    ++j;
    }
    if( j == '\0' ){
    HCWarning( HPJ_BADINCLUDE, _scanner.lineNum(), _scanner.name() );
    return;
    }

    // Now try to find it in the ROOT path and/or current directory.
    i_str[j] = '\0';
    StrNode *current = _root;
    InFile  source;
    if( current == NULL ){
    source.open( i_str+i );
    } else while( current != NULL ){
    chdir( current->_name );
    source.open( i_str+i );
    chdir( _homeDir );
    if( !source.bad() ) break;
    current = current->_next;
    }

    if( source.bad() ){
    HCWarning(INCLUDE_ERR, (const char *) (i_str+i),
              _scanner.lineNum(), _scanner.name() );
    return;
    }

    HCStartFile( i_str+i );

    // Now parse the secondary file.
    HPJScanner  input( &source );
    int     not_done;
    char    *token;
    int     is_good_str, con_num;
    uint_32 hash_value;
    for( ;; ){
    not_done = input.getLine();
    if( !not_done ) break;

    token = input.tokLine();

    if( stricmp( token, Sinclude ) == 0 ){

        // "#include" directives may be nested.
        includeMapFile( input.endTok() );
        continue;
    } else if( stricmp( token, Sdefine ) == 0 ){

        // "#define" directives specify a context string.
        token = input.tokLine();
        if( token == NULL ) continue;
        is_good_str = 1;
        for( i=0; token[i] != '\0'; ++i ){
        if( !isalnum( token[i] ) && token[i] != '.' && token[i] != '_' ){
            is_good_str = 0;
        }
        }
        if( !is_good_str ){
        HCWarning( CON_BAD, token, input.lineNum(), input.name() );
        } else {
        hash_value = Hash(token);
        token = input.tokLine();
        if( token == NULL ){
            HCWarning( CON_NONUM, token, input.lineNum(),
                       input.name() );
        } else {
            con_num = atol( token );
            _theFiles->_mapFile->addMapRec( con_num, hash_value );
        }
        }
    } else if( strncmp( token, SstartComment, 2 ) == 0 ){

        // #include-d files may contain comments.
        int startcomment = input.lineNum();
        while( token != NULL && strstr( token, SendComment ) == NULL ){
        do{
            token = input.tokLine();
            if( token != NULL ) break;
            not_done = input.getLine();
        } while( not_done );
        }

        if( token == NULL ){
        HCWarning( HPJ_RUNONCOMMENT, startcomment, input.name() );
        break;
        }
    } else {
        HCWarning( HPJ_INC_JUNK, input.lineNum(), input.name() );
        continue;
    }
    }
    HCDoneTick();
    return;
}