more tweaks and fixes.
[apps/madmutt.git] / makedoc.c
index 3844569..69df277 100644 (file)
--- a/makedoc.c
+++ b/makedoc.c
  **
  **/
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <errno.h>
-#include <lib-lib/str.h>
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
+#include <lib-lib/lib-lib.h>
 
 #ifdef HAVE_GETOPT_H
 # include <getopt.h>
 #endif
 
-#ifndef HAVE_STRERROR
-#ifndef STDC_HEADERS
-extern int sys_nerr;
-extern char *sys_errlist[];
-#endif
-
-#define strerror(x) ((x) > 0 && (x) < sys_nerr) ? sys_errlist[(x)] : 0
-#endif /* !HAVE_STRERROR */
-
-extern int optind;
-
-#define BUFFSIZE 2048
-
-#define STRLEN(s) (s ? strlen(s) : 0)
-
 typedef struct {
   short seen;
   char *name;
@@ -179,7 +150,7 @@ int main (int argc, char *argv[])
   }
 
   if (f != stdin)
-    fclose (f);
+    m_fclose(&f);
 
   exit (1);
 }
@@ -194,7 +165,7 @@ static void add_var (const char *name)
 
 static int add_s (const char *s)
 {
-  size_t lnew = STRLEN (s), lold = STRLEN (outbuf[outcount - 1].descr);
+  size_t lnew = m_strlen(s), lold = m_strlen(outbuf[outcount - 1].descr);
 
   if (lnew == 0)
     return (0);
@@ -224,8 +195,8 @@ static int add_c (int c)
 
 static void makedoc (FILE * in, FILE * out)
 {
-  char buffer[BUFFSIZE];
-  char token[BUFFSIZE];
+  char buffer[BUFSIZ];
+  char token[BUFSIZ];
   char *p;
   int active = 0;
   int line = 0;
@@ -288,7 +259,6 @@ static char *get_token (char *d, size_t l, char *s)
 {
   char *t;
   short is_quoted = 0;
-  char *dd = d;
 
   s = skip_ws (s);
 
@@ -377,26 +347,24 @@ enum {
 };
 
 struct {
-  char *machine;
-  char *human;
+  const char *machine;
+  const char *human;
 } types[] = {
-  {
-  "DT_NONE", "-none-"}, {
-  "DT_BOOL", "boolean"}, {
-  "DT_NUM", "number"}, {
-  "DT_STR", "string"}, {
-  "DT_PATH", "path"}, {
-  "DT_QUAD", "quadoption"}, {
-  "DT_SORT", "sort order"}, {
-  "DT_RX", "regular expression"}, {
-  "DT_MAGIC", "folder magic"}, {
-  "DT_SYN", NULL}, {
-  "DT_ADDR", "e-mail address"}, {
-  "DT_SYS", "system property"}, {
-  NULL, NULL}
+  {"DT_NONE",  "-none-"},
+  {"DT_BOOL",  "boolean"},
+  {"DT_NUM",   "number"},
+  {"DT_STR",   "string"},
+  {"DT_PATH",  "path"},
+  {"DT_QUAD",  "quadoption"},
+  {"DT_SORT",  "sort order"},
+  {"DT_RX",    "regular expression"},
+  {"DT_MAGIC", "folder magic"},
+  {"DT_SYN",   NULL},
+  {"DT_ADDR",  "e-mail address"},
+  {"DT_SYS",   "system property"},
+  {NULL, NULL}
 };
 
-
 static int buff2type (const char *s)
 {
   int type;
@@ -414,11 +382,11 @@ static const char *type2human (int type)
 }
 static void handle_confline (char *s)
 {
-  char varname[BUFFSIZE];
-  char buff[BUFFSIZE];
+  char varname[BUFSIZ];
+  char buff[BUFSIZ];
   int type;
 
-  char val[BUFFSIZE];
+  char val[BUFSIZ];
 
   /* xxx - put this into an actual state machine? */
 
@@ -571,28 +539,8 @@ static int sgml_fputc (int c)
     return add_s ("&lt;");
   case '>':
     return add_s ("&gt;");
-#if 0
-  case '$':
-    return add_s ("&dollar;");
-  case '_':
-    return add_s ("&lowbar;");
-  case '%':
-    return add_s ("&percnt;");
-#endif
   case '&':
     return add_s ("&amp;");
-#if 0
-  case '\\':
-    return add_s ("&bsol;");
-  case '"':
-    return add_s ("&quot;");
-  case '[':
-    return add_s ("&lsqb;");
-  case ']':
-    return add_s ("&rsqb;");
-  case '~':
-    return add_s ("&tilde;");
-#endif
   default:
     return add_c (c);
   }
@@ -887,7 +835,7 @@ static int print_it (int special, char *str, int docstat)
           if (docstat & D_DT) {
             int i;
 
-            for (i = STRLEN (str); i < 8; i++)
+            for (i = m_strlen(str); i < 8; i++)
               add_c (' ');
             docstat &= ~D_DT;
             docstat |= D_NL;
@@ -995,11 +943,11 @@ static int print_it (int special, char *str, int docstat)
                 add_s ("\\(rq");
               else if (*str == '\\')
                 add_s ("\\\\");
-              else if (!strncmp (str, "``", 2)) {
+              else if (!m_strncmp (str, "``", 2)) {
                 add_s ("\\(lq");
                 str++;
               }
-              else if (!strncmp (str, "''", 2)) {
+              else if (!m_strncmp (str, "''", 2)) {
                 add_s ("\\(rq");
                 str++;
               }
@@ -1148,7 +1096,7 @@ static int print_it (int special, char *str, int docstat)
   return docstat;
 }
 
-void print_ref (int output_dollar, const char *ref)
+static void print_ref (int output_dollar, const char *ref)
 {
   switch (OutputFormat) {
   case F_CONF:
@@ -1186,54 +1134,54 @@ static int commit_buff (char *buff, char **d, int docstat)
 
 static int handle_docline (char *l, int docstat)
 {
-  char buff[BUFFSIZE];
+  char buff[BUFSIZ];
   char *s, *d;
 
   l = skip_ws (l);
 
-  if (!strncmp (l, ".pp", 3))
+  if (!m_strncmp (l, ".pp", 3))
     return print_it (SP_NEWPAR, NULL, docstat);
-  else if (!strncmp (l, ".ts", 3))
+  else if (!m_strncmp (l, ".ts", 3))
     return print_it (SP_START_TAB, NULL, docstat);
-  else if (!strncmp (l, ".te", 3))
+  else if (!m_strncmp (l, ".te", 3))
     return print_it (SP_END_TAB, NULL, docstat);
-  else if (!strncmp (l, ".dl", 3))
+  else if (!m_strncmp (l, ".dl", 3))
     return print_it (SP_START_DL, NULL, docstat);
-  else if (!strncmp (l, ".de", 3))
+  else if (!m_strncmp (l, ".de", 3))
     return print_it (SP_END_DL, NULL, docstat);
-  else if (!strncmp (l, ". ", 2))
+  else if (!m_strncmp (l, ". ", 2))
     *l = ' ';
 
   for (s = l, d = buff; *s; s++) {
-    if (!strncmp (s, "\\(as", 4)) {
+    if (!m_strncmp (s, "\\(as", 4)) {
       *d++ = '*';
       s += 3;
     }
-    else if (!strncmp (s, "\\(rs", 4)) {
+    else if (!m_strncmp (s, "\\(rs", 4)) {
       *d++ = '\\';
       s += 3;
     }
-    else if (!strncmp (s, "\\fI", 3)) {
+    else if (!m_strncmp (s, "\\fI", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_START_EM, NULL, docstat);
       s += 2;
     }
-    else if (!strncmp (s, "\\fB", 3)) {
+    else if (!m_strncmp (s, "\\fB", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_START_BF, NULL, docstat);
       s += 2;
     }
-    else if (!strncmp (s, "\\fT", 3)) {
+    else if (!m_strncmp (s, "\\fT", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_START_TT, NULL, docstat);
       s += 2;
     }
-    else if (!strncmp (s, "\\fP", 3)) {
+    else if (!m_strncmp (s, "\\fP", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_END_FT, NULL, docstat);
       s += 2;
     }
-    else if (!strncmp (s, ".dt", 3)) {
+    else if (!m_strncmp (s, ".dt", 3)) {
       if (docstat & D_DD) {
         docstat = commit_buff (buff, &d, docstat);
         docstat = print_it (SP_END_DD, NULL, docstat);
@@ -1242,7 +1190,7 @@ static int handle_docline (char *l, int docstat)
       docstat = print_it (SP_DT, NULL, docstat);
       s += 3;
     }
-    else if (!strncmp (s, ".dd", 3)) {
+    else if (!m_strncmp (s, ".dd", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_DD, NULL, docstat);
       s += 3;