]> diplodocus.org Git - nmh/blobdiff - h/fmt_scan.h
new.c: Order two return statements to match comment.
[nmh] / h / fmt_scan.h
index 466a9b5decc272ce156fac8f15210449a34884ed..2574c5798662be55d1dcfda32dc7dfe19caa7f6d 100644 (file)
@@ -1,12 +1,10 @@
-
-/*
- * fmt_scan.h -- definitions for fmt_scan()
+/* fmt_scan.h -- definitions for fmt_scan()
  */
 
 /*
  * This structure describes an "interesting" component.  It holds
  * the name & text from the component (if found) and one piece of
- * auxilary info.  The structure for a particular component is located
+ * auxiliary info.  The structure for a particular component is located
  * by (open) hashing the name and using it as an index into the ptr array
  * "wantcomp".  All format entries that reference a particular component
  * point to its comp struct (so we only have to do component specific
@@ -37,6 +35,8 @@ struct comp {
 #define        CT_ADDR       (1<<0)    /* referenced as address    */
 #define        CT_DATE       (1<<1)    /* referenced as date       */
 
+#define CT_BITS       "\020\01ADDR\02DATE"
+
 /*
  * c_flags bits
  */
@@ -45,7 +45,7 @@ struct comp {
 #define        CF_DATEFAB    (1<<2)    /* datefield fabricated */
 #define CF_TRIMMED    (1<<3)   /* Component has been trimmed */
 
-extern int fmt_norm;
+#define CF_BITS       "\020\01TRUE\02PARSED\03CF_DATEFAB\04TRIMMED"
 
 /*
  * This structure defines one formatting instruction.
@@ -81,6 +81,21 @@ struct format {
  * prototypes used by the format engine
  */
 
+/*
+ * These are the definitions used by the callbacks for fmt_scan()
+ */
+
+typedef char * (*formataddr_cb)(char *, char *);
+typedef char * (*concataddr_cb)(char *, char *);
+typedef void (*trace_cb)(void *, struct format *, int, char *, const char *);
+
+struct fmt_callbacks {
+    formataddr_cb      formataddr;
+    concataddr_cb      concataddr;
+    trace_cb           trace_func;
+    void *             trace_context;
+};
+
 /*
  * Create a new format string.  Arguments are:
  *
@@ -97,6 +112,12 @@ struct format {
 
 char *new_fs (char *form, char *format, char *default_fs);
 
+/*
+ * Free memory allocated by new_fs().  It allocates to a static so
+ * no argument is necessary.
+ */
+void free_fs(void);
+
 /*
  * Compile a format string into a set of format instructions.  Arguments are:
  *
@@ -106,7 +127,7 @@ char *new_fs (char *form, char *format, char *default_fs);
  *               format engine.
  * reset       - If set to true, the format compiler will reset the
  *               component hash table.  The component hash table contains
- *               all of the references to message components refered to in
+ *               all of the references to message components referred to in
  *               the format instructions.  If you have multiple format
  *               strings that you want to compile and operate on the
  *               same message, this should be set to false.
@@ -121,13 +142,13 @@ int fmt_compile (char *fstring, struct format **fmt, int reset);
  * Interpret a sequence of compiled format instructions.  Arguments are:
  *
  * format      - Array of format instructions generated by fmt_compile()
- * scanl       - Passed-in character array that will contain the output
- *               of the format instructions.  Is always terminated with
- *               a newline (\n).
- * max         - Maximum number of bytes to be written to "scanl" (in other
- *               words, the buffer size).  Includes the trailing NUL.
+ * scanl       - Passed-in charstring_t object (created with
+ *               charstring_create() and later destroyed with
+ *               charstring_free()) that will contain the output of the
+ *               format instructions.  Is always terminated with a
+ *               newline (\n).
  * width       - Maximum number of displayed characters.  Does not include
- *               characters marked as nonprinting or (depending on the
+ *               characters marked as non-printing or (depending on the
  *               encoding) bytes in a multibyte encoding that exceed the
  *               character's column width.
  * dat         - An integer array that contains data used by certain format
@@ -140,12 +161,20 @@ int fmt_compile (char *fstring, struct format **fmt, int reset);
  *             dat[3] - %(width)
  *             dat[4] - %(unseen)
  *
+ * callbacks   - A set of a callback functions used by the format engine.
+ *               Can be NULL.  If structure elements are NULL, a default
+ *               function will be used.  Callback structure elements are:
+ *
+ *             formataddr      - A callback for the %(formataddr) instruction
+ *             concataddr      - A callback for the %(concataddr) instruction
+ *             trace           - Called for every format instruction executed
+ *
  * The return value is a pointer to the next format instruction to
  * execute, which is currently always NULL.
  */
 
-struct format *fmt_scan (struct format *format, char *scanl, size_t max,
-                        int width, int *dat);
+struct format *fmt_scan (struct format *format, charstring_t scanl, int width,
+                        int *dat, struct fmt_callbacks *callbacks);
 
 /*
  * Free a format structure and/or component hash table.  Arguments are:
@@ -158,6 +187,12 @@ struct format *fmt_scan (struct format *format, char *scanl, size_t max,
 
 void fmt_free (struct format *fmt, int reset);
 
+/*
+ * Free all of the component text structures in the component hash table
+ */
+
+void fmt_freecomptext(void);
+
 /*
  * Search for a component structure in the component hash table.  Arguments are:
  *
@@ -170,7 +205,26 @@ void fmt_free (struct format *fmt, int reset);
  * or NULL if the component is not found in the hash table.
  */
 
-struct comp *fmt_findcomp(char *component);
+struct comp *fmt_findcomp(char *component) PURE;
+
+/*
+ * Search for a component structure in the component hash table.
+ *
+ * Identical to fmd_findcomp(), but is case-INSENSITIVE.
+ */
+
+struct comp *fmt_findcasecomp(char *component) PURE;
+
+/*
+ * Add a component entry to the component hash table
+ *
+ * component   - The name of the component to add to the hash table.
+ *
+ * If the component is already in the hash table, this function will do
+ * nothing.  Returns 1 if a component was added, 0 if it already existed.
+ */
+
+int fmt_addcompentry(char *component);
 
 /*
  * Add a string to a component hash table entry.  Arguments are:
@@ -187,7 +241,7 @@ struct comp *fmt_findcomp(char *component);
  *                component buffer is a newline, it will be separated
  *                from previous text by ",\n\t"; otherwise if the last
  *                character of the previous text is a newline it will
- *                simply be seperated by a "\t".  This unusual processing
+ *                simply be separated by a "\t".  This unusual processing
  *               is designed to handle the case where you have multiple
  *               headers with the same name (e.g.: multiple "cc:" headers,
  *               even though that isn't technically allowed in the RFCs).
@@ -198,7 +252,7 @@ struct comp *fmt_findcomp(char *component);
  * in the component hash table, this function will return -1.
  */
 
-int fmt_addcomp(char *component, char *text);
+int fmt_addcomptext(char *component, char *text);
 
 /*
  * Append to an existing component.  Arguments are:
@@ -217,6 +271,25 @@ int fmt_addcomp(char *component, char *text);
 
 void fmt_appendcomp(int bucket, char *component, char *text);
 
+/*
+ * Iterate over the complete hash table of component structures.
+ *
+ * Arguments are:
+ *
+ * comp                - Pointer to the current component structure.  The next
+ *               component in the hash table after this component.  To
+ *               start (or restart) the iteration of the hash table
+ *               this argument should be NULL.
+ * bucket      - Pointer to hash bucket.  Will be managed by this function,
+ *               the caller should not modify this value.
+ *
+ * Returns the next component in the hash table.  This value should be
+ * passed into the next call to fmt_nextcomp().  Returns NULL at the end
+ * of the hash table.
+ */
+
+struct comp *fmt_nextcomp(struct comp *comp, unsigned int *bucket);
+
 /*
  * The implementation of the %(formataddr) function.  This is available for
  * programs to provide their own local implementation if they wish to do