[3ae31e9] | 1 | /*
|
---|
| 2 | ============================================================================
|
---|
| 3 | newline.c -- standard pagination functions
|
---|
| 4 | Version 6 -- 1988-11-02 -- D.N. Lynx Crowe
|
---|
| 5 | ============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "stdio.h"
|
---|
| 9 | #include "stddefs.h"
|
---|
| 10 | #include "pageparm.h"
|
---|
| 11 |
|
---|
| 12 | #ifndef VERSION
|
---|
| 13 | #define VERSION "0.00 (Experimental)"
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
| 16 | int pgmhdr(); /* forward declaration */
|
---|
| 17 |
|
---|
| 18 | /* variables for pagination functions */
|
---|
| 19 |
|
---|
| 20 | int npage = 1; /* current page number */
|
---|
| 21 | int nline = NLPAGE; /* current line number */
|
---|
| 22 | int nlpage = NLPAGE; /* number of lines per page */
|
---|
| 23 | int martop = MTOP; /* top margin size -- lines */
|
---|
| 24 | int marbot = MBOT; /* bottom margin size -- lines */
|
---|
| 25 | int marsize = MARGIN; /* left margin size -- characters */
|
---|
| 26 | int newsub = 1; /* flag for new sub-heading */
|
---|
| 27 | int minleft = MINLEFT; /* minimum remaining lines on the page */
|
---|
| 28 |
|
---|
| 29 | int (*prhead)() = pgmhdr; /* pointer to page heading routine */
|
---|
| 30 |
|
---|
| 31 | char *hdr = "?????"; /* pointer to program header (for pgmhdr) */
|
---|
| 32 | char *subhdg = ""; /* pointer to subheading */
|
---|
| 33 | char *verstr = VERSION; /* pointer to version string */
|
---|
| 34 |
|
---|
| 35 | FILE *printer; /* printer file pointer */
|
---|
| 36 |
|
---|
| 37 | /* |
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | /*
|
---|
| 41 | ============================================================================
|
---|
| 42 | newline(fp) -- advance line counter before printing a new line
|
---|
| 43 |
|
---|
| 44 | Invoke this function BEFORE printing a new line.
|
---|
| 45 |
|
---|
| 46 | Uses: nlpage = number of lines per page,
|
---|
| 47 | nline = current line number,
|
---|
| 48 | npage = current page number
|
---|
| 49 |
|
---|
| 50 | Invokes (*prhead)(fp) if nline overflows.
|
---|
| 51 |
|
---|
| 52 | Initialize:
|
---|
| 53 |
|
---|
| 54 | npage = 1,
|
---|
| 55 | nline = nlpage,
|
---|
| 56 | prhead = address of page heading routine
|
---|
| 57 |
|
---|
| 58 | before first line on page is printed.
|
---|
| 59 | ============================================================================
|
---|
| 60 | */
|
---|
| 61 |
|
---|
| 62 | newline(fp)
|
---|
| 63 | FILE *fp;
|
---|
| 64 | {
|
---|
| 65 | if (nline++ GE (nlpage - (martop + marbot))) {
|
---|
| 66 |
|
---|
| 67 | nline = 1; /* set current line number = 1 */
|
---|
| 68 | fprintf(fp, "\f"); /* force new page */
|
---|
| 69 | (*prhead)(fp); /* call page heading routine */
|
---|
| 70 | npage++; /* update page number */
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | /* |
---|
| 76 | */
|
---|
| 77 |
|
---|
| 78 | /*
|
---|
| 79 | ============================================================================
|
---|
| 80 | margin(fp) -- print spaces for a left margin
|
---|
| 81 |
|
---|
| 82 | marsize = number of blanks for left margin
|
---|
| 83 | ============================================================================
|
---|
| 84 | */
|
---|
| 85 |
|
---|
| 86 | margin(fp)
|
---|
| 87 | FILE *fp;
|
---|
| 88 | {
|
---|
| 89 | int n;
|
---|
| 90 |
|
---|
| 91 | for (n = 0; n < marsize; n++)
|
---|
| 92 | putc(' ', fp);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | /* |
---|
| 96 | */
|
---|
| 97 |
|
---|
| 98 | /*
|
---|
| 99 | ============================================================================
|
---|
| 100 | pgmhdr(fp) -- print program header
|
---|
| 101 |
|
---|
| 102 | Prints a standard 2+martop line program heading
|
---|
| 103 | including version and page number on the second line.
|
---|
| 104 |
|
---|
| 105 | hdr = pointer to program heading line (must include a newline)
|
---|
| 106 | ============================================================================
|
---|
| 107 | */
|
---|
| 108 |
|
---|
| 109 | pgmhdr(fp)
|
---|
| 110 | FILE *fp;
|
---|
| 111 | {
|
---|
| 112 | int n;
|
---|
| 113 |
|
---|
| 114 | for (n = 0; n < martop; n++) {
|
---|
| 115 | fprintf(fp, "\n");
|
---|
| 116 | nline++;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | margin(fp);
|
---|
| 120 | fprintf(fp, "%s\n", hdr);
|
---|
| 121 | nline++;
|
---|
| 122 |
|
---|
| 123 | margin(fp);
|
---|
| 124 | fprintf(fp, "Version %s Page %4.4d\n\n",
|
---|
| 125 | verstr, npage);
|
---|
| 126 | nline++;
|
---|
| 127 | nline++;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 | /* |
---|
| 132 | */
|
---|
| 133 |
|
---|
| 134 | /*
|
---|
| 135 | ============================================================================
|
---|
| 136 | skipnl(fp, n) -- output n newlines to fp
|
---|
| 137 | ============================================================================
|
---|
| 138 | */
|
---|
| 139 |
|
---|
| 140 | skipnl(fp, n)
|
---|
| 141 | FILE *fp;
|
---|
| 142 | int n;
|
---|
| 143 | {
|
---|
| 144 | int j;
|
---|
| 145 |
|
---|
| 146 | if (n LE 0)
|
---|
| 147 | return;
|
---|
| 148 |
|
---|
| 149 | for (j = 0; j < n; j++) {
|
---|
| 150 |
|
---|
| 151 | newline(fp);
|
---|
| 152 | fprintf(fp, "\n");
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | /* |
---|
| 157 | */
|
---|
| 158 |
|
---|
| 159 | /*
|
---|
| 160 | ============================================================================
|
---|
| 161 | subhdr(fp) -- standard subheading function
|
---|
| 162 | ============================================================================
|
---|
| 163 | */
|
---|
| 164 |
|
---|
| 165 | subhdr(fp)
|
---|
| 166 | FILE *fp;
|
---|
| 167 | {
|
---|
| 168 | if (newsub) { /* new sub-heading */
|
---|
| 169 |
|
---|
| 170 | newsub = FALSE;
|
---|
| 171 | newline(fp);
|
---|
| 172 | newline(fp);
|
---|
| 173 | margin(fp);
|
---|
| 174 | fprintf(fp, "%s\n\n", subhdg);
|
---|
| 175 |
|
---|
| 176 | } else { /* continuation of old sub heading */
|
---|
| 177 |
|
---|
| 178 | newline(fp);
|
---|
| 179 | newline(fp);
|
---|
| 180 | margin(fp);
|
---|
| 181 | fprintf(fp, "%s -- Continued\n\n", subhdg);
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | /* |
---|
| 186 | */
|
---|
| 187 |
|
---|
| 188 | /*
|
---|
| 189 | ============================================================================
|
---|
| 190 | heading(fp) -- standard heading function
|
---|
| 191 | ============================================================================
|
---|
| 192 | */
|
---|
| 193 |
|
---|
| 194 | heading(fp)
|
---|
| 195 | FILE *fp;
|
---|
| 196 | {
|
---|
| 197 | newline(fp);
|
---|
| 198 | pgmhdr(fp);
|
---|
| 199 | subhdr(fp);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /* |
---|
| 203 | */
|
---|
| 204 |
|
---|
| 205 | /*
|
---|
| 206 | ============================================================================
|
---|
| 207 | newsect(fp) -- standard new section function
|
---|
| 208 |
|
---|
| 209 | Invoke to begin a new section BEFORE printing the first line of the
|
---|
| 210 | section, and BEFORE calling newline(). For example,
|
---|
| 211 |
|
---|
| 212 | subhdg = "Sub-heading for this section.";
|
---|
| 213 | newsect(fp);
|
---|
| 214 | newline(fp);
|
---|
| 215 | printf(fp, "your line goes here");
|
---|
| 216 |
|
---|
| 217 | This will force a page break if there are not at least 'minleft'
|
---|
| 218 | left on the page.
|
---|
| 219 | ============================================================================
|
---|
| 220 | */
|
---|
| 221 |
|
---|
| 222 | newsect(fp)
|
---|
| 223 | FILE *fp;
|
---|
| 224 | {
|
---|
| 225 | newsub = TRUE;
|
---|
| 226 |
|
---|
| 227 | if (nline NE nlpage) {
|
---|
| 228 |
|
---|
| 229 | if (nline > (nlpage - minleft))
|
---|
| 230 | nline = nlpage;
|
---|
| 231 | else
|
---|
| 232 | subhdr(fp);
|
---|
| 233 | }
|
---|
| 234 | }
|
---|