-
Notifications
You must be signed in to change notification settings - Fork 1
/
print.c
82 lines (66 loc) · 1.79 KB
/
print.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* $Id: print.c,v 1.2 1992/10/02 01:02:32 craigs Exp $
*
* This code was written by Craig Southeren whilst under contract
* to Computer Sciences of Australia, Systems Engineering Division.
* It has been kindly released by CSA into the public domain.
*
* Neither CSA or me guarantee that this source code is fit for anything,
* so use it at your peril. I don't even work for CSA any more, so
* don't bother them about it. If you have any suggestions or comments
* (or money, cheques, free trips =8^) !!!!! ) please contact me
* care of [email protected]
*
*/
#include "machdep.h"
#include "defs.h"
#include "print.h"
#include "paper.h"
#include "postscri.h"
#include "main.h"
/********************************
defines
********************************/
#define PAGEBREAK ('L' - 0x40)
/********************************
print_file
********************************/
void print_file (input, output, filename, line_numbers)
FILE *input;
FILE *output;
char *filename;
int line_numbers;
{
char line[8192+1];
int touched = False;
char *p;
long line_num = 1;
char *buffer;
int bufflen;
buffer = line;
bufflen = 8192;
if (line_numbers) {
buffer += 8;
bufflen -= 8;
sprintf (line, "%7lu:", line_num);
}
StartDocument (output, filename);
while (fgets (buffer, bufflen, input) != NULL) {
/* remove the trailing newline from the line */
buffer [strlen(buffer)-1] = 0;
/* if the line is a page break, then handle it */
for (p = buffer; *p == ' ' || *p == '\t'; p++)
;
if (*p == PAGEBREAK) {
if (touched)
EndColumn (output);
} else {
WriteLine (output, line);
touched = True;
line_num++;
}
if (line_numbers)
sprintf (line, "%7lu:", line_num);
}
EndDocument (output);
}