midrange.com code scratchpad
Name:
SEU user command exit program
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
05/18/2016 01:37:25 pm
IP:
Logged
Description:
SEU user command exit program
Code:
  1.      h dftactgrp(*no) actgrp('QILE') indent(*none)
  2.  
  3.       * dbgview(*list)
  4.  
  5.       * Buck Calabro April 2000
  6.       * large portions lifted from the SEU User's Guide and Reference SC09-2605-00
  7.       * If you have a really large source file, increase the size of SourceStmt
  8.       * Note that this is really a boiler-plate more than anything else.
  9.  
  10.       * To activate, STRSEU, press F13, page down and fill in the name of this program
  11.  
  12.       * SEU puts data in QTEMP/QSUSPC
  13.       * this space has 3 data blocks:
  14.       *   1. Input from SEU
  15.       *   2. Output back to SEU
  16.       *   3. Actual source lines
  17.  
  18.       * Supports the following line commands:
  19. €     * ATTRxx - set line attribute (colour, hilight, etc.)
  20.  
  21.       * Supports the following F keys:
  22.       * F7 - Split/join a line (Splits this line to next if cursor in the middle of a line,
  23.       *                         joins next line to this if cursor at the end of a line)
  24.  
  25.       * Uses messages in a user-created message file:
  26.       *   Message ID  Severity  Message Text
  27.       *    SEU0001        0     Cursor is not positioned within a source statement.
  28.       *    SEU0002        0     Line split complete.
  29.       *    SEU0003        0     Line join complete.
  30.       *    SEU0004        0     Cannot update in Browse mode
  31.       *    SEU0005        0     ATTR command processed
  32.       *    SEU0006        0     ATTR command not valid for this member type
  33.       *    SEU0007        0     &1
  34.  
  35.       * Input from SEU
  36.      D SEUInput        DS                  BASED(SEUInputP)
  37.      D  StmtLength                   10i 0
  38.      D  CurRec                       10i 0
  39.      D  CurCol                       10i 0
  40.      D  CCSID                        10i 0
  41.      D  InputRecords                 10i 0
  42.      D  SrcMbr                       10
  43.      D  SrcFil                       10
  44.      D  SrcLib                       10
  45.      D  MbrType                      10
  46.      D  FnKey                         1
  47.      D  SEUMode                       1
  48.      D  SplitSession                  1
  49.      D  ReservedInp                   1
  50.  
  51.       * Output to SEU
  52.      D SEUOutput       DS                  BASED(SEUOutputP)
  53.      D  ReturnCode                    1
  54.      D  ReservedOut1                  3
  55.      D  OutputRecords                10i 0
  56.      D  InsertedSeq                   7
  57.      D  ReservedOut2                 21
  58.  
  59.       * Source statements.  SEU passes the line the cursor is on,
  60.       *                     and the next line
  61.      D SEUSource       DS                  BASED(SEUSourceP)
  62.      D  LineCmd                       7
  63.      D  LineRetCode                   1
  64.      D  SourceSeq                     6
  65.      D  SourceDate                    6
  66.      D  SourceStmt                  256
  67.  
  68.       * Work variables
  69.      D SEUInputPParm   S               *
  70.      D SEUOutputPParm  S               *
  71.      D SEUSourcePParm  S               *
  72.      D ThisLineP       S               *
  73.      D NextLineP       S               *
  74.      D WorkLineP       S               *
  75.  
  76.      D i               s             10i 0 inz
  77.      D CutColumns      s                   like(SourceStmt)
  78.      D ThisLineCmd     s                   like(LineCmd)
  79.      D ThisStmt        s                   like(SourceStmt)
  80.      D NextStmt        s                   like(SourceStmt)
  81.      D SourceLength    s             10i 0
  82.      D CutLen          s             10i 0
  83.      D BlankLineCmd    s                   like(LineCmd)
  84.      D RtnCode         s              7
  85.  
  86.      DSndMsg           pr
  87.      D MsgID                          7    const
  88.      D RtnCodeOut                          Like(RtnCode)
  89.      D MsgDta                        80    options(*nopass) const
  90.  
  91.      DLoadWorkFromInp  pr
  92.      D SrcDtaPtrInp                    *   const
  93.      D LineCmdOut                          like(LineCmd)     Options(*Omit)
  94.      D LineRetCodeOut                      like(LineRetCode) Options(*Omit)
  95.      D SourceSeqOut                        like(SourceSeq)   Options(*Omit)
  96.      D SourceDateOut                       like(SourceDate)  Options(*Omit)
  97.      D SourceStmtOut                       like(SourceStmt)  Options(*Omit)
  98.  
  99.      DLoadOutFromWork  pr
  100.      D SrcDtaPtrInp                    *                     const
  101.      D LineCmdInp                          like(LineCmd)     Options(*Omit)
  102.      D LineRetCodeInp                      like(LineRetCode) Options(*Omit)
  103.      D SourceSeqInp                        like(SourceSeq)   Options(*Omit)
  104.      D SourceDateInp                       like(SourceDate)  Options(*Omit)
  105.      D SourceStmtInp                       like(SourceStmt)  Options(*Omit)
  106.  
  107.      DGetAttrFromCmd   pr             1
  108.      D LineCmdInp                          like(LineCmd) const
  109.  
  110.       *================================================================
  111.      C     *Entry        Plist
  112.      C                   Parm                    SEUInputPParm
  113.      C                   Parm                    SEUOutputPParm
  114.      C                   Parm                    SEUSourcePParm
  115.  
  116.       * Get the data referred to by the input pointers
  117.      C                   Eval      SEUInputP    = SEUInputPParm
  118.      C                   Eval      SourceLength = %len(SEUSource) -
  119.      C                                            %len(SourceStmt) +
  120.      C                                            StmtLength
  121.      C                   Eval      SEUOutputP   = SEUOutputPParm
  122.      C                   Eval      ThisLineP    = SEUSourcePParm
  123.      C                   Eval      NextLineP    = SEUSourcePParm + SourceLength
  124.  
  125.       * Set default values
  126.      C                   Eval      ReturnCode = '0'
  127.      C                   Eval      OutputRecords = InputRecords - 1
  128.      C                   Eval      InsertedSeq = '0000000'
  129.  
  130.       * Allow updates only if in Update mode
  131.      C                   If        SeuMode = 'U'
  132.      C                   Exsr      LineCommands
  133.      C                   Exsr      CmdKeys
  134.      C                   Else
  135.      C                   Eval      ReturnCode = '1'
  136.       * Send back "Not in update mode" message
  137.      C*#*                   CallP     SndMsg('SEU0004': RtnCode)
  138.      C                   CallP     SndMsg('SEU0007': RtnCode: 'In browse!')
  139.      C                   EndIf
  140.  
  141.      C                   Eval      *InLR = *On
  142.      C                   Return
  143.  
  144.       *================================================================
  145.       * Process all the line commands (commands typed in the seq number area)
  146.       * InputRecords includes the "next" line.
  147. €     * For example, if a line command is placed on lines 1 and 5, InputRecords will be 6
  148.  
  149.      C     LineCommands  Begsr
  150.  
  151.      C                   Eval      WorkLineP = ThisLineP
  152.      C                   Eval      i = 1
  153.  
  154.      C                   DoW       i <= (InputRecords - 1)
  155.      C                   Callp     LoadWorkFromInp(WorkLineP:
  156.      C                                             ThisLineCmd:
  157.      C                                             *Omit:
  158.      C                                             *Omit:
  159.      C                                             *Omit:
  160.      C                                             ThisStmt)
  161.  
  162.      C                   Select
  163.  
  164.       * Line command to set the attribute of the line
  165.      C                   When      %subst(ThisLineCmd: 1: 4)  = 'ATTR'
  166.  
  167.       * Blank out the line command
  168.      C                   Callp     LoadOutFromWork(WorkLineP:
  169.      C                                             BlankLineCmd:
  170.      C                                             *Omit:
  171.      C                                             *Omit:
  172.      C                                             *Omit:
  173.      C                                             *Omit)
  174.  
  175.       * Highlight the line by forcing an attribute byte in the proper column
  176.       * based on the source member type
  177.      C                   If        MbrType = 'RPG'      or
  178.      C                             MbrType = 'RPGLE'    or
  179.      C                             MbrType = 'SQLRPG'   or
  180.      C                             MbrType = 'SQLRPGLE' or
  181.      C                             MbrType = 'PF'       or
  182.      C                             MbrType = 'PRTF'     or
  183.      C                             MbrType = 'DSPF'
  184.      C                   Eval      %subst(ThisStmt: 1: 1) =
  185.      C                               GetAttrFromCmd(ThisLineCmd)
  186.  
  187.       * Put the work fields back into the source space
  188.      C                   Callp     LoadOutFromWork(ThisLineP:
  189.      C                                             *Omit:
  190.      C                                             *Omit:
  191.      C                                             *Omit:
  192.      C                                             *Omit:
  193.      C                                             ThisStmt)
  194.  
  195.       * Send back a message to show that we saw and processed the line cmd
  196.      C                   CallP     SndMsg('SEU0005': RtnCode)
  197.      C                   Else
  198.       * Send back a message to show that we saw and ignored the line cmd
  199.      C                   CallP     SndMsg('SEU0006': RtnCode)
  200.      C                   EndIf
  201.  
  202.      C                   EndSL
  203.  
  204.      C                   Eval      i = i + 1
  205.      C                   Eval      WorkLineP = WorkLineP + SourceLength
  206.      C                   EndDO
  207.  
  208.      C                   EndSR
  209.  
  210.       *================================================================
  211.       * Process the command keys (F7/F8)
  212.  
  213.      C     CmdKeys       Begsr
  214.  
  215.      C                   Select
  216.  
  217.       * Is the cursor outside of the source statement with an F key press?
  218.      C                   When      (FnKey = '7'  or
  219.      C                              FnKey = '8') and
  220.      C                             CurCol = 0
  221.  
  222.       * Tell SEU that the cursor is outside the source area
  223.      C                   CallP     SndMsg('SEU0001': RtnCode)
  224.  
  225.       * F7 = split/join
  226.      C                   When      FnKey = '7'
  227.  
  228.       * Should we do a split or a join?
  229.       * Get the line the cursor is on
  230.      C                   Callp     LoadWorkFromInp(ThisLineP:
  231.      C                                             *Omit:
  232.      C                                             *Omit:
  233.      C                                             *Omit:
  234.      C                                             *Omit:
  235.      C                                             ThisStmt)
  236.       * Get the next line
  237.      C                   Callp     LoadWorkFromInp(NextLineP:
  238.      C                                             *Omit:
  239.      C                                             *Omit:
  240.      C                                             *Omit:
  241.      C                                             *Omit:
  242.      C                                             NextStmt)
  243.  
  244.       * If there is data beyond the current column, split it
  245.       * If the rest of the line is blank, join the next line to this one
  246.      C                   if        %subst(ThisStmt: CurCol:
  247.      C                                    StmtLength - CurCol - 1) <>
  248.      C                                      *Blanks
  249.      C                   Exsr      SplitLine
  250.      C                   Else
  251.      C                   Exsr      JoinLine
  252.      C                   EndIf
  253.  
  254.      C                   EndSL
  255.  
  256.      C                   EndSR
  257.  
  258.       *================================================================
  259.       * Split line at blank
  260.  
  261.      C     SplitLine     Begsr
  262.  
  263.       * Cut the columns to the right including the column the cursor is in
  264.      C                   Eval      CutColumns = %subst(ThisStmt:
  265.      C                                                 CurCol)
  266.  
  267.       * Drop the rightmost columns into the next line
  268.      C                   Eval      NextStmt = CutColumns
  269.  
  270.       * Trim the cut columns off the right side of this line
  271.      C                   If        CurCol > 1
  272.      C                   Eval      ThisStmt = %subst(ThisStmt:
  273.      C                                               1:
  274.      C                                               CurCol - 1)
  275.      C                   Else
  276.      C                   Eval      ThisStmt = *Blanks
  277.      C                   EndIf
  278.  
  279.       * Put the work fields back into the source space
  280.      C                   Callp     LoadOutFromWork(ThisLineP:
  281.      C                                             *Omit:
  282.      C                                             *Omit:
  283.      C                                             *Omit:
  284.      C                                             *Omit:
  285.      C                                             ThisStmt)
  286.  
  287.      C                   Callp     LoadOutFromWork(NextLineP:
  288.      C                                             *Omit:
  289.      C                                             *Omit:
  290.      C                                             *Omit:
  291.      C                                             *Omit:
  292.      C                                             NextStmt)
  293.  
  294.       * Tell SEU that we're returning 2 lines
  295.      C                   Eval      OutputRecords = 2
  296.  
  297.       * Tell SEU that the split is complete
  298.      C                   CallP     SndMsg('SEU0002': RtnCode)
  299.      C                   EndSR
  300.  
  301.       *================================================================
  302.       * Join line
  303.  
  304.      C     JoinLine      Begsr
  305.  
  306.       * Don't try to join if the next line is a blank
  307.      C                   If        NextStmt <> *Blanks
  308.  
  309.       * Grab the leftmost columns from the next line (as many columns
  310.       * as are blank at the end of this line)
  311.      C                   Eval      CutColumns = %subst(NextStmt:
  312.      C                                                 1:
  313.      C                                                 (StmtLength -
  314.      C                                                  CurCol +
  315.      C                                                  1               ))
  316.  
  317.       * Add the columns from the next line onto the end of this line
  318.      C     ' '           Checkr    CutColumns    CutLen
  319.      C                   Eval      ThisStmt = %subst(ThisStmt:
  320.      C                                               1:
  321.      C                                               CurCol - 1)       +
  322.      C                                         %subst(CutColumns:
  323.      C                                                1:
  324.      C                                                CutLen)
  325.  
  326.       * Blank out the cut columns
  327.      C                   Eval      %subst(NextStmt: 1: CutLen) = *Blanks
  328.  
  329.       * If we've cut the entire next line, delete it.  Otherwise,
  330.       * simply cut the columns out - don't shift the remainder of the line
  331.      C                   If        NextStmt = *Blanks
  332.      C                   Eval      OutputRecords = 1
  333.      C                   Eval      InsertedSeq = 'A000000'
  334.      C                   Else
  335.      C                   Eval      OutputRecords = 2
  336.      C                   Eval      InsertedSeq = 'A000000'
  337.      C                   EndIf
  338.  
  339.       * Put the work fields back into the source space
  340.      C                   Callp     LoadOutFromWork(ThisLineP:
  341.      C                                             *Omit:
  342.      C                                             *Omit:
  343.      C                                             *Omit:
  344.      C                                             *Omit:
  345.      C                                             ThisStmt)
  346.  
  347.      C                   Callp     LoadOutFromWork(NextLineP:
  348.      C                                             *Omit:
  349.      C                                             *Omit:
  350.      C                                             *Omit:
  351.      C                                             *Omit:
  352.      C                                             NextStmt)
  353.  
  354.       * Tell SEU that the join is complete
  355.      C                   CallP     SndMsg('SEU0003': RtnCode)
  356.      C                   EndIf
  357.  
  358.      C                   EndSR
  359.  
  360.       *================================================================
  361.       * Send a "status" message back to SEU
  362.       * There's a trick in use here that you need to be aware of.
  363.       * the message stack count is determined by how deep in the call stack the
  364.       * subprocedure is!  Here's why it was set to 3:
  365.       *     STRSEU      1
  366.       *       SEUEXIT   2
  367.       *         SndMsg  3
  368.  
  369.      PSndMsg           b
  370.      DSndMsg           pi
  371.      D MsgID                          7    const
  372.      D RtnCodeOut                          Like(ErrSMsgID)
  373.      D MsgDta                        80    options(*nopass) const
  374.  
  375.       * Send message API parameters
  376.      D MsgIDWrk        s                   like(MsgID)
  377.      D MsgFil          s             20    inz('SEUEXIT   *LIBL     ')
  378.      D MsgData         s             80
  379.      D MsgDataLen      s             10i 0
  380.      D MsgType         s             10    inz('*DIAG')
  381.      D MsgStackEnt     s             10    inz('*')
  382.      D MsgStackCnt     s             10i 0 inz(3)
  383.      D MsgKey          s              4
  384.      D MsgErrStruc     s                   like(ErrStruc)
  385.  
  386.       * API error structure
  387.      D ErrStruc        DS                  inz
  388.      D  ErrSSize                     10i 0 inz(%len(ErrStruc))
  389.      D  ErrSUse                      10i 0
  390.      D  ErrSMsgID                     7
  391.      D  ErrSResrv                     1
  392.      D  ErrSData                     80
  393.  
  394.      C                   eval      MsgIdWrk = MsgID
  395.      C                   eval      MsgErrStruc = ErrStruc
  396.       * was message data provided?
  397.      c                   if        %parms >= 3
  398.      c                   eval      MsgData = msgDta
  399.      c                   eval      MsgDataLen = %len(%trimr(MsgData))
  400.      c                   else
  401.      c                   eval      MsgData = *blanks
  402.      c                   eval      MsgDataLen = 1
  403.      c                   endif
  404.  
  405.      C                   Call      'QMHSNDPM'
  406.      C                   Parm                    MsgIDWrk
  407.      C                   Parm                    MsgFil
  408.      C                   Parm                    MsgData
  409.      C                   Parm                    MsgDataLen
  410.      C                   Parm                    MsgType
  411.      C                   Parm                    MsgStackEnt
  412.      C                   Parm                    MsgStackCnt
  413.      C                   Parm                    MsgKey
  414.      C                   Parm                    MsgErrStruc
  415.  
  416.      C                   Eval      ErrStruc = MsgErrStruc
  417.      C                   Eval      RtnCodeOut = ErrSMsgID
  418.  
  419.      PSndMsg           e
  420.  
  421.       *================================================================
  422.       * Load the work fields from the data SEU sent us
  423.  
  424.      PLoadWorkFromInp  b
  425.      DLoadWorkFromInp  pi
  426.      D SrcDtaPtrInp                    *   const
  427.      D LineCmdOut                          like(LineCmd)     Options(*Omit)
  428.      D LineRetCodeOut                      like(LineRetCode) Options(*Omit)
  429.      D SourceSeqOut                        like(SourceSeq)   Options(*Omit)
  430.      D SourceDateOut                       like(SourceDate)  Options(*Omit)
  431.      D SourceStmtOut                       like(SourceStmt)  Options(*Omit)
  432.  
  433.       * Point to the data within the SEU space
  434.      C                   Eval      SEUSourceP = SrcDtaPtrInp
  435.  
  436.      C                   If        %addr(LineCmdOut) <> *Null
  437.      C                   Eval            LineCmdOut  =  LineCmd
  438.      C                   Endif
  439.      C                   If        %addr(LineRetCodeOut) <> *Null
  440.      C                   Eval            LineRetCodeOut  =  LineRetCode
  441.      C                   Endif
  442.      C                   If        %addr(SourceSeqOut) <> *Null
  443.      C                   Eval            SourceSeqOut  =  SourceSeq
  444.      C                   Endif
  445.      C                   If        %addr(SourceDateOut) <> *Null
  446.      C                   Eval            SourceDateOut  =  SourceDate
  447.      C                   Endif
  448.      C                   If        %addr(SourceStmtOut) <> *Null
  449.      C                   Eval            SourceStmtOut  =  %subst(SourceStmt: 1:
  450.      C                                                       StmtLength)
  451.      C                   Endif
  452.  
  453.      P                 e
  454.  
  455.       *================================================================
  456.       * Load data back to SEU from the work fields
  457.  
  458.      PLoadOutFromWork  b
  459.      DLoadOutFromWork  pi
  460.      D SrcDtaPtrInp                    *                     const
  461.      D LineCmdInp                          like(LineCmd)     Options(*Omit)
  462.      D LineRetCodeInp                      like(LineRetCode) Options(*Omit)
  463.      D SourceSeqInp                        like(SourceSeq)   Options(*Omit)
  464.      D SourceDateInp                       like(SourceDate)  Options(*Omit)
  465.      D SourceStmtInp                       like(SourceStmt)  Options(*Omit)
  466.  
  467.       * Point to the data within the SEU space
  468.      C                   Eval      SEUSourceP = SrcDtaPtrInp
  469.  
  470.      C                   If        %addr(LineCmdInp) <> *Null
  471.      C                   Eval            LineCmd     =  LineCmdInp
  472.      C                   Endif
  473.      C                   If        %addr(LineRetCodeInp) <> *Null
  474.      C                   Eval            LineRetCode     =  LineRetCodeInp
  475.      C                   Endif
  476.      C                   If        %addr(SourceSeqInp) <> *Null
  477.      C                   Eval            SourceSeq     =  SourceSeqInp
  478.      C                   Endif
  479.      C                   If        %addr(SourceDateInp) <> *Null
  480.      C                   Eval            SourceDate     =  SourceDateInp
  481.      C                   Endif
  482.      C                   If        %addr(SourceStmtInp) <> *Null
  483.      C                   Eval            SourceStmt     =  SourceStmtInp
  484.      C                   Endif
  485.  
  486.      P                 e
  487.  
  488.       *================================================================
  489.       * Extract an attribute byte from the input line command
  490.       * The line command is formatted "ATTRxx" where XX is a mnemnonic for
  491.       * the attribute byte to assign to the line.  The mnemnonics are the same
  492.       * as used by DDS with the addition of colours.
  493.  
  494.      PGetAttrFromCmd   b
  495.      DGetAttrFromCmd   pi             1
  496.      D LineCmdInp                          like(LineCmd) const
  497.  
  498.      D AttributeByte   s              1
  499.      D AttrTest        s              2
  500.      D i               s             10i 0
  501.  
  502.      DAttrMnemDS       ds
  503.      D                                2    inz('  ')
  504.      D                                2    inz('RI')
  505.      D                                2    inz('HI')
  506.      D                                2    inz('UL')
  507.      D                                2    inz('BL')
  508.      D                                2    inz('CS')
  509.      D                                2    inz('CP')
  510.      D                                2    inz('CL')
  511.      D AttrMnem                       2    dim(8) overlay(AttrMnemDS)
  512.  
  513.      DAttrDS           ds
  514.      D                                1    inz(x'20')
  515.      D                                1    inz(x'21')
  516.      D                                1    inz(x'22')
  517.      D                                1    inz(x'24')
  518.      D                                1    inz(x'28')
  519.      D                                1    inz(x'30')
  520.      D                                1    inz(x'38')
  521.      D                                1    inz(x'3A')
  522.      D Attr                           1    dim(8) overlay(AttrDS)
  523.  
  524.       * Default to normal
  525.      C                   Eval      AttributeByte = Attr(1)
  526.  
  527.       * Extract the mnemnonic from the line command
  528.      C                   Eval      AttrTest = %subst(ThisLineCmd: 5: 2)
  529.  
  530.       * Convert the mnemnonic to an attribute byte
  531.      C                   Eval      i = 1
  532.      C     AttrTest      Lookup    AttrMnem(i)                            20
  533.      C                   If        *In20 = *On
  534.      C                   Eval      AttributeByte = Attr(i)
  535.      C                   EndIf
  536.  
  537.      C                   Return    AttributeByte
  538.      P                 e
  539.  
© 2004-2019 by midrange.com generated in 0.01s valid xhtml & css