home *** CD-ROM | disk | FTP | other *** search
/ Multimedia & CD-ROM 3 / mmcd03-jun1995-cd.iso / utils / various / utils-1 / findtext.asm < prev    next >
Assembly Source File  |  1991-06-24  |  69KB  |  1,432 lines

  1. ;****************************************************************************
  2. ; FINDTEXT searches the files in a directory (and optionally its descendant
  3. ; directories) for a specified text string.  Its syntax is:
  4. ;
  5. ;       FINDTEXT [d:][path][filename] "text" [/S] [/C] [/I] [/A] [/M] [/7]
  6. ;
  7. ; where
  8. ;
  9. ;       filename   Specifies the file or files to search
  10. ;       "text"     Specifies the text to search for
  11. ;       /S         Search descendant directories
  12. ;       /C         Make the search case-sensitive
  13. ;       /I         Run in full-screen interactive mode
  14. ;       /A         Search hidden and system files as well as normal files
  15. ;       /M         Use monochrome video attributes on color adapters
  16. ;       /7         Do 7-bit comparisons (ignore 8th bit)
  17. ;
  18. ; If no path name is specified, the search begins in the current directory.
  19. ; Similarly, if no file name is specified, all files are searched.  If the
  20. ; /I switch is not specified, FINDTEXT lists the names of all the files that
  21. ; contain the specified text.  /I causes FINDTEXT to run in interactive mode,
  22. ; displaying the contents of the files as well as their names.  The /7 switch
  23. ; is useful for searching word processing files that use the high bit of each
  24. ; character for non-text purposes.  By default, FINDTEXT only searches files
  25. ; whose hidden and system attribute bits aren't set.  /A has it search those
  26. ; files, too.  Finally, /M has FINDTEXT use monochrome attributes in inter-
  27. ; active mode, useful for laptops that pair color adapters with black-and-
  28. ; white LCD or gas plasma screens.
  29. ;****************************************************************************
  30.  
  31. code            segment
  32.                 assume  cs:code,ds:code
  33.                 org     100h
  34. begin:          jmp     main
  35.  
  36. helpmsg         db      "Searches for files that contain a specified "
  37.                 db      "text string.",13,10,13,10
  38.                 db      "FINDTEXT [d:][path][filename] ",22h,"text",22h
  39.                 db      " [/S] [/C] [/I] [/A] [/M] [/7]",13,10,13,10
  40.                 db      "  filename  Specifies the file or files to "
  41.                 db      "search.",13,10
  42.                 db      "  text      Specifies the text to search for."
  43.                 db      13,10
  44.                 db      "  /S        Search descendant directories."
  45.                 db      13,10
  46.                 db      "  /C        Make the search case-sensitive."
  47.                 db      13,10
  48.                 db      "  /I        Run in full-screen interactive mode."
  49.                 db      13,10
  50.                 db      "  /A        Search hidden and system files also."
  51.                 db      13,10
  52.                 db      "  /M        Use monochrome video attributes "
  53.                 db      "(interactive mode only).",13,10
  54.                 db      "  /7        Do 7-bit comparisons (ignore 8th bit)."
  55. crlf            db      13,10,"$"
  56.  
  57. errmsg1         db      "Syntax: FINDTEXT [d:][path][filename] ",22h,"text"
  58.                 db      22h," [/S] [/C] [/I] [/A] [/M] [/7]",13,10,"$"
  59. errmsg2         db      "Invalid drive specification",13,10,"$"
  60. errmsg3         db      "Invalid path specification",13,10,"$"
  61. errmsg4         db      "Error opening $"
  62. errmsg5         db      "Error reading $"
  63. errmsg6         db      "Not enough memory",13,10,"$"
  64.  
  65. msg1            db      " file(s) searched in $"
  66. msg2a           db      " directory; $"
  67. msg2b           db      " directories; $"
  68. msg3            db      " file(s) found containing ",22h,"$"
  69. msg4            db      22h,13,10,"$"
  70.  
  71. defspec         db      "*.*",0                 ;Default file spec
  72. filespec        dw      offset defspec          ;Address of file spec
  73. srchtext        dw      0                       ;Address of search text
  74. textsize        dw      ?                       ;Length of search text
  75. endspec         dw      ?                       ;Address of end of file spec
  76. rootdir         db      "\",0                   ;Command to go to root
  77. updir           db      "..",0                  ;Command to go up one level
  78.  
  79. descflag        db      0                       ;1=Search descendants
  80. caseflag        db      0                       ;1=Case sensitive
  81. scrnflag        db      0                       ;1=Full-screen mode
  82. bitflag         db      0                       ;1=7-bit comparisons
  83. fileattr        dw      1                       ;File attributes
  84.  
  85. drive           db      ?                       ;Default drive
  86. directory       db      "\",64 dup (?)          ;Current directory
  87. pathstring      db      "x:\",64 dup (?)        ;Current drive and directory
  88. bytesbefore     dw      ?                       ;Offset to search text
  89. filessearched   dw      0                       ;Files searched
  90. dirssearched    dw      0                       ;Directories searched
  91. filesfound      dw      0                       ;Files found
  92. foundflag       db      ?                       ;1=Match found in this file
  93. bytesread       dw      ?                       ;Bytes read from file
  94. breakflag       db      ?                       ;Ctrl-Break flag
  95. handle          dw      ?                       ;File handle
  96.  
  97. rows            db      24                      ;Rows displayed (minus 1)
  98. cursor          dw      ?                       ;Cursor mode
  99. pageno          db      ?                       ;Active display page
  100. videoseg        dw      0B800h                  ;Video segment address
  101. videobuf        dw      ?                       ;Video buffer offset
  102.  
  103. window_color1   db      1Fh                     ;Primary window color
  104. window_color2   db      1Ah                     ;Secondary window color
  105. hilite_color    db      4Fh                     ;Highlighted text color
  106. text_color      db      07h                     ;Normal text color
  107. scrn_color      db      ?                       ;Screen color on entry
  108.  
  109. scrntxt1        db      "FINDTEXT",0
  110. scrntxt2        db      "Directories searched:",12 dup (20h)
  111.                 db      "Files searched:",12 dup (20h)
  112.                 db      "Files found:",0
  113. scrntxt3        db      6 dup (20h),"Press xxxxx to continue, "
  114.                 db      "xxx to stop, or xxxxx to go to next file"
  115.                 db      7 dup (20h),0
  116. scrntxt4        db      "Searching for:",0
  117. scrntxt5        db      "Location:",0
  118. scrntxt6        db      "File:",0
  119. scrntxt7        db      22h,0
  120. scrntxt8        db      "No more files",0
  121. scrntxt9        db      "Enter",0
  122. scrntxt10       db      "Esc",0
  123. scrntxt11       db      "Space",0
  124.  
  125. row1            db      ?                       ;Starting row for DRAWBOX
  126. col1            db      ?                       ;Starting column for DRAWBOX
  127. row2            db      ?                       ;Ending row for DRAWBOX
  128. col2            db      ?                       ;Ending column for DRAWBOX
  129. boxwidth        db      ?,0                     ;Box width for DRAWBOX
  130. boxheight       db      ?,0                     ;Box height for DRAWBOX
  131.  
  132. ;****************************************************************************
  133. ; Procedure MAIN
  134. ;****************************************************************************
  135.  
  136. main            proc    near
  137.                 cld                             ;Clear direction flag
  138.                 mov     si,81h                  ;Point SI to command line
  139.                 call    scanhelp                ;Scan for "/?" switch
  140.                 jnc     checkmem                ;Branch if not found
  141.                 mov     ah,09h                  ;Display help text and exit
  142.                 mov     dx,offset helpmsg       ;  with ERRORLEVEL=0
  143.                 int     21h
  144.                 mov     ax,4C00h
  145.                 int     21h
  146.  
  147. checkmem:       mov     dx,offset errmsg6       ;Make sure there's enough
  148.                 cmp     sp,0F000h               ;  memory to run the
  149.                 ja      parse                   ;  program
  150.  
  151. error:          mov     ah,09h                  ;Display error message and
  152.                 int     21h                     ;  exit with ERRORLEVEL=1
  153.                 mov     ax,4C01h
  154.                 int     21h
  155. error1:         mov     dx,offset errmsg1
  156.                 jmp     error
  157. ;
  158. ; Parse the command line.
  159. ;
  160. parse:          call    findchar                ;Find next parameter
  161.                 jnc     parse2                  ;Continue if found
  162.                 jmp     check                   ;Branch if not
  163.  
  164. parse2:         lodsb                           ;Get next character
  165.                 cmp     al,"/"                  ;Branch if it's a "/"
  166.                 je      switch
  167.                 cmp     al,22h                  ;Branch if it's a
  168.                 je      readtext                ;  quotation mark
  169.  
  170.                 cmp     filespec,offset defspec ;Error if this parameter has
  171.                 jne     error1                  ;  already been entered
  172.                 dec     si                      ;Move back one character
  173.                 mov     filespec,si             ;Save address
  174.                 call    finddelim               ;Find the end of it
  175.                 mov     byte ptr [si],0         ;Convert it to ASCIIZ
  176.                 mov     endspec,si              ;Save ending address
  177.                 jc      check                   ;Branch if end of line
  178.                 inc     si                      ;Advance to next character
  179.                 jmp     parse                   ;Return to parsing loop
  180.  
  181. readtext:       cmp     srchtext,0              ;Error if this parameter has
  182.                 jne     error1                  ; already been entered
  183.                 mov     srchtext,si             ;Save address
  184.                 sub     cx,cx                   ;Initialize count
  185. readloop:       lodsb                           ;Get next character
  186.                 cmp     al,22h                  ;Done if quotation mark
  187.                 je      readdone
  188.                 cmp     al,0Dh                  ;Error if end of line
  189.                 je      error1
  190.                 inc     cx                      ;Increment count
  191.                 jmp     readloop                ;Go back for more
  192. readdone:       jcxz    error1                  ;Error if count is 0
  193.                 mov     textsize,cx             ;Save count
  194.                 mov     byte ptr [si-1],0       ;Convert to ASCIIZ string
  195.                 jmp     parse                   ;Go back for more
  196.  
  197. switch:         lodsb                           ;Get character after switch
  198.                 cmp     al,"7"                  ;Set bitflag if it's /7
  199.                 jne     switch1
  200.                 mov     bitflag,1
  201.                 jmp     parse
  202.  
  203. switch1:        and     al,0DFh                 ;Capitalize the character
  204.                 cmp     al,"C"                  ;Set CASEFLAG is it's /C
  205.                 jne     switch2
  206.                 mov     caseflag,1
  207.                 jmp     parse
  208.  
  209. switch2:        cmp     al,"I"                  ;Set SCRNFLAG if it's /I
  210.                 jne     switch3
  211.                 mov     scrnflag,1
  212.                 jmp     parse
  213.  
  214. switch3:        cmp     al,"S"                  ;Set DESCFLAG if it's /S
  215.                 jne     switch4
  216.                 mov     descflag,1
  217.                 jmp     parse
  218.  
  219. switch4:        cmp     al,"A"                  ;Set FILEATTR if it's /A
  220.                 jne     switch5
  221.                 mov     fileattr,07h
  222.                 jmp     parse
  223.  
  224. switch5:        cmp     al,"M"                  ;Replace color attributes
  225.                 je      switch6                 ;  with monochrome if /M
  226. goto_error:     jmp     error1                  ;  was entered
  227. switch6:        call    setmono
  228.                 jmp     parse
  229.  
  230. check:          cmp     srchtext,0              ;Make sure text string was
  231.                 je      goto_error              ;  entered before going on
  232. ;
  233. ; If a path name was entered, go to the drive and directory named.
  234. ;
  235.                 mov     ah,19h                  ;Save the default drive
  236.                 int     21h
  237.                 mov     drive,al
  238.                 mov     ah,47h                  ;Save the current directory
  239.                 sub     dl,dl
  240.                 mov     si,offset directory+1
  241.                 int     21h
  242.  
  243.                 cmp     filespec,offset defspec ;Branch if no path string
  244.                 je      gotosrch                ;  was entered
  245.  
  246.                 mov     si,filespec             ;Point SI to path
  247.                 cmp     byte ptr [si+1],":"     ;Branch if path did not
  248.                 jne     nodrive                 ;  contain a drive code
  249.                 mov     ah,0Eh                  ;Otherwise set the default
  250.                 mov     dl,[si]                 ;  drive to the one
  251.                 and     dl,0DFh                 ;  specified
  252.                 sub     dl,41h
  253.                 int     21h
  254.                 mov     ah,19h                  ;See if it worked by seeing
  255.                 int     21h                     ;  what is now the default
  256.                 cmp     al,dl                   ;Error if AL != DL
  257.                 mov     dx,offset errmsg2
  258.                 je      checkpath
  259.  
  260. error3:         jmp     error
  261.  
  262. checkpath:      add     filespec,2              ;Advance past drive code
  263.                 cmp     byte ptr [si+2],0       ;If there's no path string
  264.                 jne     nodrive                 ;  after the drive code,
  265.                 mov     filespec,offset defspec ;  begin search now
  266. gotosrch:       jmp     short beginsrch
  267.  
  268. nodrive:        mov     ah,3Bh                  ;Try to set the current
  269.                 mov     dx,filespec             ;  directory using the
  270.                 int     21h                     ;  path string entered
  271.                 jc      checkend                ;  on the command line
  272.                 mov     filespec,offset defspec ;If it worked, set FILESPEC
  273.                 jmp     short beginsrch         ;  equal to *.* and branch
  274. checkend:       mov     di,endspec              ;If it failed, make sure the
  275.                 cmp     byte ptr [di-1],"\"     ;  path didn't end in "\"
  276.                 je      badpath
  277.  
  278.                 mov     cx,di                   ;Get length in CX
  279.                 sub     cx,filespec
  280.                 dec     di
  281.                 mov     al,"\"                  ;Initialize AL
  282.                 std                             ;Set direction flag
  283.                 repne   scasb                   ;Search for "\"
  284.                 cld                             ;Clear direction flag
  285.                 jne     beginsrch               ;Begin search if no "\"
  286.  
  287.                 mov     dx,filespec             ;Point DX to path
  288.                 mov     filespec,di             ;Point FILESPEC to new
  289.                 add     filespec,2              ;  file spec string
  290.                 mov     byte ptr [di+1],0       ;Convert path to ASCIIZ
  291.                 mov     ah,3Bh                  ;Try to set the current
  292.                 mov     si,dx                   ;  directory again
  293.                 cmp     byte ptr [si],0         ;Reset DX if path pointed
  294.                 jne     chdir                   ;  to the root directory
  295.                 mov     dx,offset rootdir
  296. chdir:          int     21h
  297.                 jnc     beginsrch               ;Continue if it worked
  298.  
  299. badpath:        mov     ah,0Eh                  ;Restore default drive
  300.                 mov     dl,drive                ;  and exit if it
  301.                 int     21h                     ;  failed
  302.                 mov     dx,offset errmsg3
  303.                 jmp     error
  304. ;
  305. ; Perform initializations and do the search.
  306. ;
  307. beginsrch:      mov     ah,19h                  ;Initialize path string with
  308.                 int     21h                     ;  the letter of the current
  309.                 add     al,41h                  ;  drive
  310.                 mov     pathstring,al
  311.  
  312.                 mov     si,srchtext             ;Copy the search string to
  313.                 mov     di,offset text          ;  buffer at end of program
  314.                 mov     cx,textsize
  315.                 rep     movsb
  316.  
  317.                 cmp     caseflag,0              ;Convert search string to
  318.                 jne     docase                  ;  uppercase if /C was not
  319.                 mov     si,offset text          ;  entered
  320.                 mov     cx,textsize
  321.                 call    stripcase
  322.  
  323. docase:         cmp     bitflag,0               ;Strip high bits from the
  324.                 je      do8bits                 ;  search string if /7 was
  325.                 mov     si,offset text          ;  entered
  326.                 mov     cx,textsize
  327.                 call    striphigh
  328.  
  329. do8bits:        mov     ax,3300h                ;Get the state of Ctrl-
  330.                 int     21h                     ;  Break checking
  331.                 mov     dl,breakflag
  332.                 mov     ax,3301h                ;Turn Ctrl-Break checking
  333.                 mov     dl,1                    ;  on
  334.                 int     21h
  335.                 mov     ax,2523h                ;Point interrupt 23H to
  336.                 mov     dx,offset exit          ;  internal Ctrl-Break
  337.                 cmp     scrnflag,0              ;  handler
  338.                 je      exit_ok
  339.                 mov     dx,offset abort
  340. exit_ok:        int     21h
  341.  
  342.                 cmp     scrnflag,0              ;Initialize video if full-
  343.                 je      dosearch                ;  screen mode
  344.                 call    init_video
  345.  
  346. dosearch:       call    searchdir               ;Do the search
  347.  
  348.                 cmp     scrnflag,0              ;Branch if not full-screen
  349.                 je      show_results
  350.                 mov     ax,0600h                ;Blank the window
  351.                 mov     cx,090Bh
  352.                 mov     dx,0D44h
  353.                 mov     bh,window_color1
  354.                 int     10h
  355.                 mov     si,offset scrntxt8      ;Display "No more files"
  356.                 mov     dx,0B21h
  357.                 mov     bl,window_color1
  358.                 call    bios_outtext
  359.                 mov     ah,0                    ;Wait for a keypress
  360.                 int     16h
  361. abort:          call    restore_video           ;Clear the screen and exit
  362.                 jmp     short exit
  363. ;
  364. ; Summarize the results of the search.
  365. ;
  366. show_results:   mov     ah,09h                  ;Advance cursor to next line
  367.                 mov     dx,offset crlf
  368.                 int     21h
  369.                 mov     ax,filessearched        ;Echo number of files
  370.                 call    dos_outnum              ;  searched
  371.                 mov     ah,09h
  372.                 mov     dx,offset msg1
  373.                 int     21h
  374.                 mov     ax,dirssearched         ;Echo number of directories
  375.                 call    dos_outnum              ;  searched
  376.                 mov     ah,09h
  377.                 mov     dx,offset msg2a
  378.                 cmp     dirssearched,1
  379.                 je      singular
  380.                 mov     dx,offset msg2b
  381. singular:       int     21h
  382.                 mov     ax,filesfound           ;Echo number of files
  383.                 call    dos_outnum              ;  found containing
  384.                 mov     ah,09h                  ;  the text string
  385.                 mov     dx,offset msg3
  386.                 int     21h
  387.                 mov     si,srchtext             ;Echo the text string
  388.                 call    dos_out
  389.                 mov     ah,09h
  390.                 mov     dx,offset msg4
  391.                 int     21h
  392. ;
  393. ; Restore the default drive and directory and exit.
  394. ;
  395. exit:           mov     ax,3301h                ;Restore the state of Ctrl-
  396.                 mov     dl,breakflag            ;  Break checking
  397.                 int     21h
  398.                 mov     ah,0Eh                  ;Restore default drive
  399.                 mov     dl,drive
  400.                 int     21h
  401.                 mov     ah,3Bh                  ;Restore current directory
  402.                 mov     dx,offset directory
  403.                 int     21h
  404.                 mov     ax,4C00h                ;Exit with ERRORLEVEL=0
  405.                 int     21h
  406. main            endp
  407.  
  408. ;****************************************************************************
  409. ; FINDCHAR advances SI to the next non-space or non-comma character.
  410. ; On return, carry set indicates EOL was encountered.
  411. ;****************************************************************************
  412.  
  413. findchar        proc    near
  414.                 lodsb                           ;Get the next character
  415.                 cmp     al,20h                  ;Loop if space
  416.                 je      findchar
  417.                 cmp     al,2Ch                  ;Loop if comma
  418.                 je      findchar
  419.                 dec     si                      ;Point SI to the character
  420.                 cmp     al,0Dh                  ;Exit with carry set if end
  421.                 je      eol                     ;  of line is reached
  422.  
  423.                 clc                             ;Clear carry and exit
  424.                 ret
  425.  
  426. eol:            stc                             ;Set carry and exit
  427.                 ret
  428. findchar        endp
  429.  
  430. ;****************************************************************************
  431. ; FINDDELIM advances SI to the next space or comma character.  On return,
  432. ; carry set indicates EOL was encountered.
  433. ;****************************************************************************
  434.  
  435. finddelim       proc    near
  436.                 lodsb                           ;Get the next character
  437.                 cmp     al,20h                  ;Exit if space
  438.                 je      fd_exit
  439.                 cmp     al,2Ch                  ;Exit if comma
  440.                 je      fd_exit
  441.                 cmp     al,0Dh                  ;Loop back for more if end
  442.                 jne     finddelim               ;  of line isn't reached
  443.  
  444.                 dec     si                      ;Set carry and exit
  445.                 stc
  446.                 ret
  447.  
  448. fd_exit:        dec     si                      ;Clear carry and exit
  449.                 clc
  450.                 ret
  451. finddelim       endp
  452.  
  453. ;****************************************************************************
  454. ; SCANHELP scans the command line for a /? switch.  If found, carry returns
  455. ; set and SI contains its offset.  If not found, carry returns clear.
  456. ;****************************************************************************
  457.  
  458. scanhelp        proc    near
  459.                 push    si                      ;Save SI
  460. scanloop:       lodsb                           ;Get a character
  461.                 cmp     al,0Dh                  ;Exit if end of line
  462.                 je      scan_exit
  463.                 cmp     al,22h                  ;Branch if it's a quotation
  464.                 je      skip                    ;  mark
  465.                 cmp     al,"?"                  ;Loop if not "?"
  466.                 jne     scanloop
  467.                 cmp     byte ptr [si-2],"/"     ;Loop if not "/"
  468.                 jne     scanloop
  469.  
  470.                 add     sp,2                    ;Clear the stack
  471.                 sub     si,2                    ;Adjust SI
  472.                 stc                             ;Set carry and exit
  473.                 ret
  474.  
  475. scan_exit:      pop     si                      ;Restore SI
  476.                 clc                             ;Clear carry and exit
  477.                 ret
  478.  
  479. skip:           lodsb                           ;Get a character
  480.                 cmp     al,0Dh                  ;Exit if end of line
  481.                 je      scan_exit
  482.                 cmp     al,22h                  ;Reenter the loop if it's
  483.                 je      scanloop                ;  a quotation mark
  484.                 jmp     skip                    ;Continue scanning
  485. scanhelp        endp
  486.  
  487. ;****************************************************************************
  488. ; SEARCHDIR searches files in the current directory for a text string.  If
  489. ; FINDTEXT was started with a /S switch, SEARCHDIR calls itself recursively
  490. ; to search the current directory and all its descendants.
  491. ;****************************************************************************
  492.  
  493. searchdir       proc    near
  494.                 push    bp                      ;Save BP
  495.                 mov     ah,2Fh                  ;Get current DTA address
  496.                 int     21h
  497.                 push    bx                      ;Save it
  498.                 push    es
  499.                 sub     sp,2Bh                  ;Make room on the stack
  500.                 mov     bp,sp                   ;Establish addressability
  501.                 mov     ah,1Ah                  ;Set DTA address to a
  502.                 mov     dx,bp                   ;  location in the
  503.                 int     21h                     ;  stack
  504.  
  505.                 inc     dirssearched            ;Increment directory count
  506.                 mov     ah,47h                  ;Add the current directory
  507.                 sub     dl,dl                   ;  to the path string for
  508.                 mov     si,offset pathstring+3  ;  output
  509.                 int     21h
  510.  
  511.                 cmp     scrnflag,0              ;Branch if not full-screen
  512.                 je      findfirstfile
  513.                 call    win_showdir             ;Display directory name
  514.                 mov     dh,rows                 ;Blank the directory count
  515.                 mov     dl,23                   ;  currently displayed
  516.                 mov     cx,5
  517.                 mov     bl,window_color1
  518.                 call    blankcells
  519.                 mov     ax,dirssearched         ;Display the new number of
  520.                 mov     dl,23                   ;  directories searched
  521.                 call    bios_outnum
  522. ;
  523. ; Search all the files in the current directory.
  524. ;
  525. findfirstfile:  mov     ah,4Eh                  ;Find first file matching
  526.                 mov     cx,fileattr             ;  the search criteria
  527.                 mov     dx,filespec
  528.                 int     21h
  529.                 jc      findfirstdir            ;Branch if no files found
  530.  
  531. search_another: call    searchfile              ;Search the file
  532.  
  533.                 mov     ah,4Fh                  ;Find next file matching
  534.                 int     21h                     ;  the search criteria
  535.                 jnc     search_another
  536. ;
  537. ; Search for a subdirectory to go to if /S was specified.
  538. ;
  539. findfirstdir:   cmp     descflag,0              ;Exit if /S was not entered
  540.                 je      sd_exit
  541.                 mov     ah,4Eh                  ;Find first file or
  542.                 mov     cx,17h                  ;  subdirectory
  543.                 mov     dx,offset defspec
  544.                 int     21h
  545.                 jc      sd_exit                 ;Exit if nothing found
  546.  
  547. testdir:        cmp     byte ptr [bp+30],2Eh    ;Skip . and .. entries
  548.                 je      findnextdir
  549.                 test    byte ptr [bp+21],10h    ;Branch if name returned
  550.                 jz      findnextdir             ;  is not a subdirectory
  551.  
  552.                 mov     ah,3Bh                  ;Change to the subdirectory
  553.                 mov     dx,bp                   ;  whose name was just
  554.                 add     dx,30                   ;  returned
  555.                 int     21h
  556.  
  557.                 call    searchdir               ;Search it too
  558.  
  559.                 mov     ah,3Bh                  ;Go up a directory level
  560.                 mov     dx,offset updir
  561.                 int     21h
  562.  
  563. findnextdir:    mov     ah,4Fh                  ;Find next subdirectory
  564.                 int     21h
  565.                 jnc     testdir                 ;Loop back if found
  566. ;
  567. ; Restore BP, the DTA, and the stack, then exit.
  568. ;
  569. sd_exit:        add     sp,2Bh                  ;Adjust the stack pointer
  570.                 mov     ah,1Ah                  ;Restore the DTA to where
  571.                 mov     bx,ds                   ;  it was on entry
  572.                 pop     ds
  573.                 pop     dx
  574.                 int     21h
  575.                 mov     ds,bx
  576.                 pop     bp                      ;Restore BP
  577.                 ret                             ;Return to caller
  578. searchdir       endp
  579.  
  580. ;****************************************************************************
  581. ; SEARCHFILE searches the file whose name is at [BP+30] for a text string.
  582. ;****************************************************************************
  583.  
  584. searchfile      proc    near
  585.                 mov     foundflag,0             ;Initialize flag
  586.                 inc     filessearched           ;Increment search count
  587.                 cmp     scrnflag,0              ;Branch if not full-screen
  588.                 je      openfile
  589.                 call    win_showfile            ;Display file name
  590.                 mov     dh,rows                 ;Blank the file count
  591.                 mov     dl,50                   ;  currently displayed
  592.                 mov     cx,5
  593.                 mov     bl,window_color1
  594.                 call    blankcells
  595.                 mov     ax,filessearched        ;Display the new number of
  596.                 mov     dl,50                   ;  files searched
  597.                 call    bios_outnum
  598. ;
  599. ; Open the file.
  600. ;
  601. openfile:       mov     ax,3D00h                ;Open the file for
  602.                 mov     dx,bp                   ;  reading
  603.                 add     dx,30
  604.                 int     21h
  605.                 jnc     savehandle              ;Branch if no error
  606.                 mov     dx,offset errmsg4       ;Exit on error
  607. search_error:   cmp     scrnflag,0              ;Branch if not full-screen
  608.                 je      serror1
  609.                 push    dx                      ;Save DX
  610.                 call    restore_video           ;Restore video before exit
  611.                 pop     dx                      ;Restore DX
  612. serror1:        mov     ah,09h                  ;Output the error message
  613.                 int     21h
  614.                 call    dos_outname             ;Followed by the file name
  615.                 mov     ah,09h                  ;Advance cursor to next
  616.                 mov     dx,offset crlf          ;  line before exit
  617.                 int     21h
  618.                 jmp     exit                    ;Terminate the program
  619. savehandle:     mov     handle,ax               ;Save file handle
  620. ;
  621. ; Read a block of data and search it.
  622. ;
  623. readblock:      mov     ah,3Fh                  ;Read one 24K block of data
  624.                 mov     bx,handle               ;  from the file
  625.                 mov     cx,6000h
  626.                 mov     dx,offset buffer1
  627.                 int     21h
  628.                 mov     dx,offset errmsg5       ;Exit on error
  629.                 jc      search_error
  630.                 cmp     ax,textsize             ;Done if bytes read is less
  631.                 jae     search1                 ;  then search text length
  632.                 jmp     search_done
  633.  
  634. search1:        mov     bytesread,ax            ;Save bytes read count
  635.                 cmp     bitflag,0               ;Strip the high bits off
  636.                 je      search2                 ;  characters in the buffer
  637.                 mov     si,offset buffer1       ;  if /7 was entered
  638.                 mov     cx,bytesread
  639.                 call    striphigh
  640.  
  641. search2:        cmp     caseflag,0              ;Branch if /C was not entered
  642.                 jne     search3
  643.                 cmp     scrnflag,0              ;Also branch if /I was not
  644.                 je      nocopy                  ;  entered
  645.                 mov     si,offset buffer1       ;Copy everything in BUFFER1
  646.                 mov     di,offset buffer2       ;  to BUFFER2
  647.                 mov     cx,bytesread
  648.                 rep     movsb
  649. nocopy:         mov     si,offset buffer1       ;Capitalize everything in
  650.                 mov     cx,bytesread            ;  BUFFER1
  651.                 call    stripcase
  652.  
  653. search3:        mov     cx,bytesread            ;Compute number of string
  654.                 sub     cx,textsize             ;  comparisons to be
  655.                 inc     cx                      ;  performed
  656.                 mov     si,offset buffer1       ;Point SI to buffer
  657.  
  658. search4:        push    cx                      ;Save CX and SI
  659.                 push    si
  660.                 mov     di,offset text          ;Point DI to search string
  661.                 mov     cx,textsize             ;Initialize CX with length
  662.                 repe    cmpsb                   ;Compare the strings
  663.                 je      match                   ;Branch if match found
  664. continue:       pop     si                      ;Restore SI and CX
  665.                 pop     cx
  666.                 inc     si                      ;Increment SI
  667.                 loop    search4                 ;Loop back for more
  668.  
  669.                 cmp     bytesread,6000h         ;Search done if end of
  670.                 jb      search_done             ;  file reached
  671.  
  672.                 mov     ax,textsize             ;Set the file pointer
  673.                 neg     ax                      ;  back to make sure
  674.                 cwd                             ;  text strings that
  675.                 mov     cx,dx                   ;  straddle buffer
  676.                 mov     dx,ax                   ;  boundaries are
  677.                 mov     bx,handle               ;  not missed
  678.                 mov     ax,4201h
  679.                 int     21h
  680.                 jmp     readblock               ;Process another block
  681. ;
  682. ; Process a match.
  683. ;
  684. match:          cmp     scrnflag,0              ;Branch if not full-screen
  685.                 je      match2
  686.                 cmp     foundflag,0             ;Increment files found count
  687.                 jne     alreadyfound            ;  if this is the first match
  688.                 mov     foundflag,1             ;  in this file
  689.                 inc     filesfound
  690.                 push    si                      ;Save SI
  691.                 mov     dh,rows                 ;Blank the found count
  692.                 mov     dl,74                   ;  currently displayed
  693.                 mov     cx,5
  694.                 mov     bl,window_color1
  695.                 call    blankcells
  696.                 mov     ax,filesfound           ;Display the new number of
  697.                 mov     dl,74                   ;  files found
  698.                 call    bios_outnum
  699.                 pop     si                      ;Restore SI
  700.  
  701. alreadyfound:   call    showfile                ;Show the file
  702.                 or      ah,ah                   ;Reenter the search loop
  703.                 je      continue                ;  if Enter was pressed
  704.                 add     sp,4                    ;Clean off the stack
  705.                 cmp     ah,2                    ;Search complete if spacebar
  706.                 je      search_done             ;  was pressed
  707.                 call    restore_video           ;Restore video and terminate
  708.                 jmp     exit                    ;  if Esc was pressed
  709.         
  710. match2:         add     sp,4                    ;Clean off the stack
  711.                 call    dos_outname             ;Display the file name
  712.                 inc     filesfound              ;Increment files found count
  713. ;
  714. ; Close the file and exit.
  715. ;
  716. search_done:    mov     ah,3Eh                  ;Close file with DOS
  717.                 mov     bx,handle               ;  function 3EH
  718.                 int     21h
  719.                 ret
  720. searchfile      endp
  721.  
  722. ;****************************************************************************
  723. ; SHOWFILE displays the contents of a file surrounding the point where
  724. ; a match was found in the search for matching text.  On entry, SI points
  725. ; to the address just after the text string in BUFFER1 and [BP+30] points
  726. ; to the name of the file.  On exit, AH=0 if Enter was pressed, AH=1 if
  727. ; Esc was pressed, or AH=2 if the spacebar was pressed.
  728. ;****************************************************************************
  729.  
  730. showfile        proc    near
  731.                 push    si                      ;Save SI
  732.                 mov     dx,0020h                ;Blank "FINDTEXT" at the
  733.                 mov     cx,8                    ;  top of the screen
  734.                 mov     bl,window_color1
  735.                 call    blankcells
  736. ;
  737. ; Display the file name at the top of the screen and instructions at bottom.
  738. ;
  739.                 mov     di,offset pathstring    ;Compute length of path
  740.                 call    strlen                  ;  name string
  741.                 mov     bx,cx                   ;Save it in BX
  742.                 mov     di,bp                   ;Compute length of file
  743.                 add     di,30                   ;  name string
  744.                 call    strlen
  745.                 add     bx,cx                   ;Add it to BX
  746.                 mov     dx,79                   ;Calculate where to write
  747.                 sub     dx,bx                   ;  string such that it is
  748.                 shr     dx,1                    ;  centered
  749.                 sub     dh,dh
  750.                 mov     bl,window_color1
  751.                 mov     si,offset pathstring    ;Output path string
  752.                 call    bios_outtext
  753.                 cmp     byte ptr [bp+3],0       ;Branch if this is the
  754.                 je      show1                   ;  root directory
  755.                 mov     si,offset rootdir       ;Output a "\" to separate
  756.                 call    bios_outtext            ;  the path and file names
  757. show1:          mov     si,bp                   ;Output file name
  758.                 add     si,30
  759.                 call    bios_outtext
  760.  
  761.                 mov     dh,rows                 ;Display instructions at the
  762.                 mov     dl,1                    ;  bottom of the screen
  763.                 mov     bl,window_color2
  764.                 mov     si,offset scrntxt3
  765.                 call    bios_outtext
  766.                 mov     bl,window_color1
  767.                 mov     dl,13
  768.                 mov     si,offset scrntxt9
  769.                 call    bios_outtext
  770.                 mov     dl,32
  771.                 mov     si,offset scrntxt10
  772.                 call    bios_outtext
  773.                 mov     dl,48
  774.                 mov     si,offset scrntxt11
  775.                 call    bios_outtext
  776.  
  777.                 mov     ax,0600h                ;Clear the screen
  778.                 mov     cx,0100h
  779.                 mov     dh,rows
  780.                 dec     dh
  781.                 mov     dl,79
  782.                 mov     bh,text_color
  783.                 call    exec10h
  784. ;
  785. ; Calculate starting and ending buffer offsets and show the file.
  786. ;
  787.                 pop     si                      ;Retrieve buffer pointer
  788.                 sub     si,textsize             ;Point SI to start of text
  789.                 mov     dx,si                   ;Save it in DX
  790.                 mov     al,80                   ;Compute the maximum number
  791.                 mov     bl,rows                 ;  of characters that can be
  792.                 dec     bl                      ;  displayed
  793.                 mul     bl
  794.                 push    ax                      ;Save it
  795.                 mov     al,80                   ;Redo the calculation, this
  796.                 mov     bl,rows                 ;  time making sure that the
  797.                 shr     bl,1                    ;  number of rows is an even
  798.                 shl     bl,1                    ;  number
  799.                 dec     bl
  800.                 mul     bl
  801.                 sub     ax,textsize             ;Now compute the buffer
  802.                 shr     ax,1                    ;  offset where display
  803.                 sub     si,ax                   ;  should begin
  804.                 cmp     si,offset buffer1
  805.                 jnb     start_ok
  806.                 mov     si,offset buffer1
  807. start_ok:       pop     cx                      ;Retrieve count
  808.                 sub     dx,si                   ;Calculate offset to text
  809.                 push    si                      ;Save starting offset
  810.                 add     si,cx                   ;Compute ending offset
  811.                 mov     di,offset buffer1       ;Compute maximum offset
  812.                 add     di,bytesread
  813.                 cmp     si,di                   ;Compare the offsets
  814.                 jbe     end_ok                  ;CX okay if end < maximum
  815.                 sub     si,di                   ;Otherwise subtract the
  816.                 sub     cx,si                   ;  difference from CX
  817. end_ok:         pop     si                      ;Retrieve starting offset
  818.                 cmp     caseflag,0
  819.                 jne     blast_it
  820.                 add     si,6000h                ;Adjust if case-sensitive
  821. blast_it:       push    es                      ;Save ES
  822.                 mov     es,videoseg             ;Point ES:DI to video buffer
  823.                 mov     di,videobuf
  824.                 add     di,160
  825. out_loop1:      lodsb                           ;Get a character
  826.                 cmp     al,32                   ;Substitute a period if
  827.                 jb      period                  ;  it's non-displayable
  828.                 cmp     al,126
  829.                 jbe     copy_it
  830. period:         mov     al,"."
  831. copy_it:        stosb                           ;Copy it to the video buffer
  832.                 inc     di                      ;Advance to next character
  833.                 loop    out_loop1               ;Loop until done
  834. ;
  835. ; Highlight the search text.
  836. ;
  837.                 mov     di,videobuf             ;Point DI to the byte that
  838.                 add     di,160                  ;  corresponds to the first
  839.                 shl     dx,1                    ;  attribute of the search
  840.                 add     di,dx                   ;  text
  841.                 inc     di
  842.                 mov     al,hilite_color         ;Load attribute in AL
  843.                 mov     cx,textsize             ;Load string length in CX
  844. out_loop2:      stosb                           ;Highlight the search text
  845.                 inc     di
  846.                 loop    out_loop2
  847.                 pop     es                      ;Restore ES
  848. ;
  849. ; Get a keyboard response from the user.
  850. ;
  851. getkey:         mov     ah,0                    ;Read keyboard
  852.                 int     16h
  853.                 sub     ah,ah                   ;Set AH to 0
  854.                 cmp     al,0Dh                  ;Exit if Enter was pressed
  855.                 je      show_exit
  856.                 inc     ah                      ;Set AH to 1
  857.                 cmp     al,1Bh                  ;Exit if Esc was pressed
  858.                 je      show_abort
  859.                 mov     ah,2
  860.                 cmp     al,20h                  ;Exit if spacebar was pressed
  861.                 jne     getkey                  ;Otherwise loop back for more
  862. ;
  863. ; Redraw the title bar, status bar, and search window, then exit.
  864. ;
  865. show_exit:      push    ax                      ;Save return code
  866.                 mov     ax,0600h                ;Clear the screen
  867.                 mov     cx,0100h
  868.                 mov     dh,rows
  869.                 dec     dh
  870.                 mov     dl,79
  871.                 mov     bh,text_color
  872.                 call    exec10h
  873.                 call    drawtitle               ;Redraw the title bar
  874.                 call    drawstatus              ;Redraw the status bar
  875.                 call    drawwindow              ;Redraw the window
  876.                 call    win_showdir             ;Display directory name
  877.                 call    win_showfile            ;Display file name
  878.                 pop     ax                      ;Retrieve return code
  879. show_abort:     ret
  880. showfile        endp
  881.  
  882. ;****************************************************************************
  883. ; DOS_OUTNUM converts the number in AX to ASCII and displays it.
  884. ;****************************************************************************
  885.  
  886. dos_outnum      proc    near
  887.                 mov     bx,10                   ;Initialize BX with divisor
  888.                 sub     cx,cx                   ;Initialize digit counter
  889. divide:         inc     cx                      ;Increment counter
  890.                 sub     dx,dx                   ;Zero high word of DX:AX
  891.                 div     bx                      ;Divide AX by 10
  892.                 push    dx                      ;Save remainder on stack
  893.                 or      ax,ax                   ;Loop if AX != 0
  894.                 jnz     divide
  895. output:         mov     ah,02h                  ;Use DOS function 02H
  896.                 pop     dx                      ;Retrieve digit from stack
  897.                 add     dl,30h                  ;Convert to ASCII
  898.                 int     21h                     ;Output it
  899.                 loop    output                  ;Loop until done
  900.                 ret
  901. dos_outnum      endp
  902.  
  903. ;****************************************************************************
  904. ; DOS_OUTNAME displays the ASCIIZ file name addressed by [BP+30] prefixed
  905. ; by the ASCIIZ string PATHSTRING.
  906. ;****************************************************************************
  907.  
  908. dos_outname     proc    near
  909.                 mov     si,offset pathstring    ;Output path string
  910.                 call    dos_out
  911.                 mov     ah,02h
  912.                 mov     si,offset pathstring    ;Output "\" if this is
  913.                 cmp     byte ptr [si+3],0       ;  not the root directory
  914.                 je      notroot
  915.                 mov     ah,02h
  916.                 mov     dl,"\"
  917.                 int     21h
  918. notroot:        mov     si,bp                   ;Output file name
  919.                 add     si,30
  920.                 call    dos_out
  921.                 mov     ah,09h                  ;Move cursor to next line
  922.                 mov     dx,offset crlf
  923.                 int     21h
  924.                 ret
  925. dos_outname     endp
  926.  
  927. ;****************************************************************************
  928. ; WIN_SHOWDIR displays the name of the directory being searched in
  929. ; the search window.
  930. ;****************************************************************************
  931.  
  932. win_showdir     proc    near
  933.                 mov     dx,0B1Bh                ;Blank the directory name
  934.                 mov     cx,42                   ;  currently displayed
  935.                 mov     bl,window_color1
  936.                 call    blankcells
  937.                 mov     si,offset pathstring    ;Point SI to PATHSTRING
  938.                 mov     dx,0B1Bh                ;Starting row and column
  939.                 mov     di,si                   ;Get length of PATHSTRING
  940.                 call    strlen
  941.                 cmp     cx,41                   ;Branch if it's greater
  942.                 ja      wsd1                    ;  than 41
  943.                 call    bios_outtext            ;Output PATHSTRING
  944.                 ret                             ;Return to caller
  945. wsd1:           mov     cx,41                   ;Output first 41 characters
  946.                 call    bios_out                ;  of PATHSTRING
  947.                 ret                             ;Return to caller
  948. win_showdir     endp
  949.  
  950. ;****************************************************************************
  951. ; WIN_SHOWFILE displays the name of the file being searched in the
  952. ; search window.  On entry, [BP+30] points to the file name.
  953. ;****************************************************************************
  954.  
  955. win_showfile    proc    near
  956.                 mov     dx,0C1Bh                ;Blank the file name
  957.                 mov     cx,42                   ;  currently displayed
  958.                 mov     bl,window_color1
  959.                 call    blankcells
  960.                 mov     si,bp
  961.                 add     si,30
  962.                 mov     dx,0C1Bh                ;Display the file name
  963.                 call    bios_outtext
  964.                 ret
  965. win_showfile    endp
  966.  
  967. ;****************************************************************************
  968. ; STRIPCASE converts lowercase characters to uppercase in the buffer
  969. ; pointed ot by DS:SI.  On entry, CX the buffer length.
  970. ;****************************************************************************
  971.  
  972. stripcase       proc    near
  973.                 cmp     byte ptr [si],"a"       ;Skip if less than "a"
  974.                 jb      notlower
  975.                 cmp     byte ptr [si],"z"       ;Skip if greater than "z"
  976.                 ja      notlower
  977.                 and     byte ptr [si],0DFh      ;Capitalize the character
  978. notlower:       inc     si                      ;Advance SI
  979.                 loop    stripcase               ;Loop until done
  980.                 ret
  981. stripcase       endp
  982.  
  983. ;****************************************************************************
  984. ; STRIPHIGH strips the high bits off the characters in the buffer pointed
  985. ; to by DS:SI.  On entry, CX holds the buffer length.
  986. ;****************************************************************************
  987.  
  988. striphigh       proc    near
  989.                 and     byte ptr [si],7Fh       ;Zero the high bit
  990.                 inc     si                      ;Advance SI
  991.                 loop    striphigh               ;Loop until done
  992.                 ret
  993. striphigh       endp
  994.  
  995. ;****************************************************************************
  996. ; DOS_OUT displays the ASCIIZ text string pointed to by DS:SI using DOS
  997. ; function 02H.  Text is displayed at the current cursor position.
  998. ;***************************************************************************
  999.  
  1000. dos_out         proc    near
  1001.                 lodsb                           ;Get a character
  1002.                 or      al,al                   ;Exit if zero
  1003.                 jz      dos_exit
  1004.                 mov     ah,02h                  ;Display it using DOS
  1005.                 mov     dl,al                   ;  function 02H
  1006.                 int     21h
  1007.                 jmp     dos_out                 ;Loop back for more
  1008. dos_exit:       ret
  1009. dos_out         endp
  1010.  
  1011. ;****************************************************************************
  1012. ; INIT_VIDEO sets the video environment for full-screen mode.
  1013. ;****************************************************************************
  1014.  
  1015. init_video      proc    near
  1016.                 push    es                      ;Point ES to the BIOS
  1017.                 mov     ax,40h                  ;  Data Area
  1018.                 mov     es,ax
  1019.                 mov     al,es:[49h]             ;Get display mode in AL
  1020.                 cmp     al,7                    ;Continue if mode 2, 3,
  1021.                 je      mode_ok                 ;  or 7
  1022.                 cmp     al,2
  1023.                 je      mode_ok
  1024.                 cmp     al,3
  1025.                 je      mode_ok
  1026.                 mov     ax,0003h                ;Reset video mode
  1027.                 test    byte ptr es:[63h],40h
  1028.                 jnz     reset
  1029.                 mov     ax,0007h
  1030. reset:          int     10h
  1031. mode_ok:        test    byte ptr es:[63h],40h   ;Determine whether video is
  1032.                 jnz     is_color                ;  color or monochrome
  1033.                 call    setmono         ;Switch to monochrome video
  1034.                 mov     videoseg,0B000h
  1035. is_color:       mov     ax,es:[4Eh]             ;Get starting page address
  1036.                 mov     videobuf,ax
  1037.                 mov     al,es:[62h]             ;Get active page number
  1038.                 mov     pageno,al
  1039.                 mov     ax,es:[60h]             ;Get cursor type
  1040.                 mov     cursor,ax
  1041.                 mov     ah,12h                  ;Find out if there's an
  1042.                 mov     bl,10h                  ;  an EGA, VGA, or XGA
  1043.                 int     10h                     ;  installed
  1044.                 cmp     bl,10h
  1045.                 je      noega
  1046.                 mov     al,es:[84h]             ;Determine number of rows
  1047.                 mov     rows,al                 ;  displayed if there is
  1048. noega:          pop     es                      ;Restore ES
  1049.                 mov     ah,08h                  ;Get the color of the
  1050.                 mov     bh,pageno               ;  character at the
  1051.                 int     10h                     ;  cursor
  1052.                 mov     scrn_color,ah
  1053. ;
  1054. ; Paint the screen.
  1055. ;
  1056.                 mov     ah,01h                  ;Hide the cursor
  1057.                 mov     ch,20h
  1058.                 int     10h
  1059.                 mov     ax,0600h                ;Clear the screen
  1060.                 sub     cx,cx
  1061.                 mov     dh,rows
  1062.                 mov     dl,79
  1063.                 mov     bh,text_color
  1064.                 int     10h
  1065.                 call    drawtitle               ;Display the title bar
  1066.                 call    drawstatus              ;Display the status bar
  1067.                 call    drawwindow              ;Display the status window
  1068.                 ret
  1069. init_video      endp
  1070.  
  1071. ;****************************************************************************
  1072. ; RESTORE_VIDEO cleans up the screen before the program terminates.
  1073. ;****************************************************************************
  1074.  
  1075. restore_video   proc    near
  1076.                 mov     ax,0600h                ;Clear the screen
  1077.                 sub     cx,cx
  1078.                 mov     dh,rows
  1079.                 mov     dl,79
  1080.                 mov     bh,scrn_color
  1081.                 int     10h
  1082.                 mov     ah,02h                  ;Home the cursor
  1083.                 mov     bh,pageno
  1084.                 sub     dx,dx
  1085.                 int     10h
  1086.                 mov     ah,01h                  ;Redisplay the cursor
  1087.                 mov     cx,cursor
  1088.                 int     10h
  1089.                 ret
  1090. restore_video   endp
  1091.  
  1092. ;****************************************************************************
  1093. ; SETMONO replaces color video attributes with monochrome attributes.
  1094. ;****************************************************************************
  1095.  
  1096. setmono proc    near
  1097.                 mov     window_color1,70h
  1098.                 mov     window_color2,70h
  1099.                 mov     hilite_color,70h
  1100.                 mov     text_color,07h
  1101.                 ret
  1102. setmono endp
  1103.  
  1104. ;****************************************************************************
  1105. ; DRAWTITLE displays the screen title at the top of the screen.
  1106. ;****************************************************************************
  1107.  
  1108. drawtitle       proc    near
  1109.                 sub     dx,dx                   ;Blank the line
  1110.                 mov     cx,80
  1111.                 mov     bl,window_color1
  1112.                 call    blankcells
  1113.                 mov     dx,0024h                ;Display title
  1114.                 mov     si,offset scrntxt1
  1115.                 call    bios_outtext
  1116.                 ret
  1117. drawtitle       endp
  1118.  
  1119. ;****************************************************************************
  1120. ; DRAWSTATUS displays the status bar at the bottom of the screen.
  1121. ;****************************************************************************
  1122.  
  1123. drawstatus      proc    near
  1124.                 mov     dh,rows                 ;Blank the line
  1125.                 sub     dl,dl
  1126.                 mov     cx,80
  1127.                 mov     bl,window_color1
  1128.                 call    blankcells
  1129.                 mov     dl,1                    ;Display status bar text
  1130.                 mov     si,offset scrntxt2
  1131.                 mov     bl,window_color2
  1132.                 call    bios_outtext
  1133.  
  1134.                 mov     ax,dirssearched         ;Display number of
  1135.                 mov     bl,window_color1        ;  directories searched
  1136.                 mov     dl,23
  1137.                 call    bios_outnum
  1138.  
  1139.                 mov     ax,filessearched        ;Display number of files
  1140.                 mov     dl,50                   ;  searched
  1141.                 call    bios_outnum
  1142.  
  1143.                 mov     ax,filesfound           ;Display number of files
  1144.                 mov     dl,74                   ;  found containing the
  1145.                 call    bios_outnum             ;  search string
  1146.                 ret
  1147. drawstatus      endp
  1148.  
  1149. ;****************************************************************************
  1150. ; DRAWWINDOW displays the search window on the screen.
  1151. ;****************************************************************************
  1152.  
  1153. drawwindow      proc    near
  1154.                 mov     ax,0600h                ;Blank the area where the
  1155.                 mov     cx,080Ah                ;  window will lie
  1156.                 mov     dx,0E45h
  1157.                 mov     bh,window_color1
  1158.                 call    exec10h
  1159.  
  1160.                 mov     cx,080Ah                ;Draw a border around the
  1161.                 mov     dx,0E45h                ;  window
  1162.                 mov     bh,pageno
  1163.                 mov     bl,window_color1
  1164.                 call    drawbox
  1165.  
  1166.                 mov     dx,0A0Ch                ;Display "Searching for:"
  1167.                 mov     si,offset scrntxt4
  1168.                 mov     bl,window_color2
  1169.                 call    bios_outtext
  1170.                 mov     dx,0B11h                ;Display "Location:"
  1171.                 mov     si,offset scrntxt5
  1172.                 call    bios_outtext
  1173.                 mov     dx,0C15h                ;Display "File:"
  1174.                 mov     si,offset scrntxt6
  1175.                 call    bios_outtext
  1176.  
  1177.                 mov     dx,0A1Bh                ;Display opening quotation
  1178.                 mov     bl,window_color1        ;  mark
  1179.                 mov     si,offset scrntxt7
  1180.                 call    bios_outtext
  1181.  
  1182.                 mov     si,srchtext             ;Display search text
  1183.                 mov     di,si
  1184.                 call    strlen
  1185.                 cmp     cx,39
  1186.                 ja      dw1
  1187.                 call    bios_outtext
  1188.                 jmp     short dw2
  1189. dw1:            mov     cx,39
  1190.                 call    bios_out
  1191.  
  1192. dw2:            mov     si,offset scrntxt7      ;Display closing quotation
  1193.                 call    bios_outtext            ;  mark
  1194.                 ret
  1195. drawwindow      endp
  1196.  
  1197. ;****************************************************************************
  1198. ; EXEC10H executes an INT 10H and preserves BP across the call.
  1199. ;****************************************************************************
  1200.  
  1201. exec10h         proc    near
  1202.                 push    bp                      ;Save BP
  1203.                 int     10h                     ;Do the interrupt
  1204.                 pop     bp                      ;Restore BP
  1205.                 ret
  1206. exec10h         endp
  1207.  
  1208. ;****************************************************************************
  1209. ; STRLEN returns the length of the ASCIIZ string pointed to by ES:DI in CX.
  1210. ;****************************************************************************
  1211.  
  1212. strlen          proc    near
  1213.                 mov     cx,0FFFFh               ;Initialize count
  1214.                 sub     al,al                   ;Intialize AL
  1215.                 repne   scasb                   ;Search for zero
  1216.                 inc     cx                      ;Calculate number of
  1217.                 mov     ax,0FFFFh               ;  bytes that were
  1218.                 xchg    ax,cx                   ;  examined
  1219.                 sub     cx,ax
  1220.                 ret
  1221. strlen          endp
  1222.  
  1223. ;****************************************************************************
  1224. ; BIOS_OUT displays an ASCII string.  On entry, DS:SI points to the string,
  1225. ; DH and DL hold the starting row and column, BL holds the attribute to be
  1226. ; used, and CX holds the character count.
  1227. ;****************************************************************************
  1228.  
  1229. bios_out        proc    near
  1230.                 mov     ah,02h                  ;Set the cursor position
  1231.                 mov     bh,pageno
  1232.                 call    exec10h
  1233.                 push    cx                      ;Save count
  1234.                 lodsb                           ;Get a character
  1235.                 mov     ah,09h                  ;Display it
  1236.                 mov     cx,1
  1237.                 call    exec10h
  1238.                 inc     dl                      ;Advance column number
  1239.                 pop     cx                      ;Retrieve count
  1240.                 loop    bios_out                ;Loop until done
  1241.                 ret
  1242. bios_out        endp
  1243.  
  1244. ;****************************************************************************
  1245. ; BIOS_OUTTEXT displays the ASCIIZ text string pointed to by DS:SI using
  1246. ; BIOS text output functions.  On entry, DH and DL hold the row and column
  1247. ; where output should begin and BL holds the attribute to be used.
  1248. ;****************************************************************************
  1249.  
  1250. bios_outtext    proc    near
  1251.                 mov     ah,02h                  ;Set the cursor position
  1252.                 mov     bh,pageno
  1253.                 call    exec10h
  1254.                 lodsb                           ;Get a character
  1255.                 or      al,al                   ;Exit if zero
  1256.                 jz      bios_exit
  1257.                 mov     ah,09h                  ;Display it
  1258.                 mov     cx,1
  1259.                 call    exec10h
  1260.                 inc     dl                      ;Advance column number
  1261.                 jmp     bios_outtext            ;Loop back for more
  1262. bios_exit:      ret
  1263. bios_outtext    endp
  1264.  
  1265. ;****************************************************************************
  1266. ; BIOS_OUTNUM converts the number in AX to ASCII form and displays it using
  1267. ; BIOS output functions.  On entry, AX holds the number, DH and DL hold the
  1268. ; row and column address, and BL holds the attribute to be used.
  1269. ;****************************************************************************
  1270.  
  1271. bios_outnum     proc    near
  1272.                 mov     si,bx                   ;Save BX and DX
  1273.                 mov     di,dx
  1274.                 mov     bx,10                   ;Initialize BX with divisor
  1275.                 sub     cx,cx                   ;Initialize digit counter
  1276. bnum1:          inc     cx                      ;Increment counter
  1277.                 sub     dx,dx                   ;Zero high word of DX:AX
  1278.                 div     bx                      ;Divide AX by 10
  1279.                 push    dx                      ;Save remainder on stack
  1280.                 or      ax,ax                   ;Loop if AX != 0
  1281.                 jnz     bnum1
  1282.  
  1283.                 mov     bx,si                   ;Retrieve BX and DX
  1284.                 mov     dx,di
  1285.                 mov     bh,pageno               ;Place page number in BH
  1286.  
  1287. bnum2:          mov     ah,02h                  ;Position the cursor
  1288.                 call    exec10h
  1289.                 pop     ax                      ;Retrieve digit from stack
  1290.                 add     al,30h                  ;Convert to ASCII
  1291.                 mov     ah,09h                  ;Output it using BIOS
  1292.                 push    cx                      ;  function 09H
  1293.                 mov     cx,1
  1294.                 call    exec10h
  1295.                 pop     cx
  1296.                 inc     dl                      ;Advance the cursor
  1297.                 loop    bnum2                   ;Loop until done
  1298.                 ret
  1299. bios_outnum     endp
  1300.  
  1301. ;****************************************************************************
  1302. ; BLANKCELLS blanks a line or part of a line.  On entry, DH and DL hold the
  1303. ; starting row and column, CX holds the number of cells to blank, and BL
  1304. ; holds the attribute to be used.
  1305. ;****************************************************************************
  1306.  
  1307. blankcells      proc    near
  1308.                 mov     ah,02h                  ;Position the cursor
  1309.                 mov     bh,pageno
  1310.                 call    exec10h
  1311.                 mov     ax,0920h                ;Blank the cells
  1312.                 call    exec10h
  1313.                 ret
  1314. blankcells      endp
  1315.  
  1316. ;****************************************************************************
  1317. ; DRAWBOX draws a single line box.  On entry, CH and CL hold the row and
  1318. ; column address of the upper left corner of the box, DH and DL the address
  1319. ; of the lower right corner, BH the page number, and BL the attribute to be
  1320. ; used.
  1321. ;****************************************************************************
  1322.  
  1323. drawbox         proc    near
  1324.                 mov     row1,ch                 ;Save box coordinates and
  1325.                 mov     col1,cl                 ;  compute the box height
  1326.                 mov     row2,dh                 ;  and box width
  1327.                 mov     col2,dl
  1328.                 push    cx
  1329.                 sub     dh,ch
  1330.                 dec     dh
  1331.                 mov     boxheight,dh
  1332.                 sub     dl,cl
  1333.                 dec     dl
  1334.                 mov     boxwidth,dl
  1335.  
  1336.                 mov     ah,02h                  ;Position the cursor at the
  1337.                 pop     dx                      ;  upper left corner
  1338.                 call    exec10h
  1339.  
  1340.                 mov     ah,09h                  ;Draw upper left corner
  1341.                 mov     al,218
  1342.                 mov     cx,1
  1343.                 call    exec10h
  1344.  
  1345.                 mov     dh,row1                 ;Draw upper horizontal
  1346.                 mov     dl,col1
  1347.                 inc     dl
  1348.                 mov     cx,word ptr boxwidth
  1349.                 call    drawhorizontal
  1350.  
  1351.                 mov     ah,02h                  ;Draw upper right corner
  1352.                 mov     dl,col2
  1353.                 call    exec10h
  1354.                 mov     ah,09h
  1355.                 mov     al,191
  1356.                 mov     cx,1
  1357.                 call    exec10h
  1358.  
  1359.                 inc     dh                      ;Draw right vertical
  1360.                 mov     cx,word ptr boxheight
  1361.                 call    drawvertical
  1362.  
  1363.                 mov     ah,02h                  ;Draw lower right corner
  1364.                 mov     dh,row2
  1365.                 call    exec10h
  1366.                 mov     ah,09h
  1367.                 mov     al,217
  1368.                 mov     cx,1
  1369.                 call    exec10h
  1370.  
  1371.                 mov     dl,col1                 ;Draw lower horizontal
  1372.                 inc     dl
  1373.                 mov     cx,word ptr boxwidth
  1374.                 call    drawhorizontal
  1375.  
  1376.                 mov     ah,02h                  ;Draw lower left corner
  1377.                 dec     dl
  1378.                 call    exec10h
  1379.                 mov     ah,09h
  1380.                 mov     al,192
  1381.                 mov     cx,1
  1382.                 call    exec10h
  1383.  
  1384.                 mov     dh,row1                 ;Draw left vertical
  1385.                 inc     dh
  1386.                 mov     cx,word ptr boxheight
  1387.                 call    drawvertical
  1388.                 ret
  1389. drawbox         endp
  1390.  
  1391. ;****************************************************************************
  1392. ; DRAWHORIZONTAL draws a horizontal line at the cursor position passed in
  1393. ; DH and DL.  Length is specified in CX, attribute in BL, and page number in
  1394. ; BH.  The line is drawn left to right.
  1395. ;****************************************************************************
  1396.  
  1397. drawhorizontal  proc    near
  1398.                 mov     ah,02h                  ;Position the cursor
  1399.                 call    exec10h
  1400.                 mov     ah,09h                  ;Draw horizontal
  1401.                 mov     al,196
  1402.                 call    exec10h
  1403. dh_exit:        ret
  1404. drawhorizontal  endp
  1405.  
  1406. ;****************************************************************************
  1407. ; DRAWVERTICAL draws a vertical line at the cursor position passed in
  1408. ; DH and DL.  Length is specified in CX, attribute in BL, and page number
  1409. ; in BH.  The line is drawn top to bottom.
  1410. ;****************************************************************************
  1411.  
  1412. drawvertical    proc    near
  1413.                 mov     ah,02h                  ;Position the cursor
  1414.                 call    exec10h
  1415.                 push    cx                      ;Save CX
  1416.                 mov     ah,09h                  ;Draw one character
  1417.                 mov     al,179
  1418.                 mov     cx,1
  1419.                 call    exec10h
  1420.                 inc     dh
  1421.                 pop     cx                      ;Retrieve CX
  1422.                 loop    drawvertical            ;Loop until done
  1423. dv_exit:        ret
  1424. drawvertical    endp
  1425.  
  1426. text            =       $                       ;Text being searched for
  1427. buffer1         =       $+80h                   ;File I/O buffer 1 (24K)
  1428. buffer2         =       $+6080h                 ;File I/O buffer 2 (24K)
  1429.  
  1430. code            ends
  1431.                 end     begin
  1432.