**
**/
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <errno.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;
enum output_formats_t OutputFormat = F_NONE;
char *Progname;
-short Debug = 0;
static char *get_token (char *, size_t, char *);
static char *skip_ws (char *);
case 's':
OutputFormat = F_SGML;
break;
- case 'd':
- Debug++;
- break;
default:
{
fprintf (stderr, "%s: bad command line parameter.\n", Progname);
}
if (f != stdin)
- fclose (f);
+ m_fclose(&f);
exit (1);
}
{
outbuf = realloc (outbuf, (++outcount) * sizeof (var_t));
outbuf[outcount - 1].seen = 0;
- outbuf[outcount - 1].name = strdup (name);
+ outbuf[outcount - 1].name = strdup(name);
outbuf[outcount - 1].descr = NULL;
}
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);
}
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);
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;
if (!(p = get_token (token, sizeof (token), buffer)))
continue;
- if (Debug) {
- fprintf (stderr, "%s: line %d. first token: \"%s\".\n",
- Progname, line, token);
- }
-
if (!strcmp (token, "/*++*/"))
active = 1;
else if (!strcmp (token, "/*--*/")) {
{
char *t;
short is_quoted = 0;
- char *dd = d;
-
- if (Debug)
- 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);
-
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) {
- fprintf (stderr, "%s: found single character token `%c'.\n",
- Progname, *s);
- }
d[0] = *s++;
d[1] = 0;
return s;
}
if (*s == '"') {
- if (Debug) {
- fprintf (stderr, "%s: found quote character.\n", Progname);
- }
-
s++;
is_quoted = 1;
}
*d = '\0';
- if (Debug) {
- fprintf (stderr, "%s: Got %stoken: `%s'.\n",
- Progname, is_quoted ? "quoted " : "", dd);
- fprintf (stderr, "%s: Remainder: `%s'.\n", Progname, t);
- }
-
return t;
}
};
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;
}
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? */
return;
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 (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;
}
- memset (val, 0, sizeof (val));
+ memset(val, 0, sizeof(val));
do {
if (!strcmp (buff, "}"))
break;
- strncpy (val + STRLEN (val), buff, sizeof (val) - STRLEN (val));
+ m_strcat(val, sizeof(val), buff);
}
while ((s = get_token (buff, sizeof (buff), s)));
return add_s ("<");
case '>':
return add_s (">");
- case '$':
- return add_s ("$");
- case '_':
- return add_s ("_");
- case '%':
- return add_s ("%");
case '&':
return add_s ("&");
- case '\\':
- return add_s ("\");
- case '"':
- return add_s (""");
- case '[':
- return add_s ("[");
- case ']':
- return add_s ("]");
- case '~':
- return add_s ("˜");
default:
return add_c (c);
}
/* SGML based manual */
case F_SGML:
{
- add_s ("\n<sect1 id=\"");
- sgml_id_fputs (varname);
- add_s ("\">\n<title>");
+ add_s ("\n<madmutt-doc:vardef name=\"");
sgml_fputs (varname);
- add_s ("</title>\n<para>Type: <literal>");
+ add_s ("\">\n<para>Type: <literal>");
add_s (type2human (type));
add_s ("</literal></para>\n");
- add_s ("<indexterm><primary>Configuration Variables</primary><secondary>");
- sgml_fputs (varname);
- add_s ("</secondary></indexterm>\n\n");
if (type == DT_STR || type == DT_RX || type == DT_ADDR
|| type == DT_PATH) {
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;
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++;
}
}
case SP_END_SECT:
{
- add_s ("</sect1>\n");
+ add_s ("</madmutt-doc:vardef>\n");
break;
}
case SP_STR:
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:
sgml_id_fputs (ref);
add_s ("\">\n");
if (output_dollar)
- add_s ("$");
+ add_s ("$");
sgml_fputs (ref);
add_s ("</link>");
break;
static int handle_docline (char *l, int docstat)
{
- char buff[BUFFSIZE];
+ char buff[BUFSIZ];
char *s, *d;
l = skip_ws (l);
- if (Debug)
- fprintf (stderr, "%s: handle_docline `%s'\n", Progname, 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);
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;