X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=makedoc.c;h=6910e54621beef90b02ee30e96beadba4ecfd45f;hp=54f35494e5e2a0fea8cfe6208ca887070ea196d6;hb=b07d69b15852a06183f7b2298436e18150c36958;hpb=11dfc0aa39e31496da16c708f972a6718dd7ee5c diff --git a/makedoc.c b/makedoc.c index 54f3549..6910e54 100644 --- a/makedoc.c +++ b/makedoc.c @@ -31,6 +31,7 @@ #include #include +#include #ifdef HAVE_UNISTD_H # include @@ -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_DD (1 << 9) +#define D_PA (1 << 10) enum { SP_START_EM, SP_START_BF, SP_START_TT, SP_END_FT, + SP_END_PAR, SP_NEWLINE, SP_NEWPAR, SP_STR, @@ -96,7 +100,9 @@ enum { SP_START_DL, SP_DT, SP_DD, + SP_END_DD, SP_END_DL, + SP_END_SECT, SP_REFER }; @@ -114,9 +120,9 @@ static int print_it (int, char *, int); static void print_confline (const char *, int, const char *); static void handle_confline (char *); 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 int sgml_id_fputs (const char *); static void add_var (const char *); static int add_s (const char *); static int add_c (int); @@ -186,7 +192,7 @@ 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].name = strdup(name); outbuf[outcount - 1].descr = NULL; } @@ -202,7 +208,7 @@ static int add_s (const char *s) } 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); @@ -397,7 +403,8 @@ enum { DT_RX, DT_MAGIC, DT_SYN, - DT_ADDR + DT_ADDR, + DT_SYS }; struct { @@ -416,6 +423,7 @@ struct { "DT_MAGIC", "folder magic"}, { "DT_SYN", NULL}, { "DT_ADDR", "e-mail address"}, { + "DT_SYS", "system property"}, { NULL, NULL} }; @@ -439,7 +447,6 @@ static void handle_confline (char *s) { char varname[BUFFSIZE]; char buff[BUFFSIZE]; - char tmp[BUFFSIZE]; int type; char val[BUFFSIZE]; @@ -507,80 +514,20 @@ static void handle_confline (char *s) return; } - memset (tmp, 0, sizeof (tmp)); + memset(val, 0, sizeof(val)); do { if (!strcmp (buff, "}")) break; - strncpy (tmp + STRLEN (tmp), buff, sizeof (tmp) - STRLEN (tmp)); + m_strcat(val, sizeof(val), buff); } while ((s = get_token (buff, sizeof (buff), s))); - pretty_default (val, sizeof (val), tmp, type); add_var (varname); print_confline (varname, type, val); } -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); - break; - } - case DT_BOOL: - { - if (atoi (s)) - strncpy (t, "yes", l); - else - strncpy (t, "no", l); - break; - } - case DT_SORT: - { - /* heuristic! */ - strncpy (t, s + 5, l); - for (; *t; t++) - *t = tolower ((unsigned char) *t); - break; - } - case DT_MAGIC: - { - /* heuristic! */ - strncpy (t, s + 2, l); - for (; *t; t++) - *t = tolower ((unsigned char) *t); - break; - } - case DT_STR: - case DT_RX: - case DT_ADDR: - case DT_PATH: - { - if (!strcmp (s, "0")) - break; - /* fallthrough */ - } - default: - { - strncpy (t, s, l); - break; - } - } -} - static void char_to_escape (char *dest, unsigned int c) { switch (c) { @@ -662,24 +609,28 @@ static int sgml_fputc (int c) return add_s ("<"); case '>': return add_s (">"); +#if 0 case '$': return add_s ("$"); case '_': return add_s ("_"); case '%': return add_s ("%"); +#endif case '&': return add_s ("&"); +#if 0 case '\\': return add_s ("\"); case '"': - return add_s ("&dquot;"); + return add_s ("""); case '[': return add_s ("["); case ']': return add_s ("]"); case '~': return add_s ("˜"); +#endif default: return add_c (c); } @@ -694,6 +645,21 @@ static int sgml_fputs (const char *s) 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) @@ -703,11 +669,18 @@ static void print_confline (const char *varname, int type, const char *val) /* configuration file */ case F_CONF: { + if (type == DT_SYS) { + add_s ("\n# set ?"); + add_s (varname); + add_s (" prints "); + add_s (val); + break; + } if (type == DT_STR || type == DT_RX || type == DT_ADDR || type == DT_PATH) { add_s ("\n# set "); add_s (varname); - add_s ("\""); + add_s ("=\""); conf_print_strval (val); add_s ("\""); } @@ -753,7 +726,7 @@ static void print_confline (const char *varname, int type, const char *val) add_s ("\\(rq\n"); } else { - add_s ("Default: "); + add_s (type == DT_SYS ? "Value: " : "Default: "); add_s (val); add_c ('\n'); } @@ -765,26 +738,26 @@ static void print_confline (const char *varname, int type, const char *val) /* SGML based manual */ case F_SGML: { - add_s ("\n"); + add_s ("\n"); - add_s ("\n

