#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,
SP_DD,
SP_END_DD,
SP_END_DL,
+ SP_START_IL,
+ SP_END_IL,
SP_END_SECT,
SP_REFER
};
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[])
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;
}
{
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;
fputs ("\n<sect2 id=\"", out);
sgml_id_fputs(varname, out);
fputs ("\">\n<title>", out);
- sgml_fputs (varname, out);
+ sgml_fputs (varname, out, 1);
fprintf (out, "</title>\n<literallayout>Type: %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 (""</literallayout>\n", out);
+ if (val && *val)
+ {
+ fputs ("\nDefault: <quote><literal>", out);
+ sgml_print_strval (val, out);
+ fputs ("</literal></quote>", out);
+ }
+ else
+ {
+ fputs ("\nDefault: (empty)", out);
+ }
+ fputs ("</literallayout>\n", out);
}
else
fprintf (out, "\nDefault: %s</literallayout>\n", val);
** - .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.
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);
{
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)
}
case SP_DD:
{
+ if (docstat & D_IL)
+ fputs ("- ", out);
Continuation = 0;
break;
}
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)
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)
}
case SP_DD:
{
- fputs ("\n", out);
+ if (docstat & D_IL)
+ fputs (".TP\n\\(hy ", out);
+ else
+ fputs ("\n", out);
break;
}
case SP_END_DL:
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)
{
if (docstat & D_EM) fputs ("</emphasis>", out);
if (docstat & D_BF) fputs ("</emphasis>", out);
- docstat &= ~(D_EM|D_BF);
+ if (docstat & D_TT) fputs ("</literal>", out);
+ docstat &= ~(D_EM|D_BF|D_TT);
break;
}
case SP_START_BF:
{
fputs ("<emphasis role=\"bold\">", out);
docstat |= D_BF;
- docstat &= ~D_EM;
+ docstat &= ~(D_EM|D_TT);
break;
}
case SP_START_EM:
{
fputs ("<emphasis>", out);
docstat |= D_EM;
- docstat &= ~D_BF;
+ docstat &= ~(D_BF|D_TT);
break;
}
+ case SP_START_TT:
+ {
+ fputs ("<literal>", out);
+ docstat |= D_TT;
+ docstat &= ~(D_BF|D_EM);
+ break;
+ }
case SP_NEWLINE:
{
if (onl)
}
case SP_START_TAB:
{
+ if (docstat & D_PA)
+ {
+ fputs ("\n</para>\n", out);
+ docstat &= ~D_PA;
+ }
fputs ("\n<screen>\n", out);
docstat |= D_TAB | D_NL;
break;
}
case SP_START_DL:
{
+ if (docstat & D_PA)
+ {
+ fputs ("\n</para>\n", out);
+ docstat &= ~D_PA;
+ }
fputs ("\n<variablelist>\n", out);
docstat |= D_DL;
break;
case SP_DD:
{
docstat |= D_DD;
- fputs ("</term>\n<listitem><para>", out);
+ if (docstat & D_DL)
+ fputs("</term>\n", out);
+ fputs ("<listitem><para>", out);
break;
}
case SP_END_DD:
{
docstat &= ~D_DD;
- fputs ("</para></listitem></varlistentry>\n", out);
+ fputs ("</para></listitem>", out);
+ if (docstat & D_DL)
+ fputs("</varlistentry>\n", out);
break;
}
case SP_END_DL:
docstat &= ~(D_DD|D_DL);
break;
}
+ case SP_START_IL:
+ {
+ if (docstat & D_PA)
+ {
+ fputs ("\n</para>\n", out);
+ docstat &= ~D_PA;
+ }
+ fputs ("\n<itemizedlist>\n", out);
+ docstat |= D_IL;
+ break;
+ }
+ case SP_END_IL:
+ {
+ fputs ("</para></listitem></itemizedlist>\n", out);
+ docstat &= ~(D_DD|D_DL);
+ break;
+ }
case SP_END_SECT:
{
fputs ("</sect2>", out);
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 ("<quote>", out);
+ str++;
+ }
+ else if (!strncmp (str, "''", 2))
+ {
+ fputs ("</quote>", out);
+ str++;
+ }
+ else
+ sgml_fputc (*str, out, 1);
+ }
+ }
+ }
break;
}
}
fputs ("\">", out);
if (output_dollar)
fputs ("$", out);
- sgml_fputs (ref, out);
+ sgml_fputs (ref, out, 1);
fputs ("</link>", out);
break;
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 = ' ';
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);
}
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;
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);