X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=makedoc.c;h=91f6630281bd364240158913f211cd15f38a6895;hp=e2cfc67cfd759436d76da7a14f55e85e5031d0cd;hb=8ad2844734ab84cbcc90c8a47e7fd22935fe7619;hpb=9ed7a487e3a922f2cbb222961c2c9710c3a65f91 diff --git a/makedoc.c b/makedoc.c index e2cfc67..91f6630 100644 --- a/makedoc.c +++ b/makedoc.c @@ -27,21 +27,6 @@ # include #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; @@ -53,7 +38,7 @@ 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)); + return (m_strcmp (((var_t *) a)->name, ((var_t *) b)->name)); } enum output_formats_t { @@ -172,7 +157,7 @@ int main (int argc, char *argv[]) static void add_var (const char *name) { - outbuf = realloc (outbuf, (++outcount) * sizeof (var_t)); + p_realloc(&outbuf, ++outcount); outbuf[outcount - 1].seen = 0; outbuf[outcount - 1].name = strdup(name); outbuf[outcount - 1].descr = NULL; @@ -180,7 +165,7 @@ static void add_var (const char *name) 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); @@ -192,9 +177,8 @@ static int add_s (const char *s) if (lold == 0) 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); + p_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'; return (1); @@ -210,8 +194,8 @@ static int add_c (int c) 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; @@ -230,15 +214,15 @@ static void makedoc (FILE * in, FILE * out) if (!(p = get_token (token, sizeof (token), buffer))) continue; - if (!strcmp (token, "/*++*/")) + if (!m_strcmp (token, "/*++*/")) active = 1; - else if (!strcmp (token, "/*--*/")) { + else if (!m_strcmp (token, "/*--*/")) { docstat = flush_doc (docstat); active = 0; } - else if (active && (!strcmp (token, "/**") || !strcmp (token, "**"))) + else if (active && (!m_strcmp (token, "/**") || !m_strcmp (token, "**"))) docstat = handle_docline (p, docstat); - else if (active && !strcmp (token, "{")) { + else if (active && !m_strcmp (token, "{")) { docstat = flush_doc (docstat); handle_confline (p); } @@ -249,11 +233,11 @@ static void makedoc (FILE * in, FILE * out) for (line = 0; line < outcount; line++) { if (outbuf[line].descr) { fprintf (out, "%s\n", outbuf[line].descr); - free (outbuf[line].descr); + p_delete(&outbuf[line].descr); } - free (outbuf[line].name); + p_delete(&outbuf[line].name); } - free (outbuf); + p_delete(&outbuf); } /* skip whitespace */ @@ -274,7 +258,6 @@ static char *get_token (char *d, size_t l, char *s) { char *t; short is_quoted = 0; - char *dd = d; s = skip_ws (s); @@ -363,32 +346,30 @@ enum { }; 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; for (type = DT_NONE; types[type].machine; type++) - if (!strcmp (types[type].machine, s)) + if (!m_strcmp (types[type].machine, s)) return type; return DT_NONE; @@ -400,11 +381,11 @@ static const char *type2human (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? */ @@ -426,7 +407,7 @@ static void handle_confline (char *s) if (!(s = get_token (buff, sizeof (buff), s))) return; - if (!strcmp (buff, "|")) { + if (!m_strcmp (buff, "|")) { /* ignore subtype and comma */ if (!(s = get_token (buff, sizeof (buff), s))) return; @@ -439,14 +420,14 @@ static void handle_confline (char *s) while (1) { if (!(s = get_token (buff, sizeof (buff), s))) return; - if (!strcmp (buff, ",")) + if (!m_strcmp (buff, ",")) break; } /* option name or UL &address */ if (!(s = get_token (buff, sizeof (buff), s))) return; - if (!strcmp (buff, "UL")) + if (!m_strcmp (buff, "UL")) if (!(s = get_token (buff, sizeof (buff), s))) return; @@ -457,7 +438,7 @@ static void handle_confline (char *s) /* or UL */ if (!(s = get_token (buff, sizeof (buff), s))) return; - if (!strcmp (buff, "UL")) { + if (!m_strcmp (buff, "UL")) { if (!(s = get_token (buff, sizeof (buff), s))) return; } @@ -465,7 +446,7 @@ static void handle_confline (char *s) memset(val, 0, sizeof(val)); do { - if (!strcmp (buff, "}")) + if (!m_strcmp (buff, "}")) break; m_strcat(val, sizeof(val), buff); @@ -476,23 +457,23 @@ static void handle_confline (char *s) print_confline (varname, type, val); } -static void char_to_escape (char *dest, unsigned int c) +static void char_to_escape (char *dest, int len, unsigned int c) { switch (c) { case '\r': - strcpy (dest, "\\r"); - break; /* __STRCPY_CHECKED__ */ + m_strcpy(dest, len, "\\r"); + break; case '\n': - strcpy (dest, "\\n"); - break; /* __STRCPY_CHECKED__ */ + m_strcpy(dest, len, "\\n"); + break; case '\t': - strcpy (dest, "\\t"); - break; /* __STRCPY_CHECKED__ */ + m_strcpy(dest, len, "\\t"); + break; case '\f': - strcpy (dest, "\\f"); - break; /* __STRCPY_CHECKED__ */ + m_strcpy(dest, len, "\\f"); + break; default: - sprintf (dest, "\\%03o", c); + sprintf (dest, len, "\\%03o", c); break; } } @@ -500,7 +481,7 @@ static void conf_char_to_escape (unsigned int c) { char buff[16]; - char_to_escape (buff, c); + char_to_escape(buff, sizeof(buff), c); add_s (buff); } @@ -542,7 +523,7 @@ static void sgml_print_strval (const char *v) for (; *v; v++) { if (*v < ' ' || *v & 0x80) { - char_to_escape (buff, (unsigned int) *v); + char_to_escape(buff, sizeof(buff), (unsigned int) *v); sgml_fputs (buff); continue; } @@ -557,28 +538,8 @@ 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 ("""); - case '[': - return add_s ("["); - case ']': - return add_s ("]"); - case '~': - return add_s ("˜"); -#endif default: return add_c (c); } @@ -873,7 +834,7 @@ static int print_it (int special, char *str, int docstat) 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; @@ -981,11 +942,11 @@ static int print_it (int special, char *str, int docstat) 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++; } @@ -1134,7 +1095,7 @@ static int print_it (int special, char *str, int docstat) 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: @@ -1172,54 +1133,54 @@ static int commit_buff (char *buff, char **d, int docstat) static int handle_docline (char *l, int docstat) { - char buff[BUFFSIZE]; + char buff[BUFSIZ]; char *s, *d; l = skip_ws (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); @@ -1228,7 +1189,7 @@ static int handle_docline (char *l, int 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;