\nType: "); + add_s ("\">\nType: "); add_s (type2human (type)); - add_s ("\n\n"); + add_s ("\n"); if (type == DT_STR || type == DT_RX || type == DT_ADDR || type == DT_PATH) { - add_s ("

\nDefault: &dquot;"); + add_s ("\nDefault: ""); sgml_print_strval (val); - add_s ("&dquot;"); + add_s ("""); } else { - add_s ("

\nDefault: "); + add_s ("\n"); + add_s (type == DT_SYS ? "Value: " : "Default: "); + add_s (""); add_s (val); - add_s (""); + add_s (""); } + add_s ("\n"); break; } /* make gcc happy */ @@ -835,6 +808,9 @@ static int flush_doc (int docstat) 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); @@ -844,6 +820,8 @@ static int flush_doc (int 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--; @@ -1080,31 +1058,31 @@ static int print_it (int special, char *str, int docstat) case SP_END_FT: { if (docstat & D_EM) - add_s (""); + add_s (""); if (docstat & D_BF) - add_s (""); + add_s (""); if (docstat & D_TT) - add_s (""); + add_s (""); docstat &= ~(D_EM | D_BF | D_TT); break; } case SP_START_BF: { - add_s (""); + add_s (""); docstat |= D_BF; docstat &= ~(D_EM | D_TT); break; } case SP_START_EM: { - add_s (""); + add_s (""); docstat |= D_EM; docstat &= ~(D_BF | D_TT); break; } case SP_START_TT: { - add_s (""); + add_s (""); docstat |= D_TT; docstat &= ~(D_EM | D_BF); break; @@ -1128,44 +1106,65 @@ static int print_it (int special, char *str, int docstat) if (!(onl & D_NL)) add_s ("\n"); - add_s ("\n

\n"); + if (docstat & D_PA) + add_s ("\n"); + add_s ("\n"); docstat |= D_NP; + docstat |= D_PA; break; } case SP_START_TAB: { - add_s ("\n\n"); + add_s ("\n\n"); docstat |= D_TAB | D_NL; break; } case SP_END_TAB: { - add_s ("\n"); + add_s ("\n"); docstat &= ~D_TAB; docstat |= D_NL; break; } case SP_START_DL: { - add_s ("\n\n"); + add_s ("\n\n"); docstat |= D_DL; break; } case SP_DT: { - add_s (""); + add_s (""); break; } case SP_DD: { - add_s (""); + add_s ("\n\n"); + docstat |= D_DD; break; } case SP_END_DL: { - add_s ("\n"); - docstat &= ~D_DL; + add_s ("\n"); + docstat &= ~(D_DL|D_DD); + break; + } + case SP_END_PAR: + { + add_s ("\n"); + docstat &= ~D_PA; + break; + } + case SP_END_DD: + { + add_s ("\n"); + docstat &= ~D_DD; + break; + } + case SP_END_SECT: + { + add_s ("\n"); break; } case SP_STR: @@ -1198,13 +1197,13 @@ void print_ref (int output_dollar, const char *ref) break; case F_SGML: - add_s ("\n"); if (output_dollar) - add_s ("$"); + add_s ("$"); sgml_fputs (ref); - add_s ("\">"); + add_s (""); break; default: @@ -1276,6 +1275,10 @@ static int handle_docline (char *l, int docstat) 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;