Example #1
0
//------------------------------------------------------------
static void
writeTOC(BookCaseDB &db,
	 info_lib *mmdb,
	 const char *bcname,
	 const char *thisBook,
	 DBCursor &toc_cursor )
{
  DBTable *out = db.DB::table(DATABASE_STDIO,
			      TOC_CODE, NUM_TOC_FIELDS,
			      DB::CREATE);
  const char *aBook;
  const char *nodeLoc;
  const char *parent;
  int childQty;
  char **children;
  int treeSize;
  
  while(toc_cursor.next(STRING_CODE, &aBook,
			STRING_CODE, &nodeLoc,
			STRING_CODE, &parent,
			SHORT_LIST_CODE, &childQty, STRING_CODE, &children,
			INTEGER_CODE, &treeSize,
			NULL)){
    StringList heap;
    
    if(strcmp(aBook, thisBook) != 0){ /* book id has changed! We're done... */
      toc_cursor.undoNext();
      break;
    }

    for(int i = 0; i < childQty; i++){
      heap.append(to_oid(mmdb, bcname, children[i]));
    }
    
    const char *nodeOID = heap.append(to_oid(mmdb, bcname, nodeLoc));
    const char *parentOID = heap.append(to_oid(mmdb, bcname, parent));
    
#ifdef FISH_DEBUG
    DBUG_PRINT("TOC", ("TOC Entry: O:%s treesize: %d\n", nodeOID, treeSize));
#endif
    
    out->insert(OID_CODE, nodeOID,
		OID_CODE, parentOID,
		INTEGER_CODE, treeSize,
		/* first childQty strings in heap are oids for children */
		OID_LIST_CODE, childQty, heap.array(),
		NULL);
  }

  delete out;
}
Example #2
0
//------------------------------------------------------------
static void
writeCCF(BookCaseDB& db,
	 info_lib *mmdb,
	 const char *bcname )
{

  DBTable *bookMeta = db.table(BookCaseDB::BookMeta, DB::READ);
  DBCursor cursor(*bookMeta);
  DBTable *ccf = db.DB::table(DATABASE_STDIO,
			      DOC_CODE, BT_NUM_DOC_FIELDS,
			      DB::CREATE);

  const char *bookLocator;
  const char *stitle;
  const char *title;
  int seq_no;
  int tabQty;
  const char **tabLines;
  const char *access;

  /*
   * First put the global node table into hash dictionary
   */

  hashTable<CC_String,BTCollectable> global_node_tab(hash_func);
  create_node_dict( global_node_tab , db);  /* throw exception if duplicate
					   node locator is found */
  
  int exception_flag = 0;
  while(cursor.next(STRING_CODE, &bookLocator,
		    STRING_CODE, &stitle,
		    STRING_CODE, &title,
		    INTEGER_CODE, &seq_no,
		    SHORT_LIST_CODE, &tabQty, STRING_CODE, &tabLines,
		    STRING_CODE, &access,
		    NULL)){

    StringList heap;

    /* convert tab to oids in forst tabQty items in heap */
    for(int i = 0; i < tabQty; i++){

      char *t = (char *)tabLines[i];                   

      const char *name = strtok( t, "\t" );
      const char *loc  = strtok( NULL, "\t");
      const char *line = strtok( NULL, "\t");
      const char *file_name = strtok( NULL, "\t");

      int nameLen = strlen( name );

      /*
       * First check if the tab link is resolved
       */

      CC_String key ( loc );
      
      BTCollectable *tab_link = (BTCollectable *)global_node_tab.
	                                            findValue( &key );


      if ( !tab_link ) {
	cerr << "(ERROR)         Tab ID = " << loc << endl
	     << "               of book = " << title << endl
	     << "     specified in file = " << file_name << endl
	     << "               at line = " << line << endl
	     << "     is not pointing to any section ID found in the book\n\n";	
	exception_flag = 1;
      }
      else {
	/*
	 * see if it is a node locator within the same book
	 */
	if ( strcmp( tab_link->get_value(), bookLocator ))  {
	  cerr << "(ERROR)         Tab ID = " << loc << endl
	       << "               of book = " << title << endl
	       << "     specified in file = " << file_name << endl
	       << "               at line = " << line << endl
	       << "     is not pointing to any section ID found in the book\n\n";

	  exception_flag = 1;
	}
      }
	
      // if exception_flag is set, calling to_oid will throw exception
      // It will just loop through all the tabs, and report all the bad ones
      if ( !exception_flag ) {
	const char *tabOID = to_oid(mmdb, bcname, loc);
	char *result = new char[nameLen + 1 + strlen(tabOID) + 1];
	sprintf(result, "%s\t%s", name, tabOID );
	heap.add(result);
      }
    }

    if ( !exception_flag ) {
  
      const char *bookOID = heap.append(to_oid(mmdb, bcname, bookLocator));
      
#ifdef FISH_DEBUG
      DBUG_PRINT("CCF", ("Load Book: O:%s `%s'\n", bookOID, title));
#endif
    
      ccf->insert(OID_CODE, bookOID,
		  STRING_CODE, stitle,
		  STRING_CODE, title,
		  INTEGER_CODE, seq_no,
		  SHORT_LIST_CODE, tabQty, STRING_CODE, heap.array(),
		  STRING_CODE, access,
		  NULL);
    }
  }

  if ( exception_flag ) {
    throw(Unexpected("Tab validation failed"));
  }

  delete ccf;
  global_node_tab.clearAndDestroy();
}