X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..b09ee204d1b5bdba9dbc99691a6caf08e5cc4af2:/doc/makedoc.c?ds=sidebyside diff --git a/doc/makedoc.c b/doc/makedoc.c index 528d372..07d3405 100644 --- a/doc/makedoc.c +++ b/doc/makedoc.c @@ -76,11 +76,14 @@ enum output_formats_t #define D_DT (1 << 7) #define D_DD (1 << 8) #define D_PA (1 << 9) +#define D_IL (1 << 10) +#define D_TT (1 << 11) enum { SP_START_EM, SP_START_BF, + SP_START_TT, SP_END_FT, SP_NEWLINE, SP_NEWPAR, @@ -93,6 +96,8 @@ enum SP_DD, SP_END_DD, SP_END_DL, + SP_START_IL, + SP_END_IL, SP_END_SECT, SP_REFER }; @@ -112,8 +117,8 @@ static void print_confline (const char *, int, const char *, FILE *); static void handle_confline (char *, FILE *); static void makedoc (FILE *, FILE *); static void pretty_default (char *, size_t, const char *, int); -static int sgml_fputc (int, FILE *); -static int sgml_fputs (const char *, FILE *); +static int sgml_fputc (int, FILE *, int); +static int sgml_fputs (const char *, FILE *, int); static int sgml_id_fputs (const char *, FILE *); int main (int argc, char *argv[]) @@ -571,6 +576,8 @@ static void man_print_strval (const char *v, FILE *out) fputs ("\\(rq", out); else if (*v == '\\') fputs ("\\\\", out); + else if (*v == '-') + fputs ("\\-", out); else fputc (*v, out); } @@ -584,38 +591,42 @@ static void sgml_print_strval (const char *v, FILE *out) if (*v < ' ' || *v & 0x80) { char_to_escape (buff, (unsigned int) *v); - sgml_fputs (buff, out); + sgml_fputs (buff, out, 1); continue; } - sgml_fputc ((unsigned int) *v, out); + sgml_fputc ((unsigned int) *v, out, 1); } } -static int sgml_fputc (int c, FILE *out) +static int sgml_fputc (int c, FILE *out, int full) { switch (c) { + /* the bare minimum for escaping */ case '<': return fputs ("<", out); case '>': return fputs (">", out); - case '$': return fputs ("$", out); - case '_': return fputs ("_", out); - case '%': return fputs ("%", out); case '&': return fputs ("&", out); - case '\\': return fputs ("\", out); - case '"': return fputs (""", out); - case '[': return fputs ("[", out); - case ']': return fputs ("]", out); - case '~': return fputs ("˜", out); + /* map to entities, fall-through to raw if !full */ + case '$': if (full) return fputs ("$", out); + case '_': if (full) return fputs ("_", out); + case '%': if (full) return fputs ("%", out); + case '\\': if (full) return fputs ("\", out); + case '"': if (full) return fputs (""", out); + case '[': if (full) return fputs ("[", out); + case ']': if (full) return fputs ("]", out); + case '~': if (full) return fputs ("˜", out); + case '|': if (full) return fputs ("|", out); + case '^': if (full) return fputs ("ˆ", out); default: return fputc (c, out); } } -static int sgml_fputs (const char *s, FILE *out) +static int sgml_fputs (const char *s, FILE *out, int full) { for (; *s; s++) - if (sgml_fputc ((unsigned int) *s, out) == EOF) + if (sgml_fputc ((unsigned int) *s, out, full) == EOF) return EOF; - + return 0; } @@ -624,12 +635,17 @@ static int sgml_id_fputs (const char *s, FILE* out) { char id; + if (*s == '<') + s++; + for (; *s; s++) { if (*s == '_') id = '-'; else id = *s; + if (*s == '>' && !*(s+1)) + break; if (fputc ((unsigned int) id, out) == EOF) return EOF; @@ -683,8 +699,11 @@ static void print_confline (const char *varname, int type, const char *val, FILE man_print_strval (val, out); fputs ("\\(rq\n", out); } - else - fprintf (out, "Default: %s\n", val); + else { + fputs ("Default: ", out); + man_print_strval (val, out); + fputs ("\n", out); + } fputs (".fi", out); @@ -697,14 +716,23 @@ static void print_confline (const char *varname, int type, const char *val, FILE fputs ("\n\n", out); - sgml_fputs (varname, out); + sgml_fputs (varname, out, 1); fprintf (out, "\nType: %s", type2human (type)); + if (type == DT_STR || type == DT_RX || type == DT_ADDR || type == DT_PATH) { - fputs ("\nDefault: "", out); - sgml_print_strval (val, out); - fputs (""\n", out); + if (val && *val) + { + fputs ("\nDefault: ", out); + sgml_print_strval (val, out); + fputs ("", out); + } + else + { + fputs ("\nDefault: (empty)", out); + } + fputs ("\n", out); } else fprintf (out, "\nDefault: %s\n", val); @@ -733,6 +761,9 @@ static void print_confline (const char *varname, int type, const char *val, FILE ** - .dt starts a term in a definition list. ** - .dd starts a definition in a definition list. ** - .de on a line finishes a definition list. + ** - .il on a line starts an itemzied list + ** - .dd starts an item in an itemized list + ** - .ie on a line finishes an itemized list ** - .ts on a line starts a "tscreen" environment (name taken from SGML). ** - .te on a line finishes this environment. ** - .pp on a line starts a paragraph. @@ -766,7 +797,7 @@ static int flush_doc (int docstat, FILE *out) if (docstat & (D_DL)) docstat = print_it (SP_END_DL, NULL, out, docstat); - if (docstat & (D_EM | D_BF)) + if (docstat & (D_EM | D_BF | D_TT)) docstat = print_it (SP_END_FT, NULL, out, docstat); docstat = print_it (SP_END_SECT, NULL, out, docstat); @@ -794,9 +825,10 @@ static int print_it (int special, char *str, FILE *out, int docstat) { static int Continuation = 0; - case SP_END_FT: docstat &= ~(D_EM|D_BF); break; + case SP_END_FT: docstat &= ~(D_EM|D_BF|D_TT); break; case SP_START_BF: docstat |= D_BF; break; case SP_START_EM: docstat |= D_EM; break; + case SP_START_TT: docstat |= D_TT; break; case SP_NEWLINE: { if (onl) @@ -850,6 +882,8 @@ static int print_it (int special, char *str, FILE *out, int docstat) } case SP_DD: { + if (docstat & D_IL) + fputs ("- ", out); Continuation = 0; break; } @@ -859,6 +893,17 @@ static int print_it (int special, char *str, FILE *out, int docstat) docstat &= ~D_DL; break; } + case SP_START_IL: + { + docstat |= D_IL; + break; + } + case SP_END_IL: + { + Continuation = 0; + docstat &= ~D_IL; + break; + } case SP_STR: { if (Continuation) @@ -890,23 +935,30 @@ static int print_it (int special, char *str, FILE *out, int docstat) case SP_END_FT: { fputs ("\\fP", out); - docstat &= ~(D_EM|D_BF); + docstat &= ~(D_EM|D_BF|D_TT); break; } case SP_START_BF: { fputs ("\\fB", out); docstat |= D_BF; - docstat &= ~D_EM; + docstat &= ~(D_EM|D_TT); break; } case SP_START_EM: { fputs ("\\fI", out); docstat |= D_EM; - docstat &= ~D_BF; + docstat &= ~(D_BF|D_TT); break; } + case SP_START_TT: + { + fputs ("\\fC", out); + docstat |= D_TT; + docstat &= ~(D_BF|D_EM); + break; + } case SP_NEWLINE: { if (onl) @@ -959,7 +1011,10 @@ static int print_it (int special, char *str, FILE *out, int docstat) } case SP_DD: { - fputs ("\n", out); + if (docstat & D_IL) + fputs (".TP\n\\(hy ", out); + else + fputs ("\n", out); break; } case SP_END_DL: @@ -968,6 +1023,18 @@ static int print_it (int special, char *str, FILE *out, int docstat) docstat &= ~D_DL; break; } + case SP_START_IL: + { + fputs (".RS\n.PD 0\n", out); + docstat |= D_IL; + break; + } + case SP_END_IL: + { + fputs (".RE\n.PD 1", out); + docstat &= ~D_DL; + break; + } case SP_STR: { while (*str) @@ -978,6 +1045,8 @@ static int print_it (int special, char *str, FILE *out, int docstat) fputs ("\\(rq", out); else if (*str == '\\') fputs ("\\\\", out); + else if (*str == '-') + fputs ("\\-", out); else if (!strncmp (str, "``", 2)) { fputs ("\\(lq", out); @@ -1007,23 +1076,31 @@ static int print_it (int special, char *str, FILE *out, int docstat) { if (docstat & D_EM) fputs ("", out); if (docstat & D_BF) fputs ("", out); - docstat &= ~(D_EM|D_BF); + if (docstat & D_TT) fputs ("", out); + docstat &= ~(D_EM|D_BF|D_TT); break; } case SP_START_BF: { fputs ("", out); docstat |= D_BF; - docstat &= ~D_EM; + docstat &= ~(D_EM|D_TT); break; } case SP_START_EM: { fputs ("", out); docstat |= D_EM; - docstat &= ~D_BF; + docstat &= ~(D_BF|D_TT); break; } + case SP_START_TT: + { + fputs ("", out); + docstat |= D_TT; + docstat &= ~(D_BF|D_EM); + break; + } case SP_NEWLINE: { if (onl) @@ -1062,43 +1139,76 @@ static int print_it (int special, char *str, FILE *out, int docstat) } case SP_START_TAB: { + if (docstat & D_PA) + { + fputs ("\n\n", out); + docstat &= ~D_PA; + } fputs ("\n\n", out); docstat |= D_TAB | D_NL; break; } case SP_END_TAB: { - fputs ("\n", out); + fputs ("", out); docstat &= ~D_TAB; docstat |= D_NL; break; } case SP_START_DL: { - fputs ("\n\n", out); + if (docstat & D_PA) + { + fputs ("\n\n", out); + docstat &= ~D_PA; + } + fputs ("\n\n\n\n", out); docstat |= D_DL; break; } case SP_DT: { - fputs ("", out); + fputs ("", out); break; } case SP_DD: { docstat |= D_DD; - fputs ("\n", out); + if (docstat & D_DL) + fputs("", out); + else + fputs ("", out); break; } case SP_END_DD: { + if (docstat & D_DL) + fputs ("\n", out); + else + fputs ("", out); docstat &= ~D_DD; - fputs ("\n", out); break; } case SP_END_DL: { - fputs ("\n", out); + fputs ("\n", out); + docstat &= ~(D_DD|D_DL); + break; + } + case SP_START_IL: + { + if (docstat & D_PA) + { + fputs ("\n\n", out); + docstat &= ~D_PA; + } + fputs ("\n\n", out); + docstat |= D_IL; + break; + } + case SP_END_IL: + { + fputs ("\n", out); docstat &= ~(D_DD|D_DL); break; } @@ -1110,9 +1220,28 @@ static int print_it (int special, char *str, FILE *out, int docstat) case SP_STR: { if (docstat & D_TAB) - fputs (str, out); + sgml_fputs (str, out, 0); else - sgml_fputs (str, out); + { + while (*str) + { + for (; *str; str++) + { + if (!strncmp (str, "``", 2)) + { + fputs ("", out); + str++; + } + else if (!strncmp (str, "''", 2)) + { + fputs ("", out); + str++; + } + else + sgml_fputc (*str, out, 1); + } + } + } break; } } @@ -1143,7 +1272,7 @@ void print_ref (FILE *out, int output_dollar, const char *ref) fputs ("\">", out); if (output_dollar) fputs ("$", out); - sgml_fputs (ref, out); + sgml_fputs (ref, out, 1); fputs ("", out); break; @@ -1183,6 +1312,10 @@ static int handle_docline (char *l, FILE *out, int docstat) return print_it (SP_START_DL, NULL, out, docstat); else if (!strncmp (l, ".de", 3)) return print_it (SP_END_DL, NULL, out, docstat); + else if (!strncmp (l, ".il", 3)) + return print_it (SP_START_IL, NULL, out, docstat); + else if (!strncmp (l, ".ie", 3)) + return print_it (SP_END_IL, NULL, out, docstat); else if (!strncmp (l, ". ", 2)) *l = ' '; @@ -1210,6 +1343,12 @@ static int handle_docline (char *l, FILE *out, int docstat) docstat = print_it (SP_START_BF, NULL, out, docstat); s += 2; } + else if (!strncmp (s, "\\fC", 3)) + { + docstat = commit_buff (buff, &d, out, docstat); + docstat = print_it (SP_START_TT, NULL, out, docstat); + s += 2; + } else if (!strncmp (s, "\\fP", 3)) { docstat = commit_buff (buff, &d, out, docstat); @@ -1229,6 +1368,11 @@ static int handle_docline (char *l, FILE *out, int docstat) } else if (!strncmp (s, ".dd", 3)) { + if ((docstat & D_IL) && (docstat & D_DD)) + { + docstat = commit_buff (buff, &d, out, docstat); + docstat = print_it (SP_END_DD, NULL, out, docstat); + } docstat = commit_buff (buff, &d, out, docstat); docstat = print_it (SP_DD, NULL, out, docstat); s += 3; @@ -1252,7 +1396,7 @@ static int handle_docline (char *l, FILE *out, int docstat) else { ref = s; - while (isalnum ((unsigned char) *s) || *s == '-' || *s == '_') + while (isalnum ((unsigned char) *s) || (*s && strchr("-_<>", *s))) ++s; docstat = commit_buff (buff, &d, out, docstat);