8000 minix/minix/commands/cawf/pass3.c at R3.3.0 · fyy3/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
614 lines (591 loc) · 12.9 KB

pass3.c

File metadata and controls

614 lines (591 loc) · 12.9 KB
Outlx += i;
Outll += Eollen;
}
/*
* Trim trailing spaces from the output line.
*/
while (Outlx > 0) {
if (Outln[Outlx - 1] != ' ')
break;
if (Padx > 0 && (Outlx - 1) == Padchar[Padx - 1])
Padx--;
Outlx--;
Outln[Outlx] = '\0';
Outll--;
}
if (Outlx == 0)
Charput((int)'\n');
else if (len == DOBREAK && strcmp((char *)word, "center") == 0)
{
/*
* Center the output line.
*/
i = (LL - Pgoff - Outll) / 2;
if (i < 0)
i = 0;
for (j = (Pgoff + Ind + Tind + i); j; j--)
Charput((int)' ');
Stringput(Outln);
Charput((int)'\n');
} else if (Adj == LEFTADJ
|| (Adj == BOTHADJ && (len < 0 || Padx == 0))) {
/*
* No right margin adjustment - disabled, inappropriate
* (line ended by break) or impossible.
*/
for (i = 0; i < (Pgoff + Ind + Tind); i++)
Charput((int)' ');
Stringput(Outln);
Charput((int)'\n');
} else if (Adj == BOTHADJ) {
/*
* Adjust right margin.
*/
for (i = 0; i < (Pgoff + Ind + Tind); i++)
Charput((int)' ');
i = LL - (Pgoff + Ind + Tind);
j = i - Outll;
addto = Padx ? (j / Padx) : 0;
xsp = j - (Padx * addto);
for (i = 0, s1 = Outln; i < Padx; i++) {
while (*s1 && (s1 - Outln) <= Padchar[i])
Charput((int)*s1++);
if (*s1 == '\0')
break;
j = addto;
if (Padfrom == PADLEFT) {
if (i < xsp)
j++;
} else if (i >= (Padx - xsp))
j++;
while (j-- > 0)
Charput((int)' ');
}
while (*s1)
Charput((int)*s1++);
Charput((int)'\n');
Padfrom = (Padfrom == PADLEFT) ? PADRIGHT : PADLEFT;
}
/*
* End of line housekeeping
*/
Nxtln++;
Outll = -1;
Outlx = 0;
Padx = 0;
Tind = 0;
Nospmode = 0;
if (vsp == 0 && len == DOBREAK
&& strcmp((char *)word, "need") == 0) {
/*
* Break caused by "need" - satisfy it.
*/
while (Nxtln < (Pglen + 1 - Botmarg)) {
Charput((int)'\n');
Nxtln++;
}
}
if (Nxtln >= (Pglen + 1 - Botmarg)) {
/*
* Footer required
*/
for (i = (Botmarg - 1)/2; i > 0; i--) {
Charput((int)'\n');
Nxtln++;
}
i = LenprtHF(Ftl, Thispg, 0) + LenprtHF(Ftc, Thispg, 0)
+ LenprtHF(Ftr, Thispg, 0) + 2;
j = (LL - i - Pgoff) / 2 + 1;
n = LL - Pgoff - i - j + 2;
for (k = 0; k < Pgoff; k++)
Charput((int)' ');
if (Ftl)
LenprtHF(Ftl, Thispg, 1);
while (j-- > 0)
Charput((int)' ');
if (Ftc)
LenprtHF(Ftc, Thispg, 1);
while (n-- > 0)
Charput((int)' ');
if (Ftr)
LenprtHF(Ftr, Thispg, 1);
Charput((int)'\n');
Nxtln++;
/*
* The last blank line on the page is suppressed to assist
* printers that can't look ahead to the following FF.
*/
while (Nxtln < Pglen) {
Charput((int)'\n');
Nxtln++;
}
Nxtln = 1;
Thispg++;
Nospmode = 1;
Padfrom = PADRIGHT;
}
/*
* Initiate any extra vertical spacing.
*/
if (++vsp < Vspace)
goto print_line;
/*
* Save any input word that might have forced output.
*/
if (len >= 0) {
(void) strcpy((char *)Outln, (char *)word);
Outll = len;
Outlx = wl;
Padx = 0;
}
}
/*
* A break causes padding reversal.
*/
if (len == DOBREAK)
Padfrom = PADRIGHT;
if (len >= 0 || strcmp((char *)word, "nohyphen") == 0) {
/*
* Reset continuation and hyphenation.
*/
if (Contlen != 1 || Cont[0] != ' ') {
Free(&Cont);
Cont = Newstr((unsigned char *)" ");
Contlen = 1;
}
if (Eollen > 0) {
Free(&Eol);
Eollen = 0;
}
return;
}
/*
* Now post-process any special commands.
*/
if (len == MESSAGE) {
Error3(len, (char *)word, (char *)sarg, narg, NULL);
return;
}
switch (*word) {
case 'b': /* both */
/*
* Adjust on both margins.
*/
Adj = BOTHADJ;
return;
case 'c': /* center */
return;
case 'e': /* errsto */
/*
* "errsto" comes from awf.
*/
return;
case 'f': /* flush and fph */
if (word[1] == 'l')
return;
else if (word[1] == 'p') {
/*
* First page header status
*/
Fph = narg;
return;
}
break;
case 'g': /* gap */
/*
* Increase word gap. (Space is not paddable.)
*/
if (Outll >= 0) {
if ((Outlx + narg - 1) >= MAXOLL)
goto line_too_big;
for (i = 0; i < (narg - 1); i++) {
Outln[Outlx++] = ' ';
Outll++;
}
}
return;
case 'h': /* hyphen */
/*
* Set discretionary hyphen.
*/
Free(&Cont);
Contlen = 0;
Free(&Eol);
Eol = (sarg != NULL) ? Newstr(sarg) : NULL;
Eollen = narg;
return;
case 'i': /* indent */
/*
* Set indentation.
*/
Ind = narg;
return;
case 'l': /* left or linelen */
if (word[1] == 'e') {
/*
* Adjust on left margin.
*/
Adj = LEFTADJ;
return;
} else if (word[1] == 'i') {
/*
* Set line length.
*/
LL = narg;
return;
}
break;
case 'n': /* need or nospace */
if (word[1] == 'e')
return; /* need */
else if (word[1] == 'o') {
/*
* Set no space mode.
*/
Nospmode = 1;
return;
}
break;
case 'p': /* pagelen or pageoffset */
if (strncmp((char *)&word[1], "age", 3) != 0)
break;
if (word[4] == 'l') {
/*
* Set page length.
*/
Pglen = narg;
return;
} else if (word[4] == 'o') {
/*
* Set page offset.
*/
Pgoff = narg;
return;
}
break;
case 's': /* space */
if (sp) {
/*
* Restore values after NOBREAK spacing ("^'sp").
*/
Outlx = sp_Outlx;
Outln[0] = sp_Outln;
Padx = sp_Padx;
Outll = sp_Outll;
Tind = sp_Tind;
return;
}
if (Nospmode == 0) {
if (len == NOBREAK) {
/*
* Set up for NOBREAK spacing.
*/
sp_Outlx = Outlx;
sp_Outln = Outln[0];
sp_Padx = Padx;
sp_Outll = Outll;
sp_Tind = Tind;
vsp = Vspace + 1;
sp = 1;
}
/*
* Generate a blank line.
*/
Outlx = 0;
Outln[0] = '\0';
Padx = 0;
Outll = LL - 1;
if (sp)
goto print_line;
}
return;
case 't': /* tabto, tempindent, or
* toindent */
if (word[1] == 'a') {
/*
* Move to TAB stop.
*/
if (Outll < 0)
Outll = 0;
if ((n = narg - Outll) > 0) {
if ((Outlx + n) >= MAXOLL)
goto line_too_big;
Outll += n;
for (i = n; i > 0; i--)
Outln[Outlx++] = ' ';
Free(&Cont);
Contlen = 0;
Padx = 0;
}
return;
} else if (word[1] == 'e') {
/*
* Set temporary indentation.
*/
if (*sarg == '\0' && narg >= 0)
Tind = narg - Ind;
else
Tind = ((Ind + narg) >= 0) ? narg : -Ind;
return;
} else if (word[1] == 'o')
return; /* toindent */
break;
case 'u': /* userhyphen */
/*
* Set line length.
*/
Free(&Cont);
Free(&Eol);
Contlen = Eollen = narg;
Cont = (sarg == NULL) ? NULL : Newstr(sarg);
Eol = (sarg == NULL) ? NULL : Newstr(sarg);
return;
case 'v': /* vspace */
/*
* Set vertical spacing.
*/
Vspace = (narg == 0) ? 1 : narg;
return;
case 'y': /* yesspace */
/*
* Set space mode.
*/
Nospmode = 0;
return;
} /* end of switch(*word) */
/*
* Locate header and footer defintions.
*/
if (regexec(Pat[14].pat, word)) {
if (strcmp((char *)word, "LH") == 0) {
/*
* Left header
*/
Free(&Hdl);
if (sarg != NULL)
Hdl = Newstr(sarg);
return;
}
if (strcmp((char *)word, "CH") == 0) {
/*
* Center header
*/
Free(&Hdc);
if (sarg != NULL)
Hdc = Newstr(sarg);
return;
}
if (strcmp((char *)word, "RH") == 0) {
/*
* Right header
*/
Free(&Hdr);
if (sarg != NULL)
Hdr = Newstr(sarg);
return;
4DD8
}
if (strcmp((char *)word, "LF") == 0) {
/*
* Left footer
*/
Free(&Ftl);
if (sarg != NULL)
Ftl = Newstr(sarg);
return;
}
if (strcmp((char *)word, "CF") == 0) {
/*
* Center footer
*/
Free(&Ftc);
if (sarg != NULL)
Ftc = Newstr(sarg);
return;
}
if (strcmp((char *)word, "RF") == 0) {
/*
* Right footer
*/
Free(&Ftr);
if (sarg != NULL)
Ftr = Newstr(sarg);
return;
}
}
/*
* Error on unknown arguments
*/
Error3(len, (char *)word, (char *)sarg, narg, "unknown request");
}
0