Andreas Krennmair:
[apps/madmutt.git] / makedoc.c
index 0ac67a3..92c3221 100644 (file)
--- a/makedoc.c
+++ b/makedoc.c
@@ -14,7 +14,7 @@
  *     You should have received a copy of the GNU General Public License
  *     along with this program; if not, write to the Free Software
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- */ 
+ */
 
 /**
  ** This program parses mutt's init.h and generates documentation in
@@ -63,19 +63,19 @@ extern int optind;
 
 typedef struct {
   short seen;
-  charname;
-  chardescr;
+  char *name;
+  char *descr;
 } var_t;
 
 static int outcount = 0;
-static var_toutbuf = NULL;
+static var_t *outbuf = NULL;
 
-static int var_cmp (const void* a, const void* b) {
-  return (strcmp (((var_t*) a)->name, ((var_t*) b)->name));
+static int var_cmp (const void *a, const void *b)
+{
+  return (strcmp (((var_t *) a)->name, ((var_t *) b)->name));
 }
 
-enum output_formats_t
-{
+enum output_formats_t {
   F_CONF, F_MAN, F_SGML, F_NONE
 };
 
@@ -88,8 +88,7 @@ enum output_formats_t
 #define D_DL            (1 << 6)
 #define D_DT            (1 << 7)
 
-enum
-{
+enum {
   SP_START_EM,
   SP_START_BF,
   SP_END_FT,
@@ -122,8 +121,8 @@ static void makedoc (FILE *, FILE *);
 static void pretty_default (char *, size_t, const char *, int);
 static int sgml_fputc (int);
 static int sgml_fputs (const char *);
-static void add_var (const char*);
-static int add_s (const char*);
+static void add_var (const char *);
+static int add_s (const char *);
 static int add_c (int);
 
 int main (int argc, char *argv[])
@@ -135,16 +134,22 @@ int main (int argc, char *argv[])
     Progname++;
   else
     Progname = argv[0];
-  
-  while ((c = getopt (argc, argv, "cmsd")) != EOF)
-  {
-    switch (c)
-    {
-      case 'c': OutputFormat = F_CONF; break;
-      case 'm': OutputFormat = F_MAN; break;
-      case 's': OutputFormat = F_SGML; break;
-      case 'd': Debug++; break;
-      default: 
+
+  while ((c = getopt (argc, argv, "cmsd")) != EOF) {
+    switch (c) {
+    case 'c':
+      OutputFormat = F_CONF;
+      break;
+    case 'm':
+      OutputFormat = F_MAN;
+      break;
+    case 's':
+      OutputFormat = F_SGML;
+      break;
+    case 'd':
+      Debug++;
+      break;
+    default:
       {
         fprintf (stderr, "%s: bad command line parameter.\n", Progname);
         exit (1);
@@ -152,71 +157,74 @@ int main (int argc, char *argv[])
     }
   }
 
-  if (optind != argc)
-  {
-    if ((f = fopen (argv[optind], "r")) == NULL)
-    {
+  if (optind != argc) {
+    if ((f = fopen (argv[optind], "r")) == NULL) {
       fprintf (stderr, "%s: Can't open %s (%s).\n",
                Progname, argv[optind], strerror (errno));
       exit (1);
     }
   }
-  else 
+  else
     f = stdin;
 
-  switch (OutputFormat)
-  {
-    case F_CONF: 
-    case F_MAN:  
-    case F_SGML: makedoc (f, stdout); break;
-    default:
+  switch (OutputFormat) {
+  case F_CONF:
+  case F_MAN:
+  case F_SGML:
+    makedoc (f, stdout);
+    break;
+  default:
     {
-      fprintf (stderr, "%s: No output format specified.\n",
-               Progname);
+      fprintf (stderr, "%s: No output format specified.\n", Progname);
       exit (1);
     }
   }
-  
+
   if (f != stdin)
     fclose (f);
-  
+
   exit (1);
 }
 
-static void add_var (const char* name) {
-  outbuf = realloc (outbuf, (++outcount) * sizeof(var_t));
-  outbuf[outcount-1].seen = 0;
-  outbuf[outcount-1].name = strdup (name);
-  outbuf[outcount-1].descr = NULL;
+static void add_var (const char *name)
+{
+  outbuf = realloc (outbuf, (++outcount) * sizeof (var_t));
+  outbuf[outcount - 1].seen = 0;
+  outbuf[outcount - 1].name = strdup (name);
+  outbuf[outcount - 1].descr = NULL;
 }
 
-static int add (const char* s) {
-  size_t lnew = STRLEN(s), lold = STRLEN(outbuf[outcount-1].descr);
+static int add (const char *s)
+{
+  size_t lnew = STRLEN (s), lold = STRLEN (outbuf[outcount - 1].descr);
 
   if (lnew == 0)
     return (0);
-  if (!outbuf[outcount-1].seen) {
+  if (!outbuf[outcount - 1].seen) {
     lold = 0;
-    outbuf[outcount-1].seen = 1;
+    outbuf[outcount - 1].seen = 1;
   }
 
   if (lold == 0)
-    outbuf[outcount-1].descr = strdup (s);
+    outbuf[outcount - 1].descr = strdup (s);
   else {
-    outbuf[outcount-1].descr = realloc (outbuf[outcount-1].descr, lold + lnew + 1);
-    memcpy (&(outbuf[outcount-1].descr[lold-1])+1, s, lnew);
+    outbuf[outcount - 1].descr =
+      realloc (outbuf[outcount - 1].descr, lold + lnew + 1);
+    memcpy (&(outbuf[outcount - 1].descr[lold - 1]) + 1, s, lnew);
   }
-  outbuf[outcount-1].descr[lold+lnew] = '\0';
+  outbuf[outcount - 1].descr[lold + lnew] = '\0';
   return (1);
 }
 
-static int add_c (int c) {
+static int add_c (int c)
+{
   char buf[2] = "\0\0";
+
   buf[0] = c;
   return (add (buf));
 }
 
-static void makedoc (FILE *in, FILE *out)
+static void makedoc (FILE * in, FILE * out)
 {
   char buffer[BUFFSIZE];
   char token[BUFFSIZE];
@@ -225,13 +233,11 @@ static void makedoc (FILE *in, FILE *out)
   int line = 0;
   int docstat = D_INIT;
 
-  while ((fgets (buffer, sizeof (buffer), in)))
-  {
+  while ((fgets (buffer, sizeof (buffer), in))) {
     line++;
-    if ((p = strchr (buffer, '\n')) == NULL)
-    {
+    if ((p = strchr (buffer, '\n')) == NULL) {
       fprintf (stderr, "%s: Line %d too long.  Ask a wizard to enlarge\n"
-                       "%s: my buffer size.\n", Progname, line, Progname);
+               "%s: my buffer size.\n", Progname, line, Progname);
       exit (1);
     }
     else
@@ -240,23 +246,20 @@ static void makedoc (FILE *in, FILE *out)
     if (!(p = get_token (token, sizeof (token), buffer)))
       continue;
 
-    if (Debug)
-    {
+    if (Debug) {
       fprintf (stderr, "%s: line %d.  first token: \"%s\".\n",
                Progname, line, token);
     }
-    
+
     if (!strcmp (token, "/*++*/"))
       active = 1;
-    else if (!strcmp (token, "/*--*/"))
-    {
+    else if (!strcmp (token, "/*--*/")) {
       docstat = flush_doc (docstat);
       active = 0;
     }
     else if (active && (!strcmp (token, "/**") || !strcmp (token, "**")))
       docstat = handle_docline (p, docstat);
-    else if (active && !strcmp (token, "{"))
-    {
+    else if (active && !strcmp (token, "{")) {
       docstat = flush_doc (docstat);
       handle_confline (p);
     }
@@ -295,26 +298,21 @@ static char *get_token (char *d, size_t l, char *s)
   char *dd = d;
 
   if (Debug)
-     fprintf (stderr, "%s: get_token called for `%s'.\n",
-              Progname, s);
-  
+    fprintf (stderr, "%s: get_token called for `%s'.\n", Progname, s);
+
   s = skip_ws (s);
 
   if (Debug > 1)
-    fprintf (stderr, "%s: argumet after skip_ws():  `%s'.\n",
-             Progname, s);
+    fprintf (stderr, "%s: argumet after skip_ws():  `%s'.\n", Progname, s);
 
-  if (!*s)
-  {
+  if (!*s) {
     if (Debug)
       fprintf (stderr, "%s: no more tokens on this line.\n", Progname);
     return NULL;
   }
 
-  if (strchr (single_char_tokens, *s))
-  {
-    if (Debug)
-    {
+  if (strchr (single_char_tokens, *s)) {
+    if (Debug) {
       fprintf (stderr, "%s: found single character token `%c'.\n",
                Progname, *s);
     }
@@ -323,38 +321,40 @@ static char *get_token (char *d, size_t l, char *s)
     return s;
   }
 
-  if (*s == '"')
-  {
-    if (Debug)
-    {
+  if (*s == '"') {
+    if (Debug) {
       fprintf (stderr, "%s: found quote character.\n", Progname);
     }
-      
+
     s++;
     is_quoted = 1;
   }
 
-  for (t = s; *t && --l > 0; t++)
-  {
+  for (t = s; *t && --l > 0; t++) {
     if (*t == '\\' && !t[1])
       break;
 
-    if (is_quoted && *t == '\\')
-    {
-      switch ((*d = *++t))
-      {
-        case 'n': *d = '\n'; break;
-        case 't': *d = '\t'; break;
-        case 'r': *d = '\r'; break;
-        case 'a': *d = '\a'; break;
+    if (is_quoted && *t == '\\') {
+      switch ((*d = *++t)) {
+      case 'n':
+        *d = '\n';
+        break;
+      case 't':
+        *d = '\t';
+        break;
+      case 'r':
+        *d = '\r';
+        break;
+      case 'a':
+        *d = '\a';
+        break;
       }
 
       d++;
       continue;
     }
 
-    if (is_quoted && *t == '"')
-    {
+    if (is_quoted && *t == '"') {
       t++;
       break;
     }
@@ -368,14 +368,12 @@ static char *get_token (char *d, size_t l, char *s)
 
   *d = '\0';
 
-  if (Debug)
-  {
+  if (Debug) {
     fprintf (stderr, "%s: Got %stoken: `%s'.\n",
              Progname, is_quoted ? "quoted " : "", dd);
-    fprintf (stderr, "%s: Remainder: `%s'.\n",
-             Progname, t);
+    fprintf (stderr, "%s: Remainder: `%s'.\n", Progname, t);
   }
-  
+
   return t;
 }
 
@@ -392,8 +390,7 @@ static char *get_token (char *d, size_t l, char *s)
  * following string definitions!
  */
 
-enum 
-{
+enum {
   DT_NONE = 0,
   DT_BOOL,
   DT_NUM,
@@ -407,36 +404,34 @@ enum
   DT_ADDR
 };
 
-struct 
-{
+struct {
   char *machine;
   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" },
-  { NULL, NULL }
+} 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"}, {
+  NULL, NULL}
 };
-    
+
 
 static int buff2type (const char *s)
 {
   int type;
-  
+
   for (type = DT_NONE; types[type].machine; type++)
     if (!strcmp (types[type].machine, s))
-        return type;
-  
+      return type;
+
   return DT_NONE;
 }
 
@@ -450,68 +445,79 @@ static void handle_confline (char *s)
   char buff[BUFFSIZE];
   char tmp[BUFFSIZE];
   int type;
-  
+
   char val[BUFFSIZE];
 
   /* xxx - put this into an actual state machine? */
 
   /* variable name */
-  if (!(s = get_token (varname, sizeof (varname), s))) return;
-  
+  if (!(s = get_token (varname, sizeof (varname), s)))
+    return;
+
   /* comma */
-  if (!(s = get_token (buff, sizeof (buff), s))) return;
-    
+  if (!(s = get_token (buff, sizeof (buff), s)))
+    return;
+
   /* type */
-  if (!(s = get_token (buff, sizeof (buff), s))) return;
+  if (!(s = get_token (buff, sizeof (buff), s)))
+    return;
 
   type = buff2type (buff);
 
   /* possibly a "|" or comma */
-  if (!(s = get_token (buff, sizeof (buff), s))) return;
+  if (!(s = get_token (buff, sizeof (buff), s)))
+    return;
 
-  if (!strcmp (buff, "|"))
-  {
-    if (Debug) fprintf (stderr, "%s: Expecting <subtype> <comma>.\n", Progname);
+  if (!strcmp (buff, "|")) {
+    if (Debug)
+      fprintf (stderr, "%s: Expecting <subtype> <comma>.\n", Progname);
     /* ignore subtype and comma */
-    if (!(s = get_token (buff, sizeof (buff), s))) return;
-    if (!(s = get_token (buff, sizeof (buff), s))) return;
+    if (!(s = get_token (buff, sizeof (buff), s)))
+      return;
+    if (!(s = get_token (buff, sizeof (buff), s)))
+      return;
   }
 
   /* redraw, comma */
-  
-  while (1)
-  {
-    if (!(s = get_token (buff, sizeof (buff), s))) return;
+
+  while (1) {
+    if (!(s = get_token (buff, sizeof (buff), s)))
+      return;
     if (!strcmp (buff, ","))
       break;
   }
 
   /* option name or UL &address */
-  if (!(s = get_token (buff, sizeof (buff), s))) return;
+  if (!(s = get_token (buff, sizeof (buff), s)))
+    return;
   if (!strcmp (buff, "UL"))
-    if (!(s = get_token (buff, sizeof (buff), s))) return;
+    if (!(s = get_token (buff, sizeof (buff), s)))
+      return;
 
   /* comma */
-  if (!(s = get_token (buff, sizeof (buff), s))) return;
+  if (!(s = get_token (buff, sizeof (buff), s)))
+    return;
+
+  if (Debug)
+    fprintf (stderr, "%s: Expecting default value.\n", Progname);
 
-  if (Debug) fprintf (stderr, "%s: Expecting default value.\n", Progname);
-  
   /* <default value> or UL <default value> */
-  if (!(s = get_token (buff, sizeof (buff), s))) return;
-  if (!strcmp (buff, "UL"))
-  {
-    if (Debug) fprintf (stderr, "%s: Skipping UL.\n", Progname);
-    if (!(s = get_token (buff, sizeof (buff), s))) return;
+  if (!(s = get_token (buff, sizeof (buff), s)))
+    return;
+  if (!strcmp (buff, "UL")) {
+    if (Debug)
+      fprintf (stderr, "%s: Skipping UL.\n", Progname);
+    if (!(s = get_token (buff, sizeof (buff), s)))
+      return;
   }
 
   memset (tmp, 0, sizeof (tmp));
 
-  do 
-  {
+  do {
     if (!strcmp (buff, "}"))
       break;
 
-    strncpy (tmp + STRLEN(tmp), buff, sizeof (tmp) - STRLEN(tmp));
+    strncpy (tmp + STRLEN (tmp), buff, sizeof (tmp) - STRLEN (tmp));
   }
   while ((s = get_token (buff, sizeof (buff), s)));
 
@@ -525,17 +531,20 @@ static void pretty_default (char *t, size_t l, const char *s, int type)
   memset (t, 0, l);
   l--;
 
-  switch (type)
-  {
-    case DT_QUAD:
-    {    
-      if (!strcasecmp (s, "M_YES")) strncpy (t, "yes", l);
-      else if (!strcasecmp (s, "M_NO")) strncpy (t, "no", l);
-      else if (!strcasecmp (s, "M_ASKYES")) strncpy (t, "ask-yes", l);
-      else if (!strcasecmp (s, "M_ASKNO")) strncpy (t, "ask-no", l);
+  switch (type) {
+  case DT_QUAD:
+    {
+      if (!strcasecmp (s, "M_YES"))
+        strncpy (t, "yes", l);
+      else if (!strcasecmp (s, "M_NO"))
+        strncpy (t, "no", l);
+      else if (!strcasecmp (s, "M_ASKYES"))
+        strncpy (t, "ask-yes", l);
+      else if (!strcasecmp (s, "M_ASKNO"))
+        strncpy (t, "ask-no", l);
       break;
     }
-    case DT_BOOL:
+  case DT_BOOL:
     {
       if (atoi (s))
         strncpy (t, "yes", l);
@@ -543,30 +552,32 @@ static void pretty_default (char *t, size_t l, const char *s, int type)
         strncpy (t, "no", l);
       break;
     }
-    case DT_SORT:
+  case DT_SORT:
     {
       /* heuristic! */
       strncpy (t, s + 5, l);
-      for (; *t; t++) *t = tolower ((unsigned char) *t);
+      for (; *t; t++)
+        *t = tolower ((unsigned char) *t);
       break;
     }
-    case DT_MAGIC:
+  case DT_MAGIC:
     {
       /* heuristic! */
       strncpy (t, s + 2, l);
-      for (; *t; t++) *t = tolower ((unsigned char) *t);
+      for (; *t; t++)
+        *t = tolower ((unsigned char) *t);
       break;
     }
-    case DT_STR:
-    case DT_RX:
-    case DT_ADDR:
-    case DT_PATH:
+  case DT_STR:
+  case DT_RX:
+  case DT_ADDR:
+  case DT_PATH:
     {
       if (!strcmp (s, "0"))
         break;
       /* fallthrough */
     }
-    default:
+  default:
     {
       strncpy (t, s, l);
       break;
@@ -576,33 +587,41 @@ static void pretty_default (char *t, size_t l, const char *s, int type)
 
 static void char_to_escape (char *dest, unsigned int c)
 {
-  switch (c)
-  {
-    case '\r': strcpy (dest, "\\r"); break;        /* __STRCPY_CHECKED__ */
-    case '\n': strcpy (dest, "\\n"); break;        /* __STRCPY_CHECKED__ */
-    case '\t': strcpy (dest, "\\t"); break;        /* __STRCPY_CHECKED__ */
-    case '\f': strcpy (dest, "\\f"); break;        /* __STRCPY_CHECKED__ */
-    default: sprintf (dest, "\\%03o", c); break;
+  switch (c) {
+  case '\r':
+    strcpy (dest, "\\r");
+    break;                      /* __STRCPY_CHECKED__ */
+  case '\n':
+    strcpy (dest, "\\n");
+    break;                      /* __STRCPY_CHECKED__ */
+  case '\t':
+    strcpy (dest, "\\t");
+    break;                      /* __STRCPY_CHECKED__ */
+  case '\f':
+    strcpy (dest, "\\f");
+    break;                      /* __STRCPY_CHECKED__ */
+  default:
+    sprintf (dest, "\\%03o", c);
+    break;
   }
 }
 static void conf_char_to_escape (unsigned int c)
 {
   char buff[16];
+
   char_to_escape (buff, c);
   add (buff);
 }
 
 static void conf_print_strval (const char *v)
 {
-  for (; *v; v++)
-  {
-    if (*v < ' ' || *v & 0x80)
-    {
+  for (; *v; v++) {
+    if (*v < ' ' || *v & 0x80) {
       conf_char_to_escape ((unsigned int) *v);
       continue;
     }
 
-    if (*v == '"'  || *v == '\\')
+    if (*v == '"' || *v == '\\')
       add_c ('\\');
     add_c (*v);
   }
@@ -610,15 +629,13 @@ static void conf_print_strval (const char *v)
 
 static void man_print_strval (const char *v)
 {
-  for (; *v; v++)
-  {
-    if (*v < ' ' || *v & 0x80)
-    {
+  for (; *v; v++) {
+    if (*v < ' ' || *v & 0x80) {
       add_c ('\\');
       conf_char_to_escape ((unsigned int) *v);
       continue;
     }
-    
+
     if (*v == '"')
       add ("\\(rq");
     else if (*v == '\\')
@@ -631,10 +648,9 @@ static void man_print_strval (const char *v)
 static void sgml_print_strval (const char *v)
 {
   char buff[16];
-  for (; *v; v++)
-  {
-    if (*v <  ' ' || *v & 0x80)
-    {
+
+  for (; *v; v++) {
+    if (*v < ' ' || *v & 0x80) {
       char_to_escape (buff, (unsigned int) *v);
       sgml_fputs (buff);
       continue;
@@ -645,20 +661,31 @@ static void sgml_print_strval (const char *v)
 
 static int sgml_fputc (int c)
 {
-  switch (c)
-  {
-    case '<': return add ("&lt;");
-    case '>': return add ("&gt;");
-    case '$': return add ("&dollar;");
-    case '_': return add ("&lowbar;");
-    case '%': return add ("&percnt;");
-    case '&': return add ("&amp;");
-    case '\\': return add ("&bsol;");
-    case '"': return add ("&dquot;");
-    case '[': return add ("&lsqb;");
-    case ']': return add ("&rsqb;");
-    case '~': return add ("&tilde;");
-    default:  return add_c (c);
+  switch (c) {
+  case '<':
+    return add ("&lt;");
+  case '>':
+    return add ("&gt;");
+  case '$':
+    return add ("&dollar;");
+  case '_':
+    return add ("&lowbar;");
+  case '%':
+    return add ("&percnt;");
+  case '&':
+    return add ("&amp;");
+  case '\\':
+    return add ("&bsol;");
+  case '"':
+    return add ("&dquot;");
+  case '[':
+    return add ("&lsqb;");
+  case ']':
+    return add ("&rsqb;");
+  case '~':
+    return add ("&tilde;");
+  default:
+    return add_c (c);
   }
 }
 
@@ -667,47 +694,45 @@ static int sgml_fputs (const char *s)
   for (; *s; s++)
     if (sgml_fputc ((unsigned int) *s) == EOF)
       return EOF;
-  
+
   return 0;
 }
 
 static void print_confline (const char *varname, int type, const char *val)
 {
-  if (type == DT_SYN) return;
-  
-  switch (OutputFormat)
-  {
+  if (type == DT_SYN)
+    return;
+
+  switch (OutputFormat) {
     /* configuration file */
-    case F_CONF:
+  case F_CONF:
     {
-      if (type == DT_STR || type == DT_RX || type == DT_ADDR || type == DT_PATH)
-      {
+      if (type == DT_STR || type == DT_RX || type == DT_ADDR
+          || type == DT_PATH) {
         add ("\n# set ");
         add (varname);
         add ("\"");
         conf_print_strval (val);
         add ("\"");
       }
-      else if (type != DT_SYN)
-      {
+      else if (type != DT_SYN) {
         add ("\n# set ");
         add (varname);
         add ("=");
         add (val);
       }
-      
+
       add ("\n#\n# Name: ");
       add (varname);
       add ("\n# Type: ");
       add (type2human (type));
-      if (type == DT_STR || type == DT_RX || type == DT_ADDR || type == DT_PATH)
-      {
+      if (type == DT_STR || type == DT_RX || type == DT_ADDR
+          || type == DT_PATH) {
         add ("\n# Default: \"");
         conf_print_strval (val);
         add ("\"");
       }
-      else
-      {
+      else {
         add ("\n# Default: ");
         add (val);
       }
@@ -717,7 +742,7 @@ static void print_confline (const char *varname, int type, const char *val)
     }
 
     /* manual page */
-    case F_MAN:
+  case F_MAN:
     {
       add (".TP\n.B ");
       add (varname);
@@ -725,8 +750,8 @@ static void print_confline (const char *varname, int type, const char *val)
       add ("Type: ");
       add (type2human (type));
       add_c ('\n');
-      if (type == DT_STR || type == DT_RX || type == DT_ADDR || type == DT_PATH)
-      {
+      if (type == DT_STR || type == DT_RX || type == DT_ADDR
+          || type == DT_PATH) {
         add ("Default: \\(lq");
         man_print_strval (val);
         add ("\\(rq\n");
@@ -740,9 +765,9 @@ static void print_confline (const char *varname, int type, const char *val)
 
       break;
     }
-    
+
     /* SGML based manual */
-    case F_SGML:
+  case F_SGML:
     {
       add ("\n<sect2>");
       sgml_fputs (varname);
@@ -753,14 +778,13 @@ static void print_confline (const char *varname, int type, const char *val)
       add (type2human (type));
       add ("</tt>\n\n");
 
-      if (type == DT_STR || type == DT_RX || type == DT_ADDR || type == DT_PATH)
-      {
+      if (type == DT_STR || type == DT_RX || type == DT_ADDR
+          || type == DT_PATH) {
         add ("<p>\nDefault: <tt>&dquot;");
         sgml_print_strval (val);
         add ("&dquot;</tt>");
       }
-      else
-      {
+      else {
         add ("<p>\nDefault: <tt>");
         add (val);
         add ("</tt>");
@@ -768,8 +792,8 @@ static void print_confline (const char *varname, int type, const char *val)
       break;
     }
     /* make gcc happy */
-    default:
-      break;
+  default:
+    break;
   }
 }
 
@@ -808,9 +832,9 @@ static int flush_doc (int docstat)
   if (docstat & D_INIT)
     return D_INIT;
 
-  if (fd_recurse++)
-  {
-    fprintf (stderr, "%s: Internal error, recursion in flush_doc()!\n", Progname);
+  if (fd_recurse++) {
+    fprintf (stderr, "%s: Internal error, recursion in flush_doc()!\n",
+             Progname);
     exit (1);
   }
 
@@ -833,39 +857,41 @@ static int flush_doc (int docstat)
 
 static int print_it (int special, char *str, int docstat)
 {
-  int onl = docstat & (D_NL|D_NP);
-  
-  docstat &= ~(D_NL|D_NP|D_INIT);
+  int onl = docstat & (D_NL | D_NP);
 
-  switch (OutputFormat)
-  {
+  docstat &= ~(D_NL | D_NP | D_INIT);
+
+  switch (OutputFormat) {
     /* configuration file */
-    case F_CONF:
+  case F_CONF:
     {
-      switch (special)
-      {
+      switch (special) {
         static int Continuation = 0;
 
-        case SP_END_FT: docstat &= ~(D_EM|D_BF); break;
-        case SP_START_BF: docstat |= D_BF; break;
-        case SP_START_EM: docstat |= D_EM; break;
-        case SP_NEWLINE: 
+      case SP_END_FT:
+        docstat &= ~(D_EM | D_BF);
+        break;
+      case SP_START_BF:
+        docstat |= D_BF;
+        break;
+      case SP_START_EM:
+        docstat |= D_EM;
+        break;
+      case SP_NEWLINE:
         {
           if (onl)
             docstat |= onl;
-          else
-          {
+          else {
             add ("\n# ");
             docstat |= D_NL;
           }
           if (docstat & D_DL)
-            ++ Continuation;
+            ++Continuation;
           break;
         }
-        case SP_NEWPAR:
+      case SP_NEWPAR:
         {
-          if (onl & D_NP)
-          {
+          if (onl & D_NP) {
             docstat |= onl;
             break;
           }
@@ -876,54 +902,52 @@ static int print_it (int special, char *str, int docstat)
           docstat |= D_NP;
           break;
         }
-        case SP_START_TAB: 
+      case SP_START_TAB:
         {
-          if (!onl) 
+          if (!onl)
             add ("\n# ");
           docstat |= D_TAB;
           break;
         }
-        case SP_END_TAB:
+      case SP_END_TAB:
         {
           docstat &= ~D_TAB;
           docstat |= D_NL;
           break;
         }
-        case SP_START_DL:
+      case SP_START_DL:
         {
           docstat |= D_DL;
           break;
         }
-        case SP_DT:
+      case SP_DT:
         {
           Continuation = 0;
           docstat |= D_DT;
           break;
         }
-        case SP_DD:
+      case SP_DD:
         {
           Continuation = 0;
           break;
         }
-        case SP_END_DL:
+      case SP_END_DL:
         {
           Continuation = 0;
           docstat &= ~D_DL;
           break;
         }
-        case SP_STR:
+      case SP_STR:
         {
-          if (Continuation)
-          {
+          if (Continuation) {
             Continuation = 0;
             add ("        ");
           }
           add (str);
-          if (docstat & D_DT)
-          { 
+          if (docstat & D_DT) {
             int i;
 
-            for (i = STRLEN(str) ; i < 8 ; i++)
+            for (i = STRLEN (str); i < 8; i++)
               add_c (' ');
             docstat &= ~D_DT;
             docstat |= D_NL;
@@ -935,45 +959,42 @@ static int print_it (int special, char *str, int docstat)
     }
 
     /* manual page */
-    case F_MAN:
+  case F_MAN:
     {
-      switch (special)
-      {
-        case SP_END_FT: 
+      switch (special) {
+      case SP_END_FT:
         {
           add ("\\fP");
-          docstat &= ~(D_EM|D_BF);
+          docstat &= ~(D_EM | D_BF);
           break;
         }
-        case SP_START_BF: 
+      case SP_START_BF:
         {
           add ("\\fB");
           docstat |= D_BF;
           docstat &= ~D_EM;
           break;
         }
-        case SP_START_EM:
+      case SP_START_EM:
         {
           add ("\\fI");
           docstat |= D_EM;
           docstat &= ~D_BF;
           break;
         }
-        case SP_NEWLINE:
+      case SP_NEWLINE:
         {
           if (onl)
             docstat |= onl;
-          else
-          {
+          else {
             add_c ('\n');
             docstat |= D_NL;
           }
           break;
         }
-        case SP_NEWPAR:
+      case SP_NEWPAR:
         {
-          if (onl & D_NP)
-          {
+          if (onl & D_NP) {
             docstat |= onl;
             break;
           }
@@ -985,58 +1006,54 @@ static int print_it (int special, char *str, int docstat)
           docstat |= D_NP;
           break;
         }
-        case SP_START_TAB:
+      case SP_START_TAB:
         {
           add ("\n.IP\n.DS\n.sp\n.ft CR\n.nf\n");
           docstat |= D_TAB | D_NL;
           break;
         }
-        case SP_END_TAB:
+      case SP_END_TAB:
         {
           add ("\n.fi\n.ec\n.ft P\n.sp\n");
           docstat &= ~D_TAB;
           docstat |= D_NL;
           break;
         }
-        case SP_START_DL:
+      case SP_START_DL:
         {
           add ("\n.RS");
           docstat |= D_DL;
           break;
         }
-        case SP_DT:
+      case SP_DT:
         {
           add ("\n.IP ");
           break;
         }
-        case SP_DD:
+      case SP_DD:
         {
           add ("\n");
           break;
         }
-        case SP_END_DL:
+      case SP_END_DL:
         {
           add ("\n.RE");
           docstat &= ~D_DL;
           break;
         }
-        case SP_STR:
+      case SP_STR:
         {
-          while (*str)
-          {
-            for (; *str; str++)
-            {
+          while (*str) {
+            for (; *str; str++) {
               if (*str == '"')
                 add ("\\(rq");
               else if (*str == '\\')
                 add ("\\\\");
-              else if (!strncmp (str, "``", 2))
-              {
+              else if (!strncmp (str, "``", 2)) {
                 add ("\\(lq");
                 str++;
               }
-              else if (!strncmp (str, "''", 2))
-              {
+              else if (!strncmp (str, "''", 2)) {
                 add ("\\(rq");
                 str++;
               }
@@ -1051,46 +1068,45 @@ static int print_it (int special, char *str, int docstat)
     }
 
     /* SGML based manual */
-    case F_SGML:
+  case F_SGML:
     {
-      switch (special)
-      {
-        case SP_END_FT: 
+      switch (special) {
+      case SP_END_FT:
         {
-          if (docstat & D_EM) add("</em>");
-          if (docstat & D_BF) add("</bf>");
-          docstat &= ~(D_EM|D_BF);
+          if (docstat & D_EM)
+            add ("</em>");
+          if (docstat & D_BF)
+            add ("</bf>");
+          docstat &= ~(D_EM | D_BF);
           break;
         }
-        case SP_START_BF: 
+      case SP_START_BF:
         {
           add ("<bf>");
           docstat |= D_BF;
           docstat &= ~D_EM;
           break;
         }
-        case SP_START_EM:
+      case SP_START_EM:
         {
           add ("<em>");
           docstat |= D_EM;
           docstat &= ~D_BF;
           break;
         }
-        case SP_NEWLINE:
+      case SP_NEWLINE:
         {
           if (onl)
             docstat |= onl;
-          else
-          {
+          else {
             add ("\n");
-                   docstat |= D_NL;
+            docstat |= D_NL;
           }
           break;
         }
-        case SP_NEWPAR:
+      case SP_NEWPAR:
         {
-          if (onl & D_NP)
-          {
+          if (onl & D_NP) {
             docstat |= onl;
             break;
           }
@@ -1102,42 +1118,42 @@ static int print_it (int special, char *str, int docstat)
           docstat |= D_NP;
           break;
         }
-        case SP_START_TAB:
+      case SP_START_TAB:
         {
           add ("\n<tscreen><verb>\n");
           docstat |= D_TAB | D_NL;
           break;
         }
-        case SP_END_TAB:
+      case SP_END_TAB:
         {
           add ("\n</verb></tscreen>");
           docstat &= ~D_TAB;
           docstat |= D_NL;
           break;
         }
-        case SP_START_DL:
+      case SP_START_DL:
         {
           add ("\n<descrip>\n");
           docstat |= D_DL;
           break;
         }
-        case SP_DT:
+      case SP_DT:
         {
           add ("<tag>");
           break;
         }
-        case SP_DD:
+      case SP_DD:
         {
           add ("</tag>");
           break;
         }
-        case SP_END_DL:
+      case SP_END_DL:
         {
           add ("</descrip>\n");
           docstat &= ~D_DL;
           break;
         }
-        case SP_STR:
+      case SP_STR:
         {
           if (docstat & D_TAB)
             add (str);
@@ -1149,8 +1165,8 @@ static int print_it (int special, char *str, int docstat)
       break;
     }
     /* make gcc happy (unreached) */
-    default:
-      break;
+  default:
+    break;
   }
 
   return docstat;
@@ -1158,8 +1174,7 @@ static int print_it (int special, char *str, int docstat)
 
 void print_ref (int output_dollar, const char *ref)
 {
-  switch (OutputFormat)
-  {
+  switch (OutputFormat) {
   case F_CONF:
   case F_MAN:
     if (output_dollar)
@@ -1184,8 +1199,7 @@ void print_ref (int output_dollar, const char *ref)
 
 static int commit_buff (char *buff, char **d, int docstat)
 {
-  if (*d > buff)
-  {
+  if (*d > buff) {
     **d = '\0';
     docstat = print_it (SP_STR, buff, docstat);
     *d = buff;
@@ -1198,11 +1212,12 @@ static int handle_docline (char *l, int docstat)
 {
   char buff[BUFFSIZE];
   char *s, *d;
+
   l = skip_ws (l);
 
   if (Debug)
     fprintf (stderr, "%s: handle_docline `%s'\n", Progname, l);
-  
+
   if (!strncmp (l, ".pp", 3))
     return print_it (SP_NEWPAR, NULL, docstat);
   else if (!strncmp (l, ".ts", 3))
@@ -1216,66 +1231,54 @@ static int handle_docline (char *l, int docstat)
   else if (!strncmp (l, ". ", 2))
     *l = ' ';
 
-  for (s = l, d = buff; *s; s++)
-  {
-    if (!strncmp (s, "\\(as", 4))
-    {
+  for (s = l, d = buff; *s; s++) {
+    if (!strncmp (s, "\\(as", 4)) {
       *d++ = '*';
       s += 3;
     }
-    else if (!strncmp (s, "\\(rs", 4))
-    {
+    else if (!strncmp (s, "\\(rs", 4)) {
       *d++ = '\\';
       s += 3;
     }
-    else if (!strncmp (s, "\\fI", 3))
-    {
+    else if (!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 (!strncmp (s, "\\fB", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_START_BF, NULL, docstat);
       s += 2;
     }
-    else if (!strncmp (s, "\\fP", 3))
-    {
+    else if (!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 (!strncmp (s, ".dt", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_DT, NULL, docstat);
       s += 3;
     }
-    else if (!strncmp (s, ".dd", 3))
-    {
+    else if (!strncmp (s, ".dd", 3)) {
       docstat = commit_buff (buff, &d, docstat);
       docstat = print_it (SP_DD, NULL, docstat);
       s += 3;
     }
-    else if (*s == '$')
-    {
+    else if (*s == '$') {
       int output_dollar = 0;
       char *ref;
       char save;
 
       ++s;
-      if (*s == '$')
-      {
+      if (*s == '$') {
         output_dollar = 1;
         ++s;
       }
-      if (*s == '$')
-      {
+      if (*s == '$') {
         *d++ = '$';
       }
-      else
-      {
+      else {
         ref = s;
         while (isalnum ((unsigned char) *s) || *s == '-' || *s == '_')
           ++s;