//------------------------------------------------------------ static void create_node_dict( hashTable<CC_String,BTCollectable> &dict, BookCaseDB& db ) { DBTable *nodeMeta = db.table(BookCaseDB::NodeMeta, DB::READ); DBCursor cursor(*nodeMeta); const char *bookLocator; const char *nodeLocator; const char *filename; int line_num; const char *title; const char *stitle; const char *style; int throw_exception = 0; while(cursor.next(STRING_CODE, &bookLocator, STRING_CODE, &nodeLocator, STRING_CODE, &filename, INTEGER_CODE, &line_num, SKIP_CODE, /* TOC num */ STRING_CODE, &title, STRING_CODE, &stitle, STRING_CODE, &style, NULL)){ CC_String *key = new CC_String ( nodeLocator ); BTCollectable *value = new BTCollectable ( filename,line_num,bookLocator ); BTCollectable *val = (BTCollectable *)dict.findValue( key ); if ( !val ) { dict.insertKeyAndValue( key, value ); } else { delete key; delete value; throw_exception = 1; cerr << "(ERROR) Duplicate section ID = " << (const char *)*key << endl << " found in file = " << filename << endl << " at line = " << line_num << endl << " is in conflict with " << endl << " section ID = " << (const char *)*key << endl << " found in file = " << val->filename() << endl << " at line = " << val->linenum() << "\n\n"; } } if ( throw_exception ) { throw(Unexpected("Duplicate section IDs are found")); } }
//------------------------------------------------------------ static void node_table( DBCursor *node_meta_cursor, const char *this_book, hashTable<CC_String, BTCollectable> &this_node_table ) { assert( node_meta_cursor != NULL ); assert( this_book != NULL ); const char *bookLocator; const char *nodeLocator; const char *file_name; int line_num; const char *title; const char *stitle; const char *style; while ( node_meta_cursor->next(STRING_CODE, &bookLocator, STRING_CODE, &nodeLocator, STRING_CODE, &file_name, INTEGER_CODE, &line_num, SKIP_CODE, /* TOC num */ STRING_CODE, &title, STRING_CODE, &stitle, STRING_CODE, &style, NULL)){ /* this book has changed */ if ( strcmp( bookLocator, this_book ) != 0 ) { node_meta_cursor->undoNext(); break; } CC_String *key = new CC_String( nodeLocator ); BTCollectable *value = new BTCollectable( file_name,line_num,bookLocator ); this_node_table.insertKeyAndValue( key, value ); } }
//------------------------------------------------------------ static void locator_table( BookCaseDB& db, hashTable<CC_String, BTCollectable> &hd) { DBTable *locTable = db.table(BookCaseDB::Locator, DB::READ); DBCursor cursor(*locTable); const char *locator; const char *nodeloc; const char *reflabel; const char *filename; int line_num; int dup_count = 0; while(cursor.next(STRING_CODE, &locator, STRING_CODE, &nodeloc, STRING_CODE, &reflabel, STRING_CODE, &filename, INTEGER_CODE, &line_num, NULL)){ char *buf = new char[strlen(nodeloc) + strlen(reflabel) + 2]; sprintf(buf, "%s\t%s", nodeloc, reflabel); CC_String *loc_collect = new CC_String( locator ); BTCollectable *node_collect = new BTCollectable( filename, line_num, buf ); delete[] buf; BTCollectable *val = hd.findValue( loc_collect ); if ( !val ) { hd.insertKeyAndValue( loc_collect, node_collect ); } else { delete loc_collect; delete node_collect; dup_count++; cerr << "(ERROR) Duplicate ID = " << locator << endl << " found in file = " << filename << endl << " at line = " << line_num << endl << " is in conflict with " << endl << " ID = " << locator << endl << " found in file = " << val->filename() << endl << " at line = " << val->linenum() << "\n\n"; } } if ( dup_count ) { throw(Unexpected(form("Number of duplicate IDs found = %d\n", dup_count))); } }