⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 man2html.c

📁 android-w.song.android.widget
💻 C
📖 第 1 页 / 共 5 页
字号:
			break;		case 'i':		case 'I':		case 'B':		case 'b':			curfield->font = toupper(*c);			c++;			break;		case 'f':		case 'F':			c++;			curfield->font = toupper(*c);			c++;			if (!isspace(*c))				c++;			break;		case 't':		case 'T':			curfield->valign = 't';			c++;			break;		case 'p':		case 'P':			c++;			i = j = 0;			if (*c == '+') {				j = 1;				c++;			}			if (*c == '-') {				j = -1;				c++;			}			while (isdigit(*c))				i = i * 10 + (*c++) - '0';			if (j)				curfield->size = i * j;			else				curfield->size = j - 10;			break;		case 'v':		case 'V':		case 'w':		case 'W':			c = scan_expression(c + 2, &curfield->width);			break;		case '|':			if (curfield->align)				curfield->vleft++;			else				curfield->vright++;			c++;			break;		case 'e':		case 'E':			c++;			break;		case '0':		case '1':		case '2':		case '3':		case '4':		case '5':		case '6':		case '7':		case '8':		case '9':			i = 0;			while (isdigit(*c))				i = i * 10 + (*c++) - '0';			curfield->space = i;			break;		case ',':		case '\n':			currow->next = (TABLEROW *) malloc(sizeof(TABLEROW));			currow->next->prev = currow;			currow = currow->next;			currow->next = NULL;			curfield = currow->first = (TABLEITEM *) malloc(sizeof(TABLEITEM));			*curfield = emptyfield;			c++;			break;		default:			c++;			break;		}	}	if (*c == '.')		while (*c++ != '\n');	*maxcol = 0;	currow = layout;	while (currow) {		curfield = layout->first;		i = 0;		while (curfield) {			i++;			curfield = curfield->next;		}		if (i > *maxcol)			*maxcol = i;		currow = currow->next;	}	*result = layout;	return c;}static TABLEROW *next_row(TABLEROW * tr){	if (tr->next) {		tr = tr->next;		if (!tr->next)			next_row(tr);		return tr;	} else {		TABLEITEM *ti, *ti2;		tr->next = (TABLEROW *) malloc(sizeof(TABLEROW));		tr->next->prev = tr;		ti = tr->first;		tr = tr->next;		tr->next = NULL;		if (ti)			tr->first = ti2 = (TABLEITEM *) malloc(sizeof(TABLEITEM));		else			tr->first = ti2 = NULL;		while (ti != ti2) {			*ti2 = *ti;			ti2->contents = NULL;			if ((ti = ti->next)) {				ti2->next = (TABLEITEM *) malloc(sizeof(TABLEITEM));			}			ti2 = ti2->next;		}		return tr;	}}static char itemreset[20] = "\\fR\\s0";static char *scan_table(char *c){	char   *t, *h, *g;	int     center = 0, expand = 0, box = 0, border = 0, linesize = 1;	int     i, j, maxcol = 0, finished = 0;	int     oldfont, oldsize, oldfillout;	char    itemsep = '\t';	TABLEROW *layout = NULL, *currow, *ftable;	TABLEITEM *curfield;	while (*c++ != '\n');	h = c;	if (*h == '.')		return c - 1;	oldfont = current_font;	oldsize = current_size;	oldfillout = fillout;	out_html(change_to_font(0));	out_html(change_to_size(0));	if (!fillout) {		fillout = 1;		out_html("</PRE>");	}	while (*h && *h != '\n')		h++;	if (h[-1] == ';') {		/* scan table options */		while (c < h) {			while (isspace(*c))				c++;			for (i = 0; tableopt[i] && strncmp(tableopt[i], c, tableoptl[i]); i++);			c = c + tableoptl[i];			switch (i) {			case 0:				center = 1;				break;			case 1:				expand = 1;				break;			case 2:				box = 1;				break;			case 3:				border = 1;				break;			case 4:				box = 2;				break;			case 5:				while (*c++ != '(');				itemsep = *c++;				break;			case 6:				while (*c++ != '(');				linesize = 0;				while (isdigit(*c))					linesize = linesize * 10 + (*c++) - '0';				break;			case 7:				while (*c != ')')					c++;			default:				break;			}			c++;		}		c = h + 1;	}	/* scan layout */	c = scan_format(c, &layout, &maxcol);	currow = layout;	next_row(currow);	curfield = layout->first;	i = 0;	while (!finished) {		/* search item */		h = c;		if ((*c == '_' || *c == '=') && (c[1] == itemsep || c[1] == '\n')) {			if (c[-1] == '\n' && c[1] == '\n') {				if (currow->prev) {					currow->prev->next = (TABLEROW *) malloc(sizeof(TABLEROW));					currow->prev->next->next = currow;					currow->prev->next->prev = currow->prev;					currow->prev = currow->prev->next;				} else {					currow->prev = layout = (TABLEROW *) malloc(sizeof(TABLEROW));					currow->prev->prev = NULL;					currow->prev->next = currow;				}				curfield = currow->prev->first =					(TABLEITEM *) malloc(sizeof(TABLEITEM));				*curfield = emptyfield;				curfield->align = *c;				curfield->colspan = maxcol;				curfield = currow->first;				c = c + 2;			} else {				if (curfield) {					curfield->align = *c;					do {						curfield = curfield->next;					} while (curfield && curfield->align == 'S');				}				if (c[1] == '\n') {					currow = next_row(currow);					curfield = currow->first;				}				c = c + 2;			}		} else if (*c == 'T' && c[1] == '{') {			h = c + 2;			c = strstr(h, "\nT}");			c++;			*c = '\0';			g = NULL;			scan_troff(h, 0, &g);			scan_troff(itemreset, 0, &g);			*c = 'T';			c += 3;			if (curfield) {				curfield->contents = g;				do {					curfield = curfield->next;				} while (curfield && curfield->align == 'S');			} else if (g)				free(g);			if (c[-1] == '\n') {				currow = next_row(currow);				curfield = currow->first;			}		} else if (*c == '.' && c[1] == 'T' && c[2] == '&' && c[-1] == '\n') {			TABLEROW *hr;			while (*c++ != '\n');			hr = currow;			currow = currow->prev;			hr->prev = NULL;			c = scan_format(c, &hr, &i);			hr->prev = currow;			currow->next = hr;			currow = hr;			next_row(currow);			curfield = currow->first;		} else if (*c == '.' && c[1] == 'T' && c[2] == 'E' && c[-1] == '\n') {			finished = 1;			while (*c++ != '\n');			if (currow->prev)				currow->prev->next = NULL;			currow->prev = NULL;			clear_table(currow);		} else if (*c == '.' && c[-1] == '\n' && !isdigit(c[1])) {			/*			 * skip troff request inside table (usually only .sp			 * )			 */			while (*c++ != '\n');		} else {			h = c;			while (*c && (*c != itemsep || c[-1] == '\\') &&			       (*c != '\n' || c[-1] == '\\'))				c++;			i = 0;			if (*c == itemsep) {				i = 1;				*c = '\n';			}			if (h[0] == '\\' && h[2] == '\n' &&			    (h[1] == '_' || h[1] == '^')) {				if (curfield) {					curfield->align = h[1];					do {						curfield = curfield->next;					} while (curfield && curfield->align == 'S');				}				h = h + 3;			} else {				g = NULL;				h = scan_troff(h, 1, &g);				scan_troff(itemreset, 0, &g);				if (curfield) {					curfield->contents = g;					do {						curfield = curfield->next;					} while (curfield && curfield->align == 'S');				} else if (g)					free(g);			}			if (i)				*c = itemsep;			c = h;			if (c[-1] == '\n') {				currow = next_row(currow);				curfield = currow->first;			}		}	}	/* calculate colspan and rowspan */	currow = layout;	while (currow->next)		currow = currow->next;	while (currow) {		TABLEITEM *ti, *ti1 = NULL, *ti2 = NULL;		ti = currow->first;		if (currow->prev)			ti1 = currow->prev->first;		while (ti) {			switch (ti->align) {			case 'S':				if (ti2) {					ti2->colspan++;					if (ti2->rowspan < ti->rowspan)						ti2->rowspan = ti->rowspan;				}				break;			case '^':				if (ti1)					ti1->rowspan++;			default:				if (!ti2)					ti2 = ti;				else {					do {						ti2 = ti2->next;					} while (ti2 && curfield->align == 'S');				}				break;			}			ti = ti->next;			if (ti1)				ti1 = ti1->next;		}		currow = currow->prev;	}	/* produce html output */	if (center)		out_html("<CENTER>");	if (box == 2)		out_html("<TABLE BORDER><TR><TD>");	out_html("<TABLE");	if (box || border) {		out_html(" BORDER");		if (!border)			out_html("><TR><TD><TABLE");		if (expand)			out_html(" WIDTH=100%");	}	out_html(">\n");	currow = layout;	while (currow) {		j = 0;		out_html("<TR VALIGN=top>");		curfield = currow->first;		while (curfield) {			if (curfield->align != 'S' && curfield->align != '^') {				out_html("<TD");				switch (curfield->align) {				case 'N':					curfield->space += 4;				case 'R':					out_html(" ALIGN=right");					break;				case 'C':					out_html(" ALIGN=center");				default:					break;				}				if (!curfield->valign && curfield->rowspan > 1)					out_html(" VALIGN=center");				if (curfield->colspan > 1) {					char    buf[5];					out_html(" COLSPAN=");					sprintf(buf, "%i", curfield->colspan);					out_html(buf);				}				if (curfield->rowspan > 1) {					char    buf[5];					out_html(" ROWSPAN=");					sprintf(buf, "%i", curfield->rowspan);					out_html(buf);				}				j = j + curfield->colspan;				out_html(">");				if (curfield->size)					out_html(change_to_size(curfield->size));				if (curfield->font)					out_html(change_to_font(curfield->font));				switch (curfield->align) {				case '=':					out_html("<HR><HR>");					break;				case '_':					out_html("<HR>");					break;				default:					if (curfield->contents)						out_html(curfield->contents);					break;				}				if (curfield->space)					for (i = 0; i < curfield->space; i++)						out_html("&nbsp;");				if (curfield->font)					out_html(change_to_font(0));				if (curfield->size)					out_html(change_to_size(0));				if (j >= maxcol && curfield->align > '@' && curfield->align != '_')					out_html("<BR>");				out_html("</TD>");			}			curfield = curfield->next;		}		out_html("</TR>\n");		currow = currow->next;	}	if (box && !border)		out_html("</TABLE>");	out_html("</TABLE>");	if (box == 2)		out_html("</TABLE>");	if (center)		out_html("</CENTER>\n");	else		out_html("\n");	if (!oldfillout)		out_html("<PRE>");	fillout = oldfillout;	out_html(change_to_size(oldsize));	out_html(change_to_font(oldfont));	return c;}static char *scan_expression(char *c, int *result){	int     value = 0, value2, j = 0, sign = 1, opex = 0;	char    oper = 'c';	if (*c == '!') {		c = scan_expression(c + 1, &value);		value = (!value);	} else if (*c == 'n') {		c++;		value = NROFF;	} else if (*c == 't') {		c++;		value = 1 - NROFF;	} else if (*c == '\'' || *c == '"' || *c < ' ' || (*c == '\\' && c[1] == '(')) {		/*		 * ?string1?string2? test if string1 equals string2.		 */		char   *st1 = NULL, *st2 = NULL, *h;		char   *tcmp = NULL;		char    sep;		sep = *c;		if (sep == '\\') {			tcmp = c;			c = c + 3;		}		c++;		h = c;		while (*c != sep && (!tcmp || strncmp(c, tcmp, 4)))			c++;		*c = '\n';		scan_troff(h, 1, &st1);		*c = sep;		if (tcmp)			c = c + 3;		c++;		h = c;		while (*c != sep && (!tcmp || strncmp(c, tcmp, 4)))			c++;		*c = '\n';		scan_troff(h, 1, &st2);		*c = sep;		if (!st1 && !st2)			value = 1;		else if (!st1 || !st2)			value = 0;		else			value = (!strcmp(st1, st2));		if (st1)			free(st1);		if (st2)			free(st2);		if (tcmp)			c = c + 3;		c++;	} else {		while (*c && !isspace(*c) && *c != ')') {			opex = 0;			switch (*c) {			case '(':				c = scan_expression(c + 1, &value2);				value2 = sign * value2;				opex = 1;				break;			case '.':			case '0':			case '1':			case '2':			case '3':			case '4':			case '5':			case '6':			case '7':			case '8':			case '9':{					int     num = 0, denum = 1;					value2 = 0;					while (isdigit(*c))						value2 = value2 * 10 + ((*c++) - '0');					if (*c == '.') {						c++;						while (isdigit(*c)) {							num = num * 10 + ((*c++) - '0');							denum = denum * 10;						}					}					if (isalpha(*c)) {						/* scale indicator */						switch (*c) {						case 'i':	/* inch -> 10pt */							value2 = value2 * 10 + (num * 10 + denum / 2) / denum;							num = 0;							break;						default:							break;						}						c++;					}					value2 = value2 + (num + denum / 2) / denum;					value2 = sign * value2;					opex = 1;					break;				}			case '\\':				c = scan_escape(c + 1);				value2 = intresult * sign;				if (isalpha(*c))					c++;	/* scale indicator */				opex = 1;				break;			case '-':				if (oper) {					sign = -1;					c++;					break;				}			case '>':			case '<':			case '+':			case '/':			case '*':			case '%':			case '&':			case '=':			case ':':				if (c[1] == '=')					oper = (*c++) + 16;				else					oper = *c;				c++;				break;			default:				c++;				break;			}			if (opex) {				sign = 1;				switch (oper) {				case 'c':					value = value2;					break;				case '-':					value = value - value2;					break;				case '+':					value = value + value2;					break;				case '*':					value = value * value2;					break;				case '/':					if (value2)						value = value / value2;					break;				case '%':					if (value2)						value = value % value2;					break;				case '<':					value = (value < value2);					break;				case '>':

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -