📄 man2html.c
字号:
} } *f = '\0'; fputs(c, stdout); *f = '('; idtest[4] = f - 1; c = f;#endif break; /* manpage */ case 3: /* ftp */ case 2: /* www */ g = f = idtest[j]; while (*g && (isalnum(*g) || *g == '_' || *g == '-' || *g == '+' || *g == '.')) g++; if (g[-1] == '.') g--; if (g - f > 4) { char t; t = *f; *f = '\0'; fputs(c, stdout); *f = t; t = *g; *g = '\0'; printf("<A HREF=\"%s://%s\">%s</A>", (j == 3 ? "ftp" : "http"), f, f); *g = t; c = g; } else { f[3] = '\0'; fputs(c, stdout); c = f + 3; f[3] = '.'; } break; case 1: /* mailto */ g = f = idtest[1]; while (g > c && (isalnum(g[-1]) || g[-1] == '_' || g[-1] == '-' || g[-1] == '+' || g[-1] == '.' || g[-1] == '%')) g--; h = f + 1; while (*h && (isalnum(*h) || *h == '_' || *h == '-' || *h == '+' || *h == '.')) h++; if (*h == '.') h--; if (h - f > 4 && f - g > 1) { char t; t = *g; *g = '\0'; fputs(c, stdout); *g = t; t = *h; *h = '\0'; printf("<A HREF=\"mailto:%s\">%s</A>", g, g); *h = t; c = h; } else { *f = '\0'; fputs(c, stdout); *f = '@'; idtest[1] = c; c = f; } break; case 0: /* url */ g = f = idtest[0]; while (g > c && isalpha(g[-1]) && islower(g[-1])) g--; h = f + 3; while (*h && !isspace(*h) && *h != '<' && *h != '>' && *h != '"' && *h != '&') h++; if (f - g > 2 && f - g < 7 && h - f > 3) { char t; t = *g; *g = '\0'; fputs(c, stdout); *g = t; t = *h; *h = '\0'; printf("<A HREF=\"%s\">%s</A>", g, g); *h = t; c = h; } else { f[1] = '\0'; fputs(c, stdout); f[1] = '/'; c = f + 1; } break; default: break; } nr = 0; if (idtest[0] && idtest[0] < c) idtest[0] = strstr(c + 1, "://"); if (idtest[1] && idtest[1] < c) idtest[1] = strchr(c + 1, '@'); if (idtest[2] && idtest[2] < c) idtest[2] = strstr(c, "www."); if (idtest[3] && idtest[3] < c) idtest[3] = strstr(c, "ftp."); if (idtest[4] && idtest[4] < c) idtest[4] = strchr(c + 1, '('); if (idtest[5] && idtest[5] < c) idtest[5] = strstr(c + 1, ".h>"); for (i = 0; i < 6; i++) nr += (idtest[i] != NULL); } fputs(c, stdout);}static int current_font = 0;static int current_size = 0;static int fillout = 1;static voidout_html(char *c){ if (!c) return; if (no_newline_output) { int i = 0; no_newline_output = 1; while (c[i]) { if (!no_newline_output) c[i - 1] = c[i]; if (c[i] == '\n') no_newline_output = 1; i++; } if (!no_newline_output) c[i - 1] = 0; } if (scaninbuff) { while (*c) { if (buffpos >= buffmax) { char *h; h = realloc(buffer, buffmax * 2); if (!h) return; buffer = h; buffmax *= 2; } buffer[buffpos++] = *c++; } } else if (output_possible) { while (*c) { outbuffer[obp++] = *c; if (*c == '\n' || obp > HUGE_STR_MAX) { outbuffer[obp] = '\0'; add_links(outbuffer); obp = 0; } c++; } }}#define FO0 ""#define FC0 ""#define FO1 "<I>"#define FC1 "</I>"#define FO2 "<B>"#define FC2 "</B>"#define FO3 "<TT>"#define FC3 "</TT>"static char *switchfont[16] = { "", FC0 FO1, FC0 FO2, FC0 FO3, FC1 FO0, "", FC1 FO2, FC1 FO3, FC2 FO0, FC2 FO1, "", FC2 FO3, FC3 FO0, FC3 FO1, FC3 FO2, ""};static char *change_to_font(int nr){ int i; switch (nr) { case '0': nr++; case '1': case '2': case '3': case '4': nr = nr - '1'; break; case V('C', 'W'): nr = 3; break; case 'L': nr = 3; break; case 'B': nr = 2; break; case 'I': nr = 1; break; case 'P': case 'R': nr = 0; break; case 0: case 1: case 2: case 3: break; default: nr = 0; break; } i = current_font * 4 + nr % 4; current_font = nr % 4; return switchfont[i];}static char sizebuf[200];static char *change_to_size(int nr){ int i; switch (nr) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': nr = nr - '0'; break; case '\0': break; default: nr = current_size + nr; if (nr > 9) nr = 9; if (nr < -9) nr = -9; break; } if (nr == current_size) return ""; i = current_font; sizebuf[0] = '\0'; strcat(sizebuf, change_to_font(0)); if (current_size) strcat(sizebuf, "</FONT>"); current_size = nr; if (nr) { int l; strcat(sizebuf, "<FONT SIZE="); l = strlen(sizebuf); if (nr > 0) sizebuf[l++] = '+'; else sizebuf[l++] = '-', nr = -nr; sizebuf[l++] = nr + '0'; sizebuf[l++] = '>'; sizebuf[l] = '\0'; } strcat(sizebuf, change_to_font(i)); return sizebuf;}static int asint = 0;static int intresult = 0;#define SKIPEOL while (*c && *c++!='\n')static int skip_escape = 0;static int single_escape = 0;static char *scan_escape(char *c){ char *h = NULL; char b[5]; INTDEF *intd; int exoutputp, exskipescape; int i, j; intresult = 0; switch (*c) { case 'e': h = "\\"; curpos++; break; case '0': case ' ': h = " "; curpos++; break; case '|': h = ""; break; case '"': SKIPEOL; c--; h = ""; break; case '$': if (argument) { c++; i = (*c - '1'); if (!(h = argument[i])) h = ""; } break; case 'z': c++; if (*c == '\\') { c = scan_escape(c + 1); c--; h = ""; } else { b[0] = *c; b[1] = '\0'; h = ""; } break; case 'k': c++; if (*c == '(') c += 2; case '^': case '!': case '%': case 'a': case 'd': case 'r': case 'u': case '\n': case '&': h = ""; break; case '(': c++; i = c[0] * 256 + c[1]; c++; h = expand_char(i); break; case '*': c++; if (*c == '(') { c++; i = c[0] * 256 + c[1]; c++; } else i = *c * 256 + ' '; h = expand_string(i); break; case 'f': c++; if (*c == '\\') { c++; c = scan_escape(c); c--; i = intresult; } else if (*c != '(') i = *c; else { c++; i = c[0] * 256 + c[1]; c++; } if (!skip_escape) h = change_to_font(i); else h = ""; break; case 's': c++; j = 0; i = 0; if (*c == '-') { j = -1; c++; } else if (*c == '+') { j = 1; c++; } if (*c == '0') c++; else if (*c == '\\') { c++; c = scan_escape(c); i = intresult; if (!j) j = 1; } else while (isdigit(*c) && (!i || (!j && i < 4))) i = i * 10 + (*c++) - '0'; if (!j) { j = 1; if (i) i = i - 10; } if (!skip_escape) h = change_to_size(i * j); else h = ""; c--; break; case 'n': c++; j = 0; switch (*c) { case '+': j = 1; c++; break; case '-': j = -1; c++; break; default: break; } if (*c == '(') { c++; i = V(c[0], c[1]); c = c + 1; } else { i = V(c[0], ' '); } intd = intdef; while (intd && intd->nr != i) intd = intd->next; if (intd) { intd->val = intd->val + j * intd->incr; intresult = intd->val; } else { switch (i) { case V('.', 's'): intresult = current_size; break; case V('.', 'f'): intresult = current_font; break; default: intresult = 0; break; } } h = ""; break; case 'w': c++; i = *c; c++; exoutputp = output_possible; exskipescape = skip_escape; output_possible = 0; skip_escape = 1; j = 0; while (*c != i) { j++; if (*c == escapesym) c = scan_escape(c + 1); else c++; } output_possible = exoutputp; skip_escape = exskipescape; intresult = j; break; case 'l': h = "<HR>"; curpos = 0; case 'b': case 'v': case 'x': case 'o': case 'L': case 'h': c++; i = *c; c++; exoutputp = output_possible; exskipescape = skip_escape; output_possible = 0; skip_escape = 1; while (*c != i) if (*c == escapesym) c = scan_escape(c + 1); else c++; output_possible = exoutputp; skip_escape = exskipescape; break; case 'c': no_newline_output = 1; break; case '{': newline_for_fun++; h = ""; break; case '}': if (newline_for_fun) newline_for_fun--; h = ""; break; case 'p': h = "<BR>\n"; curpos = 0; break; case 't': h = "\t"; curpos = (curpos + 8) & 0xfff8; break; case '<': h = "<"; curpos++; break; case '>': h = ">"; curpos++; break; case '\\': if (single_escape) { c--; break; } default: b[0] = *c; b[1] = 0; h = b; curpos++; break; } c++; if (!skip_escape) out_html(h); return c;}typedef struct TABLEITEM TABLEITEM;struct TABLEITEM { char *contents; int size, align, valign, colspan, rowspan, font, vleft, vright, space, width; TABLEITEM *next;};static TABLEITEM emptyfield = {NULL, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, NULL};typedef struct TABLEROW TABLEROW;struct TABLEROW { TABLEITEM *first; TABLEROW *prev, *next;};static char *tableopt[] = { "center", "expand", "box", "allbox", "doublebox", "tab", "linesize", "delim", NULL};static int tableoptl[] = {6, 6, 3, 6, 9, 3, 8, 5, 0};static voidclear_table(TABLEROW * table){ TABLEROW *tr1, *tr2; TABLEITEM *ti1, *ti2; tr1 = table; while (tr1->prev) tr1 = tr1->prev; while (tr1) { ti1 = tr1->first; while (ti1) { ti2 = ti1->next; if (ti1->contents) free(ti1->contents); free(ti1); ti1 = ti2; } tr2 = tr1; tr1 = tr1->next; free(tr2); }}static char *scan_expression(char *c, int *result);static char *scan_format(char *c, TABLEROW ** result, int *maxcol){ TABLEROW *layout, *currow; TABLEITEM *curfield; int i, j; if (*result) { clear_table(*result); } layout = currow = (TABLEROW *) malloc(sizeof(TABLEROW)); currow->next = currow->prev = NULL; currow->first = curfield = (TABLEITEM *) malloc(sizeof(TABLEITEM)); *curfield = emptyfield; while (*c && *c != '.') { switch (*c) { case 'C': case 'c': case 'N': case 'n': case 'R': case 'r': case 'A': case 'a': case 'L': case 'l': case 'S': case 's': case '^': case '_': if (curfield->align) { curfield->next = (TABLEITEM *) malloc(sizeof(TABLEITEM)); curfield = curfield->next; *curfield = emptyfield; } curfield->align = toupper(*c); c++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -