Hi all,

Here's a quick hack of htdig that lists docdb contents...
(not sure the Makefile.in is correct...)

                Paul

-- 
-=-=-=-=-  Paul COURBIS -=- Responsable Informatique / IT Manager  -=-=-=-=-=
-=-=-=-  Centre de Recherche Motorola  -=-  [EMAIL PROTECTED]  -=-=-=-
-=-         Voice: +33 (0)1 69.35.25.37  Fax: +33 (0)1 69.35.25.01        -=-
<legal>Opinions hereabove are my own and not those of my organization</legal>

//
// 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 <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fstream.h>
#include <getopt.h>

DocumentDB              docs;
String                  configFile = DEFAULT_CONFIG_FILE;

// If we have this, we probably want it.
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#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);
}
top_srcdir=             @top_srcdir@
srcdir=                 @srcdir@
VPATH=                  @srcdir@
INSTALL=                @INSTALL@
INSTALL_PROGRAM=        @INSTALL_PROGRAM@

top_builddir= ..
include $(top_builddir)/Makefile.config

OBJS = htlist

TARGET=         htlist

all:    $(TARGET)

$(TARGET):      $(OBJS) $(HTLIBS)
        $(CXX) -o $(TARGET) $(LDFLAGS) $(OBJS) $(LIBS)

install:        $(TARGET)
        transform=@program_transform_name@
        $(INSTALL_PROGRAM) $(TARGET) $(INSTALL_ROOT)$(BIN_DIR)/`echo $(TARGET) | sed 
'$(transform)'`

clean:
        rm -f $(TARGET) $(OBJS) *~ *.bak *% a.out *.orig core

mostlyclean: clean

distclean:      clean
        rm -f Makefile *.proj

depend:
        $(MAKEDEPEND) @CPPFLAGS@ $(CXXFLAGS) $(INCS) -- $(OBJS)

main.o: $(top_builddir)/CONFIG


------------------------------------
To unsubscribe from the htdig mailing list, send a message to
[EMAIL PROTECTED]
You will receive a message to confirm this.

Reply via email to