// // htlist.cc // // Quick hack of htdig to list docdb contents // // #include "Configuration.h" #include "DocumentDB.h" #include "List.h" #include "Object.h" #include "defaults.h" #include #include #include #include #include DocumentDB docs; String configFile = DEFAULT_CONFIG_FILE; // If we have this, we probably want it. #ifdef HAVE_GETOPT_H #include #endif void usage(); // // Start of the program. // main( int ac, char **av ) { int c; extern char *optarg; int alt_work_area = 0; int count = 0; // // Parse command line arguments // while ((c = getopt(ac, av, "ac")) != -1) { int pos; switch (c) { case 'a': alt_work_area++; break; case 'c': count++; break; case '?': usage(); } } // // First set all the defaults and then read the specified config // file to override the defaults. // config.Defaults(&defaults[0]); if (access(configFile, R_OK) < 0) { printf("Unable to find configuration file '%s'", configFile.get()); } config.Read(configFile); // Check "uncompressed"/"uncoded" urls at the price of time // (extra DB probes). docs. SetCompatibility(config. Boolean("uncoded_db_compatible", TRUE)); // // If indicated, change the database file names to have the .work // extension // if (alt_work_area != 0) { String configValue; configValue = config["doc_db"]; if (configValue.length() != 0) { configValue << ".work"; config.Add("doc_db", configValue); } configValue = config["word_list"]; if (configValue.length() != 0) { configValue << ".work"; config.Add("word_list", configValue); } } // // Open the document database // String filename = config["doc_db"]; if (docs.Open(filename) < 0) { printf("Unable to open/create document database '%s'", filename.get()); } List *list = docs.URLs(); if( list->Count() <= 0 ) { printf("Database is empty...\n" ); docs.Close(); exit(0); } if( count ) { printf( "Database contains %d URL%s\n", list->Count(), (list->Count()>1)?"s":"" ); docs.Close(); exit(0); } String *url; list->Start_Get(); while( (url = (String *) list->Get_Next()) != NULL ) { printf( "%s\n", url->get()); } docs.Close(); exit(0); } void usage() { cout << "htlist [-a] [-c]\n"; cout << "\n"; cout << "-a\tUse alternate work files.\n"; cout << "-c\tShow URL count only.\n"; exit(1); }