1706
|
1 *
|
|
2 * Parse options line for ``view'' utility.
|
|
3 *
|
|
4 * Global labels:
|
|
5 * Parse: Do command line parsing, set flags, open file
|
|
6 * Getnum: Interpret a number, for use by options subs in view_table.a
|
|
7 *
|
|
8 * The table of options is in the file view_table.a
|
|
9 * This file contains the actual parsing code.
|
|
10 *
|
|
11 * An option without `-' is interpreted as a filename, and the corresponding
|
|
12 * file is opened for buffered input, via the routines in view_io.a
|
|
13 *
|
|
14 ifp1
|
1912
|
15 use os9defs.d
|
1706
|
16 endc
|
|
17
|
|
18 StdIn equ 0
|
|
19 StdOut equ 1
|
|
20 StdErr equ 2
|
|
21 OPT.DTP equ 0 Offset to Device TyPe byte in Path Descriptor Options section
|
|
22
|
|
23 psect view_parse_a,0,0,0,0,0
|
|
24
|
|
25 vsect dp
|
|
26 fnameptr rmb 2 Pointer to filename
|
|
27 endsect
|
|
28
|
|
29 vsect
|
|
30 Option rmb 20
|
|
31 endsect
|
|
32
|
|
33
|
|
34 *
|
|
35 * Entry point
|
|
36 *
|
|
37 Parse:
|
|
38 pshs a,b,x,y,u
|
|
39
|
|
40 ldd #0000
|
|
41 std <fnameptr
|
|
42
|
|
43 Parse1
|
|
44 lbsr Skipblanks Move past blanks, return first non-blank char.
|
|
45
|
|
46 cmpa #$0d CR marks end of options.
|
|
47 beq Openfile Try to open the file
|
|
48
|
|
49 cmpa #'- Does this word start with '-'?
|
|
50 beq Parse2
|
|
51 stx <fnameptr No, must be filename
|
|
52 lbsr Skipword
|
|
53 bra Parse1
|
|
54 Parse2
|
|
55 leax 1,x Bump past `-'
|
|
56
|
|
57 leau PTable,pcr Check table with format type options
|
|
58 lbsr DoOption Try to perform this option.
|
|
59 beq Parse3
|
|
60 lbsr Help
|
|
61 ldb #1 Illegal argument error.
|
|
62 lbra _error unrecognized option.
|
|
63
|
|
64 Parse3
|
|
65 lda ,x+ Skip any remaining chars in this option word
|
|
66 cmpa #$20
|
|
67 bgt Parse3
|
|
68 beq Parse4 Exit on Space
|
|
69 cmpa #$0d Exit on CR
|
|
70 beq Parse4
|
|
71 lbsr Help Other control-- report error
|
|
72 ldb #1
|
|
73 lbra _error
|
|
74 Parse4
|
|
75 leax -1,x
|
|
76 bra Parse1
|
|
77
|
|
78 Openfile
|
|
79 ldx <fnameptr
|
|
80 bne Parse6 If ptr is null, then no name was given.
|
|
81
|
|
82 lda #StdIn Is StdIn from an SCF device?
|
|
83 ldb #SS.Opt
|
|
84 leax altbuff,y
|
|
85 os9 I$GetStt Get options section of StdIn path descriptor
|
|
86 lbcs _error
|
|
87 lda OPT.DTP,x
|
|
88 bne Parse7 Not SCF, so must be redirected picture coming in.
|
|
89
|
|
90 lbsr Help If StdIn is SCF, then give help message and exit.
|
|
91 ldb #1
|
|
92 lbra _error
|
|
93
|
|
94 * "fnameptr" points to first char of filename, so search for period
|
|
95 Parse6
|
|
96 lda ,x+
|
|
97 cmpa #$20 If we find a space first, then there is no extension.
|
|
98 beq Parse7
|
|
99 cmpa #$0d ...or a CR.
|
|
100 beq Parse7
|
|
101 cmpa #'. If we find a period first, then we've found the extension.
|
|
102 bne Parse6
|
|
103 leau PTable,pcr
|
|
104 lbsr DoOption Treat extension as an option spec.
|
|
105 bra Parse6
|
|
106
|
|
107 * Set default format and open file for input
|
|
108 Parse7
|
|
109 lbsr DefFormat If no other file format specification, Set default format.
|
|
110
|
|
111 ldx <fnameptr
|
|
112 lda #READ. open file
|
|
113 lbsr I_Open
|
|
114 lbcs _error
|
|
115
|
|
116 puls a,b,x,y,u,pc
|
|
117
|
|
118 *
|
|
119 * Call subroutine indicated by option pointed to by X
|
|
120 *
|
|
121 * Returns B=1 if error, B=0 otherwise
|
|
122 *
|
|
123 DoOption
|
|
124 pshs a,u
|
|
125 DoOpt1
|
|
126 tst ,u Is this the null string?
|
|
127 bne DoOpt11 If yes, end of table.
|
|
128 ldb #1 Illegal Argument error
|
|
129 bra DoOpt3
|
|
130 DoOpt11
|
|
131 lbsr CompOptions Compare with this option.
|
|
132 beq DoOpt2
|
|
133 leau 4,u Skip format specifier, branch instruction.
|
|
134 bra DoOpt1
|
|
135 DoOpt2
|
|
136 lda ,u Get code to hand to option processor.
|
|
137 jsr 1,u Jump to routine to handle this option.
|
|
138 clrb Exit with no error.
|
|
139 DoOpt3
|
|
140 tstb
|
|
141 puls a,u,pc
|
|
142
|
|
143 *
|
|
144 * Compare initial part of string at X to string at U.
|
|
145 * B=0 -> match
|
|
146 * X is advanced to first character difft from string at U
|
|
147 * U string is null-terminated, U advanced to point to byte after null.
|
|
148 *
|
|
149 CompOptions
|
|
150 pshs a,x We'll overwrite X value if we get a match
|
|
151 CompLoop
|
|
152 ldb ,u+
|
|
153 bne CompGo
|
|
154 stx 1,s Return first different X
|
|
155 bra CompEnd
|
|
156 CompGo
|
|
157 lda ,x+
|
|
158 cmpa #'A
|
|
159 blo CompCase Convert letter to lowercase
|
|
160 cmpa #'Z
|
|
161 bhi CompCase
|
|
162 adda #'a-'A
|
|
163 CompCase
|
|
164 pshs a
|
|
165 subb ,s+ Does this character match?
|
|
166 beq CompLoop
|
|
167 leax -1,x
|
|
168 Comp1
|
|
169 lda ,u+ Match failed, advance U anyway
|
|
170 bne Comp1
|
|
171 CompEnd
|
|
172 tstb
|
|
173 puls a,x,pc
|
|
174
|
|
175 *
|
|
176 * Get decimal number at X into D, move X to first non-digit
|
|
177 *
|
|
178 Getnum:
|
|
179 ldd #0
|
|
180 pshs d
|
|
181 Getnum0
|
|
182 lda ,x+ Skip leading spaces.
|
|
183 cmpa #$20
|
|
184 beq Getnum0
|
|
185 leax -1,x
|
|
186 Getnum1
|
|
187 lda ,x+
|
|
188 cmpa #$0d
|
|
189 beq Getnum2
|
|
190 cmpa #$20
|
|
191 bge Getnum10
|
|
192 lbsr Help
|
|
193 ldb #1
|
|
194 lbra _error
|
|
195 Getnum10
|
|
196 cmpa #'0
|
|
197 blo Getnum2
|
|
198 cmpa #'9
|
|
199 bhi Getnum2
|
|
200 suba #'0
|
|
201 pshs a
|
|
202 ldd 1,s
|
|
203 lslb
|
|
204 rola
|
|
205 pshs d
|
|
206 lslb
|
|
207 rola
|
|
208 lslb
|
|
209 rola
|
|
210 addd ,s++
|
|
211 addb ,s+
|
|
212 adca #0
|
|
213 std ,s
|
|
214 bra Getnum1
|
|
215 Getnum2
|
|
216 leax -1,x
|
|
217 puls d
|
|
218 rts
|
|
219
|
|
220 *
|
|
221 * Move X to point to first non-blank char. Return char in A.
|
|
222 *
|
|
223 Skipblanks
|
|
224 lda ,x+
|
|
225 cmpa #$20
|
|
226 beq Skipblanks
|
|
227 cmpa #$09
|
|
228 beq Skipblanks
|
|
229 leax -1,x
|
|
230 rts
|
|
231
|
|
232 Skipword
|
|
233 lda ,x+
|
|
234 cmpa #$20
|
|
235 bgt Skipword
|
|
236 leax -1,x
|
|
237 rts
|
|
238
|
|
239 endsect
|