Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to invoke this EXEC?

Status
Not open for further replies.

mnellutla

Vendor
Nov 26, 2003
15
US
Hi Again,

I downloaded the following utility from the web which indents rexx and clist programs.

I have tried to invoke it from command line "TSO INDENT",
"TSO INDENT (member-name)" and etc.... I have even tried to invoke it as a line command in the edit dataset mode.


Code:
/* REXX : FP         REFORMAT REXX AND CLIST SOURCE                */
/* THIS EDIT MACRO WILL READ THE EDIT FILE AND APPLY STRUCTURING   */
/* AND INDENTATION TO IT BEFORE REPLACING THE EDIT DATA. YOU MUST  */
/* MANUALLY CHECK IT AFTERWARDS ESPECIALLY WHERE LINES ARE SPLIT.  */
/* OPTIONAL PARM OF LOGICAL LINE (NOT LRECL) LENGTH TO FORMAT TO.  */
/*******************************************************************/
ADDRESS ISREDIT "MACRO (LEN)"
IF LEN = '' THEN
   LEN = 71                                  /* OUTPUT LINE LENGTH */
ADDRESS ISREDIT "RESET"             /* REMOVE MESSAGE LINES IF ANY */
ADDRESS ISREDIT "(ML) = LINENUM .ZLAST"         /* MAXIMUM LINES   */
ADDRESS ISREDIT "(LINE) = LINE 1"               /* GET FIRST LINE  */
IF INDEX(LINE,'REXX') > 0 THEN               /* REXX OR CLIST TYPE */
   DO; C1 = ','; C2 = ','; END               /* REXX LINE BREAKS   */
ELSE
   DO; C1 = '+'; C2 = '-'; END               /* CLIST LINE BREAKS  */
/* PROCESS THE EDIT LINES INTO A CONTINUOUS VARIABLE */
DATA = ''
DO I = 1 TO ML                       /* COMBINE INTO SINGLE STRING */
   ADDRESS ISREDIT "(LINE) = LINE" I   /* GET LINE FROM EDITOR     */
   SRC = STRIP(LINE)                   /* REMOVE LEAD/TRAIL BLANKS */
   IF LENGTH(SRC) > 0 THEN
      DO
         A = SUBSTR(SRC,LENGTH(SRC),1)        /* LAST CHAR ON LINE */
         IF A = C1 | A = C2 THEN
            SRC = OVERLAY(' ',SRC,LENGTH(SRC),1)   /* JOIN SPLITS  */
         ELSE
            IF A \= ';' THEN
               SRC = SRC || '52'X           /* SEPARATE STATEMENTS */
         DATA = DATA || SRC
      END
END
/* REMOVE EXCESSIVE BLANKS UNLESS INSIDE QUOTES ETC */
J = 0; STR = 0; COM = 0; QT1 = 0; QT2 = 0
X = LENGTH(DATA)
DO UNTIL (J >= X)
   J = J + 1
   IF (COM = 0 & QT1 = 0 & QT2 = 0) THEN
      STR = SCAN('STR(' 4 ')' 1 STR)
   IF (STR = 0 & QT1 = 0 & QT2 = 0) THEN
      COM = SCAN('/*' 2 '*/' 2 COM)
   IF (COM = 0 & STR = 0 & QT2 = 0) THEN
      QT1 = SCAN("'" 1 "'" 1 QT1)
   IF (COM = 0 & STR = 0 & QT1 = 0) THEN
      QT2 = SCAN('"' 1 '"' 1 QT2)
   IF (J > 1 & STR = 0 & COM = 0 & QT1 = 0 & QT2 = 0) THEN
      DO
         DATA = OVERLAY(TRANSLATE(SUBSTR(DATA,J,1)),DATA,J)
         IF SUBSTR(DATA,J,5)  == 'THEN ' |,
            SUBSTR(DATA,J,5)  == 'ELSE ' THEN    /* FORCE NEW LINE */
            DO
               DATA = OVERLAY(';',DATA,J+4)
               IF C1 = '+' THEN
                  DATA = INSERT(' +',DATA,J+3)
            END
         IF SUBSTR(DATA,J,10) == 'OTHERWISE ' THEN
            DO
               DATA = OVERLAY(';',DATA,J+9)
               IF C1 = '+' THEN
                  DATA = INSERT(' +',DATA,J+8)
            END
         IF (SUBSTR(DATA,J-1,1) = ' ' |,
            SUBSTR(DATA,J-1,1)  = ';') &,
            SUBSTR(DATA,J,1)    = ' ' THEN
            DO
               DATA = DELSTR(DATA,J,1)            /* REMOVE BLANK */
               X = LENGTH(DATA)
               IF J < X THEN
                  J = J - 1
            END
      END
   ELSE
      IF SUBSTR(DATA,J,1) = ';' THEN          /* SEMI INSIDE DATA */
         DATA = OVERLAY('51'X,DATA,J)               /* SET TO 51X */
