home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12334.ZIP / READNAME.ASM < prev    next >
Assembly Source File  |  1989-03-20  |  3KB  |  89 lines

  1. ; ReadName.Asm - reads a list of file names into a BASIC string array
  2.  
  3. ;Syntax -
  4. ;
  5. ; Spec$ = "*.*" + CHR$(0)
  6. ; CALL ReadFile(Spec$, BYVAL VARPTR(FileName$(0)))
  7. ;
  8. ; Where Spec$ holds the directory specification, and elements in the
  9. ; FileName$() array receive the directory entries.
  10.  
  11. .286
  12. .Model Medium, Basic
  13. .Data
  14.  
  15.     FileJunk DB 22 Dup (?)
  16.     NameLen  DB ?
  17.     FileName DB 13 Dup (?)
  18.  
  19. .Code
  20.     Extrn DosFindFirst: Proc  ;declare the OS/2 calls as external
  21.     Extrn DosFindNext:  Proc
  22.     Extrn DosFindClose: Proc
  23.  
  24. ReadNames Proc, Spec:Ptr, Array:Ptr
  25.  
  26.     Local Handle:   Word
  27.     Local MaxCount: Word
  28.  
  29.     Mov  SI,Spec          ;SI holds address of Spec$ descriptor
  30.     Mov  SI,[SI+02]       ;now SI points to the first character
  31.     Mov  BX,Array         ;get address of FileName$(1) for later
  32.  
  33.     Mov  Handle, -1       ;directory handle of -1 to initiate search
  34.     Mov  MaxCount,1       ;maximum number of entries to find
  35.  
  36.     Push DS               ;push segment of Spec$
  37.     Push SI               ;push offset of Spec$ data
  38.     Push SS               ;push segment of Handle in local storage
  39.     Lea  AX,Handle        ;get address of Handle
  40.     Push AX               ;push it
  41.     Push 00100111b        ;the attribute for any type of file
  42.     Push DS               ;segment for the buffer
  43.     Push Offset FileJunk  ;push buffer address
  44.     Push 36               ;push length of buffer
  45.     Push SS               ;push segment of MaxCount
  46.     Lea  AX,MaxCount      ;get address of MaxCount
  47.     Push AX               ;push it
  48.     Push 0                ;push a DWord of 0's
  49.     Push 0
  50.     Call DosFindFirst     ;make call to find first matching file name
  51.     Or   AX,AX            ;was there a file by that name?
  52.     Jnz  Exit             ;no, exit
  53.  
  54.     Push DS               ;ensure that ES points to BASIC's string
  55.     Pop  ES               ; space for Movsb instructions below
  56.  
  57. NextFile:
  58.     Cmp  Word Ptr [BX],12 ;is the string at least 12 characters long?
  59.     Jb   Done             ;no, so get out now
  60.     Mov  DI,[BX+02]       ;DI holds address of first character in 
  61.                           ;FileName$()
  62.     Lea  SI,FileName      ;get address of the name portion of buffer
  63.     Mov  CL,NameLen       ;load CL with the number of characters to
  64.                           ;transfer
  65.     Xor  CH,CH            ;clear CH so we can use all of CX
  66.     Rep  Movsb            ;copy the string
  67.     Add  BX,4             ;point BX to next array element for later
  68.  
  69.     Push SS:Handle        ;push handle
  70.     Push DS               ;push segment of buffer
  71.     Push Offset FileJunk  ;and buffer address
  72.     Push 36               ;push length of result buffer
  73.     Push SS               ;push segment of MaxCount
  74.     Lea  AX,MaxCount      ;get address of MaxCount
  75.     Push AX               ;push it
  76.     Call DosFindNext      ;make call to find next matching file name
  77.     Or   AX,AX            ;did we get another one?
  78.     Jz   NextFile         ;if so, keep looking
  79.  
  80. Done:
  81.     Push SS:Handle        ;push the handle number
  82.     Call DosFindClose     ;free it up
  83.  
  84. Exit:
  85.     Ret                   ;return to BASIC
  86.  
  87. ReadNames Endp
  88. End
  89.