home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
623a.lha
/
TurboDEX
/
ExampleSources
/
DirSort.dex
< prev
next >
Wrap
Text File
|
1992-03-22
|
3KB
|
126 lines
' nice directory command in dex !
PROC main(ARG)
DEF lock:LONG, info=260:ARRAY, ok:LONG
DEF entries=10000:ARRAY, end:LONG, dir:LONG, nr:LONG
MCHAR argadr+argl-1,0
lock := Lock(argadr,-2)
IF lock?0
ok := Examine(lock,info)
IF ok?0
dir := MLONG(info+4)
IF dir>0
WRITE 'Directory of: \s\n',info+8
end := readentries(entries,10000)
nr := end-entries/24
IF nr>2
VOID sortentries(entries,nr)
ENDIF
VOID displayentries(entries,nr)
ELSE
WRITE 'No Dir!\n'
ENDIF
ENDIF
VOID UnLock(lock)
ELSE
WRITE 'What ?!?\n'
ENDIF
ENDPROC
PROC readentries(start,max)
LOCAL start:LONG, max:LONG, ok:REGLONG, d:REGLONG, dir:REGLONG
REPEAT
ok := ExNext(lock,info)
IF ok?0
d := MLONG(info+124)
dir := MLONG(info+4)
IF dir>0
d := -1
ENDIF
VOID CopyMemQuick(info+8,start,20)
MLONG start+20,d
start := start+24
ENDIF
UNTIL ok=0
ENDPROC start
PROC sortentries(start,nr)
LOCAL start:LONG, nr:LONG, cur:REGLONG, d:REGLONG, flag:REGLONG, p:REGLONG
LOCAL p1:LONG, p2:LONG, switch:REGLONG
DEF buf=24:ARRAY
REPEAT
flag := 0
DOWN cur,nr-1
switch := 0
p := nr-2-cur*24+start
p1 := MLONG(p)
p2 := MLONG(p+24)
IF p1>$5E000000
p1 := p1-$20000000
ENDIF
IF p2>$5E000000
p2 := p2-$20000000
ENDIF
IF p1>p2
switch := 1
ENDIF
p1 := MLONG(p+20)
p2 := MLONG(p+44)
IF p1?-1
IF p2=-1
switch := 1
ENDIF
ENDIF
IF p2?-1
IF p1=-1
switch := 0
ENDIF
ENDIF
IF switch=1
flag := 1
VOID CopyMemQuick(p,buf,24)
VOID CopyMemQuick(p+24,p,24)
VOID CopyMemQuick(buf,p+24,24)
ENDIF
ENDDOWN
UNTIL flag=0
ENDPROC
PROC displayentries(start,nr)
LOCAL start:LONG, nr:LONG, c:REGLONG, d:REGLONG, col:LONG
LOCAL first:REGLONG, item:LONG, a:REGLONG, dum:REGLONG
col := nr/3
IF col*3<nr
col := col+1
ENDIF
dum := col*3-nr
first := 0
c := 0
DOWN a,nr
IF dum+c=4
item := col*2-1
ELSE
item := c*col
ENDIF
item := item+first*24+start
INC 1,c
d := MLONG(item+20)
IF d=-1
WRITE '\e[1;32m\w25\m25\l\s\e[0;31m',item
ELSE
WRITE '\w17\m17\l\s \r\w7\d',item,d
ENDIF
IF c=3
WRITE '\n'
c := 0
INC 1,first
ELSE
WRITE ' '
ENDIF
ENDDOWN
IF c?0
WRITE '\n'
ENDIF
ENDPROC