📄 pass2.c
字号:
ordinary_char: if (Str2word(s1, 1) != 0) return; Wordl++; if (*s1 == '.' || *s1 == '!' || *s1 == '?' || *s1 == ':') period = '.'; else if (period == '.') { nm[0] = *s1; nm[1] = '\0'; if (regexec(Pat[13].pat, nm) == 0) period = '\0'; } } } /* * End of line processing */ if (!Backc) { if (period == '.') Pass3(NOBREAK, (unsigned char *)"gap", NULL, 2); if (Centering > 0) { Pass3(DOBREAK, (unsigned char *)"center", NULL, 0); Centering--; } else if (!Fill) Pass3(DOBREAK, (unsigned char *)"flush", NULL, 0); } if (Aftnxt == NULL) return; /* else fall through to process an "after next trap */ } /* * Special -man macro handling. */ if (Marg == MANMACROS) { /* * A text line - "^[^.]" - is only processed when there is an * "after next" directive. */ if (*line != '.' && *line != '\'') { if (Aftnxt != NULL) { if (regexec(Pat[9].pat, Aftnxt)) /* ",fP" */ Font[0] = Prevfont; if (regexec(Pat[16].pat, Aftnxt)) /* ",fR" */ Font[0] = 'R'; if (regexec(Pat[10].pat, Aftnxt)) /* ",tP" */ Pass3(DOBREAK, (unsigned char *)"toindent", NULL, 0); Free(&Aftnxt); } return; } /* * Special footer handling - "^.lF" */ if (line[1] == 'l' && line[2] == 'F') { s1 = Findstr((unsigned char *)"by", NULL, 0); s2 = Findstr((unsigned char *)"nb", NULL, 0); if (*s1 == '\0' || *s2 == '\0') (void) sprintf((char *)buf, "%s%s", (char *)s1, (char *)s2); else (void) sprintf((char *)buf, "%s; %s", (char *)s1, (char *)s2); Pass3(NOBREAK, (unsigned char *)"LF", buf, 0); return; } } /* * Special -ms macro handling. */ if (Marg == MSMACROS) { /* * A text line - "^[^.]" - is only processed when there is an * "after next" directive. */ if (*line != '.' && *line != '\'') { if (Aftnxt != NULL) { if (regexec(Pat[10].pat, Aftnxt)) /* ",tP" */ Pass3(DOBREAK, (unsigned char *)"toindent", NULL, 0); Free(&Aftnxt); } return; } /* * Numbered headings - "^[.']nH" */ if (line[1] == 'n' && line[2] == 'H') { s1 = Field(2, line, 0); if (s1 != NULL) { i = atoi((char *)s1) - 1; if (i < 0) { for (j = 0; j < MAXNHNR; j++) { Nhnr[j] = 0; } i = 0; } else if (i >= MAXNHNR) { (void) sprintf((char *)buf, " over NH limit (%d)", MAXNHNR); Error(WARN, LINE, (char *)buf, NULL); } } else i = 0; Nhnr[i]++; for (j = i + 1; j < MAXNHNR; j++) { Nhnr[j] = 0; } s1 = buf; for (j = 0; j <= i; j++) { (void) sprintf((char *)s1, "%d.", Nhnr[j]); s1 = buf + strlen((char *)buf); } (void) Findstr((unsigned char *)"Nh", buf, 1); return; } } /* * Remaining lines should begin with a '.' or '\'' unless an "after next" * trap has failed. */ if (*line != '.' && *line != '\'') { if (Aftnxt != NULL) Error(WARN, LINE, " failed .it: ", (char *)Aftnxt); else Error(WARN, LINE, " unrecognized line ", NULL); return; } brk = (*line == '.') ? DOBREAK : NOBREAK; /* * Evaluate expressions for "^[.'](ta|ll|ls|in|ti|po|ne|sp|pl|nr)" * Then process the requests. */ if (regexec(Pat[11].pat, &line[1])) { /* * Establish default scale factor. */ if ((line[1] == 'n' && line[2] == 'e') || (line[1] == 's' && line[2] == 'p') || (line[1] == 'p' && line[2] == 'l')) exscale = Scalev; else if (line[1] == 'n' && line[2] == 'r') exscale = Scaleu; else exscale = Scalen; /* * Determine starting argument. */ if (line[1] == 'n' && line[2] == 'r') s1 = Field(2, &line[3], 0); else s1 = Field(1, &line[3], 0); /* * Evaluate expressions. */ for (nexpr = 0; s1 != NULL &&*s1 != '\0'; ) { while (*s1 == ' ' || *s1 == '\t') s1++; if (*s1 == '+' || *s1 == '-') ssign = *s1++; else ssign = '\0'; /* * Process terms. */ val = 0.0; sp = -1; c = '+'; s1--; while (c == '+' || c == '*' || c == '%' || c == ')' || c == '-' || c == '/') { op = c; s1++; tscale = exscale; tval = 0.0; /* * Pop stack on right parenthesis. */ if (op == ')') { tval = val; if (sp >= 0) { val = valstack[sp]; op = opstack[sp]; sp--; } else { Error(WARN, LINE, " expression stack underflow", NULL); return; } tscale = Scaleu; /* * Push stack on left parenthesis. */ } else if (*s1 == '(') { sp++; if (sp >= MAXSP) { Error(WARN, LINE, " expression stack overflow", NULL); return; } valstack[sp] = val; opstack[sp] = op; val = 0.0; c = '+'; continue; } else if (*s1 == '\\') { s1++; switch(*s1) { /* * "\\"" begins a comment. */ case '"': while (*s1) s1++; break; /* * Crude width calculation for "\\w" */ case 'w': s2 = ++s1; if (*s1) { s1++; while (*s1 && *s1 != *s2) s1++; tval = (double) (s1 - s2 - 1) * Scalen; if (*s1) s1++; } break; /* * Interpolate number register if "\\n". */ case 'n': s1 = Asmcode(&s1, nm); if ((i = Findnum(nm, 0, 0)) >= 0) tval = Numb[i].val; s1++; } /* * Assemble numeric value. */ } else if (*s1 == '.' || isdigit(*s1)) { for (i = 0; isdigit(*s1) || *s1 == '.'; s1++) { if (*s1 == '.') { i = 10; continue; } d = (double) (*s1 - '0'); if (i) { tval = tval + (d / (double) i); i = i * 10; } else tval = (tval * 10.0) + d; } } else { /* * It's not an expression. Ignore extra scale. */ if ((i = Findscale((int)*s1, 0.0, 0)) < 0) { (void) sprintf((char *)buf, " \"%s\" isn't an expression", (char *)s1); Error(WARN, LINE, (char *)buf, NULL); } s1++; } /* * Add term to expression value. */ if ((i = Findscale((int)*s1, 0.0, 0)) >= 0) { tval *= Scale[i].val; s1++; } else tval *= tscale; switch (op) { case '+': val += tval; break; case '-': val -= tval; break; case '*': val *= tval; break; case '/': case '%': i = (int) val; j = (int) tval; if (j == 0) { Error(WARN, LINE, (*s1 == '/') ? "div" : "mod", " by 0"); return; } if (op == '/') val = (double) (i / j); else val = (double) (i % j); break; } c = *s1; } /* * Save expression value and sign. */ if (nexpr >= MAXEXP) { (void) sprintf((char *)buf, " at expression limit of %d", MAXEXP); Error(WARN, LINE, (char *)buf, NULL); return; } exsign[nexpr] = ssign; expr[nexpr] = val; if (ssign == '-') sexpr[nexpr] = -1.0 * val; else sexpr[nexpr] = val; nexpr++; while (*s1 == ' ' || *s1 == '\t') s1++; } /* * Set parameters "(ll|ls|in|ti|po|pl)" */ if (regexec(Pat[12].pat, &line[1])) { nm[0] = line[1]; nm[1] = line[2]; if ((i = Findparms(nm)) < 0) { Error(WARN, LINE, " can't find parameter register ", (char *)nm); return; } if (nexpr == 0 || exscale == 0.0) j = Parms[i].prev; else if (exsign[0] == '\0' || (nm[0] == 't' && nm[1] == 'i')) j = (int)(sexpr[0] / exscale); else j = Parms[i].val + (int)(sexpr[0] / exscale); Parms[i].prev = Parms[i].val; Parms[i].val = j; nm[0] = (nexpr) ? exsign[0] : '\0'; /* for .ti */ nm[1] = '\0'; Pass3(brk, (unsigned char *)Parms[i].cmd, nm, j); return; } if (line[1] == 'n') { switch(line[2]) { /* * Need - "^[.']ne <expression>" */ case 'e': if (nexpr && Scalev > 0.0) i = (int) ((expr[0]/Scalev) + 0.99); else i = 0; Pass3(DOBREAK, (unsigned char *)"need", NULL, i); return; /* * Number - "^[.']nr <name> <expression>" */ case 'r': if ((s1 = Field(2, line, 0)) == NULL) { Error(WARN, LINE, " bad number register", NULL); return; } if ((i = Findnum(s1, 0, 0)) < 0) i = Findnum(s1, 0, 1); if (nexpr < 1) { Numb[i].val = 0; return; } if (exsign[0] == '\0') Numb[i].val = (int) expr[0]; else Numb[i].val += (int) sexpr[0]; return; } } /* * Space - "^[.']sp <expression>" */ if (line[1] == 's' && line[2] == 'p') { if (nexpr == 0) i = 1; else i = (int)((expr[0] / Scalev) + 0.99); while (i--) Pass3(brk, (unsigned char *)"space", NULL, 0); return; } /* * Tab positions - "^[.']ta <pos1> <pos2> . . ." */ if (line[1] == 't' && line[2] == 'a') { tval = 0.0; for (j = 0; j < nexpr; j++) { if (exsign[j] == '\0') tval = expr[j]; else tval += sexpr[j]; Tabs[j] = (int) (tval / Scalen); } Ntabs = nexpr; return; } } /* * Process all other nroff requests via Nreq(). */ (void) Nreq(line, brk); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -