void HFBitmaps::note( char const name[] ) { Image *current; StrNode *curdir; uint_16 magic; InFile *bmp = new InFile( name, true ); for( curdir = _root; bmp->bad() && curdir != NULL; curdir = curdir->_next ) { chdir( curdir->_name ); bmp->open( name ); chdir( _startDir ); } if( bmp->bad() ) { HCWarning( FILE_ERR, name ); delete bmp; return; } bmp->reset(); bmp->read( &magic ); 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; }
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. result = (uint_16)0; for( current = _usedFiles; current != NULL; current = current->_next ) { if( stricmp( name, current->_name ) == 0 ) break; result++; } if( current != NULL ) { return result; } // Check to see if the bitmap was referenced by note(). result = (uint_16)_numImages; temp = NULL; for( current = _files; current != NULL; current = current->_next ) { if( stricmp( name, current->_name ) == 0 ) break; temp = current; } 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. bmp = new InFile( name, true ); for( curdir = _root; bmp->bad() && curdir != NULL; curdir = curdir->_next ) { chdir( curdir->_name ); bmp->open( name, true ); chdir( _startDir ); } if( bmp->bad() ) { delete bmp; throw ImageNotFound(); // EXCEPTION } else { uint_16 magic; bmp->reset(); bmp->read( &magic ); 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, "%u", result ); _dfile->addFile( current->_image, filename ); _numImages += 1; return result; }