source: buchla-68k/orig/GP/NEWLINE.C@ 08e1da1

Last change on this file since 08e1da1 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 5.0 KB
RevLine 
[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
16int pgmhdr(); /* forward declaration */
17
18/* variables for pagination functions */
19
20int npage = 1; /* current page number */
21int nline = NLPAGE; /* current line number */
22int nlpage = NLPAGE; /* number of lines per page */
23int martop = MTOP; /* top margin size -- lines */
24int marbot = MBOT; /* bottom margin size -- lines */
25int marsize = MARGIN; /* left margin size -- characters */
26int newsub = 1; /* flag for new sub-heading */
27int minleft = MINLEFT; /* minimum remaining lines on the page */
28
29int (*prhead)() = pgmhdr; /* pointer to page heading routine */
30
31char *hdr = "?????"; /* pointer to program header (for pgmhdr) */
32char *subhdg = ""; /* pointer to subheading */
33char *verstr = VERSION; /* pointer to version string */
34
35FILE *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
62newline(fp)
63FILE *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
86margin(fp)
87FILE *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
109pgmhdr(fp)
110FILE *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
140skipnl(fp, n)
141FILE *fp;
142int 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
165subhdr(fp)
166FILE *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
194heading(fp)
195FILE *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
222newsect(fp)
223FILE *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}
Note: See TracBrowser for help on using the repository browser.