-
Notifications
You must be signed in to change notification settings - Fork 26
/
fatcat.pla
49 lines (45 loc) · 1.08 KB
/
fatcat.pla
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
include "inc/cmdsys.plh"
include "inc/args.plh"
include "inc/sdfat.plh"
word arg
byte[64] cwd
byte[64] pathname
def fatCat(path)#0
byte filename[32]
sdFAT:setDir(path)
puts("Directory of "); puts(path); puts(":\n")
sdFAT:openFirstFile(@filename)
while filename
puts(" "); puts(@filename)
if sdFAT:isDir(); putc('/'); fin
putln
sdFAT:closeFile()
sdFAT:openNextFile(@filename)
loop
end
sdFAT:getDir(@cwd)
if cwd[cwd] <> '/' // append '/' to cwd if needed
cwd++
cwd[cwd] = '/'
fin
arg = argNext(argFirst)
if ^arg
while ^arg
if ^(arg + 1) <> '/' // relative path argument - append to cwd
memcpy(@pathname, @cwd, cwd + 1)
else
pathname = 0 // absolute path
fin
memcpy(@pathname + pathname + 1, arg + 1, ^arg) // append path argument
pathname = pathname + ^arg
if pathname[pathname] <> '/'
pathname++
pathname[pathname] = '/'
fin
fatCat(@pathname)
arg = argNext(arg)
loop
else
fatCat(@cwd)
fin
done