projects
/
apps
/
madmutt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
remove most of the debug code: often makes the code unreadable, for little
[apps/madmutt.git]
/
makedoc.c
diff --git
a/makedoc.c
b/makedoc.c
index
71864be
..
3844569
100644
(file)
--- a/
makedoc.c
+++ b/
makedoc.c
@@
-31,6
+31,7
@@
#include <ctype.h>
#include <errno.h>
#include <ctype.h>
#include <errno.h>
+#include <lib-lib/str.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
@@
-82,12
+83,15
@@
enum output_formats_t {
#define D_INIT (1 << 6)
#define D_DL (1 << 7)
#define D_DT (1 << 8)
#define D_INIT (1 << 6)
#define D_DL (1 << 7)
#define D_DT (1 << 8)
+#define D_DD (1 << 9)
+#define D_PA (1 << 10)
enum {
SP_START_EM,
SP_START_BF,
SP_START_TT,
SP_END_FT,
enum {
SP_START_EM,
SP_START_BF,
SP_START_TT,
SP_END_FT,
+ SP_END_PAR,
SP_NEWLINE,
SP_NEWPAR,
SP_STR,
SP_NEWLINE,
SP_NEWPAR,
SP_STR,
@@
-96,13
+100,14
@@
enum {
SP_START_DL,
SP_DT,
SP_DD,
SP_START_DL,
SP_DT,
SP_DD,
+ SP_END_DD,
SP_END_DL,
SP_END_DL,
+ SP_END_SECT,
SP_REFER
};
enum output_formats_t OutputFormat = F_NONE;
char *Progname;
SP_REFER
};
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 *);
static char *get_token (char *, size_t, char *);
static char *skip_ws (char *);
@@
-116,6
+121,7
@@
static void handle_confline (char *);
static void makedoc (FILE *, FILE *);
static int sgml_fputc (int);
static int sgml_fputs (const char *);
static void makedoc (FILE *, FILE *);
static int sgml_fputc (int);
static int sgml_fputs (const char *);
+static int sgml_id_fputs (const char *);
static void add_var (const char *);
static int add_s (const char *);
static int add_c (int);
static void add_var (const char *);
static int add_s (const char *);
static int add_c (int);
@@
-141,9
+147,6
@@
int main (int argc, char *argv[])
case 's':
OutputFormat = F_SGML;
break;
case 's':
OutputFormat = F_SGML;
break;
- case 'd':
- Debug++;
- break;
default:
{
fprintf (stderr, "%s: bad command line parameter.\n", Progname);
default:
{
fprintf (stderr, "%s: bad command line parameter.\n", Progname);
@@
-185,7
+188,7
@@
static void add_var (const char *name)
{
outbuf = realloc (outbuf, (++outcount) * sizeof (var_t));
outbuf[outcount - 1].seen = 0;
{
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;
}
outbuf[outcount - 1].descr = NULL;
}
@@
-201,7
+204,7
@@
static int add_s (const char *s)
}
if (lold == 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);
else {
outbuf[outcount - 1].descr =
realloc (outbuf[outcount - 1].descr, lold + lnew + 1);
@@
-241,11
+244,6
@@
static void makedoc (FILE * in, FILE * out)
if (!(p = get_token (token, sizeof (token), buffer)))
continue;
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, "/*--*/")) {
if (!strcmp (token, "/*++*/"))
active = 1;
else if (!strcmp (token, "/*--*/")) {
@@
-292,35
+290,19
@@
static char *get_token (char *d, size_t l, char *s)
short is_quoted = 0;
char *dd = d;
short is_quoted = 0;
char *dd = d;
- if (Debug)
- fprintf (stderr, "%s: get_token called for `%s'.\n", Progname, s);
-
s = skip_ws (s);
s = skip_ws (s);
- if (Debug > 1)
- 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)) {
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 == '"') {
d[0] = *s++;
d[1] = 0;
return s;
}
if (*s == '"') {
- if (Debug) {
- fprintf (stderr, "%s: found quote character.\n", Progname);
- }
-
s++;
is_quoted = 1;
}
s++;
is_quoted = 1;
}
@@
-363,12
+345,6
@@
static char *get_token (char *d, size_t l, char *s)
*d = '\0';
*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;
}
return t;
}
@@
-465,8
+441,6
@@
static void handle_confline (char *s)
return;
if (!strcmp (buff, "|")) {
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;
/* ignore subtype and comma */
if (!(s = get_token (buff, sizeof (buff), s)))
return;
@@
-494,26
+468,21
@@
static void handle_confline (char *s)
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")) {
/* <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;
}
- memset
(val, 0, sizeof
(val));
+ memset
(val, 0, sizeof
(val));
do {
if (!strcmp (buff, "}"))
break;
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)));
}
while ((s = get_token (buff, sizeof (buff), s)));
@@
-602,24
+571,28
@@
static int sgml_fputc (int c)
return add_s ("<");
case '>':
return add_s (">");
return add_s ("<");
case '>':
return add_s (">");
+#if 0
case '$':
return add_s ("$");
case '_':
return add_s ("_");
case '%':
return add_s ("%");
case '$':
return add_s ("$");
case '_':
return add_s ("_");
case '%':
return add_s ("%");
+#endif
case '&':
return add_s ("&");
case '&':
return add_s ("&");
+#if 0
case '\\':
return add_s ("\");
case '"':
case '\\':
return add_s ("\");
case '"':
- return add_s ("&
d
quot;");
+ 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 ("˜");
+#endif
default:
return add_c (c);
}
default:
return add_c (c);
}
@@
-634,6
+607,21
@@
static int sgml_fputs (const char *s)
return 0;
}
return 0;
}
+/* reduce CDATA to ID */
+static int sgml_id_fputs (const char *s) {
+ char id;
+
+ for (; *s; s++) {
+ if (*s == '_')
+ id = '-';
+ else
+ id = *s;
+ if (sgml_fputc ((unsigned int) id) == EOF)
+ return EOF;
+ }
+ return 0;
+}
+
static void print_confline (const char *varname, int type, const char *val)
{
if (type == DT_SYN)
static void print_confline (const char *varname, int type, const char *val)
{
if (type == DT_SYN)
@@
-712,28
+700,26
@@
static void print_confline (const char *varname, int type, const char *val)
/* SGML based manual */
case F_SGML:
{
/* SGML based manual */
case F_SGML:
{
- add_s ("\n<
sect1>
");
+ add_s ("\n<
madmutt-doc:vardef name=\"
");
sgml_fputs (varname);
sgml_fputs (varname);
- add_s ("<label id=\"");
- add_s (varname);
- add_s ("\">");
- add_s ("\n<p>\nType: <tt>");
+ add_s ("\">\n<para>Type: <literal>");
add_s (type2human (type));
add_s (type2human (type));
- add_s ("</
tt>\n
\n");
+ add_s ("</
literal></para>
\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_s ("<p
>\nDefault: <tt>&d
quot;");
+ add_s ("<p
ara>\nDefault: <literal>&
quot;");
sgml_print_strval (val);
sgml_print_strval (val);
- add_s ("&
dquot;</tt
>");
+ add_s ("&
quot;</literal
>");
}
else {
}
else {
- add_s ("<p>\n");
+ add_s ("<p
ara
>\n");
add_s (type == DT_SYS ? "Value: " : "Default: ");
add_s (type == DT_SYS ? "Value: " : "Default: ");
- add_s ("<
tt
>");
+ add_s ("<
literal
>");
add_s (val);
add_s (val);
- add_s ("</
tt
>");
+ add_s ("</
literal
>");
}
}
+ add_s ("</para>\n");
break;
}
/* make gcc happy */
break;
}
/* make gcc happy */
@@
-784,6
+770,9
@@
static int flush_doc (int docstat)
exit (1);
}
exit (1);
}
+ if (docstat & (D_PA))
+ docstat = print_it (SP_END_PAR, NULL, docstat);
+
if (docstat & (D_TAB))
docstat = print_it (SP_END_TAB, NULL, docstat);
if (docstat & (D_TAB))
docstat = print_it (SP_END_TAB, NULL, docstat);
@@
-793,6
+782,8
@@
static int flush_doc (int docstat)
if (docstat & (D_EM | D_BF | D_TT))
docstat = print_it (SP_END_FT, NULL, docstat);
if (docstat & (D_EM | D_BF | D_TT))
docstat = print_it (SP_END_FT, NULL, docstat);
+ docstat = print_it (SP_END_SECT, NULL, docstat);
+
docstat = print_it (SP_NEWLINE, NULL, 0);
fd_recurse--;
docstat = print_it (SP_NEWLINE, NULL, 0);
fd_recurse--;
@@
-1029,31
+1020,31
@@
static int print_it (int special, char *str, int docstat)
case SP_END_FT:
{
if (docstat & D_EM)
case SP_END_FT:
{
if (docstat & D_EM)
- add_s ("</em>");
+ add_s ("</em
phasis
>");
if (docstat & D_BF)
if (docstat & D_BF)
- add_s ("</
bf
>");
+ add_s ("</
emphasis
>");
if (docstat & D_TT)
if (docstat & D_TT)
- add_s ("</
tt
>");
+ add_s ("</
literal
>");
docstat &= ~(D_EM | D_BF | D_TT);
break;
}
case SP_START_BF:
{
docstat &= ~(D_EM | D_BF | D_TT);
break;
}
case SP_START_BF:
{
- add_s ("<
bf
>");
+ add_s ("<
emphasis role=\"bold\"
>");
docstat |= D_BF;
docstat &= ~(D_EM | D_TT);
break;
}
case SP_START_EM:
{
docstat |= D_BF;
docstat &= ~(D_EM | D_TT);
break;
}
case SP_START_EM:
{
- add_s ("<em>");
+ add_s ("<em
phasis
>");
docstat |= D_EM;
docstat &= ~(D_BF | D_TT);
break;
}
case SP_START_TT:
{
docstat |= D_EM;
docstat &= ~(D_BF | D_TT);
break;
}
case SP_START_TT:
{
- add_s ("<
tt
>");
+ add_s ("<
literal
>");
docstat |= D_TT;
docstat &= ~(D_EM | D_BF);
break;
docstat |= D_TT;
docstat &= ~(D_EM | D_BF);
break;
@@
-1077,44
+1068,65
@@
static int print_it (int special, char *str, int docstat)
if (!(onl & D_NL))
add_s ("\n");
if (!(onl & D_NL))
add_s ("\n");
- add_s ("\n<p>\n");
+ if (docstat & D_PA)
+ add_s ("</para>\n");
+ add_s ("<para>\n");
docstat |= D_NP;
docstat |= D_NP;
+ docstat |= D_PA;
break;
}
case SP_START_TAB:
{
break;
}
case SP_START_TAB:
{
- add_s ("\n<
tscreen><verb
>\n");
+ add_s ("\n<
screen
>\n");
docstat |= D_TAB | D_NL;
break;
}
case SP_END_TAB:
{
docstat |= D_TAB | D_NL;
break;
}
case SP_END_TAB:
{
- add_s ("\n</
verb></t
screen>");
+ add_s ("\n</screen>");
docstat &= ~D_TAB;
docstat |= D_NL;
break;
}
case SP_START_DL:
{
docstat &= ~D_TAB;
docstat |= D_NL;
break;
}
case SP_START_DL:
{
- add_s ("\n<
descrip
>\n");
+ add_s ("\n<
variablelist
>\n");
docstat |= D_DL;
break;
}
case SP_DT:
{
docstat |= D_DL;
break;
}
case SP_DT:
{
- add_s ("<
tag
>");
+ add_s ("<
varlistentry><term
>");
break;
}
case SP_DD:
{
break;
}
case SP_DD:
{
- add_s ("</tag>");
+ add_s ("</term>\n<listitem><para>\n");
+ docstat |= D_DD;
break;
}
case SP_END_DL:
{
break;
}
case SP_END_DL:
{
- add_s ("</descrip>\n");
- docstat &= ~D_DL;
+ add_s ("</para></listitem></varlistentry></variablelist>\n");
+ docstat &= ~(D_DL|D_DD);
+ break;
+ }
+ case SP_END_PAR:
+ {
+ add_s ("</para>\n");
+ docstat &= ~D_PA;
+ break;
+ }
+ case SP_END_DD:
+ {
+ add_s ("</para></listitem></varlistentry>\n");
+ docstat &= ~D_DD;
+ break;
+ }
+ case SP_END_SECT:
+ {
+ add_s ("</madmutt-doc:vardef>\n");
break;
}
case SP_STR:
break;
}
case SP_STR:
@@
-1147,13
+1159,13
@@
void print_ref (int output_dollar, const char *ref)
break;
case F_SGML:
break;
case F_SGML:
- add_s ("<
ref i
d=\"");
-
add_
s (ref);
- add_s ("\"
name=\"
");
+ add_s ("<
link linken
d=\"");
+
sgml_id_fput
s (ref);
+ add_s ("\"
>\n
");
if (output_dollar)
if (output_dollar)
- add_s ("
$
");
+ add_s ("
$
");
sgml_fputs (ref);
sgml_fputs (ref);
- add_s ("
\"
>");
+ add_s ("
</link
>");
break;
default:
break;
default:
@@
-1179,9
+1191,6
@@
static int handle_docline (char *l, int docstat)
l = skip_ws (l);
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))
if (!strncmp (l, ".pp", 3))
return print_it (SP_NEWPAR, NULL, docstat);
else if (!strncmp (l, ".ts", 3))
@@
-1225,6
+1234,10
@@
static int handle_docline (char *l, int docstat)
s += 2;
}
else if (!strncmp (s, ".dt", 3)) {
s += 2;
}
else if (!strncmp (s, ".dt", 3)) {
+ if (docstat & D_DD) {
+ docstat = commit_buff (buff, &d, docstat);
+ docstat = print_it (SP_END_DD, NULL, docstat);
+ }
docstat = commit_buff (buff, &d, docstat);
docstat = print_it (SP_DT, NULL, docstat);
s += 3;
docstat = commit_buff (buff, &d, docstat);
docstat = print_it (SP_DT, NULL, docstat);
s += 3;