ISREDIT MACRO       /* CATMTSIM EDIT SIM$$OUT  */
 
/* 05/15/2006 JL.NELSON Created to verify dataset findings.
/* 05/16/2006 JL.NELSON Added code for privilege program access.
/* 05/25/2006 JL.NELSON Return access level granted.
/* 05/25/2006 JL.NELSON Coded for overrides, no "allowed access"
/* 05/26/2006 JL.NELSON TSSSIM "allowed access" multiple accesses.
 
SET PGMNAME = &STR(CATMTSIM 05/26/06)
 
SET SYSPROMPT = OFF                /* CONTROL NOPROMPT          */
SET SYSFLUSH  = OFF                /* CONTROL NOFLUSH           */
SET SYSASIS   = ON                 /* CONTROL ASIS - caps off   */
 
/* ERROR ROUTINE */
ERROR DO
  SET RETURN_CODE = &LASTCC          /* SAVE LAST ERROR CODE */
  IF &LASTCC GE 16 THEN +
    WRITE &PGMNAME LASTCC = &LASTCC &ZERRLM
  RETURN
  END
 
/* *************************************** */
/* VARIABLES ARE PASSED TO THIS MACRO      */
/* CONSLIST                                */
/* COMLIST                                 */
/* SYMLIST                                 */
/* TERMMSGS                                */
/* *************************************** */
 
SET RETURN_CODE = 0
 
ISPEXEC VGET ( +
  CONSLIST     +
  COMLIST      +
  SYMLIST      +
  TERMMSGS     +
  ) ASIS
 
SET TMSIMVG = &RETURN_CODE
IF &RETURN_CODE NE 0 THEN DO
  WRITE &PGMNAME VGET RC = &RETURN_CODE  &ZERRSM
  WRITE &PGMNAME CONSLIST/&CONSLIST COMLIST/&COMLIST SYMLIST/&SYMLIST +
    TERMMSGS/&TERMMSGS
  SET RETURN_CODE = &RETURN_CODE + 16
  GOTO ERR_EXIT
  END
 
/* *************************************** */
/* TURN ON MESSAGES                        */
/* *************************************** */
 
SET SYSSYMLIST = &SYMLIST          /* CONTROL SYMLIST/NOSYMLIST */
SET SYSCONLIST = &CONSLIST         /* CONTROL CONLIST/NOCONLIST */
SET SYSLIST    = &COMLIST          /* CONTROL LIST/NOLIST       */
SET SYSMSG     = &TERMMSGS         /* CONTROL MSG/NOMSG         */
 
/* *************************************** */
/* MAIN PROCESS                            */
/* *************************************** */
 
SET TSSSIMDS = &STR( )
SET TSSSIMRC = 0
 
ISREDIT (MEMBER) = MEMBER
ISREDIT (DSNAME) = DATASET
SET RETURN_CODE = 0
 
ISREDIT (LASTLINE) = LINENUM .ZLAST
 