END
/* BREAK UP INTO NEW LINES FOR EACH STATEMENT */
J = 1; L = 0;
X = LENGTH(DATA)
DO WHILE (J < X)
   L = L + 1                                         /* NEXT LINE */
   NEW.L = ''
   A = SUBSTR(DATA,J,1)
   DO WHILE (A \= ';' & A \= '52'X & J < X)      /* BUILD UP LINE */
      IF SUBSTR(DATA,J,7)  = 'THEN;/*' |,
         SUBSTR(DATA,J,7)  = 'ELSE;/*' THEN
         DATA = OVERLAY(' ',DATA,J+4)        /* PRESERVE COMMENTS */
      IF SUBSTR(DATA,J,12) = 'OTHERWISE;/*' THEN
         DATA = OVERLAY(' ',DATA,J+9)
      NEW.L = NEW.L || A
      J = J + 1
      A = SUBSTR(DATA,J,1)
   END
   J = J + 1                                  /* SKIP ENDING SEMI */
END
/* CALCULATE BASIC INDENTATION BASED ON KEYWORDS */
I = 0; T = 0
OFF.1 = 0; LEV.1 = 0
DO J = 2 TO L
   K = J - 1
   A4 = SUBSTR(NEW.J,1,4)                   /* EXTRACTS FROM LINE */
   B3 = SUBSTR(NEW.K,1,3)          /* EXTRACTS FROM PREVIOUS LINE */
   B5 = SUBSTR(NEW.K,1,5)
   B7 = SUBSTR(NEW.K,1,7)
   B10 = SUBSTR(NEW.K,1,10)
   SELECT                             /* PREVIOUS LINE CONDITIONS */
   WHEN (B3  = 'IF ' | B5 = 'WHEN ' | B5 = 'ELSE ' |,
         B10 = 'OTHERWISE ') THEN
      T = T + 3
   WHEN (B3 = 'DO ' | B7 = 'SELECT ') THEN
      DO
         I = I + 3
         T = 0
      END
   OTHERWISE
      T = 0
   END
   SELECT                             /* CURRENT LINE CONDITIONS */
   WHEN (A4 = 'END ') THEN
      I = I - 3
   OTHERWISE
      NOP
   END
   IF I < 0 THEN                      /* INDENTATION VALUE       */
      I = 0
   IF T < 0 THEN                      /* TEMPORARY INDENT (IF)   */
      T = 0
   OFF.J = I + T
   LEV.J = I
END
/* ADJUST DO/END INDENTATION AFTER IF TO DESIRED FORMAT */
CALL ADJEND
/* ADJUST ELSES TO BIND TO NEAREST IF AT SAME LEVEL */
DO J = L TO 2 BY -1
   IF SUBSTR(NEW.J,1,5)  = 'ELSE ' THEN
      DO
         W = 0
         DO K = J-1 TO 2 BY -1 WHILE (W = 0)
            IF SUBSTR(NEW.K,1,3) = 'IF ' &,
               LEV.K = LEV.J THEN
               W = K
         END
         IF W > 0 THEN
            DO
               D = OFF.W - OFF.J
               IF D > 0 THEN
                  DO
                     OFF.J = OFF.J + D
                     W = J + 1
                     OFF.W = OFF.W + D
                     IF SUBSTR(NEW.W,1,3) = 'DO ' THEN
                        DO K = W+1 TO L WHILE (D \= 0)
                           OFF.K = OFF.K + D
                           IF SUBSTR(NEW.K,1,4) = 'END ' THEN
                              D = 0
                        END
                  END
            END
      END
