Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
/*
|
|
|
|
print.c
|
|
|
|
|
|
|
|
the code that formats each individual paragraph is here.
|
|
|
|
|
1999-01-15 15:45:04 +00:00
|
|
|
$Id: print.c,v 1.3 1999/01/15 15:45:04 gdr-ftp Exp $
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <types.h>
|
|
|
|
#include <texttool.h>
|
1999-01-15 15:45:04 +00:00
|
|
|
#include "aroff.h"
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
extern saveArray *docSaveArray;
|
|
|
|
extern Ruler *docRulers;
|
|
|
|
extern textBlock **docTextBlocks; /* an array of textBlockPtrs */
|
|
|
|
extern word docSACount, numRulers, numBlocks;
|
|
|
|
|
|
|
|
/*
|
|
|
|
1 2
|
|
|
|
01234567890123456 7890
|
|
|
|
This is a bloody ^car
|
|
|
|
z = 16;
|
|
|
|
|
|
|
|
This is a bloody
|
|
|
|
^car
|
|
|
|
|
|
|
|
col=4 (width - z - 1)
|
|
|
|
printcol=3
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 100 lines should be more than enough */
|
|
|
|
char paraBuf[100][80];
|
|
|
|
|
|
|
|
|
|
|
|
/* given a paragraph, and a pointer to it's ruler, format the
|
|
|
|
paragraph according to the ruler. */
|
|
|
|
void printPara(RulerPtr ruler, pgraphPtr pptr)
|
|
|
|
{
|
1999-01-15 08:36:31 +00:00
|
|
|
char *txt;
|
|
|
|
int width,z;
|
|
|
|
int curLine, col, printcol, numctrl;
|
|
|
|
int i,left,style;
|
|
|
|
|
|
|
|
curLine = col = printcol = 0;
|
|
|
|
txt = ((char *)pptr) + sizeof(pgraph);
|
|
|
|
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
calcLine:
|
|
|
|
/* width determines how long this line is in characters; thus, where
|
|
|
|
the break for word wrap will occur */
|
1999-01-15 15:45:04 +00:00
|
|
|
if (curLine == 0) {
|
|
|
|
width = (ruler->rightMargin - ruler->indentMargin)/8;
|
|
|
|
} else {
|
|
|
|
width = (ruler->rightMargin - ruler->leftMargin)/8;
|
|
|
|
}
|
|
|
|
|
1999-01-15 08:36:31 +00:00
|
|
|
while (*txt != 0x0d) {
|
|
|
|
switch (*txt) {
|
|
|
|
case 1: txt+=3; break;
|
|
|
|
case 2:
|
|
|
|
style = *(++txt);
|
1999-01-15 15:45:04 +00:00
|
|
|
if (noboldflag) { /* turn off boldfacing */
|
|
|
|
++txt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (style & 3) {
|
|
|
|
paraBuf[curLine][col++] = 15;
|
|
|
|
} else {
|
|
|
|
paraBuf[curLine][col++] = 14;
|
|
|
|
}
|
1999-01-15 08:36:31 +00:00
|
|
|
txt++;
|
|
|
|
break;
|
|
|
|
case 3: txt+=2; break;
|
|
|
|
case 4: txt+=2; break;
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7: break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (printcol == width) {
|
|
|
|
numctrl = 0;
|
|
|
|
for (z = col - 1; z > 0; z--) {
|
|
|
|
if (paraBuf[curLine][z] == ' ') {
|
1999-01-15 15:45:04 +00:00
|
|
|
if (z != col - 1) {
|
1999-01-15 08:36:31 +00:00
|
|
|
memcpy(¶Buf[curLine+1][0],¶Buf[curLine][z+1],
|
|
|
|
(size_t) (col - z - 1));
|
1999-01-15 15:45:04 +00:00
|
|
|
}
|
1999-01-15 08:36:31 +00:00
|
|
|
paraBuf[curLine][z] = 0;
|
|
|
|
curLine++; printcol -= (z + 1 + numctrl);
|
|
|
|
col -= (z + 1);
|
|
|
|
goto calcLine;
|
1999-01-15 15:45:04 +00:00
|
|
|
} else if (paraBuf[curLine][z] < ' ') {
|
|
|
|
numctrl++;
|
1999-01-15 08:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
curLine++; col = printcol = 0;
|
|
|
|
/* one big word... don't break line */
|
|
|
|
goto calcLine;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
1999-01-15 08:36:31 +00:00
|
|
|
paraBuf[curLine][col] = *(txt++);
|
|
|
|
printcol++; col++;
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
1999-01-15 08:36:31 +00:00
|
|
|
}
|
|
|
|
paraBuf[curLine][col] = 0;
|
|
|
|
for (z = 0; z <= curLine; z++) {
|
|
|
|
if (z == 0) {
|
|
|
|
width = (ruler->rightMargin - ruler->indentMargin)/8;
|
|
|
|
left = (ruler->indentMargin)/8;
|
1999-01-15 15:45:04 +00:00
|
|
|
} else {
|
1999-01-15 08:36:31 +00:00
|
|
|
width = (ruler->rightMargin - ruler->leftMargin)/8;
|
|
|
|
left = (ruler->leftMargin)/8;
|
|
|
|
}
|
1999-01-15 15:45:04 +00:00
|
|
|
for (i = 0; i < left; i++) {
|
|
|
|
putchar(' ');
|
|
|
|
}
|
1999-01-15 08:36:31 +00:00
|
|
|
printf("%s\n",paraBuf[z]);
|
|
|
|
}
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this is an obsolete routine that prints a paragraph with no
|
|
|
|
formatting at all */
|
|
|
|
#ifdef NOTDEFINED
|
|
|
|
void printPara(RulerPtr ruler, pgraphPtr pptr)
|
|
|
|
{
|
1999-01-15 08:36:31 +00:00
|
|
|
char *txt;
|
|
|
|
|
|
|
|
txt = ((char *)pptr) + sizeof(pgraph);
|
|
|
|
while (*txt != 0x0D) {
|
|
|
|
switch (*txt) {
|
|
|
|
case 1: txt+=2; break;
|
|
|
|
case 2: txt++; break;
|
|
|
|
case 3: txt++; break;
|
|
|
|
case 4: txt++; break;
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7: break;
|
|
|
|
|
|
|
|
default: putchar(*txt);
|
|
|
|
}
|
|
|
|
txt++;
|
|
|
|
}
|
|
|
|
putchar('\n');
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* go through each textBlock, sending each paragraph in turn to printPara. */
|
|
|
|
|
|
|
|
void printAWGS(void)
|
|
|
|
{
|
1999-01-15 08:36:31 +00:00
|
|
|
int z;
|
|
|
|
pgraphPtr pptr;
|
|
|
|
char *txt;
|
|
|
|
char x;
|
|
|
|
|
|
|
|
for (z = 0; z < docSACount; z++) {
|
|
|
|
pptr = (pgraphPtr) (((byte *)docTextBlocks[docSaveArray[z].textBlock])
|
|
|
|
+ docSaveArray[z].offset);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1999-01-15 08:36:31 +00:00
|
|
|
fprintf(stderr, "[%d] offset %d paragraph : %08lX", z,
|
|
|
|
docSaveArray[z].offset, pptr);
|
|
|
|
fprintf(stderr, " textBlock: %08lX\n",
|
|
|
|
docTextBlocks[docSaveArray[z].textBlock]);
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
#endif
|
1999-01-15 08:36:31 +00:00
|
|
|
printPara(&docRulers[docSaveArray[z].rulerNum],pptr);
|
|
|
|
}
|
Initial checkin of aroff, binprint, center, less, ls, make, makemake,
passwd, ps, purge, shutdown, stty, upper, and vi. These sources are
for the versions of the utils shipped with GNO v2.0.4.
1998-03-09 08:30:21 +00:00
|
|
|
}
|