Example #1
0
InFile *HPJReader::nextFile()
{
    static InFile   result;
    StrNode     *curdir;

    do{
    if( _curFile == NULL ){
        return NULL;
    }

    curdir = _firstDir;
    if( curdir == NULL ){
        result.open( _curFile->_name );
    } else {
        while( curdir != NULL ){
        chdir( curdir->_name );
        result.open( _curFile->_name );
        chdir( _startDir );
        if( !result.bad() ) break;
        curdir = curdir->_next;
        }
    }
    _curFile = _curFile->_next;
    } while( result.bad() );

    return &result;
}
Example #2
0
void
setObjProperties(std::vector<std::vector<std::string> > &list, IObjContainer &ioc)
{
  std::string name;
  int id;

  for( size_t i=0 ; i < ioc.vIObj.size() ; ++i )
  {
    name = ioc.vIObj[i]->getObjName();
    id   = ioc.vIObj[i]->getObjID();

    IObj *ip = ioc.vIObj[i] ;

    if( name == "X" )
    {
      Annotation *p = dynamic_cast<Annotation*>(ip);
      p->setTablePath(::TABLE_PATH);

      if( id == 0 )
        notes = &ioc.an[i] ;
    }
    else if( name == "CS" )
      ;
    else if( name == "CF" )
    {
      CF *p = dynamic_cast<CF*>(ip);
      p->setTablePath(::TABLE_PATH);
      p->enableCheck();
    }
    else if( name == "FD" )
      ;
    else if( name == "IN" )
    {
      InFile *p = dynamic_cast<InFile*>(ip);
      p->setFilename(::NC_PATH + "/" + ::NC_FILENAME);
    }
    else if( name == "OP" )
      ;
    else if( name == "OUT" )
      ;
    else if( name == "QA" )
    {
      QA *p = dynamic_cast<QA*>(ip);
      p->setTablePath(::TABLE_PATH);
    }
    else if( name == "TC" )
      ;
  }

  return;
}
Example #3
0
void HFBitmaps::note( char const name[] )
{
    Image   *current;
    StrNode *curdir = _root;
    uint_16 magic;

    InFile  *bmp = new InFile( name, 1 );

    while( bmp->bad() && curdir != NULL ){
    chdir( curdir->_name );
    curdir = curdir->_next;
    bmp->open( name );
    chdir( _startDir );
    }
    if( bmp->bad() ){
    HCWarning( FILE_ERR, name );
    delete bmp;
    return;
    }
    bmp->reset();
    bmp->readbuf( &magic, 1, 2 );
    switch( magic ){
    case BITMAP_MAGIC:
    case SHG1_MAGIC:
    case SHG2_MAGIC:
    break;

    default:
    throw ImageNotSupported();  // EXCEPTION
    }
    bmp->reset();

    current = new Image;
    current->_name = new char[strlen(name)+1];
    strcpy( current->_name, name );
    current->_next = _files;
    _files = current;
    if( magic == BITMAP_MAGIC ){
    current->_image = new Bitmap(bmp);
    } else {
    current->_image = new SegGraph(bmp);
    }
    if( !current->_image->validImage() ){
    // Keep the bad image in the list for reference,
    // but warn the user.
    HCWarning( HLP_BADIMAGE, current->_name );
    }

    return;
}
Example #4
0
uint_16 HFBitmaps::use( char const name[] )
{
    uint_16 result;

    Image   *current, *newimage, *temp;
    StrNode *curdir;
    InFile  *bmp;

    static char filename[9] = "|bm";

    // Check to see if this bitmap has already been referenced.
    current = _usedFiles;
    result = (uint_16) 0;
    while( current != NULL && stricmp( name, current->_name ) != 0 ) {
        result ++;
        current = current->_next;
    }
    if( current != NULL ) {
        return result;
    }

    // Check to see if the bitmap was referenced by note().
    result = (uint_16) _numImages;

    current = _files;
    temp = NULL;
    while( current != NULL && stricmp( name, current->_name ) != 0 ) {
        temp = current;
        current = current->_next;
    }

    newimage = _usedFiles;
    if( newimage != NULL ) {
        while( newimage->_next != NULL ) {
            newimage = newimage->_next;
        }
    }

    if( current != NULL ) {
        if( !current->_image->validImage() ) {
            throw ImageNotValid();  // EXCEPTION
        }
    
        if( temp != NULL ){
            temp->_next = current->_next;
        } else {
            _files = current->_next;
        }
    } else {
        // Now we have to search for the file.
        curdir = _root;
        bmp = new InFile( name, 1 );
    
        while( bmp->bad() && curdir != NULL ) {
            chdir( curdir->_name );
            bmp->open( name, 1 );
            chdir( _startDir );
            curdir = curdir->_next;
        }
    
        if( bmp->bad() ) {
            delete bmp;
            throw ImageNotFound();  // EXCEPTION
        } else {
            uint_16 magic;
    
            bmp->reset();
            bmp->readbuf( &magic, 1, sizeof( uint_16 ) );
            switch( magic ) {
            case BITMAP_MAGIC:
            case SHG1_MAGIC:
            case SHG2_MAGIC:
                break;
    
            default:
                throw ImageNotSupported();  // EXCEPTION
            }
            bmp->reset();
    
            current = new Image;
            current->_name = new char[strlen(name)+1];
            strcpy( current->_name, name );
            if( magic == BITMAP_MAGIC ) {
                current->_image = new Bitmap(bmp);
            } else {
                current->_image = new SegGraph(bmp);
            }
        }
    }

    current->_next = NULL;
    if( newimage != NULL ){
        newimage->_next = current;
    } else {
        _usedFiles = current;
    }
    sprintf( filename + 3, "%d", result );
    _dfile->addFile( current->_image, filename );

    _numImages += 1;

    return result;
}
Example #5
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;
}
Example #6
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;
    }
}