home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tasm / iwhereis.asm < prev    next >
Assembly Source File  |  1988-08-28  |  8KB  |  242 lines

  1.  
  2. ;   FILENAME: IWHEREIS.ASM
  3. ;
  4. ;   Copyright (c) 1988 by Borland International
  5. ;
  6. ;   DESCRIPTION:  This program does a search for the file(s) specified on the
  7. ;   command line.
  8. ;
  9. ;   ASSEMBLY INSTRUCTIONS: To assemble this module use the following
  10. ;   TASM command line.
  11. ;
  12. ;       TASM /dMDL=memorymodel iwhereis
  13. ;
  14. ;   'memorymodel' in the above command line may be replaced by TINY, SMALL,
  15. ;   MEDIUM, COMPACT, LARGE or HUGE. If assembling this module to run on
  16. ;   a 286/386 machine, turn on the P286 directive in order to take advantage of
  17. ;   286/386 specific instructions. For example:
  18. ;
  19. ;       TASM /dMDL=memorymodel /jP286 iwhereis
  20. ;
  21. ;   SYSTEM REQUIREMENTS:
  22. ;       TASM 1.0
  23. ;       256K
  24. ;       DOS 2.0 or later
  25.  
  26. %tabsize 4
  27.  
  28. ifndef  MDL
  29.     display "Error: This module requires that you provide a memory model"
  30.     display "    definition on the command line. I.E. /dMDL=SMALL."
  31.     err ; Force a fatal error
  32. else
  33.  
  34.     ideal                   ; Use TASM's Ideal mode
  35.     model   MDL             ; Define the memory model
  36.  
  37.     Version EQU "1.00"
  38.  
  39.     include "iwhglobl.inc"  ; Public symbol declarations
  40.     include "imacros.mac"   ; Various macros
  41.     include "bios.inc"
  42.     include "ibios.mac"
  43.     include "kbd.inc"      ; Keyboard scan codes
  44.     include "dos.inc"      ; Equates representing DOS functions/services
  45.     include "idos.mac"
  46.  
  47.     stack   7FFFh           ; Allocate 32K stack
  48.  
  49.     dataseg
  50.  
  51.     PspAddress  dw  ?       ; Segment address of Program Segment Prefix(PSP)
  52.     DisplayPage db  0       ; Current display page
  53.     include "WHUSAGE.INC"   ; Usage screen declaration
  54.  
  55.     ; Pascal style strings to store the parsed file specification.
  56.  
  57.     global  Drive:byte:5
  58.     Drive       db  0," :  "
  59.     Path        db  MAX_PATH_LENGTH  dup (0)
  60.     FileSpec    db  15  dup (0) ; Make room for the filename with a preceding
  61.                                 ; length byte and terminating 0
  62.     db  '\'
  63.     HomeDirectory   db  MAX_PATH_LENGTH dup (0)
  64.     OldDrive    db  ?
  65.  
  66.  
  67.     codeseg
  68.  
  69.     proc    main
  70.  
  71.  
  72.     ;************************* Program Entry Point ***************************
  73.     ; Execution of the program begins here.
  74.  
  75.     EntryPoint:
  76.         mov     ax, @data       ; Initialize ds by moving segment address
  77.         mov     ds, ax          ; of data segment into ds register
  78.         push    bp
  79.         mov     bp, sp
  80.         call    Initialize      ; Initialize data structures, etc.
  81.         mov     al, 1
  82.         call    ParamString
  83.         push    es              ; Store the location of the file spec.
  84.         push    di
  85.     @@DeleteSpaces:
  86.         cmp     [byte es:di+1], SPACE
  87.         jne     short @@NoMoreSpaces
  88.         mov     cx, 1           ; Remove the first character
  89.         mov     ax, 1           ; from the string
  90.         push    es              ; Pass the location of the parameter to
  91.         push    di              ; DeletChar
  92.         call    DeleteChar
  93.         jmp     @@DeleteSpaces
  94.     @@NoMoreSpaces:
  95.  
  96.         ; Pull apart the drive, path and filename so we can store the
  97.         ; filename specification.
  98.  
  99.         push    ds              ; Push the address to store the drive spec. in
  100.         if (@Cpu and 100b) eq 100b
  101.             push    offset Drive
  102.         else
  103.             mov     ax, offset Drive
  104.             push    ax
  105.         endif
  106.         push    ds              ; Push the address to store the path spec. in
  107.         if (@Cpu and 100b) eq 100b
  108.             push    offset Path
  109.         else
  110.             mov     ax, offset Path
  111.             push    ax
  112.         endif
  113.         push    ds              ; Push address to store filename spec. in
  114.         if (@Cpu and 100b) eq 100b
  115.             push    offset FileSpec
  116.         else
  117.             mov     ax, offset FileSpec
  118.             push    ax
  119.         endif
  120.         call    ParseFilename           ; Parse the filename
  121.         cmp     [byte Path], 0          ; Check if the path is empty
  122.         jne     short HaveAPath
  123.         mov     [byte Path], 1
  124.         mov     [byte Path+1], '\'
  125.     HaveAPath:
  126.         cmp     [byte Drive], 0         ; Check if a drive definition exists
  127.         je      short DontChangeDrives
  128.         cmp     [byte Drive+1], 61h     ; Check if the drive letter is lower
  129.         jng     short IsCapitalized     ; case
  130.         sub     [byte Drive+1], 20h     ; Capitalize the drive letter
  131.     IsCapitalized:
  132.         mov     al, [byte Drive+1]
  133.         sub     al, 'A'
  134.         ChangeDrive <al>                ; Change to the appropriate drive
  135.         jmp     short CopyPath
  136.     DontChangeDrives:
  137.         mov     [byte Drive], 2         ; Initialize the drive
  138.         mov     al, [byte OldDrive]
  139.         mov     [byte Drive+1], al      ; string with the
  140.         add     [byte Drive+1], 'A'     ; current drive.
  141.     CopyPath:
  142.  
  143.         ; Copy the start path onto the stack
  144.  
  145.         sub     sp, MAX_PATH_LENGTH     ; Make room on the stack
  146.         mov     si, sp
  147.         push    ds                      ; Push segment address of Path
  148.         if (@Cpu and 100b) eq 100b       ; Push offset
  149.             push    offset Path
  150.         else
  151.             mov     ax, offset Path
  152.             push    ax
  153.         endif
  154.         push    ss                      ; Push address to copy to
  155.         push    si
  156.         xor     ah, ah
  157.         mov     al, [byte Path]         ; Get the path length
  158.         inc     al                      ; We want to copy the length byte also
  159.         inc     al                      ; And the null terminator
  160.         call    ByteCopy                ; Copy the path onto the stack
  161.         call    FindFiles               ; Do the search for the file(s)
  162.         add     sp, MAX_PATH_LENGTH     ; Remove data on stack
  163.         call    Terminate               ; End the program
  164.     ;*************************************************************************
  165.     endp    main
  166.  
  167.     proc    Initialize
  168.  
  169.     ;   This procedure initializes all global variables and data structures
  170.     ;   used by the program.
  171.     ;
  172.     ;   Input
  173.     ;       none
  174.     ;   Output
  175.     ;       none
  176.     ;   Calling conventions
  177.     ;       NA
  178.     ;   Registers modified
  179.     ;       ax, flags
  180.  
  181.         ; Store the PSP address by storing es in the variable PspAddress.
  182.         ; Note that we do it this way instead of using DOS function 62h because
  183.         ; the function is only available on DOS 3.0 or later.
  184.  
  185.         mov     [PspAddress], es
  186.         push    ds
  187.         GetCurrentDir   <0>, <seg HomeDirectory>, <offset HomeDirectory>
  188.         pop     ds
  189.         GetDrive                        ; Get the current disk drive
  190.         mov     [byte OldDrive], al     ; Save it
  191.  
  192.         ; Verify that the user provided command line parameters.
  193.  
  194.         call    ParamCount
  195.         cmp     al, 0                   ; Were any parameters passed by user?
  196.         jne     SHORT @@Exit
  197.         call    UsageScreen             ; If no, display usage screen
  198.  
  199.     @@Exit:
  200.         ret
  201.     endp    ; Initialize
  202.  
  203.  
  204.     proc    Terminate   ;   This routine terminates the WHEREIS program.
  205.         mov     al, [byte OldDrive]     ; Get the original disk drive
  206.         ChangeDrive <al>                ; Restore the original disk drive
  207.         ChangeDirectory <seg HomeDirectory>, <((offset HomeDirectory) - 1)>
  208.         mov     ah, DOS_TERMINATE_EXE
  209.         int     DOS_FUNCTION
  210.     endp    Terminate
  211.  
  212.  
  213.     proc    UsageScreen
  214.  
  215.     ;   This routine displays a 'usage' screen that describes the syntax for
  216.     ;   using WHEREIS. It then terminates the program.
  217.     ;
  218.     ;   Input
  219.     ;       ds - Points to data segment where usage screen text is located
  220.     ;   Output
  221.     ;       none
  222.     ;   Calling conventions
  223.     ;       NA
  224.     ;   Registers modified
  225.     ;       ax, cx, dx
  226.  
  227.         push    ds
  228.         if (@Cpu and 100b) eq 100b
  229.             push    offset Syntax
  230.         else
  231.             mov     ax, offset Syntax
  232.             push    ax
  233.         endif
  234.         call    WritePascalString
  235.         call    Terminate               ; Terminate program
  236.     endp    ; UsageScreen
  237.  
  238.  
  239. endif   ; ifndef MDL
  240.  
  241. end EntryPoint
  242.