/*
- * "$Id$"
- *
* Man page to HTML conversion program.
*
- * Copyright 2007-2010, 2014 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
* Copyright 2004-2006 by Easy Software Products.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
*/
/*
*outfile; /* Output file */
char line[1024], /* Line from file */
*lineptr, /* Pointer into line */
- name[1024]; /* Man page name */
+ anchor[1024], /* Anchor */
+ name[1024], /* Man page name */
+ ddpost[256]; /* Tagged list post markup */
int section = -1, /* Man page section */
pre = 0, /* Preformatted */
font = 0, /* Current font */
linenum = 0; /* Current line number */
- const char *list = NULL; /* Current list, if any */
+ float list_indent = 0.0f, /* Current list indentation */
+ nested_indent = 0.0f; /* Nested list indentation, if any */
+ const char *list = NULL, /* Current list, if any */
+ *nested = NULL; /* Nested list, if any */
const char *post = NULL; /* Text to add after the current line */
"\t<link rel=\"stylesheet\" type=\"text/css\" "
"href=\"../cups-printable.css\">\n", outfile);
+ anchor[0] = '\0';
+
while (fgets(line, sizeof(line), infile))
{
size_t linelen = strlen(line); /* Length of line */
else
fputs("<h3><a name=\"", outfile);
- for (lineptr = line + 4; *lineptr; lineptr ++)
- if (*lineptr == '\"')
- continue;
- else if (isalnum(*lineptr & 255))
- html_putc(*lineptr, outfile);
- else
- html_putc('_', outfile);
+ if (anchor[0])
+ {
+ fputs(anchor, outfile);
+ anchor[0] = '\0';
+ }
+ else
+ {
+ for (lineptr = line + 4; *lineptr; lineptr ++)
+ if (*lineptr == '\"')
+ continue;
+ else if (isalnum(*lineptr & 255))
+ html_putc(*lineptr, outfile);
+ else
+ html_putc('_', outfile);
+ }
fputs("\">", outfile);
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 3, "b", "b", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".I ", 3))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 3, "i", "i", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".BI ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, "b", "i", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".BR ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, "b", NULL, outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".IB ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, "i", "b", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".IR ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, "i", NULL, outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".RB ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, NULL, "b", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".RI ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, NULL, "i", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".SB ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, "small", "b", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strncmp(line, ".SM ", 4))
{
fputs(end_fonts[font], outfile);
font = 0;
+ if (anchor[0])
+ fprintf(outfile, "<a name=\"%s\">", anchor);
+
html_alternate(line + 4, "small", "small", outfile);
+
+ if (anchor[0])
+ {
+ fputs("</a>", outfile);
+ anchor[0] = '\0';
+ }
+
+ if (post)
+ {
+ fputs(post, outfile);
+ post = NULL;
+ }
}
else if (!strcmp(line, ".LP") || !strcmp(line, ".PP") || !strcmp(line, ".P"))
{
}
fputs("<p>", outfile);
+
+ if (anchor[0])
+ {
+ fprintf(outfile, "<a name=\"%s\"></a>", anchor);
+ anchor[0] = '\0';
+ }
}
else if (!strcmp(line, ".RS") || !strncmp(line, ".RS ", 4))
{
float amount = 3.0; /* Indentation */
if (line[3])
- amount = atof(line + 4);
+ amount = (float)atof(line + 4);
fputs(end_fonts[font], outfile);
font = 0;
if (list)
{
- fprintf(outfile, "</%s>\n", list);
- list = NULL;
+ nested = list;
+ list = NULL;
+ nested_indent = list_indent;
+ list_indent = 0.0f;
}
- fprintf(outfile, "<div style=\"margin-left: %.1fem;\">\n", amount);
+ fprintf(outfile, "<div style=\"margin-left: %.1fem;\">\n", amount - nested_indent);
}
else if (!strcmp(line, ".RE"))
{
font = 0;
fputs("</div>\n", outfile);
+
+ if (nested)
+ {
+ list = nested;
+ nested = NULL;
+
+ list_indent = nested_indent;
+ nested_indent = 0.0f;
+ }
}
- else if (!strcmp(line, ".HP") || !strncmp(line, ".HP ", 4) ||
- !strcmp(line, ".TP") || !strncmp(line, ".TP ", 4))
+ else if (!strcmp(line, ".HP") || !strncmp(line, ".HP ", 4))
{
/*
- * Hanging paragraph/tagged list...
+ * Hanging paragraph...
*
* .HP i
- * .TP i
*/
float amount = 3.0; /* Indentation */
if (line[3])
- amount = atof(line + 4);
+ amount = (float)atof(line + 4);
fputs(end_fonts[font], outfile);
font = 0;
fprintf(outfile, "<p style=\"margin-left: %.1fem; text-indent: %.1fem\">", amount, -amount);
+ if (anchor[0])
+ {
+ fprintf(outfile, "<a name=\"%s\"></a>", anchor);
+ anchor[0] = '\0';
+ }
+
if (line[1] == 'T')
post = "<br>\n";
}
+ else if (!strcmp(line, ".TP") || !strncmp(line, ".TP ", 4))
+ {
+ /*
+ * Tagged list...
+ *
+ * .TP i
+ */
+
+ float amount = 3.0; /* Indentation */
+
+ if (line[3])
+ amount = (float)atof(line + 4);
+
+ fputs(end_fonts[font], outfile);
+ font = 0;
+
+ if (list && strcmp(list, "dl"))
+ {
+ fprintf(outfile, "</%s>\n", list);
+ list = NULL;
+ }
+
+ if (!list)
+ {
+ fputs("<dl class=\"man\">\n", outfile);
+ list = "dl";
+ list_indent = amount;
+ }
+
+ fputs("<dt>", outfile);
+ snprintf(ddpost, sizeof(ddpost), "<dd style=\"margin-left: %.1fem\">", amount);
+ post = ddpost;
+
+ if (anchor[0])
+ {
+ fprintf(outfile, "<a name=\"%s\"></a>", anchor);
+ anchor[0] = '\0';
+ }
+ }
else if (!strncmp(line, ".IP ", 4))
{
/*
lineptr ++;
if (isdigit(*lineptr & 255))
- amount = atof(lineptr);
+ amount = (float)atof(lineptr);
if (newlist && list && strcmp(newlist, list))
{
fprintf(outfile, "<li style=\"margin-left: %.1fem;\">", amount);
else
fprintf(outfile, "<p style=\"margin-left: %.1fem;\">", amount);
+
+ if (anchor[0])
+ {
+ fprintf(outfile, "<a name=\"%s\"></a>", anchor);
+ anchor[0] = '\0';
+ }
}
else if (!strncmp(line, ".br", 3))
{
* Ignore unused commands...
*/
}
- else if (!strncmp(line, ".Vb", 3) || !strncmp(line, ".nf", 3))
+ else if (!strncmp(line, ".Vb", 3) || !strncmp(line, ".nf", 3) || !strncmp(line, ".EX", 3))
{
/*
* Start preformatted...
fputs(end_fonts[font], outfile);
font = 0;
- if (list)
- {
- fprintf(outfile, "</%s>\n", list);
- list = NULL;
- }
+// if (list)
+// {
+// fprintf(outfile, "</%s>\n", list);
+// list = NULL;
+// }
pre = 1;
- fputs("<pre>\n", outfile);
+ fputs("<pre class=\"man\">\n", outfile);
}
- else if (!strncmp(line, ".Ve", 3) || !strncmp(line, ".fi", 3))
+ else if (!strncmp(line, ".Ve", 3) || !strncmp(line, ".fi", 3) || !strncmp(line, ".EE", 3))
{
/*
* End preformatted...
*/
}
#endif /* 0 */
+ else if (!strncmp(line, ".\\\"#", 4))
+ {
+ /*
+ * Anchor for HTML output...
+ */
+
+ strlcpy(anchor, line + 4, sizeof(anchor));
+ }
else if (strncmp(line, ".\\\"", 3))
{
/*
{
if (*s == '\"')
quote = !quote;
- else if (*s == '\\' && s[1])
+
+ if (*s == '\\' && s[1])
{
s ++;
html_putc(*s++, fp);
while (isspace(*s & 255))
s ++;
-
- if (*s && *s != '(' && *s != '.' && *s != ',')
- putc(' ', fp);
}
putc('\n', fp);
break;
}
}
+ else if (*s == '(')
+ {
+ if (!strncmp(s, "(em", 3))
+ {
+ fputs("—", fp);
+ s += 3;
+ }
+ else if (!strncmp(s, "(en", 3))
+ {
+ fputs("–", fp);
+ s += 3;
+ }
+ else
+ {
+ putc(*s, fp);
+ s ++;
+ }
+ }
else if (*s == '[')
{
/*
}
else
{
- if (*s != '\\' && *s == '\"' && *s == '\'' && *s == '-')
+ if (*s != '\\' && *s != '\"' && *s != '\'' && *s != '-')
+ {
fprintf(stderr, "mantohtml: Unrecognized escape \"\\%c\" ignored.\n", *s);
+ html_putc('\\', fp);
+ }
html_putc(*s++, fp);
}
* Embed URL...
*/
+ char temp[1024]; /* Temporary string */
const char *end = s + 6; /* End of URL */
while (*end && !isspace(*end & 255))
end ++;
- fprintf(fp, "<a href=\"%*s\">%*s</a>", (int)(end - s), s, (int)(end - s), s);
+ if (end[-1] == ',' || end[-1] == '.' || end[-1] == ')')
+ end --;
+
+ strlcpy(temp, s, sizeof(temp));
+ if ((size_t)(end -s) < sizeof(temp))
+ temp[end - s] = '\0';
+
+ fprintf(fp, "<a href=\"%s\">%s</a>", temp, temp);
s = end;
}
else
*d = '\0';
}
-
-
-/*
- * End of "$Id$".
- */