home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / macros / seucmd.lx < prev    next >
Encoding:
Text File  |  1996-02-22  |  28.3 KB  |  654 lines

  1. /******************************************************************************
  2.  * SEU Prefix commands                                                        *
  3.  *                                                                            *
  4.  * Arguments:  cmd  - prefix command to be executed.  This may be any of the  *
  5.  *                    following:  add                                         *
  6.  *                                delete                                      *
  7.  *                                target                                      *
  8.  *                                show                                        *
  9.  *                                exclude                                     *
  10.  *                                shift                                       *
  11.  *                                duplicate                                   *
  12.  *                                current                                     *
  13.  *                                window                                      *
  14.  *                                scroll                                      *
  15.  *                                locate                                      *
  16.  *                                skeleton                                    *
  17.  *                                                                            *
  18.  *             parm - command specific parameters                             *
  19.  *                                                                            *
  20.  *****************************************************************************/
  21. arg cmd parm
  22.  
  23. markno = 0                             /* global mark count */
  24. 'extract prefixentry'                  /* get text in prefix entry field */
  25. parse upper var prefixentry pe         /* uppercase text */
  26. count = getcount(pe)                   /* pull out numeric part of command */
  27.  
  28. select
  29.    /* Add command.  This command inserts one or more lines into the file.
  30.       Parameters: [skeleton] - indicates an insert skeleton command */
  31.    when "ADD" = cmd then do
  32.  
  33.       'set prefixentry'                /* reset prefix entry field */
  34.       'extract class'                  /* get the class of this line */
  35.       if pos("PFXSHOW",class) \= 0 then do
  36.                                        /* this is an exclude header */
  37.          if nextline("next visible") then
  38.                                        /* move to next visible line */
  39.             'prev class PFXEXCLUDE'    /* find previous exclude line */
  40.          else do                       /* no more visible lines */
  41.             do forever                 /* loop through file */
  42.                if \nextline() then     /* if at end of file */
  43.                   leave                /* get out of loop */
  44.                'extract class'         /* get class of line */
  45.                if pos("PFXEXCLUDE",class) = 0 then do
  46.                                        /* if not exclude line */
  47.                   'prev'               /* go back one */
  48.                   leave                /* get out of loop */
  49.                end
  50.             end
  51.          end
  52.       end
  53.       if "SKELETON" = parm then do     /* if insert skeleton */
  54.          'extract global.skeleton into skeleton'
  55.                                        /* get skeleton line */
  56.          do i = 1 to count             /* insert count lines */
  57.             'insert 'skeleton
  58.          end
  59.       end
  60.       else
  61.          'add 'count                   /* insert count lines */
  62.       exit                             /* done */
  63.    end
  64.  
  65.    /* Target command.  This command executes a block copy or move.
  66.       Parameters: before | after | overlay [block] */
  67.    when "TARGET" = cmd then do
  68.       parse var parm target block
  69.  
  70.       call setmark                     /* set a mark */
  71.  
  72.       overlay = "OVERLAY" = target     /* set overlay flag */
  73.       if overlay then do               /* if overlay... */
  74.          target = before               /* copy/move before */
  75.          if "BLOCK" = block then do    /* block overlay */
  76.             if \nextline() | findprefix(substr(pe,1,2)) = "" then
  77.                call errormsg(2 pe)
  78.          end
  79.          else do                       /* not block overlay */
  80.             lines = count - 1          /* number of lines to scroll */
  81.             if lines > 0 then
  82.                'scroll down 'lines     /* scroll down to last line */
  83.             count = 1                  /* reset count */
  84.          end
  85.          call setmark                  /* mark last overlay line */
  86.       end
  87.  
  88.       'top'                            /* go to top of file */
  89.       src = findprefix("C M")          /* search for copy or move */
  90.       if src = "" then                 /* if not found issue error */
  91.          call errormsg(1 pe)
  92.       'block clear'                    /* clear current block */
  93.       'block mark element'             /* mark the current element */
  94.       c1 = substr(src,1,1)             /* get first char of copy or move */
  95.       clear = ((c1 = "C") & (pos("R",src) = 0))
  96.                                        /* set flag if entry field should be cleared */
  97.       if clear then call setmark       /* set a mark */
  98.       if c1 = substr(src,2,1) then do  /* if block copy or move... */
  99.          if \nextline() |,
  100.             findprefix(substr(src,1,2)) = "" then call errormsg(2 src)
  101.                                        /* find matching block */
  102.          if clear then call setmark    /* if copy, set another mark */
  103.       end
  104.       else do                          /* not block copy or move... */
  105.          lines = getcount(src) - 1     /* get number of lines */
  106.          if lines > 0 then
  107.             'scroll down 'lines        /* scroll down to last line */
  108.       end
  109.       'block mark element'             /* set block on last line */
  110.  
  111.       if c1 = "C" then                 /* set type of block operation */
  112.          action = "COPY"
  113.       else
  114.          action = "MOVE"
  115.  
  116.       'mark find PFXMARK1'             /* locate target */
  117.       'block 'action target            /* issue copy or move */
  118.       do i = 1 to count - 1            /* repeat as necessary */
  119.          'block copy 'target           
  120.       end
  121.       if RC = -3 then                  /* if copy/move into itself, error */
  122.          call errormsg(6 action)
  123.       'block clear'
  124.  
  125.       if overlay then do               /* if overlay command */
  126.          'mark find PFXMARK1'          /* find overlay line */
  127.          'block mark element'          /* set the block on the line */
  128.          'mark find PFXMARK2'          /* find last overlay line */
  129.          'block mark element'          /* mark the whole block */
  130.          'block delete'                /* delete the overlayed lines */
  131.       end
  132.  
  133.    end
  134.  
  135.    /* Delete command.  This command deletes one or more lines.
  136.       Parameters:  [block] - indicate block delete */
  137.    when "DELETE" = cmd then do
  138.       'block clear'                    /* clear the current block */
  139.       'block mark element'             /* mark this element */
  140.       if parm = "BLOCK" then do        /* if block delete... */
  141.          if \nextline() | findprefix("DD") = "" then call errormsg(2 pe)
  142.                                        /* look for end of block */
  143.       end
  144.       else do                          /* else not block delete */
  145.          lines = count - 1
  146.          if lines > 0 then
  147.             'scroll down' lines        /* find last line to be deleted */
  148.       end
  149.       'extract class'                  /* get the class of the last line */
  150.       if pos("PFXSHOW",class) \= 0 then do
  151.                                        /* this is an exclude header */
  152.          if nextline("next visible") then
  153.                                        /* move to next visible line */
  154.             'prev class PFXEXCLUDE'    /* find previous exclude line */
  155.          else do                       /* no more visible lines */
  156.             do forever                 /* loop through file */
  157.                if \nextline() then     /* if at end of file */
  158.                   leave                /* get out of loop */
  159.                'extract class'         /* get class of line */
  160.                if pos("PFXEXCLUDE",class) = 0 then do
  161.                                        /* if not exclude line */
  162.                   'prev'               /* go back one */
  163.                   leave                /* get out of loop */
  164.                end
  165.             end
  166.          end
  167.       end
  168.       'extract deleting'               /* get deleting command */
  169.       'set deleting'                   /* remove it */
  170.       'block mark element'             /* mark the delete block */
  171.       'block delete'                   /* delete the block */
  172.       if headers() then                /* if there are still header lines */
  173.          'set deleting' deleting       /* restore deleting command */
  174.       exit                             /* all done */
  175.    end
  176.  
  177.    /* Show command.  This command shows one or more excluded lines.
  178.       Parameters: all | first | last - indicates which part of the excluded
  179.                                        block to show. */
  180.    when "SHOW" = cmd then do
  181.       'extract class'                  /* get class of current line */
  182.       if pos("PFXSHOW",class) == 0 then
  183.          call errormsg(3)              /* issue error if not exclude header */
  184.       call setmark                     /* set a mark on this line */
  185.       'set prefixentry'                /* clear the prefix entry text */
  186.  
  187.       if parm = "LAST" then do         /* if show last command */
  188.          do forever                    /* look for end of block */
  189.             if \nextline() then leave  /* if no more lines, leave */
  190.             'extract class'            /* get class of line */
  191.             if pos("PFXEXCLUDE",class) = 0 then do
  192.                                        /* if not part of block, leave */
  193.                'prev'
  194.                leave
  195.             end
  196.          end
  197.          dir = 'prev'                  /* set direction */
  198.       end
  199.       else do
  200.          dir = 'next'                  /* set direction */
  201.          'next'
  202.       end
  203.  
  204.       if parm = "ALL" then             /* if showing whole block */
  205.          'extract elements into count' /* set count to file size */
  206.  
  207.       do i = 1 to count                /* loop through the lines */
  208.          'extract class'               /* get class of line */
  209.          if pos("PFXEXCLUDE",class) == 0 then leave
  210.                                        /* if not an excluded line, leave */
  211.          parse var class pre "PFXEXCLUDE" post
  212.          'set class 'pre post          /* remove PFXEXCLUDE from class */
  213.          if \nextline(dir) then leave  /* if no more lines, leave */
  214.       end
  215.  
  216.       if "FIRST" = parm then do        /* if show fisrt command */
  217.          call beginchange              /* make sure changes not recorded */
  218.          'prev'                        /* back up a line */
  219.          'add'                         /* add a new exclude header */
  220.          'set class PFXSHOW'           /* set exclude header class */
  221.          'set show on'                 /* make it a show line */
  222.          call setmark                  /* mark this line */
  223.          'mark find PFXMARK1'          /* find old header */
  224.          call deleteheader             /* delete it */
  225.          'mark find PFXMARK2'          /* find new header */
  226.          'mark clear PFXMARK2'         /* change mark name to PFXMARK1 */
  227.          markno = 0
  228.          call setmark
  229.          call endchange                /* restore recording status */
  230.       end
  231.       else                             /* not a show first */
  232.          'mark find PFXMARK1'          /* find header */
  233.  
  234.       call excludeheader               /* set exclude header text */
  235.    end
  236.  
  237.    /* Exclude command.  This command excludes one or more lines.
  238.       Parameters - [ALL | BLOCK] - indicates exclude all or block exclude */
  239.    when "EXCLUDE" = cmd then do
  240.       'extract classes'                /* Add PFXEXCLUDE and PFXSHOW classes */
  241.       if pos("PFXEXCLUDE",classes) = 0 then
  242.          'set classes 'classes' PFXSHOW PFXEXCLUDE'
  243.       'extract highlight'              /* Add PFXSHOW to highlight classes */
  244.       if pos("PFXSHOW",highlight) = 0 then
  245.          'set highlight 'highlight' PFXSHOW'
  246.       'extract exclude'                /* Add PFXEXCLUDE to exclude classes */
  247.       if pos("PFXEXCLUDE",exclude) = 0 then
  248.          'set exclude 'exclude' PFXEXCLUDE'
  249.       'extract protect'                /* Add PFXSHOW to protect classes */
  250.       if pos("PFXSHOW",protect) = 0 then
  251.          'set protect 'protect' PFXSHOW'
  252.  
  253.       'extract class'                  /* get class of current line */
  254.       if pos("PFXEXCLUDE",class) > 0 then do
  255.          'set prefixentry'             /* clear prefix entry field */
  256.          exit                          /* quit if line already hidden */
  257.       end
  258.  
  259.       call setmark                     /* set a mark */
  260.       'extract element into startline' /* get element number */
  261.  
  262.       if parm = "BLOCK" then do        /* if block exclude... */
  263.          if \nextline() |,
  264.             findprefix(substr(pe,1,2)) = "" then call errormsg(2 pe)
  265.                                        /* if block not found issue error */
  266.          'set prefixentry'             /* clear prefix entry field text */
  267.          'extract element into endline'/* get element number of end of block */
  268.          count = endline - startline + 1
  269.                                        /* calculate number of lines to exclude*/
  270.       end
  271.       else if parm = "ALL" then        /* if excluding all the lines */
  272.          'extract elements into count' /* get file size */
  273.  
  274.       call beginchange                 /* make sure changes not recorded */
  275.       'mark find PFXMARK1'             /* find first line to exclude */
  276.       'splitjoin split'                /* open a new line before it */
  277.       'set class PFXSHOW'              /* set exclude header class */
  278.       'set show on'                    /* make it a show line */
  279.       call endchange                   /* restore recording */
  280.  
  281.       'next'                           /* move to next line */
  282.       do i = 1 to count                /* loop through and exclude the lines */
  283.          'extract class'
  284.          if pos("PFXSHOW",class) > 0 then leave
  285.          'set class 'class' PFXEXCLUDE'
  286.          if \nextline() then leave
  287.       end
  288.  
  289.       call excludeheader               /* set exclude header */
  290.    end
  291.  
  292.    /* Shift command.  This command shifts one or more lines.
  293.       Parameters: right | left - indicates shift direction
  294.                   trunc | notrunc - indicates if shift should truncate line
  295.                   [block] - indicates block shift */
  296.    when "SHIFT" = cmd then do
  297.       parse var parm dir trunc type
  298.  
  299.       call setmark                     /* set a mark on this line */
  300.       'block clear'                    /* clear the current block */
  301.       'block mark element'             /* mark this line */
  302.       
  303.       if type = "BLOCK" then do        /* if block shift */
  304.          if \nextline() |,
  305.             findprefix(substr(pe,1,2)) = "" then call errormsg(2 pe)
  306.                                        /* search for end of block */
  307.          'set prefixentry'             /* clear prefix entry field text */
  308.          'block mark element'          /* mark the block */
  309.       end
  310.  
  311.       truncate = trunc \= "NOTRUNC"    /* set truncation flag */
  312.       if truncate then do              /* if truncate... */
  313.          'extract limiterror into savelimiterror'
  314.                                        /* save limiterror mode */
  315.          'set limiterror truncate'     /* set limiterror mode to truncate */
  316.          trunc = ""                    /* no option needed for turncate */
  317.       end
  318.  
  319.       'block shift 'dir count trunc' clear'
  320.                                        /* issue shift command */
  321.  
  322.       if truncate then                 /* if truncate, restore limiterror */
  323.          'set limiterror 'savelimiterror
  324.    end
  325.  
  326.    /* Duplicate command.  This command duplicates the current line one or more times
  327.       Parameters:  none */
  328.    when "DUPLICATE" = cmd then do
  329.       call setmark                     /* set a mark on this line */
  330.       'block clear'                    /* clear the current block */
  331.       'block mark element'             /* mark this line */
  332.  
  333.       if parm = "BLOCK" then do        /* if block repeat... */
  334.                                        /* look for end of block */
  335.          if \nextline() | findprefix(substr(pe,1,3)) = "" then
  336.             call errormsg(2 pe)
  337.          'set prefixentry'             /* clear prefix entry field */
  338.          'block mark element'          /* mark the block */
  339.       end
  340.  
  341.       do i = 1 to count                /* copy the line count times */
  342.          'block copy after'
  343.       end
  344.       'block clear'                    /* clear the block */
  345.    end
  346.  
  347.    /* Current command.  This command sets the current line.
  348.       Parameters:  none */
  349.    when "CURRENT" = cmd then do
  350.       call setmark                     /* set a mark on this line */
  351.  
  352.       'set focus.next 1 '     /* get top row */
  353.       'mark find PFXMARK1'             /* make this the current line */
  354.    end
  355.  
  356.    /* Window command.  This command scrolls the window to a specified column
  357.       Parameters:  none */
  358.    when "WINDOW" = cmd then do
  359.       'set prefixentry'                /* clear prefix entry field */
  360.       'primitive beginline'            /* go to the beginning of the line */
  361.       col = count - 1
  362.       if col > 0 then                  /* if necessary, */
  363.          'scroll right 'col            /* scroll to specified column */
  364.       exit                             /* all done */
  365.    end
  366.  
  367.    /* Scroll command.  This command scrolls to a specified number of lines
  368.       Parameters:  up | down - indicates direction */
  369.    when "SCROLL" = cmd then do
  370.       'set prefixentry'                /* clear prefix entry field */
  371.       'scroll 'parm count              /* scroll to desired line */
  372.       exit                             /* all done */
  373.    end
  374.  
  375.    /* Locate command.  This command locates a specified line number or
  376.                        sequence number.
  377.       Parameters:  none */
  378.    when "LOCATE" = cmd then do
  379.       'set prefixentry'                /* clear prefix entry field */
  380.       'extract prefixformat'           /* get prefixformat */
  381.       if pos("9",prefixformat) > 0 then/* if sequence numbers */
  382.          findtype = prefixnumber       /* locate sequence number */
  383.       else
  384.          findtype = element            /* locate line */
  385.       'find 'findtype count            /* locate desired line */
  386.       exit                             /* all done */
  387.    end
  388.  
  389.    /* Skeleton command.  This command sets the current line to be the
  390.                          skeleton line.
  391.       Parameters:  none */
  392.    when "SKELETON" = cmd then do
  393.       'set prefixentry'                /* clear prefix entry field */
  394.       'extract content into skeleton'  /* get line text */
  395.       'set global.skeleton 'skeleton   /* save line text */
  396.       exit                             /* all done */
  397.    end
  398. end
  399.  
  400. call setmark                           /* save the current position */
  401. do i = 1 to (markno - 1)               /* loop through the marked lines */
  402.    'extract mark.PFXMARK'i' into markcol'
  403.    if markcol \= 0 then do             /* if mark not deleted */
  404.       'mark find PFXMARK'i             /* find the mark */
  405.       'set prefixentry'                /* clear the prefix entry field */
  406.    end
  407. end
  408. 'mark find PFXMARK'markno              /* restore the current position */
  409.  
  410. cleanup:
  411.  
  412. do i = 1 to markno                     /* loop through and delete marks */
  413.    'mark clear PFXMARK'i
  414. end
  415.  
  416. exit                                   /* all done */
  417.  
  418. /******************************************************************************
  419.  *                                                                            *
  420.  * function getcount(str)                                                     *
  421.  *                                                                            *
  422.  * This function returns the numeric part of a character string.  If there is *
  423.  * no numeric part, then 1 is returned.                                       *
  424.  *                                                                            *
  425.  ******************************************************************************/
  426. getcount:
  427.  
  428. procedure
  429.  
  430. arg count
  431.  
  432. do while datatype(substr(count,1,1)) \= "NUM"
  433.    if length(count) = 1 then
  434.       count = 1
  435.    else
  436.       count = substr(count,2)
  437. end
  438.  
  439. do while datatype(substr(count,length(count))) \= "NUM"
  440.    if length(count) = 1 then
  441.       count = 1
  442.    else
  443.       count = delstr(count,length(count))
  444. end
  445.  
  446. return abs(count)
  447.  
  448. /******************************************************************************
  449.  *                                                                            *
  450.  * setmark routine                                                            *
  451.  *                                                                            *
  452.  * This routine sets a mark on the current line.  It uses the global variable *
  453.  * markno to give the mark a unique name.                                     *
  454.  *                                                                            *
  455.  ******************************************************************************/
  456. setmark:
  457.  
  458. procedure expose markno
  459.  
  460. markno = markno + 1
  461. 'extract element into e'
  462. 'mark set PFXMARK'markno e '-1'
  463. return
  464.  
  465. /******************************************************************************
  466.  *                                                                            *
  467.  * function findprefix(str)                                                   *
  468.  *                                                                            *
  469.  * This function looks for a line whose prefix entry field contains text that *
  470.  * begins with str.  If str contains more than one string, then the first     *
  471.  * line that matches either is returned.  The actual prefix text is returned  *
  472.  * by this function.                                                          *
  473.  *                                                                            *
  474.  ******************************************************************************/
  475. findprefix:
  476.  
  477. procedure
  478.  
  479. arg parm
  480.  
  481. do forever
  482.    'extract prefixentry into pe'
  483.    parse upper var pe upperpe
  484.    cmds = parm
  485.    do while length(cmds) > 0
  486.       parse var cmds cmd cmds
  487.       if length(upperpe) >= length(cmd) then
  488.          if cmd = substr(upperpe,1,length(cmd)) then
  489.             return upperpe
  490.    end
  491.    'find prefixentry'
  492.    if RC \= 0 then return ""
  493. end
  494.  
  495. /******************************************************************************
  496.  *                                                                            *
  497.  * beginchange routine                                                        *
  498.  *                                                                            *
  499.  * This routine changes the recording state so that changes will not be       *
  500.  * recorded.                                                                  *
  501.  *                                                                            *
  502.  ******************************************************************************/
  503. beginchange:
  504.  
  505. procedure expose savechanges saverecording
  506.  
  507. 'extract changes into savechanges'
  508. 'extract recording into saverecording'
  509.  
  510. 'set recording off'
  511. return
  512.  
  513. /******************************************************************************
  514.  *                                                                            *
  515.  * endchange routine                                                          *
  516.  *                                                                            *
  517.  * This routine restored the recording state to that before beginchange was   *
  518.  * called.                                                                    *
  519.  *                                                                            *
  520.  ******************************************************************************/
  521. endchange:
  522.  
  523. procedure expose saverecording savechanges
  524.  
  525. 'set recording 'saverecording
  526. 'set changes 'savechanges
  527. return
  528.  
  529. /******************************************************************************
  530.  *                                                                            *
  531.  * excludeheader routine                                                      *
  532.  *                                                                            *
  533.  * This routine counts the number of excluded line is a block and sets the    *
  534.  * exclude header text appropriately.                                         *
  535.  *                                                                            *
  536.  ******************************************************************************/
  537. excludeheader:
  538.  
  539. procedure
  540.  
  541. 'mark find PFXMARK1'
  542. lines = 0
  543. do forever
  544.    if \nextline() then leave
  545.    'extract class'
  546.    if pos("PFXEXCLUDE",class) == 0 then leave
  547.    lines = lines + 1
  548. end
  549.  
  550. call beginchange
  551. 'mark find PFXMARK1'
  552. if 0 = lines then do
  553.    call deleteheader
  554.    call endchange
  555.    exit
  556. end
  557. 'extract limiterror into savelimiterror'
  558. 'set limiterror ignore'
  559. if 1 = lines then
  560.    'set content 'seumsg(4)
  561. else
  562.    'set content 'seumsg(5 lines)
  563. 'set limiterror 'savelimiterror
  564. call endchange
  565.  
  566. 'extract deleting'
  567. if deleting = "" then do
  568.    'macroload pfxdel.lx'
  569.    'set deleting pfxdel'
  570. end
  571.  
  572. return
  573.  
  574. /******************************************************************************
  575.  *                                                                            *
  576.  * deleteheader routine                                                       *
  577.  *                                                                            *
  578.  * This routine deletes the current exclude header line.                      *
  579.  *                                                                            *
  580.  ******************************************************************************/
  581. deleteheader:
  582.  
  583. procedure
  584.  
  585. 'extract deleting'
  586. 'set deleting'
  587. 'delete'
  588. if headers() then
  589.    'set deleting 'deleting
  590.  
  591. return
  592.  
  593. /******************************************************************************
  594.  *                                                                            *
  595.  * function headers()                                                         *
  596.  *                                                                            *
  597.  * This function returns TRUE if there are any headers remaining.             *
  598.  *                                                                            *
  599.  ******************************************************************************/
  600. headers:
  601.  
  602. procedure
  603.  
  604. 'extract classes'
  605. if (pos("PFXSHOW",classes) = 0) then
  606.    return 0
  607.  
  608. 'extract element into e'
  609. 'mark set PFXMARKH' e '-1'
  610. 'top'
  611. 'next class PFXSHOW'
  612. 'extract class'
  613. 'mark find PFXMARKH'
  614. 'mark clear PFXMARKH'
  615.  
  616. return (pos("PFXSHOW",class) \= 0)
  617.  
  618. /******************************************************************************
  619.  *                                                                            *
  620.  * function nextline(dir)                                                     *
  621.  *                                                                            *
  622.  * This function accepts a direction (prev or next) and move to the previous  *
  623.  * or next line.  It returns TRUE if the operation completed successfully.    *
  624.  *                                                                            *
  625.  ******************************************************************************/
  626. nextline:
  627.  
  628. procedure
  629.  
  630. arg dir parm
  631.  
  632. if dir \= "PREV" then
  633.    dir = 'next'
  634.  
  635. 'extract element into preve'
  636. dir parm
  637. 'extract element'
  638. return element \= preve
  639.  
  640. /******************************************************************************
  641.  *                                                                            *
  642.  * errormsg(msgno insert) routine                                             *
  643.  *                                                                            *
  644.  * This routine issues an error message msgno and exits.                      *
  645.  *                                                                            *
  646.  ******************************************************************************/
  647. errormsg:
  648.  
  649. arg msgno insert
  650.  
  651. 'msg 'seumsg(msgno insert)
  652. signal cleanup
  653.  
  654.