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; }
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; }