#!/usr/local/bin/rexx

verbose=0

PARSE ARG file
IF STRIP(file)="" THEN DO
   CALL Log "You should at least specify input file name."
   EXIT 
   END 
IF verbose>0 THEN 
   CALL Line 
IF ReadFile(file)<0 THEN DO
   CALL Log 'Error: Can not open input file "'file'"'
   EXIT 
   END  
ELSE 
   IF verbose>0 THEN 
      SAY 'File "'file'" has 'line.0' records.'
IF verbose>0 THEN DO
   CALL Line "-"
   CALL Log 'Starting translation ...'
   END 

ls1=""
new=1
newline=""
nn=0
DO i=1 TO line.0
   IF STRIP(line.i)="" THEN new=1      
   ELSE DO 
      IF new=1 THEN DO
         IF strip(newline)<>"" THEN
            SAY newline
         rbr=line.i
         IF verbose>0 THEN DO
            CALL Line "-"
            CALL Log 'Found begining of record no.'LEFT(rbr, 4) 'at line' i
         END
         ELSE DO 
            IF nn>0 THEN 
               SAY '\/-[]-\/'  
            nn=1
            END 
         new=0
         newline=""
      END
      ELSE DO
        s1=LEFT(line.i, 7)
        PARSE VAR line.i s1 7 s2 
         IF INDEX(s1, "-")>0 THEN DO 
            PARSE UPPER VAR s1 field . 
            IF newline<>"" THEN 
               SAY newline
            newline=field"#"s2
            END
         ELSE DO
            newline=newline""s2
            END          
      END 
   END 
END 
IF strip(newline)<>"" THEN DO
   SAY newline
   SAY '\/-[]-\/'  
   END 
IF verbose>0 THEN 
   CALL Line
EXIT

Line: PARSE ARG sta
IF strip(sta)="" THEN sta="="
SAY COPIES(sta, 78/length(sta))
RETURN

LOG: PARSE ARG Sta
SAY time('n')'> 'Sta
RETURN

ReadFile: PROCEDURE EXPOSE line. file
queue_old=QUEUED()
'/bin/cat' file '>LIFO'
IF rc<>0 THEN RETURN -1
queue=QUEUED()
lines=queue-queue_old
DO i=lines TO 1 BY -1
   PARSE PULL line.i
END 
line.0=lines
RETURN line.0
