aboutsummaryrefslogtreecommitdiff
path: root/sys/psio/zzdebug.x
blob: 97e78aa72e7adee7779fc718914e595959d5addf (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include <time.h>
include <psset.h>


task   pstest        = t_pstest

# PSTEST -- Test the PSIO package.  This test program pretty-prints a file
# with a header message and page number suitable for output to a printer.

procedure t_pstest()

pointer	ps
int     fd, ip, op
char    fname[SZ_FNAME], date[SZ_TIME], line[SZ_LINE], outline[SZ_LINE]

pointer ps_open()
int     open(), getline()
long    clktime()
errchk	open, close, getline, ps_setfont, ps_open

begin
        # Get the file to format and date string.
        call clgstr ("filename", fname, SZ_FNAME)
        call cnvtime (clktime(0), date, SZ_TIME)

        # Open the file.
        iferr (fd = open (fname, READ_ONLY, TEXT_FILE))
	    call error (1, "Error opening file.")

        # Initialize the PSIO interface.
        iferr (ps = ps_open (STDOUT, NO))
	    call error (1, "Error opening PSIO interface.")
        call ps_header (ps, fname, "NOAO/IRAF", date)
        call ps_footer (ps, "PSIO Test Page", "", "")
        call ps_write_prolog (ps)

        # Output the text in a fixed-width font.
        call ps_setfont (ps, F_TELETYPE)

        call ps_linebreak (ps, NO)
        while (getline (fd, line) != EOF) {
	
            if (line[1] == EOS) {
		# Simply break on a newline.
                call ps_linebreak (ps, NO)

            } else {
	        # Detab the line to preserve the spacing.
	        ip = 1
	        op = 1
                while (line[ip] != EOS && op <= SZ_LINE) {
                    if (line[ip] == '\t') {
                        repeat {
                            outline[op] = ' '
                            op = op + 1
                        } until (mod(op,8) == 1)
                        ip = ip + 1
                    } else {
                        outline[op] = line [ip]
                        ip = ip + 1
                        op = op + 1
                    }
                }
                outline[op] = EOS

                # Output the line and a newline break.
                call ps_output (ps, outline, NO)            
                call ps_newline (ps)
            }
        }
        call close (fd) 			# close the file

        # Close the PSIO interface, this writes the PS trailer.
        call ps_close (ps)
end