Index: /trunk/gsdl/src/recpt/formattools.cpp
===================================================================
--- /trunk/gsdl/src/recpt/formattools.cpp	(revision 353)
+++ /trunk/gsdl/src/recpt/formattools.cpp	(revision 354)
@@ -12,4 +12,7 @@
 /*
    $Log$
+   Revision 1.2  1999/07/08 20:48:33  rjmcnab
+   Added ability to print the result number
+
    Revision 1.1  1999/07/07 05:49:34  sjboddie
    had another crack at the format string code - created a new formattools
@@ -21,4 +24,16 @@
 
 #include "formattools.h"
+
+
+
+
+
+// a few function prototypes
+static text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr);
+
+static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 
+			  format_t *formatlistptr, text_tarray &metadata, bool &getParents,
+			  text_tmap &metamap, int &metacount);
+
 
 
@@ -48,7 +63,96 @@
 
 
-bool parse_string (const text_t &formatstring, format_t *formatlistptr, 
-		   text_tarray &metadata, bool &getParents, 
-		   text_tmap &metamap, int &metacount) {
+
+
+static void get_parent_options (text_t &instring, metadata_t &metaoption) {
+
+  metaoption.clear();
+  text_t meta, com, op;
+  bool inbraces = false;
+  bool inquotes = false;
+  bool foundcolon = false;
+  text_t::const_iterator here = instring.begin()+6;
+  text_t::const_iterator end = instring.end();
+  while (here != end) {
+    if (*here == '(') inbraces = true;
+    else if (*here == ')') inbraces = false;
+    else if (*here == '\'' && !inquotes) inquotes = true;
+    else if (*here == '\'' && inquotes) inquotes = false;
+    else if (*here == ':' && !inbraces) foundcolon = true;
+    else if (foundcolon) meta.push_back (*here);
+    else if (inquotes) op.push_back (*here);
+    else com.push_back (*here);
+    here ++;
+  }
+  instring = meta;
+  if (com.empty())
+    metaoption.parentcommand = pImmediate;
+  else if (com == "Top")
+    metaoption.parentcommand = pTop;
+  else if (is_number(com)) {
+    metaoption.parentcommand = pIndex;
+    metaoption.metaindex = com.getint();
+  } else if (com == "All") {
+    metaoption.parentcommand = pAll;
+    metaoption.parentoptions = op;
+  }
+}
+
+static bool parse_meta (text_t &meta, int &count, decision_t &decision,
+			text_tarray &metadata, bool &getParents, text_tmap &metamap) {
+
+  if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
+    getParents = true;
+    metadata_t metaoption;
+    get_parent_options (meta, metaoption);
+    decision.meta = metaoption;
+  }
+  text_tmap::const_iterator it;
+  if ((it = metamap.find(meta)) != metamap.end()) {
+      decision.meta.metaindex = (*it).second.getint();
+  } else {
+    metamap[meta] = count;
+    metadata.push_back (meta);
+    decision.meta.metaindex = count;
+    count ++;
+  }
+  return true;
+}
+
+static bool parse_meta (text_t &meta, int &count, format_t *formatlistptr,
+			text_tarray &metadata, bool &getParents, text_tmap &metamap) {
+  
+  if (meta == "link")
+    formatlistptr->command = comLink;
+  else if (meta == "/link")
+    formatlistptr->command = comEndLink;
+
+  else if (meta == "num")
+    formatlistptr->command = comNum;
+
+  else {
+    formatlistptr->command = comMeta;
+    if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
+      getParents = true;
+      metadata_t metaoption;
+      get_parent_options (meta, metaoption);
+      formatlistptr->meta = metaoption;
+    }
+    text_tmap::const_iterator it;
+    if ((it = metamap.find(meta)) != metamap.end()) {
+      (formatlistptr->meta).metaindex = (*it).second.getint();
+    } else {
+      metamap[meta] = count;
+      metadata.push_back (meta);
+      (formatlistptr->meta).metaindex = count;
+      count ++;
+    }
+  }
+  return true;
+}
+
+static bool parse_string (const text_t &formatstring, format_t *formatlistptr, 
+			  text_tarray &metadata, bool &getParents, 
+			  text_tmap &metamap, int &metacount) {
 
   text_t text;
@@ -112,7 +216,8 @@
 }
 
-bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 
-		   format_t *formatlistptr, text_tarray &metadata, bool &getParents,
-		   text_tmap &metamap, int &metacount) {
+
+static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 
+			  format_t *formatlistptr, text_tarray &metadata, bool &getParents,
+			  text_tmap &metamap, int &metacount) {
 
   text_t::const_iterator it = findchar (here, end, '}');
@@ -215,4 +320,5 @@
 }
 
+
 bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr, 
 			 text_tarray &metadata, bool &getParents) {
@@ -228,89 +334,7 @@
 }
 
-bool parse_meta (text_t &meta, int &count, decision_t &decision,
-		 text_tarray &metadata, bool &getParents, text_tmap &metamap) {
-
-  if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
-    getParents = true;
-    metadata_t metaoption;
-    get_parent_options (meta, metaoption);
-    decision.meta = metaoption;
-  }
-  text_tmap::const_iterator it;
-  if ((it = metamap.find(meta)) != metamap.end()) {
-      decision.meta.metaindex = (*it).second.getint();
-  } else {
-    metamap[meta] = count;
-    metadata.push_back (meta);
-    decision.meta.metaindex = count;
-    count ++;
-  }
-  return true;
-}
-
-bool parse_meta (text_t &meta, int &count, format_t *formatlistptr,
-		 text_tarray &metadata, bool &getParents, text_tmap &metamap) {
-  
-  if (meta == "link")
-    formatlistptr->command = comLink;
-  else if (meta == "/link")
-    formatlistptr->command = comEndLink;
-
-  else {
-    formatlistptr->command = comMeta;
-    if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
-      getParents = true;
-      metadata_t metaoption;
-      get_parent_options (meta, metaoption);
-      formatlistptr->meta = metaoption;
-    }
-    text_tmap::const_iterator it;
-    if ((it = metamap.find(meta)) != metamap.end()) {
-      (formatlistptr->meta).metaindex = (*it).second.getint();
-    } else {
-      metamap[meta] = count;
-      metadata.push_back (meta);
-      (formatlistptr->meta).metaindex = count;
-      count ++;
-    }
-  }
-  return true;
-}
-
-void get_parent_options (text_t &instring, metadata_t &metaoption) {
-
-  metaoption.clear();
-  text_t meta, com, op;
-  bool inbraces = false;
-  bool inquotes = false;
-  bool foundcolon = false;
-  text_t::const_iterator here = instring.begin()+6;
-  text_t::const_iterator end = instring.end();
-  while (here != end) {
-    if (*here == '(') inbraces = true;
-    else if (*here == ')') inbraces = false;
-    else if (*here == '\'' && !inquotes) inquotes = true;
-    else if (*here == '\'' && inquotes) inquotes = false;
-    else if (*here == ':' && !inbraces) foundcolon = true;
-    else if (foundcolon) meta.push_back (*here);
-    else if (inquotes) op.push_back (*here);
-    else com.push_back (*here);
-    here ++;
-  }
-  instring = meta;
-  if (com.empty())
-    metaoption.parentcommand = pImmediate;
-  else if (com == "Top")
-    metaoption.parentcommand = pTop;
-  else if (is_number(com)) {
-    metaoption.parentcommand = pIndex;
-    metaoption.metaindex = com.getint();
-  } else if (com == "All") {
-    metaoption.parentcommand = pAll;
-    metaoption.parentoptions = op;
-  }
-}
-
-text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta) {
+
+
+static text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta) {
   int metasize = docinfo.metadata.size();
   int mindex = meta.metaindex;
@@ -353,16 +377,35 @@
 }
 
-
-text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) {
-
-  text_t ft;
-  while (formatlistptr != NULL) {
-    ft += format_string (docinfo, formatlistptr);
-    formatlistptr = formatlistptr->nextptr;
-  }
-  return ft;
-}
-
-text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) {
+static text_t get_or (const ResultDocInfo_t &docinfo, format_t *orptr) {
+
+  text_t tmp;
+  while (orptr != NULL) {
+
+    tmp = format_string (docinfo, orptr);
+    if (!tmp.empty()) return tmp;
+
+    orptr = orptr->nextptr;
+  }
+  return "";
+}
+
+static text_t get_if (const ResultDocInfo_t &docinfo, const decision_t &decision,
+		      format_t *ifptr, format_t *elseptr) {
+
+  // not much of a choice yet ...
+  if (decision.command == dMeta) {
+    if (get_meta (docinfo, decision.meta) != "") {
+      if (ifptr != NULL)
+	return get_formatted_string (docinfo, ifptr);
+    }
+    else {
+      if (elseptr != NULL)
+	return get_formatted_string (docinfo, elseptr);
+    }
+  }
+  return "";
+}
+
+static text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) {
 
   if (formatlistptr == NULL) return "";
@@ -375,4 +418,6 @@
   case comEndLink:
     return "</a>";
+  case comNum:
+    return docinfo.result_num;
   case comMeta:
     return get_meta (docinfo, formatlistptr->meta);
@@ -386,32 +431,16 @@
 
 
-text_t get_or (const ResultDocInfo_t &docinfo, format_t *orptr) {
-
-  text_t tmp;
-  while (orptr != NULL) {
-
-    tmp = format_string (docinfo, orptr);
-    if (!tmp.empty()) return tmp;
-
-    orptr = orptr->nextptr;
-  }
-  return "";
-}
-
-text_t get_if (const ResultDocInfo_t &docinfo, const decision_t &decision,
-	       format_t *ifptr, format_t *elseptr) {
-
-  // not much of a choice yet ...
-  if (decision.command == dMeta) {
-    if (get_meta (docinfo, decision.meta) != "") {
-      if (ifptr != NULL)
-	return get_formatted_string (docinfo, ifptr);
-    }
-    else {
-      if (elseptr != NULL)
-	return get_formatted_string (docinfo, elseptr);
-    }
-  }
-  return "";
-}
-
+
+text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) {
+
+  text_t ft;
+  while (formatlistptr != NULL) {
+    ft += format_string (docinfo, formatlistptr);
+    formatlistptr = formatlistptr->nextptr;
+  }
+  return ft;
+}
+
+
+
+
Index: /trunk/gsdl/src/recpt/formattools.h
===================================================================
--- /trunk/gsdl/src/recpt/formattools.h	(revision 353)
+++ /trunk/gsdl/src/recpt/formattools.h	(revision 354)
@@ -17,5 +17,5 @@
 #include "comtypes.h"
 
-enum command_t {comIf, comOr, comMeta, comText, comLink, comEndLink};
+enum command_t {comIf, comOr, comMeta, comText, comLink, comEndLink, comNum};
 enum pcommand_t {pNone, pImmediate, pTop, pIndex, pAll};
 enum dcommand_t {dMeta};
@@ -54,20 +54,4 @@
 
 
-text_t get_or (const ResultDocInfo_t &docinfo, format_t *orptr);
-
-text_t get_if (const ResultDocInfo_t &docinfo, const decision_t &decision,
-	       format_t *ifptr, format_t *elseptr);
-
-
-
-bool parse_string (const text_t &formatstring, format_t *formatlistptr, 
-		   text_tarray &metadata, bool &getParents, 
-		   text_tmap &metamap, int &metacount);
-
-
-bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 
-		   format_t *formatlistptr, text_tarray &metadata, bool &getParents,
-		   text_tmap &metamap, int &metacount);
-
 
 bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr, 
@@ -76,17 +60,4 @@
 text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr);
 
-text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr);
-
-void get_parent_options (text_t &instring, metadata_t &metaoption);
-
-bool parse_meta (text_t &meta, int &count, format_t *formatlistptr,
-		 text_tarray &metadata, bool &getParents, text_tmap &metamap);
-
-bool parse_meta (text_t &meta, int &count, decision_t &decision,
-		 text_tarray &metadata, bool &getParents, text_tmap &metamap);
-
-
-text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta);
-
 
 #endif
