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