END
/* NESTED IF/THEN INDENTATION ADJUST */
DO J = 1 TO L-1
   K = J + 1
   IF SUBSTR(NEW.J,1,3)  = 'IF ' &,
      OFF.K > OFF.J + 3 THEN
      OFF.K = OFF.J + 3
END
/* CORRECT DO/END INDENTS AFTER IF AGAIN */
CALL ADJEND
/* SPLIT LONG LINES INTO TWO OR MORE PARTS */
X = 0
DO J = 1 TO L
   DO UNTIL (K = 0)
      X = X + 1
      P = LEN - OFF.J
      IF LENGTH(NEW.J) > P THEN       /* LOOK FOR CONVENIENT BREAK */
         DO
            W1 = LASTPOS(' ',SUBSTR(NEW.J,1,P))
            W2 = LASTPOS('|',SUBSTR(NEW.J,1,P))
            W3 = LASTPOS('&',SUBSTR(NEW.J,1,P))
            W  = MAX(W1,W2,W3)
            IF W > 0 THEN
               P = W
         END
      OUT.X = SUBSTR(NEW.J,1,P)
      IND.X = OFF.J
      NEW.J = SUBSTR(NEW.J,P+1)               /* REMAINDER OF LINE */
      K = LENGTH(NEW.J)
      IF K > 0 THEN
         OUT.X = OUT.X || C1                  /* LINE BREAK CHAR   */
   END
END
/* INSERT ACTUAL BLANKS FOR FINAL INDENTATION AND PASS TO EDITOR */
ADDRESS ISREDIT &quot;DELETE ALL NX&quot;
DO J = 1 TO X
   OUT.J = TRANSLATE(OUT.J,';','51'X)        /* REINSTATE ;        */
   IF IND.J > 0 THEN
      OUT.J = COPIES(' ',IND.J) || OUT.J
   LINE = TRANSLATE(OUT.J,'5152'X,'7F50'X)    /* HIDE QUOTES AND & */
   ADDRESS ISREDIT &quot;LINE_AFTER .ZLAST = &quot; '&quot;' || LINE || '&quot;'
END
ADDRESS ISREDIT &quot;CHANGE X'51' X'7F' ALL&quot; /* RESTORE DOUBLE QUOTES  */
ADDRESS ISREDIT &quot;CHANGE X'52' X'50' ALL&quot; /* RESTORE AMPERSANDS     */
ADDRESS ISREDIT &quot;RESET&quot;                  /* RESET                  */
ADDRESS ISREDIT &quot;CURSOR = 1 1&quot;           /* DISPLAY AT TOP         */
ZEDSMSG = 'REFORMATTED'
ADDRESS ISPEXEC &quot;SETMSG MSG(ISRZ000)&quot;    /* SHOW MESSAGE IN EDIT   */
EXIT 0                                /* END OF THE MAIN PROCEDURE */
SCAN:                          /* FUNCTION TO FIND IMBEDDED STRING */
ARG T1 L1 T2 L2 FG
IF SUBSTR(DATA,J,L1) = T1 & FG = 0 THEN
   FG = 1
ELSE
   IF SUBSTR(DATA,J,L2) = T2 THEN
      FG = 0
RETURN FG
ADJEND:     /* SUBROUTINE IF/WHEN/ELSE/OTHERWISE/END ADJUST INDENT */
DO J = 1 TO L
   IF (SUBSTR(NEW.J,1,3)  = 'IF '   |,
       SUBSTR(NEW.J,1,5)  = 'WHEN ' |,
       SUBSTR(NEW.J,1,5)  = 'ELSE ' |,
       SUBSTR(NEW.J,1,10) = 'OTHERWISE ') THEN
      DO
         W = 0
         DO K = J+1 TO L WHILE (W = 0)
            IF OFF.K = OFF.J THEN
               IF SUBSTR(NEW.K,1,4) = 'END ' THEN
                  W = K
               ELSE
                  W = -1
         END
         IF W > 0 THEN
            DO X = J+2 TO W
               OFF.X = OFF.X + 3
            END
      END
END
RETURN


-------------

thanks.
manu
(Boston)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top