home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / txtutl / strip21.arc / STRIP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-02-08  |  4.9 KB  |  223 lines

  1. {$c+}
  2. program strip;
  3.  
  4. {
  5.  This is a program to strip off the high bit of each byte of a text file.
  6.  The high bit is used by WordStar for document formatting.  This conversion
  7.  allows the user to use WS to create document files and still 'type' them or
  8.  send them to CIS.  (After the document has been stripped, of course.)
  9. }
  10.  
  11. type
  12.    s255 = string[255];
  13. var
  14.    FilVarIn,
  15.    FilVarOut       : file of byte;
  16.    FilenameIn,
  17.    FilenameOut,
  18.    temp            : s255;
  19.    ChrIn,
  20.    ChrOut          : byte;
  21.    Stats,
  22.    Scrn            : boolean;
  23.    i,j,
  24.    code,
  25.    line,chrcnt,bite,
  26.    r1,c1,
  27.    r2,c2           : integer;
  28. const
  29.    dl : Char = '═';
  30.    ls : Char = '╡';
  31.    rs : Char = '╞';
  32.    up : Char = #24;
  33.    dn : Char = #25;
  34.    sl : Char = '─';
  35.  
  36.    cr : Char = #13;
  37.    lf : Char = #12;
  38.  
  39. function FileParse(var temp : s255) : s255;
  40. var
  41.   j : integer;
  42. begin
  43.   j:=pos('/',temp);
  44.   if j=0 then
  45.     FileParse := temp
  46.   else
  47.     FileParse := copy(temp,1,j-1);
  48. end;
  49.  
  50. procedure ParamParse(temp : s255);
  51. var
  52.   switch : char;
  53.   i      : integer;
  54. begin
  55.   i:=pos('/',temp);
  56.   if i<>0 then begin
  57.     switch:=temp[i+1];
  58.     case switch of
  59.       's','S' : Stats:=false;
  60.       'd','D' : Scrn:=false;
  61.     end;
  62.     temp:=copy(temp,i+2,length(temp));
  63.     ParamParse(temp);
  64.   end;
  65. end;
  66.  
  67. procedure GetInName(var FileNameIn : s255);
  68. begin
  69.    write('Enter the name of the input file: ');
  70.    readln(FileNameIn);
  71.    ParamParse(FileNameIn);
  72.    FileNameIn := FileParse(FileNameIn);
  73. end;
  74.  
  75. procedure GetOutName(var FileNameOut : s255);
  76. begin
  77.    write('Enter the name of the output file: ');
  78.    readln(FileNameOut);
  79.    ParamParse(FileNameOut);
  80.    FileNameOut := FileParse(FileNameOut);
  81. writeln(FileNameOut);
  82. end;
  83.  
  84. BEGIN
  85. ClrScr;
  86. FileNameIn:='';   { Set names to nul to ensure that they are empty }
  87. FileNameOut:='';  { on start-up                                    }
  88. i := paramCount;
  89.  
  90. (***************************************
  91.    Parse command line
  92. ***************************************)
  93. Stats:=true;
  94. Scrn:=true;
  95. if i>0 then for j:=1 to i do begin
  96.    temp:=paramstr(j);
  97.    ParamParse(temp);
  98. end;
  99. case i of
  100. 0 : begin
  101.       GetInName(FileNameIn);
  102.       GetOutName(FileNameOut);
  103.     end;
  104. 1 : begin
  105.       temp:=paramstr(1);
  106.       FileNameIn := FileParse(temp);
  107.       GetOutName(FileNameOut);
  108.     end;
  109. 2 : begin
  110.       temp:=paramstr(1);
  111.       FileNameIn := FileParse(temp);
  112.       temp:=paramstr(2);
  113.       FileNameOut := FileParse(temp);
  114.     end;
  115. end; {case}
  116.  
  117. (***************************************
  118.     open text files
  119. ***************************************)
  120. assign(FilVarIn,FilenameIn);
  121. {$I-} reset(FilVarIn) {$I+} ;
  122. if IOresult<>0 then begin    {source file does not exist, end program}
  123.    writeln('');
  124.    TextColor(31);
  125.    write(^G^G'ERROR:');
  126.    TextColor(15);
  127.    writeln(' File ',FileNameIn,' cannot be found.');
  128.    HALT;
  129.    end;
  130. assign(FilVarOut,FilenameOut);
  131. rewrite(FilVarOut);
  132.  
  133. (***************************************
  134.     format screen
  135. ***************************************)
  136. clrscr;
  137. GotoXY(1,13);
  138. write(#17);
  139. for i:=1 to 78 do write(dl);
  140. write(#16);
  141. GotoXY(6,13);
  142. write(ls,up,' Original ',up,rs);
  143. GotoXY(68,13);
  144. write(ls,dn,' New ',dn,rs);
  145.  
  146. GotoXY(1,1);
  147. write(FileNameIn,' ',#26,' ',FileNameOut);
  148.  
  149. LowVideo;
  150. GotoXY(1,2);
  151. for i:=1 to 80 do write(sl);
  152. GotoXY(1,24);
  153. for i:=1 to 80 do write(sl);
  154.  
  155. r1:= 1 ; c1:=1;
  156. r2:= 1 ; c2:=1;
  157. i:=0;
  158. line:=1 ; chrcnt:=0; bite:=0;
  159.  
  160. GotoXY(20,24); write('┬');
  161. GotoXY(20,25); write('│');
  162. TextColor(0); TextBackground(7);
  163. GotoXY(1,25); write('     STRIP v2.1    '); {<<<< VERSION NUMBER}
  164. TextColor(15); TextBackground(0);
  165.  
  166. if Stats then begin
  167.    GotoXY(23,25);
  168.    write('Text line:');
  169.    GotoXY(42,25);
  170.    write('Column:');
  171.    GotoXY(64,25);
  172.    write('Byte:');
  173.    end;
  174.  
  175. LowVideo;
  176.  
  177. (***************************************
  178.     start strip routine
  179.        check for EOF marker and CR
  180.        and treat accordingly
  181. ***************************************)
  182. while not(eof(FilVarIn)) do begin
  183.   read(FilVarIn,ChrIn);
  184.   if ChrIn>127 then ChrOut:=ChrIn-128 else ChrOut:=ChrIn;
  185.   write(FilVarOut,ChrOut);
  186.   if Scrn and (ChrOut<>$1a) then begin
  187.      window(1,3,80,12);
  188.      GotoXY(c1,r1);
  189.      write(Chr(ChrIn));
  190.      c1:=WhereX ; r1:=WhereY;
  191.      window(1,14,80,23);
  192.      GotoXY(c2,r2);
  193.      write(Chr(ChrOut));
  194.      c2:=WhereX ; r2:=WhereY;
  195.    end;
  196.  
  197.   if Stats then begin
  198.      bite:=bite+1;
  199.      if ChrOut<>$1a then
  200.         if ChrOut=13 then begin line:=line+1; chrcnt:=0; end
  201.         else begin chrcnt:=chrcnt+1; end;
  202.      NormVideo;
  203.      window(1,1,80,25);
  204.      GotoXY(34,25);
  205.      write(line);
  206.      GotoXY(50,25);
  207.      write(chrcnt,'      ');
  208.      GotoXY(70,25);
  209.      write(bite);
  210.      LowVideo;
  211.      end;
  212.  
  213. end;
  214.  
  215. (***************************************
  216.       Terminate
  217. ***************************************)
  218. close (FilVarIn);
  219. close (FilVarOut);
  220. window(1,1,80,25);
  221. GotoXY(80,24);
  222. END.
  223.