home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc2 / filters.lzh / FORCLEAN.ASM < prev    next >
Assembly Source File  |  1985-05-11  |  3KB  |  134 lines

  1.     Name forclean
  2.     Title
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that reads a fortran file and
  7.     removes comment lines and numeric labels from the code.
  8.     Used with trunc and find, this can help list all subroutines
  9.  used by a program.
  10.  
  11.     ==>    FIND "CALL" FORTRAN.FOR|FORCLEAN|TRUNC (|SORT|UNIQUE
  12.                     --------
  13. /
  14. ;===================================================================
  15. code    segment    public
  16. ;===================================================================
  17. ;
  18. ;    command line is at 80h of psp - first byte is length
  19. ;
  20.     org    80h
  21. parmsize    db    ?
  22. parm        db    7fh dup (?)
  23. ;
  24. ; .com starts at 100h - but must jump around any data area
  25. ;
  26.     org    100h            ; com file starts here
  27.     assume    cs:code,ds:code,es:code
  28. forclean:
  29.     jmp    clear
  30. ;===================================================================
  31. ;
  32. ; data area for .com programs
  33. ;
  34. inchar      db    ?
  35. count        dw    ?
  36. ;
  37. ;===================================================================
  38. clear:
  39. ;
  40. ; start of actual code is here (clear)
  41. ;
  42. ;
  43. ; Read a character.  If it is 'C' skip the line.  If numeric, convert
  44. ; to space.
  45. ;
  46. ; These two i/o parameters are constants.
  47. ;
  48. parmok:
  49.     lea    dx,inchar    ; offset of inchar
  50.     mov    cx,1h        ; get 1 character
  51.     mov    count,0h     ; position of character in line
  52. again:
  53. ;
  54. ; read a character
  55. ;
  56.     xor    bx,bx        ; zero is handle of standard input
  57.     mov    ah,3fh        ; read a file/device function
  58.     int    21h        ; invoke the function
  59. ;
  60. ; if carry set of ax=0 exit
  61. ;
  62.     jc    oops        ; i/o error
  63.     and    ax,ax        ; set flags
  64.     jz    oops        ; eof
  65. ;
  66.     inc    count        ; character position in line
  67. ;
  68. ; compare character against parmline.
  69. ;
  70.     cmp    count,1h    ; if 1, test for '$' and 'C'
  71.     jne    notfirst
  72. ;
  73. ; if C or $ skip the whole line. (It's a comment or metacommand.)
  74. ;
  75. ; If TAB, add 7 to count.
  76. ;
  77.     cmp    inchar,09h    ; tab character?
  78.     jne    testc
  79.     add    count,07h    ; adjust for tab
  80.     jmp    notfirst
  81. testc:
  82.     cmp    inchar,'C'
  83.     je    skip
  84.     cmp    inchar,'$'
  85.     je    skip
  86. ;
  87. ; If character is '0'-'9' and count <6 convert to space.
  88. ;
  89. notfirst:
  90.     cmp    count,6h    ; test for position
  91.     jge    output        ; don't test at all if count >=6.
  92.     cmp    inchar,'0'    ; if '0' >= inchar >= '9' convert it.
  93.     jl    output
  94.     cmp    inchar,'9'
  95.     jg    output
  96.     mov    inchar,' '    ; convert to space
  97.     jmp    output        ; output the character
  98. ;
  99. ; First character was C or $ - skip the rest of the line.
  100. ;
  101. skip:
  102.     xor    bx,bx        ; zero is handle of standard input
  103.     mov    cx,1h        ; get 1 character
  104.     mov    ah,3fh        ; read a file/device function
  105.     int    21h        ; invoke the function
  106. ;
  107. ; if carry set of ax=0 exit
  108. ;
  109.     jc    oops        ; i/o error
  110.     and    ax,ax        ; set flags
  111.     jz    oops        ; eof
  112. ;
  113. ; look for <lf>
  114. ;
  115.     cmp    inchar,0Ah    ; if inchar is <LF>, start i/o again.
  116.     jne    skip        ; otherwise skip it.
  117.     mov    count,0h
  118.     jmp    again
  119. output:
  120.     mov    bx,1h        ; standard output handle
  121.     mov    ah,40h        ; dx still points at inchar
  122.     int    21h        ; call dos output function
  123. ;
  124. ; if character just output was a <lf>, re-init the position counter
  125. ;
  126.     cmp    inchar,0Ah
  127.     jne    again
  128.     mov    count,0h
  129.     jmp    again        ; repeat cycle
  130. oops:
  131.     int    20h        ; return to dos
  132. code    ends
  133.     end    forclean
  134.