0
|
1 ************************************************************
|
|
2 * More - Prompts lists a file or files one screen at a time.
|
|
3 * If no files are specified, STDIN is used.
|
|
4 *
|
|
5 * At the --More-- prompt, press:
|
|
6 * <ENTER> to go advance one line
|
|
7 * <BREAK> or 'Q' to quit
|
|
8 * <SPACE> or any other key to advance one screenful
|
|
9 *
|
|
10 * Usage: More [-l -w] [file] [...]
|
|
11 * -l = show the name of the file before viewing
|
|
12 * (handy for multiple files)
|
|
13 * -w = don't allow lines to wrap around. This option truncates
|
|
14 * the line to a length of window's X size - 1.
|
|
15 *
|
|
16 * If you are using a terminal other than the OS-9 Level II
|
|
17 * windowing system, you will need to change the reverse
|
|
18 * on/off sequence as well as the clear line sequence
|
|
19 *
|
|
20 * NOTE: More works great with Shell+'s wildcards! It also works
|
|
21 * well with external terminals. Just change the Reverse
|
|
22 * on/off and DelLine bytes to match your terminal's codes.
|
|
23 * If you are running 'more' on a terminal, it assumes an 80x24
|
|
24 * terminal screen size.
|
|
25 *
|
|
26 * By: Boisy G. Pitre
|
|
27 * 1204 Love Street
|
|
28 * Brookhaven, MS 39601
|
|
29 * Internet: bgpitre@seabass.st.usm.edu
|
|
30 *
|
|
31
|
|
32 ifp1
|
|
33 use defsfile
|
|
34 endc
|
|
35
|
|
36 * Terminal specific equates:
|
|
37 XSIZE equ 80
|
|
38 YSIZE equ 24
|
|
39 DELNE equ $3
|
|
40 REVON equ $1f20
|
|
41 REVOFF equ $1f21
|
|
42
|
|
43 mod Size,Name,Prgrm+Objct,Reent+1,Start,Fin
|
|
44 Name fcs /M/
|
|
45 Ed fcb 2
|
|
46
|
|
47 Path rmb 1
|
|
48 Response rmb 1
|
|
49 XH rmb 1
|
|
50 XL rmb 1
|
|
51 YH rmb 1
|
|
52 YL rmb 1
|
|
53 Lflag rmb 1
|
|
54 FilePtr rmb 2
|
|
55 Buffer rmb 250
|
|
56 FileBuf rmb 60
|
|
57 Stack rmb 200
|
|
58
|
|
59 * I make the Parms buffer large in case the wildcard expansion is long,
|
|
60 * else the system crashes. You can alternately use the shell's memory
|
|
61 * modifier (i.e. #4k) to insure a big buffer.
|
|
62 Parms rmb 4096
|
|
63
|
|
64 Fin equ .
|
|
65
|
|
66 Message fdb REVON Reverse Video on
|
|
67 fcc /--More--/
|
|
68 fdb REVOFF Reverse Video off
|
|
69 MessLen equ *-Message
|
|
70
|
|
71 Header fdb $0a0d
|
|
72 fcc /****** File: /
|
|
73 HeadLen equ *-Header
|
|
74
|
|
75
|
|
76 DelLine fcb DELNE Delete line char
|
|
77 CR fcb $0d Carriage Return
|
|
78
|
|
79 ****** SUBROUTINES
|
|
80 PutHead pshs x Here, we actually print the header
|
|
81 leax Header,pcr for the file we are working on.
|
|
82 ldy #HeadLen
|
|
83 lda #1
|
|
84 os9 I$Write
|
|
85 lbcs Error
|
|
86 puls x
|
|
87 bsr SaveFile
|
|
88 lda #1
|
|
89 leax FileBuf,u
|
|
90 ldy #60
|
|
91 os9 I$WritLn
|
|
92 lbcs Error
|
|
93 rts
|
|
94
|
|
95 SaveFile pshs x
|
|
96 leay FileBuf,u
|
|
97 SaveF2 lda ,x+
|
|
98 cmpa #$20
|
|
99 bne SaveF3
|
|
100 lda #$0d
|
|
101 SaveF3 sta ,y+
|
|
102 cmpa #$0d
|
|
103 bne SaveF2
|
|
104 puls x
|
|
105 rts
|
|
106
|
|
107 GetSize pshs x
|
|
108 lda #1 Using stdout...
|
|
109 ldb #$26
|
|
110 os9 I$GetStt Find the X and Y size of window
|
|
111 bcs ChekErr
|
|
112 stx XH Save the X value
|
|
113 sty YH Save the Y value
|
|
114 clr XH Clear high-order byte of X
|
|
115 dec XL Decrement the X value
|
|
116 dec YL Decrement the Y value
|
|
117 dec YL and dec Y again
|
|
118 puls x
|
|
119 lda YL Do the initial load of the counter
|
|
120 sta YH
|
|
121 rts
|
|
122
|
|
123 ChekErr cmpb #E$UnkSvc If this is true, then we are probably
|
|
124 bne Error dealing with a terminal, not a hardware
|
|
125 lda #XSIZE window. We'll assume 80x24 as the
|
|
126 sta XL terminal size.
|
|
127 lda #YSIZE
|
|
128 sta YL
|
|
129 clr XH
|
|
130 rts
|
|
131
|
|
132 ********* PROGRAM ENTRY
|
|
133 Start pshs x put away X temporarily,
|
|
134 leax IntSvc,pc point to the interrupt service routine
|
|
135 os9 F$Icpt and make the system aware of it
|
|
136 puls x then get X back for processing
|
|
137 clr Path Clear the path (assume stdin)
|
|
138 clr LFlag
|
|
139 bsr GetSize
|
|
140
|
|
141 Parse lda ,x+ Parsing of the line is done here
|
|
142 cmpa #$20
|
|
143 beq Parse
|
|
144 cmpa #'-
|
|
145 beq GetOpt
|
|
146 cmpa #$0d
|
|
147 bne TestFlag
|
|
148 tst Path
|
|
149 beq Cycle
|
|
150 bra Done
|
|
151
|
|
152 GetOpt lda ,x+
|
|
153 cmpa #$20
|
|
154 beq Parse
|
|
155 anda #$df
|
|
156 cmpa #'L
|
|
157 bne IsitW
|
|
158 com LFlag
|
|
159 bra Parse
|
|
160 IsItW cmpa #'W
|
|
161 bne Done
|
|
162 lda XL
|
|
163 deca
|
|
164 sta XH
|
|
165 bra Parse
|
|
166
|
|
167 TestFlag leax -1,x Here, we test to see if the -l
|
|
168 tst LFlag flag is set (to display the file
|
|
169 bne TestF2 header) If so, we print it, else
|
|
170 bsr OpenFile
|
|
171 bra ReadLine
|
|
172 TestF2 pshs x we continue with reading...
|
|
173 lbsr PutHead
|
|
174 puls x
|
|
175 bsr OpenFile
|
|
176 dec YH Decrement counter twice to take into
|
|
177 dec YH account the header (two lines)
|
|
178 lda YH See if the count is less than 1
|
|
179 cmpa #1
|
|
180 blt ShowMess if so, time to show prompt
|
|
181 bra ReadLine else read the line
|
|
182
|
|
183 OpenFile lda #Read. Prepare for reading
|
|
184 os9 I$Open Then open the file
|
|
185 bcs Error Exit on error
|
|
186 stx FilePtr Save X for later use
|
|
187 sta Path ...else save the path
|
|
188 rts
|
|
189
|
|
190 Done clrb
|
|
191 Error os9 F$Exit
|
|
192
|
|
193
|
|
194 Cycle lda YL Get the low order byte
|
|
195 sta YH and use the high as a counter
|
|
196 bsr PutCR
|
|
197
|
|
198 ReadLine lda Path Get the path
|
|
199 ldy #250 max chars read = 250
|
|
200 leax Buffer,u point to the buffer
|
|
201 os9 I$ReadLn and read the line
|
|
202 bcs EOF if error, check for EOF
|
|
203 tst XH Is high order byte set?
|
|
204 beq WriteOut Nope, continue as normal
|
|
205 pshs x else loop until end of the
|
|
206 ldb XH string and place a CR at the
|
|
207 Loop leax 1,x end.
|
|
208 decb This is unnecessary if the line
|
|
209 bne Loop is less than XH, but doesn't slow
|
|
210 lda #$0d down the processing considerably
|
|
211 sta ,x and would take longer if we actually
|
|
212 puls x checked to see if a CR existed.
|
|
213
|
|
214 WriteOut lda #1 Prepare to write to stdout
|
|
215 os9 I$WritLn Write!
|
|
216 bcs Error if error, leave
|
|
217 dec YH else decrement the counter
|
|
218 bne ReadLine if not 0, more lines to show
|
|
219
|
|
220 ShowMess leax Message,pc Prepare to show message
|
|
221 ldy #MessLen
|
|
222 lda #2 to stderr...
|
|
223 os9 I$Write write it!
|
|
224 bcs Error
|
|
225 lda #2 Now get response
|
|
226 ldy #1 of one character
|
|
227 leax Response,u from stderr
|
|
228 os9 I$Read
|
|
229 bcs Error
|
|
230 bsr KillLine
|
|
231 bra TestInp
|
|
232
|
|
233 PutCR leax CR,pc
|
|
234 lda #1
|
|
235 ldy #1
|
|
236 os9 I$Write
|
|
237 bcs Error
|
|
238 rts
|
|
239
|
|
240 KillLine lda #2 Here we send a delete line char
|
|
241 ldy #1 to clean the prompt.
|
|
242 leax DelLine,pc
|
|
243 os9 I$Write
|
|
244 bcs Error
|
|
245 rts
|
|
246
|
|
247 EOF cmpb #E$EOF Check for end-of-file
|
|
248 bne Error If not, exit w/ error
|
|
249 EOF2 lda Path else close the path
|
|
250 os9 I$Close
|
|
251 tst Path If the path is stdin, we can quit
|
|
252 lbeq Done
|
|
253 ldx FilePtr
|
|
254 lbra Parse command line.
|
|
255
|
|
256 TestInp lda Response Here we test the response at prompt
|
|
257 cmpa #$0d is it cr?
|
|
258 beq OneLine yep, go up one line
|
|
259 anda #$df else mask uppercase
|
|
260 cmpa #'Q is it Q?
|
|
261 beq IntSvc Yep, kill prompt and exit
|
|
262 cmpa #'N is it N?
|
|
263 lbne Cycle nope, must be space or other char
|
|
264 bsr KillLine else Kill the prompt
|
|
265 bra EOF2 and get next file
|
|
266
|
|
267 IntSvc bsr KillLine Interrupt service routine
|
|
268 lbra Done
|
|
269
|
|
270 OneLine lda #1 We go here if <ENTER> was pressed
|
|
271 sta YH,u to increment only one line
|
|
272 lbra ReadLine
|
|
273
|
|
274 emod
|
|
275 Size equ *
|
|
276 end
|