27 May 2016, 22:22 | #1 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,172
|
asm code to process DOS wildcards
Hi,
I'm really lazy, and I'm sure someone did it before, so... I'm looking for a piece of code that takes a DOS wildcard (#? or even mydir/#? or even my#?/#?) and which prints out the list of filenames matching. Doesn't need to be recursive. You'll be credited in the CD32load development |
27 May 2016, 23:07 | #2 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,753
|
Here's a stand alone program I wrote for Rosetta Code that does just that:
Code:
; ; Non-recursive directory walk for Motorola 68000 under AmigaOs 2.04+ by Thorham ; execBase equ 4 ; ; from exec includes ; _LVOOpenLibrary equ -552 _LVOCloseLibrary equ -414 _LVOAllocVec equ -684 _LVOFreeVec equ -690 MEMF_ANY equ 0 ; ; from dos includes ; _LVOVPrintf equ -954 _LVOExamine equ -102 _LVOExNext equ -108 _LVOLock equ -84 _LVOUnLock equ -90 _LVOParsePatternNoCase equ -966 _LVOMatchPatternNoCase equ -972 ACCESS_READ equ -2 rsset 0 fib_DiskKey rs.l 1 fib_DirEntryType rs.l 1 fib_FileName rs.b 108 fib_Protection rs.l 1 fib_EntryType rs.l 1 fib_Size rs.l 1 fib_NumBlocks rs.l 1 fib_DateStamp rs.b 12 fib_Comment rs.b 80 fib_OwnerUID rs.w 1 fib_OwnerGID rs.w 1 fib_Reserved rs.b 32 fib_SIZEOF rs.b 0 ; ; main ; start move.l execBase,a6 ; open dos.library lea dosName,a1 moveq #37,d0 jsr _LVOOpenLibrary(a6) move.l d0,dosBase beq exit ; allocate memory for file info block move.l #fib_SIZEOF,d0 move.l #MEMF_ANY,d1 jsr _LVOAllocVec(a6) move.l d0,fib beq exit ; get directory lock move.l dosBase,a6 move.l #pathString,d1 move.l #ACCESS_READ,d2 jsr _LVOLock(a6) move.l d0,lock beq exit ; examine directory for ExNext move.l lock,d1 move.l fib,d2 jsr _LVOExamine(a6) tst.w d0 beq exit ; parse pattern string move.l #patternString,d1 move.l #patternParsed,d2 move.l #sizeof_patternString*2+2,d3 jsr _LVOParsePatternNoCase(a6) tst.l d0 blt exit ; get some pointers for use in the loop lea printfArgs,a2 move.l fib,a3 lea fib_FileName(a3),a3 .loop ; get next directory entry move.l lock,d1 move.l fib,d2 jsr _LVOExNext(a6) tst.w d0 beq exit ; match pattern move.l #patternParsed,d1 move.l a3,d2 jsr _LVOMatchPatternNoCase(a6) ; if match then print file name tst.l d0 beq .nomatch move.l a3,(a2) move.l #formatString,d1 move.l #printfArgs,d2 jsr _LVOVPrintf(a6) .nomatch bra .loop ; cleanup and exit exit move.l dosBase,a6 move.l lock,d1 jsr _LVOUnLock(a6) move.l execBase,a6 move.l fib,a1 tst.l a1 beq .l1 jsr _LVOFreeVec(a6) .l1 move.l dosBase,a1 jsr _LVOCloseLibrary(a6) rts section data,data_p ; ; variables ; dosBase dc.l 0 lock dc.l 0 fib dc.l 0 printfArgs dc.l 0 ; ; strings ; dosName dc.b "dos.library",0 pathString dc.b "ram:",0 formatString dc.b "%s",10,0 patternString dc.b "#?",0 patternString_end sizeof_patternString=patternString_end-patternString patternParsed dcb.b sizeof_patternString*2+2 |
27 May 2016, 23:26 | #3 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,172
|
That's great and quick. Thanks.
|
28 May 2016, 00:28 | #4 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
|
28 May 2016, 09:48 | #5 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Here's how I normally do the things :
Code:
; we enter here with a0=pattern move.l dosbase,a6 ; previously opened dos.library ; do this if you want "*" to be same as "#?" ; move.l $22(a6),a1 ; dosbase.dl_Root ; bset #0,$34(a1) ; ->flags.wildstar lea anchor,a4 move.l a0,d1 ; patt move.l a4,d2 ; anchor path jsr -$336(a6) ; MatchFirst .loop tst.l d0 bne.s .done tst.l $18(a4) ; entry type (file/dir) smi d0 ; 00=file, ff=dir lea $1c(a4),a0 ; file name ; file/dir name in a0, type in d0 - do whatever stuff here with it bclr #2,$10(a4) ; don't DODIR move.l a4,d1 jsr -$33c(a6) ; MatchNext bra.s .loop .done move.l a4,d1 jsr -$342(a6) ; MatchEnd ; finished here ; somewhere in your bss section anchor ds.b $118 ; struct AnchorPath (must be longword aligned) |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can someone explain this Suntronic ASM code? | 1988 | Coders. Asm / Hardware | 1 | 31 May 2015 17:32 |
PCMCIA fault: DOS error code 225 - Not a valid DOS disk | 4am | support.Hardware | 2 | 07 April 2012 10:20 |
Problems with a little ASM code | VoltureX | Coders. General | 7 | 12 December 2011 13:10 |
dos/exec/intuition asm tutorials for Kickstart 1.3 | Photon | Coders. General | 19 | 05 January 2007 19:54 |
Lots of ASM code | Ray Norrish | Coders. General | 9 | 22 February 2006 02:20 |
|
|