Index: /trunk/gsdl/src/mgpp/text/mg_invf_dump.cpp
===================================================================
--- /trunk/gsdl/src/mgpp/text/mg_invf_dump.cpp	(revision 1897)
+++ /trunk/gsdl/src/mgpp/text/mg_invf_dump.cpp	(revision 1898)
@@ -37,4 +37,7 @@
 /*
    $Log$
+   Revision 1.2  2001/02/02 01:12:29  kjm18
+   added more command line options, and better help message
+
    Revision 1.1  2000/01/14 02:26:17  sjboddie
    Rodgers new C++ mg
@@ -72,31 +75,34 @@
 			   invf_file_header &ifh,
 			   word_dict_el &wordEl,
-			   unsigned long wordStart) {
+			   unsigned long wordStart,
+			   bool printFrags) {
   cout << wordEl.frag_occur << " \"" << wordEl.el << "\"\n";
   
-  // seek to the appropriate place in the inverted file
-  fseek (invfFile, wordStart, SEEK_SET);
-
-  stdio_bitio_buffer buffer(invfFile);
-  
-  unsigned long B = BIO_Bblock_Init (idh.num_frags, wordEl.frag_occur);
-  unsigned long fragNum = 0;
-  unsigned long i;
-  for (i=0; i<wordEl.frag_occur; i++) {
-    unsigned long delta = buffer.bblock_decode (B, NULL);
-    fragNum += delta;
-    cout << " " << fragNum;
-    
-    if (!ifh.word_level_index ) {
-      unsigned long count = buffer.gamma_decode (NULL);
-      cout << "(" << count << ")";
-    } else {
-      cout << "(1)";
-    }
-  }
-
-  cout << "\n";
-  
-  buffer.done();
+  if (printFrags) {
+    // seek to the appropriate place in the inverted file
+    fseek (invfFile, wordStart, SEEK_SET);
+    
+    stdio_bitio_buffer buffer(invfFile);
+    
+    unsigned long B = BIO_Bblock_Init (idh.num_frags, wordEl.frag_occur);
+    unsigned long fragNum = 0;
+    unsigned long i;
+    for (i=0; i<wordEl.frag_occur; i++) {
+      unsigned long delta = buffer.bblock_decode (B, NULL);
+      fragNum += delta;
+      cout << " " << fragNum;
+      
+      if (!ifh.word_level_index ) {
+	unsigned long count = buffer.gamma_decode (NULL);
+	cout << "(" << count << ")";
+      } else {
+	cout << "(1)";
+      }
+    }
+    
+    cout << "\n";
+  
+    buffer.done();
+  }
 }
 
@@ -105,29 +111,32 @@
 			  invf_file_header &/*ifh*/,
 			  dict_el &tagEl,
-			  unsigned long tagStart) {
+			  unsigned long tagStart,
+			  bool printFrags) {
   cout << tagEl.frag_occur << " \"<" << tagEl.el << ">\"\n";
   
-  // seek to the appropriate place in the inverted file
-  fseek (invfFile, tagStart, SEEK_SET);
-
-  stdio_bitio_buffer buffer(invfFile);
-  
-  unsigned long pTag = tagEl.frag_occur*2;
-  unsigned long B = BIO_Bblock_Init (idh.num_frags+pTag, pTag);
-  unsigned long fragNum = 0;
-  unsigned long i;
-  for (i=0; i<tagEl.frag_occur; i++) {
-    unsigned long delta = buffer.bblock_decode (B, NULL)-1;
-    fragNum += delta;
-    cout << " " << fragNum;
-    cout << "-";
-    delta = buffer.bblock_decode (B, NULL)-1;
-    fragNum += delta;
-    cout << fragNum;
-  }
-
-  cout << "\n";
-  
-  buffer.done();
+  if (printFrags) {
+    // seek to the appropriate place in the inverted file
+    fseek (invfFile, tagStart, SEEK_SET);
+    
+    stdio_bitio_buffer buffer(invfFile);
+    
+    unsigned long pTag = tagEl.frag_occur*2;
+    unsigned long B = BIO_Bblock_Init (idh.num_frags+pTag, pTag);
+    unsigned long fragNum = 0;
+    unsigned long i;
+    for (i=0; i<tagEl.frag_occur; i++) {
+      unsigned long delta = buffer.bblock_decode (B, NULL)-1;
+      fragNum += delta;
+      cout << " " << fragNum;
+      cout << "-";
+      delta = buffer.bblock_decode (B, NULL)-1;
+      fragNum += delta;
+      cout << fragNum;
+    }
+    
+    cout << "\n";
+    
+    buffer.done();
+  }
 }
 
