home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / ALIB40.ZIP / ALIB4B.ZIP / FILT.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-12-20  |  5.0 KB  |  234 lines

  1. ;*****************************  FILT.ASM   **********************************
  2. PAGE  70,132
  3. comment 
  4.                              FILT file
  5.                              ---------
  6.  
  7.      Purpose:
  8.      --------
  9.  
  10.      FILT is a program to find comment blocks in a file and send to stdout.
  11.      Currently it is configured to scan through library files and was used
  12.      to create the file CALLS.DOC.
  13.      
  14.  
  15.      Using FILT
  16.      ----------
  17.  
  18.      To filter file XX and send comments to file OUT
  19.  
  20.                    FILT XX > OUT
  21.  
  22.      To append file XX comment blocks to end of file OUT
  23.  
  24.                   FILT XX >> OUT
  25.  
  26.      All the block comments in the library source files can be extracted
  27.      by building a batch file which calls FILT for each file in the
  28.      library.  Using "DIR /on /b *.asm > doit.bat" is a first step in
  29.      creation of the batch file.
  30.  
  31.      It is assumed that all files are in the same directory and FILT
  32.      may not work if files are scattered around the disk.
  33.      
  34. ;-----------------------------------------------------------------------------
  35.  
  36. 
  37.     include    mac.inc
  38.     include    common.inc
  39. ;-----------------------------------------------------------------------------
  40.     extrn    library_setup:far
  41.     extrn    library_terminate:far
  42.     extrn    parse_first:far
  43.     extrn    stdout_char:far
  44.     extrn    filechar_open:far
  45.     extrn    filechar_close:far
  46.     extrn    filechar_read:far
  47.     extrn    expand_filename:far
  48. ;------------------------------------------------------------------------------
  49. code        segment para public 'CODE'
  50.         assume    cs:code, ds:code
  51. ;-----------------------------------------------------------------------------
  52. ;
  53.  
  54. pspseg        dw    0
  55. lib_info_ptr    dw    0
  56. lib_info_seg    dw    0
  57. tail_text    db    'Source File: '
  58. file_asciiz        db    80 dup (0)
  59.  
  60.         dw    200 dup (0)        ;stack
  61. stack_        dw    0
  62.  
  63.  
  64. start:
  65.     cli
  66.     mov    cs:pspseg,es    ;save PSP segment
  67.     mov    ax,cs        ;get CODE segment
  68.     mov    ss,ax
  69.     mov    ds,ax
  70.     mov    es,ax
  71.     mov    sp,offset stack_
  72.     sti
  73.     
  74. ; next, release memory beyond the end of the program
  75. ; The  definition for ZSEG marks the
  76. ; end of the program's code, data and stack area.
  77. ; When linking be sure ZSEG is at the end of the program.
  78.  
  79.     mov    ax,zseg
  80.  
  81.     mov    bx,cs:pspseg        ;
  82.     mov    es,bx
  83.     sub    bx,ax
  84.     neg    bx            ; size of program in paragraphs
  85.     mov    ah,4Ah            ; resize memory block
  86.     int    21h
  87.  
  88.     mov    ax,cs
  89.     mov    es,ax
  90. ;
  91. ; check if enough memory free to run program
  92. ;
  93.     mov    ax,pspseg        ;pass psp segment to setup
  94.     mov    bx,8            ;number of floating point variables
  95.     call    library_setup
  96.     mov    lib_info_ptr,si        ;save ptr to library info block
  97.     mov    lib_info_seg,es         ; see COMMON.INC or LIBRARY_SETUP
  98.     cmp    ax,128
  99.     jae    got_enough_mem        ;jmp if 128k of memory avail
  100.     jmp    exitx
  101.     
  102. got_enough_mem:
  103.     call    ck_for_filename
  104.     jc    exitx
  105. ;
  106. ; open file
  107. ;
  108.     mov    dx,offset file_asciiz
  109.     call    filechar_open
  110.     jc    exitx
  111. ;
  112. ; read next char
  113. ;    
  114. lp1:    call    filechar_read
  115.     jc    exit1
  116.     cmp    al,0
  117.     je    exit1
  118.  
  119.     cmp    al,'C'
  120.     je    doit
  121.     cmp    al,'c'
  122.     jne    lp1    
  123. ;
  124. ; we have found a 'c' go check for comment
  125. ;
  126. doit:    call    comment_check
  127.     jmp    lp1            
  128.  
  129. exit1:    call    filechar_close
  130.  
  131. ; normal program exit
  132.  
  133. exitx:    mov    ax,1
  134.     call    library_terminate
  135.     mov    ax,4C00h
  136.     int    21h
  137.  
  138. ;---------------------------------------------------------------------------
  139. ; ck_for_filename - get preliminary information from user
  140. ;   inputs:     none
  141. ;   outputs:    carry = aborting, insufficient info.
  142. ;            no carry = all questions answered ok
  143. ;
  144. ck_for_filename:
  145.     mov    ax,cs
  146.     mov    es,ax
  147.     mov    di,offset file_asciiz
  148.     call    parse_first
  149.     cmp    bh,0
  150.     jne    aq_test_file        ;jmp if file ok
  151.     stc
  152.     jmp    aq_exit
  153. aq_test_file:
  154. ;;    mov    si,offset file_asciiz
  155. ;;    call    expand_filename
  156.     clc
  157. aq_exit:
  158.     ret
  159. ;------------------------------------------------------
  160. comment_check:
  161.     call    filechar_read
  162.     jc    exit2
  163.     cmp    al,'o'
  164.     jne    exit2
  165.     call    filechar_read
  166.     cmp    al,'m'
  167.     jne    exit2
  168.     call    filechar_read
  169.     cmp    al,'m'
  170.     jne    exit2
  171.     call    filechar_read
  172.     cmp    al,'e'
  173.     jne    exit2
  174.     call    filechar_read
  175.     cmp    al,'n'
  176.     jne    exit2
  177.     call    filechar_read
  178.     cmp    al,'t'
  179.     jne    exit2
  180.     call    filechar_read
  181.     cmp    al,' '
  182.     jne    exit2
  183.     call    filechar_read
  184.     cmp    al,1fh
  185.     jne    exit2
  186.  
  187. ;
  188. ; we have found 'comment', send everything to stdout till end
  189. ;
  190. lp2:    call    filechar_read
  191.     cmp    al,1fh
  192.     je    add_tail
  193.     call    stdout_char
  194.     jmp    lp2
  195. ;
  196. ; append filename on end
  197. ;
  198. add_tail:
  199.     mov    si,offset tail_text
  200. lp3:    mov    al,byte ptr [si]
  201.     cmp    al,0
  202.     je    crlf
  203.     inc    si
  204.     call    stdout_char
  205.     jmp    lp3
  206.  
  207. crlf:    mov    al,0dh
  208.     call    stdout_char
  209.     mov    al,0ah
  210.     call    stdout_char
  211. exit2:    ret    
  212. ;------------------------------------------------------
  213.  
  214.  
  215.  
  216. code        ends
  217. ;-------------------------------------------------------------------------
  218. ;
  219. ; This segment definition is needed so linker will put the LIBSEG here
  220. ; before the ZSEG.  We want ZSEG to be last so memory allocation will
  221. ; work correctly.
  222. ;
  223. LIBSEG           segment byte public 'LIB'
  224. LIBSEG    ENDS
  225. ;-------------------------------------------------------------------------
  226. ; zseg must be at the end of the program for memory allocation from
  227. ; DOS.
  228. ;
  229. zseg    segment    para public 'ZZ'
  230.  
  231. zseg    ends
  232.  
  233.         end    start
  234.