home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol270 / sf.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-05-22  |  4.5 KB  |  224 lines

  1. { [SF.PAS of JUGPDS Vol.16]                85-09-15   }
  2. {                                                                  }
  3. {    Fortran Coding Format Converter: Standard to Free Format      }
  4. {                                                                  }
  5. {              by H. Miyasaka (JUG-CP/M, No.6)               }
  6. {              Created  85/02/24   Ver 1.0                         }
  7. {              Updated  85/04/29       1.0A ... all left delete    }
  8. {                                                                  }
  9.  
  10. program sf;
  11. const
  12.   MAXLINE = 80;
  13.  
  14. type
  15.   maxstr   = string[MAXLINE];          { max input line }
  16.   filstr   = string[15];               { filename }
  17.  
  18. var
  19.   Buff1     : maxstr;                  { input buff 1 }
  20.   Buff2     : maxstr;                  { input buff 2 }
  21.  
  22.   inf       : text;
  23.   tempf     : text;
  24.   eraf      : text;
  25.  
  26.   infile    : filstr;                  { input filename }
  27.   tempfile  : filstr;                  { temporary filename }
  28.   outfile   : filstr;                  { output filename }
  29.  
  30.   options   : maxstr;                  { dummy }
  31.  
  32.   cond,fend : boolean;
  33.  
  34. procedure exit;
  35. begin
  36.   bdos(0);
  37. end;
  38.  
  39. function exist(filename:filstr):boolean;
  40. var
  41.   fil : text;
  42. begin
  43.   assign(fil,filename);
  44.   {$I-}
  45.   reset(fil);
  46.   {$I+}
  47.   exist := (ioresult = 0)
  48. end;
  49.  
  50. procedure delleft(var st:maxstr);
  51. var
  52.   i : byte;
  53. begin
  54.   i := 1;
  55.   while copy(st,i,1) = ' ' do
  56.     i := i + 1;
  57.   delete(st,1,i-1);
  58. end;
  59.  
  60. procedure delmid(var st:maxstr);
  61. var
  62.   temps : maxstr;
  63.   i,j   : byte;
  64. begin
  65.   temps := ' ';
  66.   j := 0;
  67.   for i:=1 to length(st) do
  68.     if st[i] <> ' '
  69.       then
  70.         begin
  71.           j := j + 1;
  72.           insert(st[i],temps,j);
  73.         end;
  74.   st := temps;
  75. end;
  76.  
  77. procedure arguments(var arg1:filstr;var arg2:maxstr;var cond:boolean);
  78. label
  79.   001;
  80. var
  81.   arg : maxstr absolute $0080;
  82.   i   : byte;
  83. begin
  84.   if length(arg) = 0
  85.     then
  86.       cond := False
  87.     else
  88.       begin
  89.         delleft(arg);
  90.         for i := 1 to length(arg) do
  91.           if (arg[i] = ' ') or (arg[i] = '[')
  92.             then
  93.               begin
  94.                 arg2 := copy(arg,i,length(arg)-i+1);
  95.                 goto 001;
  96.               end;
  97.         arg1 := copy(arg,1,i);
  98. 001:    cond := True;
  99.       end;
  100. end;
  101.  
  102. procedure outputf(var infile,tempfile,outfile:filstr);
  103. var
  104.   name : filstr;
  105.   i    : byte;
  106. begin
  107.   i := pos ('.',infile);
  108.   if i = 0
  109.     then
  110.       begin
  111.         name  := infile;
  112.         infile:= infile + '.FOR';
  113.       end
  114.     else
  115.       name := copy(infile,1,i-1);
  116.   tempfile := name + '.$$$';
  117.   outfile  := name + '.FRE';
  118. end;
  119.  
  120. procedure linput(var st:maxstr;var fend:boolean);
  121. begin
  122.   if not EOF(inf)
  123.     then
  124.       begin
  125.         readln(inf,st);
  126.         fend := False
  127.       end
  128.     else
  129.       fend := True;
  130. end;
  131.  
  132. procedure condense(var texts:maxstr);
  133. var
  134.   text1,text2:maxstr;
  135.   i : byte;
  136. begin
  137.   text1 := copy(texts,1,6);
  138.   text2 := copy(texts,7,length(texts)-6);
  139.   delmid(text1);
  140.   delleft(text2);
  141.   if text1 = ' '
  142.     then
  143.       texts := text2
  144.     else
  145.       texts := text1 + text2;
  146. end;
  147.  
  148. procedure lastbar(var texts:maxstr);
  149. var
  150.   i : byte;
  151. begin
  152.   i := length(texts);
  153.   texts := texts + ' ';
  154.   while texts[i]=' ' do
  155.     i := i - 1;
  156.   texts[i+1] := '-';
  157. end;
  158.  
  159.  
  160. begin
  161.   arguments(infile,options,cond);
  162.   if not cond
  163.     then
  164.       begin
  165.         writeln('Fortran Standard-Format to Free-Format Converter.');
  166.         writeln('Usage : sf file-name');
  167.         exit;
  168.       end;
  169.   writeln('---------------------------------------------------------');
  170.   writeln('Fortran Standard-Format to Free-Format Converter Ver 1.0A');
  171.   writeln('---------------------------------------------------------');
  172.   outputf(infile,tempfile,outfile);
  173.   if not exist(infile)
  174.     then
  175.       begin
  176.         writeln(infile,' not found');
  177.         exit;
  178.       end;
  179.   assign(inf,infile);
  180.   assign(tempf,tempfile);
  181.   reset(inf);
  182.   rewrite(tempf);
  183.   linput(Buff1,fend);
  184.   if fend
  185.     then
  186.       begin
  187.         writeln(infile,' is empty');
  188.         exit;
  189.       end;
  190.   while not fend do
  191.     begin
  192.       Buff2 := Buff1;
  193.       linput(buff1,fend);
  194.       if fend
  195.         then
  196.           Buff1 := '';
  197.       if (Buff2[1]='C') or (Buff2[1]='*')
  198.         then
  199.           Buff2[1] := '"'
  200.         else
  201.           begin
  202.             if (Buff1[6]<>' ') and (Buff1[6]<>'0')
  203.               then
  204.                 begin
  205.                   Buff1[6] := ' ';
  206.                   lastbar(Buff2);
  207.                 end;
  208.             condense(Buff2);
  209.           end;
  210.       writeln(tempf,Buff2);
  211.     end;
  212.   close(inf);
  213.   close(tempf);
  214.   if exist(outfile)
  215.     then
  216.       begin
  217.         assign(eraf,outfile);
  218.         erase(eraf);
  219.       end;
  220.   rename(tempf,outfile);
  221.   writeln;
  222.   writeln('complete');
  223. end.
  224.