Mercurial > hg > Members > kono > nitros9-code
annotate level1/cmds/touch.as @ 2786:e333ec1907ef lwtools-port
Updated makefile(s) so correct coco1 dw boot and dwio.sb files are used.
Updated level1/coco1/modules/makefile so that boot_dw_coco1
and dwio_coco1.sb get created.
Updated level1/coco1/bootfiles/makefile added detection of PORT
status so if coco1 is detected then dwio_coco1.sb and
boot_dw_coco1 are used in place of dwio.sb and boot_dw.
author | drencor-xeen |
---|---|
date | Sun, 27 Jan 2013 00:14:03 -0600 |
parents | 03f26e88b809 |
children | 28b6ec8a14d5 |
rev | line source |
---|---|
1862 | 1 ******************************************************************** |
2 * Touch - Changes last modification date/time | |
3 * | |
4 * $Id$ | |
5 * | |
6 * Edt/Rev YYYY/MM/DD Modified by | |
7 * Comment | |
8 * ------------------------------------------------------------------ | |
9 * 2 2003/01/11 Boisy G. Pitre | |
10 * Rewrote touch from scratch, made almost 90% smaller than C version | |
11 * found in the OS-9 Development System. | |
12 | |
13 nam Touch | |
14 ttl Changes last modification date/time | |
15 | |
16 use defsfile.d | |
17 | |
1868 | 18 rev set $00 |
19 edition set 2 | |
20 | |
1862 | 21 * Here are some tweakable options |
22 DOHELP set 0 1 = include help info | |
23 STACKSZ set 128 estimated stack size | |
24 PARMSZ set 256 estimated parameter size | |
25 ZOPTSIZ set 64 max size of -z option's parameter | |
26 | |
27 * Module header definitions | |
28 rev set $00 | |
29 edition set 2 | |
30 | |
31 * Your utility's static storage vars go here | |
2782
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
1869
diff
changeset
|
32 section data |
1862 | 33 parmptr rmb 2 pointer to our command line params |
34 bufptr rmb 2 pointer to user expandable buffer | |
35 bufsiz rmb 2 size of user expandable buffer | |
36 * What follows are utility specific options | |
37 nocreate rmb 1 | |
38 quiterr rmb 1 | |
39 filemode rmb 1 | |
40 filecnt rmb 1 | |
41 zoptflg rmb 1 1 = this option has been processed once already | |
42 zpath rmb 1 path to -z file | |
1868 | 43 cleartop equ * everything up to here gets cleared at start |
1862 | 44 zopt rmb ZOPTSIZ buffer for what follows after -c= |
1868 | 45 endsect |
46 | |
1862 | 47 * Next is a user adjustable buffer with # modifier on command line. |
48 * Some utilities won't need this, some will. | |
49 * Currently set up to be larger for Level 2 than Level 1 | |
50 * Note: this buffer must come just before the stack | |
2782
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
1869
diff
changeset
|
51 section data |
1862 | 52 IFGT Level-1 |
53 bigbuff rmb 8*1024 8K default buffer for Level 2 | |
54 ELSE | |
55 bigbuff rmb 512 512 byte default buffer for Level 1 | |
56 ENDC | |
57 endsect | |
58 | |
2782
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
1869
diff
changeset
|
59 * psect touch_a,Prgrm+Objct,ReEnt+rev,edition,200,start |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
1869
diff
changeset
|
60 section text |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
1869
diff
changeset
|
61 |
1862 | 62 * Place constant strings here |
63 IFNE DOHELP | |
64 HlpMsg fcb C$LF | |
65 fcc /Use: Touch [<opts>] <path> [<path>] [<opts>]/ | |
66 fcb C$LF | |
67 fcc / -c = don't create files/ | |
68 fcb C$LF | |
69 fcc / -q = don't quit on error/ | |
70 fcb C$LF | |
71 fcc / -x = search execution directory/ | |
72 fcb C$LF | |
73 fcc / -z = get files from standard input/ | |
74 fcb C$LF | |
75 fcc / -z=<file> get files from <file>/ | |
76 fcb C$LF | |
77 CR fcb C$CR | |
78 HlpMsgL equ *-HlpMsg | |
79 ENDC | |
80 UnkOpt fcc /unknown option: / | |
81 UnkOptL equ *-UnkOpt | |
82 CantTch fcc /can't touch "/ | |
83 CantTchL equ *-CantTch | |
84 EndCant fcc /" - / | |
85 EndCantL equ *-EndCant | |
86 | |
87 * Here's how registers are set when this process is forked: | |
88 * | |
89 * +-----------------+ <-- Y (highest address) | |
90 * ! Parameter ! | |
91 * ! Area ! | |
92 * +-----------------+ <-- X, SP | |
93 * ! Data Area ! | |
94 * +-----------------+ | |
95 * ! Direct Page ! | |
96 * +-----------------+ <-- U, DP (lowest address) | |
97 * | |
98 * D = parameter area size | |
99 * PC = module entry point abs. address | |
100 * CC = F=0, I=0, others undefined | |
101 | |
102 * The start of the program is here. | |
103 * Before any command line processing is done, we clear out | |
104 * our static memory from U to cleartop, then determine the | |
105 * size of our data area (minus the stack). | |
106 start pshs u,x save registers for later | |
1868 | 107 leax <cleartop point to end of area to zero out |
1862 | 108 IFNE H6309 |
109 subr u,x subtract U from X | |
110 tfr x,w and put X in W | |
111 clr ,-s put a zero on the stack | |
112 tfm s,u+ and use TFM to clear starting at U | |
113 leas 1,s clean up the stack | |
114 ELSE | |
115 pshs x save end pointer on stack | |
116 clrnxt clr ,u+ clear out | |
117 cmpu ,s done? | |
118 bne clrnxt branch if not | |
119 leas 2,s else clear stack | |
120 ENDC | |
121 puls x,u and restore our earlier saved registers | |
122 leay bigbuff,u point Y to copy buffer offset in U | |
123 stx <parmptr save parameter pointer | |
124 sty <bufptr save pointer to buffer | |
125 tfr s,d place top of stack in D | |
126 IFNE H6309 | |
127 subr y,d | |
128 ELSE | |
129 pshs y save Y on stack | |
130 subd ,s++ get size of space between copybuf and X | |
131 ENDC | |
132 subd #STACKSZ+PARMSZ subtract out our stack | |
133 std <bufsiz size of our buffer | |
134 | |
135 * At this point we have determined our buffer space and saved pointers | |
136 * for later use. Now we will parse the command line for options that | |
137 * begin with - | |
138 lda ,x | |
139 cmpa #C$CR CR? | |
140 lbeq ShowHelp if so, no parameters... show help and exit | |
141 GetChar lda ,x+ get next character on cmd line | |
142 cmpa #C$CR CR? | |
143 lbeq DoTouch if so, do whatever this utility does | |
144 cmpa #'- is it an option? | |
145 beq GetDash if so, process it | |
146 inc <filecnt else must be a non-option argument (file) | |
147 lbsr SkipNSpc move past the argument | |
148 ChkDash lbsr SkipSpcs and any following spaces | |
149 bra GetChar start processing again | |
150 GetDash lda #C$SPAC get a space char | |
151 sta -1,x and wipe out the dash from the cmd line | |
152 GetDash2 ldd ,x+ load option char and char following | |
153 ora #$20 make lowercase | |
154 IsItC cmpa #'c is it this option? | |
155 bne IsItQ branch if not | |
156 sta <nocreate | |
157 lbra FixCmdLn | |
158 IsItQ cmpa #'q is it this option? | |
159 bne IsItX branch if not | |
160 inc <quiterr | |
161 lbra FixCmdLn | |
162 IsItX cmpa #'x is it this option? | |
163 bne IsItZ branch if not | |
164 lda #EXEC. | |
165 sta <filemode | |
166 bra FixCmdLn | |
167 IsItZ cmpa #'z is it this option? | |
168 bne BadOpt branch if not | |
169 tst <zoptflg was this option already specified? | |
170 bne BadOpt show help if so | |
171 sta <zoptflg else tag this option as parsed | |
172 cmpb #'= 2nd char =? | |
173 bne FixCmdLn | |
174 GetZFile ldb #C$SPAC get space | |
175 stb -$01,x write over c | |
176 stb ,x+ and = sign, inc X to dest dir | |
177 * check for valid char after -z= | |
178 lda ,x | |
179 cmpa #C$SPAC | |
180 lbeq ShowHelp | |
181 cmpa #C$COMA | |
182 lbeq ShowHelp | |
183 cmpa #C$CR | |
184 lbeq ShowHelp | |
185 leay <zopt,u point Y to parameber buffer | |
186 tfr y,d transfer Y to D | |
187 addd #ZOPTSIZ | |
188 pshs b,a save updated ptr value | |
189 ldb #C$SPAC get space | |
190 L0339 lda ,x get byte at X | |
191 stb ,x+ store space at X and inc | |
192 sta ,y+ save loaded byte at Y and inc | |
193 cmpy ,s are we at end? | |
194 beq L035D branch if so (buffer too small) | |
195 cmpa #C$SPAC else is char in A a space? | |
196 beq L0350 branch if so | |
197 cmpa #C$COMA coma? | |
198 beq L0350 branch if so | |
199 cmpa #C$CR cr? | |
200 bne L0339 get next byte if not | |
201 L0350 leax -1,x | |
202 sta ,x restore previous A | |
203 leas $02,s kill stack | |
204 * attempt to open a path to the file | |
205 pshs x | |
206 leax <zopt,u | |
207 lda #READ. | |
208 os9 I$Open | |
209 lbcs Exit | |
210 sta <zpath | |
211 puls x | |
212 lbra ChkDash | |
213 L035D leas $02,s | |
214 ldb #$BF else buffer size too small | |
215 orcc #Carry | |
216 lbra Exit | |
217 FixCmdLn lda #C$SPAC get space | |
218 sta -$01,x and wipe out option character | |
219 cmpb #'0 | |
220 lblt ChkDash start dash option processing again | |
221 lbra GetDash possibly another option following? | |
222 | |
223 * We branch here if we encounter an unknown option character | |
224 * A = bad option character | |
225 BadOpt leax UnkOpt,pcr | |
226 ldy #UnkOptL | |
227 ldb #C$CR | |
228 pshs d save bad option and CR on stack | |
229 lda #$02 stderr | |
230 os9 I$Write | |
231 leax ,s point X at option char on stack | |
232 os9 I$WritLn print option and CR | |
233 puls d clean up stack | |
234 lbra ShowHelp | |
235 | |
236 | |
237 * At this point options are processed. | |
238 * We load X with our parameter pointer and go down the command line | |
239 * looking at each file to process (options have been wiped out with | |
240 * spaces) | |
241 * | |
242 * Note, the following two instructions may not be needed, depending on | |
243 * if your utility requires a non-option on the command line. | |
244 DoTouch tst <zoptflg -z specified? | |
245 beq DoFiles no, do any files on command line | |
246 ReadZ lda <zpath | |
247 ldy #80 | |
248 os9 I$ReadLn | |
249 lbsr SkipSpcs | |
250 cmpa #C$CR | |
251 beq ClosEx | |
252 bcs TestErr | |
253 bsr ProcFile | |
254 bra ReadZ | |
255 TestErr cmpb #E$EOF | |
256 lbne Exit | |
257 tsta | |
258 lbeq ExitOk | |
259 ClosEx os9 I$Close close path to -z= file | |
260 lbra ExitOk | |
261 | |
262 DoFiles tst <filecnt we should have at least one file on cmdline | |
263 lbeq ShowHelp if not, exit with error | |
264 ldx <parmptr get our parameter pointer off stack | |
265 DoLoop lbsr SkipSpcs skip any leading spaces | |
266 cmpa #C$CR end of parameters? | |
267 beq ExitOk if so, end the utility | |
268 pshs x save pointer to arg | |
269 bsr ProcFile process file at X | |
270 puls x get arg pointer | |
271 lbsr SkipNSpc skip the argument we just processed | |
272 bra DoLoop | |
273 | |
274 * This routine processes one file at a time. | |
275 * Entry: X = ptr to argument on the command line. | |
276 * On exit, X can point to the argument or past it. | |
277 * Note that there are NO leading spaces. | |
278 * They have been skipped by the caller. | |
279 * The following code just echos the command line argument, followed | |
280 * by a carriage return. | |
281 ProcFile | |
282 lda #WRITE. | |
283 ora <filemode | |
284 pshs x | |
285 os9 I$Open | |
286 puls x | |
287 bcc CloseIt | |
288 ora #DIR. | |
289 pshs x | |
290 os9 I$Open | |
291 puls x | |
292 bcc CloseIt | |
293 * open failed... should we do create? | |
294 tst <nocreate | |
295 beq DoCreate | |
296 ChkQuit bsr CantTouch | |
297 tst <quiterr | |
1868 | 298 beq ExitOk |
1862 | 299 bra ProcRTS |
300 DoCreate ldb #PREAD.+UPDAT. | |
301 pshs x | |
302 os9 I$Create | |
303 puls x | |
304 bcs ChkQuit | |
305 CloseIt os9 I$Close | |
306 ProcRTS rts | |
307 | |
308 CantTouch | |
309 pshs x,b save pointer to file and error code | |
310 leax CantTch,pcr | |
311 lda #$02 | |
312 ldy #CantTchL | |
313 os9 I$Write | |
314 ldx 1,s | |
315 pshs x | |
316 bsr StrLen | |
317 puls x | |
318 os9 I$Write | |
319 leax EndCant,pcr | |
320 ldy #EndCantL | |
321 os9 I$Write | |
322 puls b | |
323 os9 F$PErr | |
324 puls x,pc | |
325 | |
326 ShowHelp equ * | |
327 IFNE DOHELP | |
328 leax >HlpMsg,pcr point to help message | |
329 ldy #HlpMsgL get length | |
330 lda #$02 std error | |
331 os9 I$WritLn write it | |
332 ENDC | |
333 ExitOk clrb clear carry | |
334 Exit os9 F$Exit and exit | |
335 | |
336 * This routine counts the number of non-whitespace characters | |
337 * starting at X | |
338 * | |
339 * Entry: | |
340 * X = ptr to string (space, comma or CR terminated) | |
341 * Exit: | |
342 * Y = length of string | |
343 * X = ptr to byte after string | |
344 StrLen pshs a | |
345 ldy #$0000 | |
346 StrLenLp lda ,x+ | |
347 cmpa #C$SPAC | |
348 beq StrLenEx | |
349 cmpa #C$COMA | |
350 beq StrLenEx | |
351 cmpa #C$CR | |
352 beq StrLenEx | |
353 leay 1,y | |
354 bra StrLenLp | |
355 StrLenEx puls a,pc | |
356 | |
357 * This routine copies a string of text from X to Y until | |
358 * a whitespace character or CR is encountered | |
359 * | |
360 * Entry: | |
361 * X = ptr to src string | |
362 * Y = ptr to dest string | |
363 * Exit: | |
364 * D = number of bytes copied | |
365 * X = ptr to byte after original string | |
366 * Y = ptr to byte after copied string | |
367 StrCpy pshs u | |
368 ldu #$0000 | |
369 CopyFnLp lda ,x+ | |
370 cmpa #C$SPAC | |
371 beq CopyFnEx | |
372 cmpa #C$COMA | |
373 beq CopyFnEx | |
374 cmpa #C$CR | |
375 beq CopyFnEx | |
376 sta ,y+ | |
377 leau 1,u | |
378 bra CopyFnLp | |
379 CopyFnEx tfr u,d | |
380 puls u,pc | |
381 | |
382 * This routine skip over spaces and commas | |
383 * | |
384 * Entry: | |
385 * X = ptr to data to parse | |
386 * Exit: | |
387 * X = ptr to first non-whitespace char | |
388 * A = non-whitespace char | |
389 SkipSpcs lda ,x+ | |
390 cmpa #C$SPAC | |
391 beq SkipSpcs | |
392 cmpa #C$COMA | |
393 beq SkipSpcs | |
394 leax -1,x | |
395 rts | |
396 | |
397 * This routine skips over everything but spaces, commas and CRs | |
398 * | |
399 * Entry: | |
400 * X = ptr to data to parse | |
401 * Exit: | |
402 * X = ptr to first whitespace char | |
403 * A = whitespace char | |
404 SkipNSpc lda ,x+ | |
405 cmpa #C$SPAC | |
406 beq EatOut | |
407 cmpa #C$COMA | |
408 beq EatOut | |
409 cmpa #C$CR | |
410 bne SkipNSpc | |
411 EatOut leax -1,x | |
412 rts | |
413 | |
414 endsect |