IF &RETURN_CODE GT 0 THEN DO    /* Empty RC = 4
  IF &LASTLINE EQ 0 THEN +
    WRITE &PGMNAME Empty file RCode = &RETURN_CODE +
          DSN=&DSNAME  MEMBER=&MEMBER  &ZERRSM
  ELSE +
    WRITE &PGMNAME LINENUM Error RCode = &RETURN_CODE +
          DSN=&DSNAME  MEMBER=&MEMBER  &ZERRSM
  SET TSSSIMRC = 9
  GOTO END_EXIT
  END
 
SET RETURN_CODE = 0
 
ISREDIT FIND ' ALLOWED ACCESS ' FIRST
 
IF &RETURN_CODE NE 0 THEN DO
  SET RETURN_CODE = 0
 
  ISREDIT FIND ' RESOURCE ACCESS GRANTED' FIRST
 
  IF &RETURN_CODE NE 0 THEN GOTO SIM_DISPLAY
 
  ISREDIT FIND ' REQUESTED ACCESS ' FIRST
 
  IF &RETURN_CODE NE 0 THEN GOTO SIM_DISPLAY
  END
 
ISREDIT (DATA) = LINE .ZCSR
 
SET X = &SYSINDEX(&STR(=),&NRSTR(&DATA))
SET Y = &SYSINDEX(&STR( ),&NRSTR(&DATA),&X+2)
IF &X GT 0 AND &X+2 LE &Y-1 THEN +
  SET ACCESSL = &SUBSTR(&X+2:&Y-1,&NRSTR(&DATA))
ELSE GOTO END_EXIT
 
SET X = 1
 
NEXT_ACC: +
SET Y = &SYSINDEX(&STR(,),&NRSTR(&ACCESSL),&X+1)
IF &Y EQ 0 THEN SET Y = &LENGTH(&NRSTR(&ACCESSL))+1
IF &X GT 0 AND &X LE &Y-1 THEN DO
  SET ACCESS = &SUBSTR(&X:&Y-1,&NRSTR(&ACCESSL))
 
  SELECT &ACCESS
    WHEN (NONE    ) SET ALVL = 0
    WHEN (FETCH   ) SET ALVL = 1
    WHEN (NOCREATE) SET ALVL = 2
    WHEN (READ    ) SET ALVL = 3
    WHEN (INQUIRE ) SET ALVL = 3
    WHEN (WRITE   ) SET ALVL = 4
    WHEN (UPDATE  ) SET ALVL = 5
    WHEN (CONTROL ) SET ALVL = 6
    WHEN (CREATE  ) SET ALVL = 7
    WHEN (SCRATCH ) SET ALVL = 8
    WHEN (ALL     ) SET ALVL = 9
    OTHERWISE DO
      WRITE &PGMNAME Unknown access &ACCESS not found in list, &DATA
      SET TSSSIMRC = 9
      GOTO SIM_DISPLAY
      END
    END
 
  IF &TSSSIMRC LT &ALVL THEN +
    SET TSSSIMRC = &ALVL
 
  IF &Y LT &LENGTH(&NRSTR(&ACCESSL)) THEN DO
    SET X = &Y + 1
    GOTO NEXT_ACC
    END
  END
 
SIM_DISPLAY: +
SET RETURN_CODE = 0
 
GOTO END_EXIT
/* Testing only - comment out GOTO END_EXIT
 
ISREDIT FIND ' SIMULATED RESOURCE ACCESS ' FIRST
 
IF &RETURN_CODE EQ 0 THEN +
  ISREDIT (SIMRA) = LINE .ZCSR
 
SET RETURN_CODE = 0
 
ISREDIT FIND ' RES ORIGIN ' FIRST
 
IF &RETURN_CODE EQ 0 THEN DO
  ISREDIT (DATA) = LINE .ZCSR
 
  SET X = &SYSINDEX(&STR(=),&NRSTR(&DATA))
  IF &X GT 0 AND &X+32 LE &LENGTH(&NRSTR(&DATA)) THEN +
    SET RESORG = &SUBSTR(&X+2:&X+32,&NRSTR(&DATA))
  END
 
SET RETURN_CODE = 0
 
ISREDIT FIND ' DSNAME ' FIRST
 
IF &RETURN_CODE EQ 0 THEN DO
  ISREDIT (DATA) = LINE .ZCSR
 
  SET X = &SYSINDEX(&STR(=),&NRSTR(&DATA))
  IF &X GT 0 AND &X+46 LE &LENGTH(&NRSTR(&DATA)) THEN +
    SET DSMASK = &SUBSTR(&X+2:&X+46,&NRSTR(&DATA))
  END
 
SET TSSSIMDS = &NRSTR(&RESORG &ACCESSL &DSMASK)
WRITE &PGMNAME &SIMRA
WRITE &PGMNAME &TSSSIMDS
ISPEXEC VPUT (TSSSIMDS) ASIS
 
END_EXIT: +
SET RETURN_CODE = 0
 
ISPEXEC VPUT (TSSSIMRC) ASIS
 
ERR_EXIT: +
IF &MAXCC GE 16 OR +
   &RETURN_CODE GT 0 THEN DO
  ISPEXEC VGET (ZISPFRC) SHARED
  IF &MAXCC GT &ZISPFRC THEN +
    SET ZISPFRC = &MAXCC
  ELSE +
    SET ZISPFRC = &RETURN_CODE
  ISPEXEC VPUT (ZISPFRC) SHARED
  WRITE &PGMNAME ZISPFRC = &ZISPFRC
  END
 
ISREDIT END
 
EXIT CODE(0)
ISREDIT MEND