@@ -148,5 +157,9 @@
 
 
-static void process_files (char *filename) {
+static void process_files (char *filename,
+			   bool printHeader,
+			   bool printWords,
+			   bool printTags,
+			   bool printFrags) {
   // open the dictionary
   FILE *dictFile = open_file (filename, INVF_DICT_SUFFIX, "rb",
@@ -166,6 +179,8 @@
 
   // print out header information
-  PrintHeaderInfo (idh, ifh);
-  
+  if (printHeader) {
+    PrintHeaderInfo (idh, ifh);
+  }
+
   // open the inverted index
   FILE *invfIdxFile = open_file (filename, INVF_IDX_SUFFIX, "rb",
@@ -176,24 +191,27 @@
 
   // process all the words
-  unsigned long wordNum;
-  unsigned long wordStart;
-  word_dict_el wordEl;
-  wordEl.SetNumLevels (idh.num_levels);
-  for (wordNum=0; wordNum<idh.word_dict_size; wordNum++) {
-    wordEl.Read (dictFile, idh.num_levels);
-    ReadUL (invfIdxFile, wordStart);
-    PrintInvfWord (invfFile, idh, ifh, wordEl, wordStart);
+  if (printWords) {
+    unsigned long wordNum;
+    unsigned long wordStart;
+    word_dict_el wordEl;
+    wordEl.SetNumLevels (idh.num_levels);
+    for (wordNum=0; wordNum<idh.word_dict_size; wordNum++) {
+      wordEl.Read (dictFile, idh.num_levels);
+      ReadUL (invfIdxFile, wordStart);
+      PrintInvfWord (invfFile, idh, ifh, wordEl, wordStart, printFrags);
+    }
   }
 
   // process all the tags
-  unsigned long tagNum;
-  unsigned long tagStart;
-  dict_el tagEl;
-  for (tagNum=0; tagNum<idh.tag_dict_size; tagNum++) {
-    tagEl.Read (dictFile);
-    ReadUL (invfIdxFile, tagStart);
-    PrintInvfTag (invfFile, idh, ifh, tagEl, tagStart);
-  }
-  
+  if (printTags) {
+    unsigned long tagNum;
+    unsigned long tagStart;
+    dict_el tagEl;
+    for (tagNum=0; tagNum<idh.tag_dict_size; tagNum++) {
+      tagEl.Read (dictFile);
+      ReadUL (invfIdxFile, tagStart);
+      PrintInvfTag (invfFile, idh, ifh, tagEl, tagStart, printFrags);
+    }
+  }
   // close the open files
   fclose (invfIdxFile);
@@ -209,7 +227,12 @@
   dir_name = getenv ("MGDATA");
   opterr = 0;
+
+  bool printHeader = false;
+  bool printWords = false;
+  bool printTags = false;
+  bool printFrags = false;
   
   msg_prefix = argv[0];
-  while ((ch = getopt (argc, argv, "hbwtf:d:")) != -1) {
+  while ((ch = getopt (argc, argv, "hrwtnf:d:")) != -1) {
     switch (ch) {
     case 'f':		// input file
@@ -219,13 +242,26 @@
       set_basepath(optarg);
       break;
+    case 'r':
+      printHeader = true;
+      break;
+    case 'w':
+      printWords = true;
+      break;
+    case 'n':
+      printFrags = true;
+      break;
+    case 't':
+      printTags = true;
+      break;
     case 'h':
     case '?':
-      fprintf (stderr, "usage: %s [-h] [-b] [-w] [-t] [-f input_file]"
-	       "[-d data directory]\n", argv[0]);
+      fprintf (stderr, "usage: %s [-h] [-r] [-w] [-t] [-n] [-f input_file]"
+	       "[-d data directory]\n(-rwnt:print header, words, tags, fragnums)\n", 
+	       argv[0]);
       exit (1);
     }
   }
   
-  process_files (filename);
+  process_files (filename, printHeader, printWords, printTags, printFrags);
 
   return 0;
