home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / lattice / lcfuncs / unws.asm < prev   
Encoding:
Assembly Source File  |  1987-04-11  |  3.4 KB  |  105 lines

  1.         TITLE    UNWS     Un-Wordstar a file.
  2.  
  3.         page     60,132
  4.  
  5.         NOMATH   = 1                         ; Force not-include of math
  6.  
  7.         include  lattice.mac
  8.         PSEG
  9.  
  10. _MAIN   proc     near
  11.         _fopen   console,imode,conin         ; Open console
  12.         _fopen   console,omode,conout
  13.  
  14.         _printf  conout,ask1                 ; Ask for input filename
  15.         _scanf   conin,sfmt,iname            ; Get input filename
  16.         _printf  conout,ask2
  17.         _scanf   conin,sfmt,oname            ; Get Output filename
  18.  
  19.         _fopen   iname,imode,fp1             ; Try to open input file
  20.         cmp      ds:word ptr fp1,0           ; Any errors?
  21.         jz       opner1                      ; Yes.
  22.  
  23.         _fopen   oname,omode,fp2             ; Try to open output file
  24.         cmp      ds:word ptr fp2,0           ; Check for open error
  25.         jnz      mloop                       ; no, continue
  26.  
  27.         _printf  conout,err1                 ; error on output file.
  28.         jmp      abort
  29.  
  30. opner1: _printf  conout,err2                 ; error on input file
  31.         jmp      abort
  32.  
  33. mloop:  cmp      ds:byte ptr tab,0
  34.         jnz      cont1
  35.         mov      ds:byte ptr tab,8
  36. cont1:  _fgetc   fp1                         ; get a character from input
  37.         cmp      al,0Ah                      ; End of a line?
  38.         jnz      cont
  39.         inc      ds:word ptr lcount
  40.         mov      ds:byte ptr tab,8
  41.  
  42. cont:   cmp      al,-1                       ; End of file?
  43.         je       m_exit                      ; If so, then quit.
  44.  
  45.         and      al,7Fh                      ; Strip WS hi bit
  46.         cmp      al,0DH                      ; Let CR thru
  47.         jz       write
  48.         cmp      al,0Ah                      ; Let LF thru
  49.         jz       write
  50.  
  51.         cmp      al,09h                      ; Tab character?
  52.         jnz      cont2                       ; No, continue
  53.         mov      cl,ds:byte ptr tab
  54.         xor      ch,ch
  55. loop2:  push     cx
  56.         mov      al,20h                      ; yes, output spaces
  57.         _fputc   fp2
  58.         pop      cx
  59.         loop     loop2
  60.         mov      ds:byte ptr tab,8
  61.         jmp      mloop
  62.  
  63. cont2:  cmp      al,' '                      ; ' ' ≤ CHAR ≥ '~'
  64.         jb       mloop
  65.         cmp      al,7Eh
  66.         ja       mloop
  67. write:  _fputc   fp2                         ; otherwise output the char
  68.         dec      ds:byte ptr tab
  69.         jmp      mloop                       ; and go back for more
  70.  
  71. m_exit: _printi  conout,ifmt,lcount
  72.         _fclose  fp1
  73.         _fclose  fp2                         ; Close output file
  74. abort:  ret                                  ; Back to dos.
  75.  
  76.  
  77. _MAIN   endp
  78.  
  79.         ENDPS
  80.         DSEG
  81. console db       'CON:',0
  82. iname   db       20 dup (?)                  ; Name of input file
  83. oname   db       20 dup (?)                  ; Name of output file
  84. imode   db       'r',0
  85. omode   db       'w',0
  86. sfmt    db       '%s',0
  87. ifmt    db       0Ah,'Processed %d lines',0
  88. ask1    db       'Un-Wordstar a file',0Ah,'Enter input filename: ',0
  89. ask2    db       0Ah,'Enter output filename: ',0
  90. err1    db       0Ah,'Cannot create file',0
  91. err2    db       0Ah,'File not found',0
  92. mess1   db       0Ah,'lines Processed : ',0
  93. lcount  dw       0
  94. tab     db       9
  95.  
  96. ; FILE HANDLES
  97.  
  98. conin   dw       ?
  99. conout  dw       ?
  100. fp1     dw       ?
  101. fp2     dw       ?
  102.  
  103.         ENDDS
  104.         end
  105.