📄 doc2html.c
字号:
}
else
fputc(*p, f);
}
p++;
}
fprintf(f,"\042>");
putquoted(c, f);
fprintf(f,"</a><br>\n");
}
}
list = list->next;
}
if (inlist)
fprintf(f,"<p>\n");
}
void
convert(FILE *a,FILE *b)
{
static char line[MAX_LINE_LEN];
/* generate html header */
fprintf(b,"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
fprintf(b,"<html>\n");
fprintf(b,"<head>\n");
fgets(line,sizeof(line)-1,a);
strtok(line, "\n");
if (charset)
fprintf(b,"<meta http-equiv=\042Content-Type\042 content=\042text/html; charset=%s\042>\n", charset);
fprintf(b,"<title>%s</title>\n", line+1);
fprintf(b,"</head>\n");
fprintf(b,"<body>\n");
fprintf(b,"<h1>%s</h1>\n", line+1);
/* process each line of the file */
while (fgets(line, sizeof(line)-1, a)) {
process_line(line, b);
}
/* close final page and generate trailer */
fprintf(b,"\n<p><hr>Created automatically by doc2html\n");
fprintf(b,"</body>\n");
fprintf(b,"</html>\n");
}
void
process_line(char *line, FILE *b)
{
static int line_count = 0;
/* quoting can increase the line length five fold */
static char line2[MAX_LINE_LEN * 5];
static int last_line;
char hyplink1[MAX_LINE_LEN] ;
int i;
int j;
static int startpage = 1;
char topic[MAX_LINE_LEN];
int k, l;
static int tabl=0;
static int para=0;
static int inquote = FALSE;
static int inref = FALSE;
line_count++;
i = 0;
j = 0;
while (line[i] != '\0')
{
switch(line[i])
{
case '<':
strcpy( &line2[j], "<" ) ;
j += strlen( "<." ) - 1 ;
break ;
case '>':
strcpy( &line2[j], ">" ) ;
j += strlen( ">." ) - 1 ;
break ;
case '&':
strcpy( &line2[j], "&" ) ;
j += strlen( "&" ) - 1 ;
break ;
case '\r':
case '\n':
break;
case '`': /* backquotes mean boldface or link */
if ((!inref) && (!inquote))
{
k=i+1; /* index into current string */
l=0; /* index into topic string */
while ((line[k] != '`') && (line[k] != '\0'))
{
topic[l] = line[k];
k++;
l++;
}
topic[l] = '\0';
k = lookup(topic);
if ((k > 0) && (k != last_line))
{
if (nolinks)
sprintf( hyplink1, "<b>") ;
else {
char *p = title_from_index(k);
char *t;
sprintf( hyplink1, "<a href=\042#");
t = hyplink1 + strlen(hyplink1);
while (p && *p) {
if (*p == ' ')
*t++ = '_';
else
*t++ = *p;
p++;
}
*t = '\0';
strcat(hyplink1, "\042>") ;
}
strcpy( line2+j, hyplink1 ) ;
j += strlen( hyplink1 )-1 ;
inref = k;
}
else
{
if (debug && k != last_line)
fprintf(stderr,"Can't make link for \042%s\042 on line %d\n",topic,line_count);
line2[j++] = '<';
line2[j++] = 'b';
line2[j] = '>';
inquote = TRUE;
}
}
else
{
if (inquote && inref)
fprintf(stderr, "Warning: Reference Quote conflict line %d\n", line_count);
if (inquote)
{
line2[j++] = '<';
line2[j++] = '/';
line2[j++] = 'b';
line2[j] = '>';
inquote = FALSE;
}
if (inref)
{
/* must be inref */
line2[j++] = '<';
line2[j++] = '/';
if (nolinks)
line2[j++] = 'b';
else
line2[j++] = 'a';
line2[j] = '>';
inref = 0;
}
}
break;
default:
if ((charset == NULL) && ((unsigned int)(line[i]) >= 127)) {
/* quote non-ASCII characters */
unsigned int value = line[i] & 0xff;
unsigned int digit;
line2[j++] = '&';
line2[j++] = '#';
digit = value / 100;
value -= digit * 100;
line2[j++] = digit + '0';
digit = value / 10;
value -= digit * 10;
line2[j++] = digit + '0';
line2[j++] = value + '0';
line2[j] = ';';
}
else
line2[j] = line[i];
}
i++;
j++;
line2[j] = '\0';
}
i = 1;
switch(line[0]) { /* control character */
case '?': { /* interactive help entry */
#ifdef FIXLATER
if( intable ) intablebut = TRUE ;
fprintf(b,"\n:i1. %s", &(line[1])); /* index entry */
#endif
break;
}
case '@': { /* start/end table */
break; /* ignore */
}
case '#': { /* latex table entry */
break; /* ignore */
}
case '%': { /* troff table entry */
break; /* ignore */
}
case '\n': /* empty text line */
if (tabl)
fprintf(b,"</pre>\n"); /* rjl */
para = 0;
tabl = 0;
fprintf(b,"<p>");
break;
case ' ': { /* normal text line */
if ((line2[1] == '\0') || (line2[1] == '\n'))
{
fprintf(b,"<p>");
para = 0;
tabl = 0;
}
if (line2[1] == ' ')
{
if (!tabl)
{
fprintf(b,"<pre>\n");
}
fprintf(b,"%s\n",&line2[1]);
tabl = 1;
para = 0;
}
else if (strncmp(line2+1, "{bml", 4)==0)
{
/* assume bitmap is available as GIF */
char *p;
fprintf(b, "\n<img src=\042");
for (p=line2+1; *p && *p!=' '; p++)
; /* skip over bml text */
for (; *p && *p==' '; p++)
; /* skip over spaces */
for (; *p && *p!='.' && *p!=' '; p++)
fprintf(b, "%c", *p);
fprintf(b, ".gif\042>\n");
}
else
{
if (tabl) {
fprintf(b,"</pre>\n"); /* rjl */
fprintf(b,"<p>"); /* rjl */
}
tabl = 0;
if (!para)
para = 1; /* not in para so start one */
fprintf(b,"%s \n",&line2[1]);
}
break;
}
default: {
if (isdigit(line[0])) { /* start of section */
if (tabl)
fprintf(b,"</pre>\n"); /* rjl */
if (!startpage)
{
refs(last_line,b);
}
para = 0; /* not in a paragraph */
tabl = 0;
last_line = line_count;
startpage = 0;
if (debug)
fprintf( stderr, "%d: %s\n", line_count, &line2[1] ) ;
k=lookup(&line2[1]) ;
/* output unique ID and section title */
if (nolinks)
fprintf(b,"<hr>\n<h%c>", line[0]=='1'?line[0]:line[0]-1);
else {
char *p = &(line2[1]);
fprintf(b,"<hr>\n<h%c><a name=\042",
line[0]=='1'?line[0]:line[0]-1);
while (*p) {
if (*p == ' ')
fputc('_', b);
else
fputc(*p, b);
p++;
}
fprintf(b,"\042>");
}
fprintf(b,&(line2[1])); /* title */
fprintf(b,"</a></h%c>\n", line[0]=='1'?line[0]:line[0]-1) ;
} else
fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
line[0], line_count);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -