void WriteEntity (unsigned char c)
{
int i;
i = 0;
while (i < NumEntities && Entities [i].character != c)
i++;
if (i < NumEntities)
fputs (Entities [i].entity, stdout);
else
putchar (c);
}
void Write (int ArticleNum, char * * Urls, int NumUrls)
{
int UrlNum, NumArticles;
char c;
printf ("\n");
printf ("\t\n");
printf ("\t\t\n");
printf ("\t\t\n");
printf ("\t\n");
printf ("\t\t\n");
NumArticles = 0;
UrlNum = 0;
c = getchar ();
while (c != EOF && c != '\n') {
NumArticles++;
if (NumArticles == ArticleNum) {
/* Title not part of printed article */
while (c != EOF && c != '\n')
c = getchar ();
}
else {
if (UrlNum < NumUrls) {
printf ("\t\t\t- ", Urls [UrlNum] );
while (c != EOF && c != '\n') {
WriteEntity (c);
c = getchar ();
}
printf ("
\n");
}
else {
fprintf (stderr, "***doctohtml: Need URL");
fprintf (stderr, " for article \"");
while (c != EOF && c != '\n') {
fputc (c, stderr);
c = getchar ();
}
fprintf (stderr, "\".\n");
}
UrlNum++;
}
if (NumArticles == ArticleNum)
printf ("\t\t\t
\n");
/* Blank line optional before first paragraph */
if (c == '\n')
c = getchar ();
/* Paragraphs */
while (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
printf ("\t\t");
while (c != EOF && c != '\n') {
while (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
WriteEntity (c);
c = getchar ();
}
if (c != EOF)
c = getchar ();
if (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
printf ("
");
}
}
if (NumArticles == ArticleNum)
printf ("
\n");
if (c != EOF)
c = getchar ();
}
if (c != EOF)
c = getchar ();
while (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
printf ("\t\t");
while (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
WriteEntity (c);
c = getchar ();
}
if (NumArticles == ArticleNum)
printf ("
\n");
if (c != EOF)
c = getchar ();
/* Blank line optional before first paragraph */
if (c == '\n')
c = getchar ();
/* Paragraphs */
while (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
printf ("\t\t");
while (c != EOF && c != '\n') {
while (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
WriteEntity (c);
c = getchar ();
}
if (c != EOF)
c = getchar ();
if (c != EOF && c != '\n') {
if (NumArticles == ArticleNum)
printf ("
");
}
}
if (NumArticles == ArticleNum)
printf ("
\n");
if (c != EOF)
c = getchar ();
}
if (c != EOF)
c = getchar ();
}
if (NumArticles == ArticleNum)
printf ("\t\t\n");
if (c != EOF)
c = getchar ();
}
printf ("\t\t\t
\n");
printf ("\t\t\n");
printf ("\t\n");
if (NumArticles < ArticleNum) {
fprintf (stderr, "***doctohtml: Never found article");
fprintf (stderr, " #%d.\n", ArticleNum);
fprintf (stderr, "***doctohtml: Only found");
fprintf (stderr, " %d articles.\n", NumArticles);
}
while (UrlNum < NumUrls) {
fprintf (stderr, "***doctohtml: Never found article");
fprintf (stderr, " for URL \"%s\".\n", Urls [UrlNum] );
UrlNum++;
}
}
int main (int argc, char * argv [] )
{
int i, ArticleNum;
char c;
if (argc < 2) {
for (i = 0; i < NumUsageLines; i++)
printf ("%s\n", UsageLines [i] );
}
else if (argc > 1) {
if (sscanf (argv [1], "%d%c", & ArticleNum, & c) != 1) {
fprintf (stderr, "***doctohtml: Expecting");
fprintf (stderr, " article number, found");
fprintf (stderr, " \"%s\".\n", argv [1] );
}
else
Write (ArticleNum, argv + 2, argc - 2);
}
return 0;
}