midrange.com code scratchpad
Name:
Dynamic Data Structure Arrays
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
08/14/2017 09:08:15 pm
IP:
Logged
Description:
An example of using heap storage to implement a dynamic data structure array (plus how to use Regular Expressions)
Code:
  1. Include Files:
  2.                                                          cpsrc.cp1400h
  3.       //--------------------------------------------------------------------------------------------------------------//
  4.       //                                                                                                              //
  5.       //                                                                                                              //
  6.       //                                    Regular Expression Server Include File                                    //
  7.       //                                                                                                              //
  8.       //                                                                                                              //
  9.       //--------------------------------------------------------------------------------------------------------------//
  10.       //
  11.       // compile regular expression, and return pointer
  12.       //
  13.        Dcl-PR cp1400_load   Pointer                                            ;
  14.          *n                 Pointer Options(*String:*Trim) Value               ;
  15.        End-PR                                                                  ;
  16.       //
  17.       // execute regular expression
  18.       //
  19.        Dcl-PR cp1400_process Ind                                               ;
  20.          *n                 Pointer                                            ;
  21.          *n                 Pointer Options(*String:*Trim) Value               ;
  22.        End-PR                                                                  ;
  23.       //
  24.       // cleanup/housekeeping
  25.       //
  26.        Dcl-PR cp1400_cleanup                                                   ;
  27.          *n                 Pointer                                            ;
  28.        End-PR                                                                  ;
  29.                                                          cpsrc.cp1400h
  30.       //--------------------------------------------------------------------------------------------------------------//
  31.       //                                                                                                              //
  32.       //                                                                                                              //
  33.       //                             dynamic data structure array management include file                             //
  34.       //                                                                                                              //
  35.       //                                                                                                              //
  36.       //--------------------------------------------------------------------------------------------------------------//
  37.       //
  38.       // parameter data structure
  39.       //
  40.        Dcl-DS cp1402_t      Template                                           ;
  41.          @heap#             Uns(10)         Inz(0)                             ;// allocated size
  42.          @heap$             Uns(10)         Inz(0)                             ;// used size
  43.          @heap@             Pointer         Inz(*Null)                         ;// begining of @heap
  44.          heap@@             Pointer         Inz(*Null)                         ;// heap@@->heap@->heap
  45.          heapSz             Uns(10)         Inz(0)                             ;// heap length
  46.        End-DS                                                                  ;
  47.       //
  48.       // allocate heap
  49.       //
  50.        Dcl-PR cp1402_alloc  Pointer                                            ;
  51.          parms              LikeDS(cp1402_t)                                   ;
  52.        End-PR                                                                  ;
  53.       //
  54.       // deallocate heap
  55.       //
  56.        Dcl-PR cp1402_dealloc                                                   ;
  57.          parms              LikeDS(cp1402_t)                                   ;
  58.        End-PR                                                                  ;
  59. Binding Source:
  60.                                                          cpsrc.cp1400b
  61. STRPGMEXP  PGMLVL(*CURRENT)
  62.    EXPORT     SYMBOL(CP1400_LOAD)
  63.    EXPORT     SYMBOL(CP1400_PROCESS)
  64.    EXPORT     SYMBOL(CP1400_CLEANUP)
  65. ENDPGMEXP
  66.                                                          cpsrc.cp1402b
  67. STRPGMEXP  PGMLVL(*CURRENT)
  68.    EXPORT     SYMBOL(CP1402_ALLOC)
  69.    EXPORT     SYMBOL(CP1402_DEALLOC)
  70. ENDPGMEXP
  71. Service Program Source:
  72.                                                          cpsrc.cp1400s
  73.       //--------------------------------------------------------------------------------------------------------------//
  74.       //                                                                                                              //
  75.       //                                                                                                              //
  76.       //                           CP1400S - Service Program - evaluate regular expression                            //
  77.       //                                                                                                              //
  78.       //                                                                                                              //
  79.       //--------------------------------------------------------------------------------------------------------------//
  80.       //
  81.       // ... compilation notes ...
  82.       //
  83.       // CRTRPGMOD MODULE(CPANDO/CP1400S)
  84.       //           SRCFILE(CPANDO/CPSRC)
  85.       //
  86.       // CRTSRVPGM SRVPGM(CPANDO/CP1400S)
  87.       //           SRCFILE(CPANDO/CPSRC)
  88.       //           SRCMBR(CP1400B)
  89.       //           TEXT('Manage/Evaluate Regular Expressions')
  90.       //
  91.        Ctl-Opt debug(*Yes) option(*SrcStmt:*NoDebugIO) noMain                  ;
  92.       //--------------------------------------------------------------------------------------------------------------//
  93.       //                                                                                                              //
  94.       // ... procedure interfaces ...                                                                                 //
  95.       //                                                                                                              //
  96.       //--------------------------------------------------------------------------------------------------------------//
  97.       //
  98.       // ... services (external) ...
  99.       //
  100.        Dcl-PR regcomp        Int(10)         ExtProc('regcomp')                ;
  101.          *n                  Pointer         Value                             ;
  102.          *n                  Pointer         Value                             ;
  103.          *n                  Int(10)         Value                             ;
  104.        End-PR                                                                  ;
  105.  
  106.        Dcl-PR regexec        Int(10)         ExtProc('regexec')                ;
  107.          *n                  Pointer         Value                             ;
  108.          *n                  Pointer         Value                             ;
  109.          *n                  Uns(10)         Value                             ;
  110.          *n                  Pointer         Value                             ;
  111.          *n                  Int(10)         Value                             ;
  112.        End-PR                                                                  ;
  113.  
  114.        Dcl-PR regerror       Uns(10)         ExtProc('regerror')               ;
  115.          *n                  Int(10)         Value                             ;
  116.          *n                  Pointer         Value                             ;
  117.          *n                  Pointer         Value                             ;
  118.          *n                  Int(10)         Value                             ;
  119.        End-PR                                                                  ;
  120.  
  121.        Dcl-PR regfree                        ExtProc('regfree')                ;
  122.          *n                  Pointer         Value                             ;
  123.        End-PR                                                                  ;
  124.       //--------------------------------------------------------------------------------------------------------------//
  125.       //                                                                                                              //
  126.       // ... data structures ...                                                                                      //
  127.       //                                                                                                              //
  128.       //--------------------------------------------------------------------------------------------------------------//
  129.        Dcl-DS regex_t        Based(regex_t@)                                   ;
  130.          re_nsub             Int(10)                                           ;
  131.          re_comp             Pointer                                           ;
  132.          re_cflags           Int(10)                                           ;
  133.          re_erroff           Int(10)                                           ;
  134.          re_len              Int(10)                                           ;
  135.          re_ucoll            Int(10)         Dim(2)                            ;
  136.          re_lsub             Pointer                                           ;
  137.          lsub                Int(10)         Dim(16)                           ;
  138.          esub                Int(10)         Dim(16)                           ;
  139.          *n                  Pointer                                           ;// reserved
  140.          re_esub             Pointer                                           ;
  141.          re_specchar         Pointer                                           ;
  142.          re_phdl             Pointer                                           ;
  143.          comp_spc            Char(1)         Dim(112)                          ;
  144.          re_map              Char(1)         Dim(256)                          ;
  145.          re_shift            Int(5)                                            ;
  146.          re_dbcs             Int(5)                                            ;
  147.          *n                  Char(12)                                          ;// forcing to 16 byte boundary
  148.        End-DS                                                                  ;
  149.       //--------------------------------------------------------------------------------------------------------------//
  150.       //                                                                                                              //
  151.       // ... standalone variables ...                                                                                 //
  152.       //                                                                                                              //
  153.       //--------------------------------------------------------------------------------------------------------------//
  154.        Dcl-S  rc             Int(10)                                           ;
  155.        Dcl-S  buf            Char(256)                                         ;
  156.       //--------------------------------------------------------------------------------------------------------------//
  157.       //                                                                                                              //
  158.       //                                                  Procedures                                                  //
  159.       //                                                                                                              //
  160.       //--------------------------------------------------------------------------------------------------------------//
  161.       //                                                     load                                                     //
  162.       //--------------------------------------------------------------------------------------------------------------//
  163.        Dcl-Proc cp1400_load                                 Export             ;
  164.        Dcl-PI *n            Pointer                                            ;
  165.          regexp@            Pointer Options(*String:*Trim)  Value              ;
  166.        End-PI                                                                  ;
  167.        //
  168.        // compile regexp
  169.        //
  170.        regex_t@ = %Alloc(%Len(regex_t))                                        ;
  171.        rc = regcomp(regex_t@:regexp@:0)                                        ;
  172.        If ( rc <> 0 )                                                          ;// minimal error handling
  173.          regerror(rc:regex_t@:%Addr(buf):%Len(buf))                            ;
  174.          regex_t@ = *Null                                                      ;
  175.        EndIf                                                                   ;
  176.        Return regex_t@                                                         ;
  177.  
  178.        End-Proc                                                                ;
  179.       //--------------------------------------------------------------------------------------------------------------//
  180.       //                                                   process                                                    //
  181.       //--------------------------------------------------------------------------------------------------------------//
  182.        Dcl-Proc cp1400_process                              Export             ;
  183.        Dcl-PI *n            Ind                                                ;
  184.          regexp@            Pointer                                            ;
  185.          string@            Pointer Options(*String:*Trim)  Value              ;
  186.        End-PI                                                                  ;
  187.        //
  188.        // execute regular expression
  189.        //
  190.        Return ( 0 = regexec(regexp@:string@:0:*Null:0) )                       ;
  191.        End-Proc                                                                ;
  192.       //--------------------------------------------------------------------------------------------------------------//
  193.       //                                                   cleanup                                                    //
  194.       //--------------------------------------------------------------------------------------------------------------//
  195.        Dcl-Proc cp1400_cleanup                              Export             ;
  196.        Dcl-PI *n                                                               ;
  197.          regex_t@          Pointer                                             ;
  198.        End-PI                                                                  ;
  199.        //
  200.        // no memory leaks here!
  201.        //
  202.        regfree(regex_t@)                                                       ;
  203.        DeAlloc regex_t@                                                        ;
  204.        Return                                                                  ;
  205.        End-Proc                                                                ;
  206.                                                          cpsrc.cp1402s
  207.       //--------------------------------------------------------------------------------------------------------------//
  208.       //                                                                                                              //
  209.       //                                                                                                              //
  210.       //                                      dynamic array management                                                //
  211.       //                                                                                                              //
  212.       //                                                                                                              //
  213.       //--------------------------------------------------------------------------------------------------------------//
  214.       //                                                                                                              //
  215.       // Instead of using array notation, where @heap($I) would be the Ith element of a data structure array, we      //
  216.       // are going to use pointer notation.                                                                           //
  217.       //                                                                                                              //
  218.       // For each element in the data structure array, we are going to allocate storage in the heap, and store        //
  219.       // the pointer to that storage in a contiguous section of memory. The first pointer points to the first         //
  220.       // array element, the second pointer to the second, and so on. When the number of pointers in contiguous        //
  221.       // memory fills the allocated area, we will double the allocated amount.                                        //
  222.       //                                                                                                              //
  223.       //                                                                                                              //
  224.       // @heap@ points to the first pointer.                                                                          //
  225.       //                                                                                                              //
  226.       // heap@@ -> heap@ -> heaprec                                                                                   //
  227.       //                                                                                                              //
  228.       // Therefore, for the Ith element in the array:                                                                 //
  229.       //                                                                                                              //
  230.       // heap@@ = @heap@ + (I-1)*#POINTERSIZE                                                                         //
  231.       //                                                                                                              //
  232.       // This is almost like a Multiple Occurrence Data Structure, w/ the above statement replacing the OCUR          //
  233.       //--------------------------------------------------------------------------------------------------------------//
  234.       //
  235.       // ... compilation notes ...
  236.       //
  237.       // CRTRPGMOD MODULE(CPANDO/CP1402S)
  238.       //           SRCFILE(CPANDO/CPSRC)
  239.       //
  240.       // CRTSRVPGM SRVPGM(CPANDO/CP1402S)
  241.       //           SRCFILE(CPANDO/CPSRC)
  242.       //           SRCMBR(CP1402B)
  243.       //           TEXT('Dynamic Data Structure Array Management')
  244.       //
  245.       //--------------------------------------------------------------------------------------------------------------//
  246.        Ctl-Opt debug(*Yes) option(*SrcStmt:*NoDebugIO:*NoUnRef) noMain         ;
  247.       //--------------------------------------------------------------------------------------------------------------//
  248.       //
  249.       // ... module include files ...
  250.       //
  251.       /copy cpsrc,cp1402h
  252.       //--------------------------------------------------------------------------------------------------------------//
  253.        Dcl-Proc cp1402_alloc                                Export             ;
  254.          Dcl-PI *n          Pointer                                            ;
  255.            parms            LikeDS(cp1402_t)                                   ;
  256.          End-PI                                                                ;
  257.  
  258.        parms.@heap$ += 1                                                       ;
  259.  
  260.        Select                                                                  ;
  261.        //
  262.        // initialization
  263.        //
  264.        When ( parms.@heap$ = 1 )                                               ;
  265.          parms.@heap@  = %Alloc(parms.@heap#*16)                               ;
  266.          parms.heap@@  = parms.@heap@                                          ;
  267.        When ( parms.@heap$ <= parms.@heap# )                                   ;
  268.        //
  269.        // same as  parms.heap@@ = parms.@heap@ + (parms.@heap$-1)*#POINTERSIZE
  270.        //
  271.          parms.heap@@ += 16                                                    ;
  272.        Other                                                                   ;
  273.        //
  274.        // double allocated space
  275.        //
  276.          parms.@heap# *= 2                                                     ;
  277.          parms.@heap@  = %Realloc( parms.@heap@ : parms.@heap#*16 )            ;
  278.          parms.heap@@  = parms.@heap@ + (parms.@heap$-1)*16                    ;
  279.        EndSl                                                                   ;
  280.  
  281.        Return %Alloc(parms.heapSz)                                             ;
  282.        End-Proc                                                                ;
  283.       //--------------------------------------------------------------------------------------------------------------//
  284.        Dcl-Proc cp1402_dealloc                              Export             ;
  285.          Dcl-PI *n                                                             ;
  286.            parms            LikeDS(cp1402_t)                                   ;
  287.          End-PI                                                                ;
  288.  
  289.        Dcl-S  heap@         Pointer         Based(parms.heap@@)                ;
  290.        Dcl-S  $I            Uns(10)                                            ;
  291.  
  292.        parms.heap@@ = parms.@heap@                                             ;
  293.        For $I = 1 to parms.@heap$                                              ;
  294.          DeAlloc heap@                                                         ;
  295.          parms.heap@@ += 16                                                    ;
  296.        EndFor                                                                  ;
  297.        DeAlloc parms.@heap@                                                    ;
  298.  
  299.        Return                                                                  ;
  300.        End-Proc                                                                ;
  301. Program Source:
  302. RPG                                                      cpsrc.cp1402s
  303.       //--------------------------------------------------------------------------------------------------------------//
  304.       //                                                                                                              //
  305.       //                                                                                                              //
  306.       //                       Regular Expression Matching test program - match mailing address                       //
  307.       //                                                                                                              //
  308.       //                                                                                                              //
  309.       //--------------------------------------------------------------------------------------------------------------//
  310.        Ctl-Opt debug(*Yes) option(*SrcStmt:*NoDebugIO:*NoUnRef) main(cp1402r)
  311.                dftActGrp(*No) actGrp(*New)
  312.                bndDir('CP1400')                                                ;
  313.       //--------------------------------------------------------------------------------------------------------------//
  314.       //                                                                                                              //
  315.       // ... files ...                                                                                                //
  316.       //                                                                                                              //
  317.       //--------------------------------------------------------------------------------------------------------------//
  318.        Dcl-F  cp1400f       Disk            UsrOpn          Prefix(inp_)       ;
  319.        Dcl-F  qsysprt       Printer(132)    UsrOpn                             ;
  320.       //--------------------------------------------------------------------------------------------------------------//
  321.       //                                                                                                              //
  322.       // ... procedure interfaces ...                                                                                 //
  323.       //                                                                                                              //
  324.       //--------------------------------------------------------------------------------------------------------------//
  325.       //
  326.       // ... service program include files ...
  327.       //
  328.       /copy cpsrc,cp1400h
  329.       //
  330.       // ... dynamic data structure array management module include files
  331.       //
  332.       /copy cpsrc,cp1402h
  333.       //
  334.       // ... from the C run-time library ...
  335.       //
  336.        Dcl-PR memcmp        Int(10)         ExtProc('memcmp')                  ;
  337.          *n                 Pointer         Value                              ;
  338.          *n                 Pointer         Value                              ;
  339.          *n                 Uns(10)         Value                              ;
  340.        End-PR                                                                  ;
  341.  
  342.        Dcl-PR qsort                         ExtProc('qsort')                   ;
  343.          *n                 Pointer         Value                              ;
  344.          *n                 Uns(10)         Value                              ;
  345.          *n                 Uns(10)         Value                              ;
  346.          *n                 Pointer(*Proc)  Value                              ;
  347.        End-PR                                                                  ;
  348.       //--------------------------------------------------------------------------------------------------------------//
  349.       //                                                                                                              //
  350.       // ... standalone variables/constants ...                                                                       //
  351.       //                                                                                                              //
  352.       //--------------------------------------------------------------------------------------------------------------//
  353.  
  354.        Dcl-DS *n                                                               ;// a routine for each sort
  355.          *n                 Pointer(*Proc)  Inz(%PAddr('QSORTCOMP1'))          ;
  356.          *n                 Pointer(*Proc)  Inz(%PAddr('QSORTCOMP2'))          ;
  357.          @qsortcomp         Pointer(*Proc)  Dim(2)              Pos(1)         ;
  358.        End-DS                                                                  ;
  359.  
  360.        Dcl-DS addrCtl       LikeDS(cp1402_t)                                   ;// one control structure per array
  361.  
  362.        Dcl-S  addr@         Pointer         Based(addrCtl.heap@@)              ;// addrCtl.heap@@->addr@->addrRec
  363.        Dcl-DS addrRec       Qualified       Based(addr@)                       ;
  364.          mType              Uns(3)                                             ;
  365.          text               Like(inp_TEXT)                                     ;
  366.        End-DS                                                                  ;
  367.  
  368.        Dcl-S  @regexp@      Pointer         Dim(3)                             ;// an array of pointers
  369.  
  370.        Dcl-C  #POINTERSIZE                  %Len(addr@)                        ;// in case pointer size ever changes
  371.        Dcl-C  #ADDRECSIZE                   1024                               ;// initial size of array
  372.       //--------------------------------------------------------------------------------------------------------------//
  373.       //                                                                                                              //
  374.       // ... What can I say? I still use 'O' specs ...                                                                //
  375.       //                                                                                                              //
  376.       //--------------------------------------------------------------------------------------------------------------//
  377.      oqsysprt   e                        1
  378.      o                       addrRec.mType z
  379.      o                                              ' '
  380.      o                       addrRec.text
  381.       //--------------------------------------------------------------------------------------------------------------//
  382.       //                                                                                                              //
  383.       //                                                  Procedures                                                  //
  384.       //                                                                                                              //
  385.       //--------------------------------------------------------------------------------------------------------------//
  386.       // ... MainLine ...                                                                                             //
  387.       //--------------------------------------------------------------------------------------------------------------//
  388.        Dcl-Proc cp1402r                                                        ;
  389.  
  390.        init()                                                                  ;
  391.        DoW ( reader() )                                                        ;
  392.          process()                                                             ;
  393.        EndDo                                                                   ;
  394.        eoj()                                                                   ;
  395.  
  396.        Return                                                                  ;
  397.        End-Proc                                                                ;
  398.       //--------------------------------------------------------------------------------------------------------------//
  399.       // ... reader ...                                                                                               //
  400.       //--------------------------------------------------------------------------------------------------------------//
  401.        Dcl-Proc reader                                                         ;
  402.          Dcl-PI *n          Ind                             End-PI             ;
  403.  
  404.        Read cp1400f                                                            ;
  405.  
  406.        Return ( Not %Eof(cp1400f) )                                            ;
  407.        End-Proc                                                                ;
  408.       //--------------------------------------------------------------------------------------------------------------//
  409.       // ... process ...                                                                                              //
  410.       //--------------------------------------------------------------------------------------------------------------//
  411.        Dcl-Proc process                                                        ;
  412.  
  413.        addr@         = cp1402_alloc( addrCtl )                                 ;// addrRec is based upon addr@
  414.        addrRec.mType = getMatchType()                                          ;
  415.        addrRec.TEXT  = inp_TEXT                                                ;
  416.  
  417.        Return                                                                  ;
  418.        End-Proc                                                                ;
  419.       //--------------------------------------------------------------------------------------------------------------//
  420.       // ... get match Type ...                                                                                       //
  421.       //--------------------------------------------------------------------------------------------------------------//
  422.        Dcl-Proc getMatchType                                                   ;
  423.        Dcl-PI *n            Like(addrRec.mType)             End-PI             ;
  424.  
  425.        Dcl-S  mType         Like(addrRec.mType)             Inz(0)             ;
  426.  
  427.        DoU ( cp1400_process( @regexp@(mType) : inp_TEXT) )                     ;// will always eventually return true
  428.          mType += 1                                                            ;
  429.        EndDo                                                                   ;
  430.  
  431.        Return mType                                                            ;
  432.        End-Proc                                                                ;
  433.       //--------------------------------------------------------------------------------------------------------------//
  434.       // ... initialize ...                                                                                           //
  435.       //--------------------------------------------------------------------------------------------------------------//
  436.        Dcl-Proc init                                                           ;
  437.        Open cp1400f                                                            ;
  438.        //
  439.        // 1815 Brunswick Court, Houston, TX, 77008
  440.        //
  441.        @regexp@(1) = cp1400_load('^[0-9]\{1,\}'                                 //^1815\
  442.                                + ' [A-Za-z. ]*,'                                // Brunswick Court,\
  443.                                + ' [A-Za-z ]*,'                                 // Houston,\
  444.                                + ' [A-Z]\{2\},'                                 // TX,\
  445.                                + ' [0-9]\{5\}$')                               ;// 77008$
  446.        //
  447.        // 1815 Brunswick Court, Houston, TX, 77008-1242
  448.        //
  449.        @regexp@(2) = cp1400_load('^[0-9]\{1,\}'                                 //^1815/
  450.                                + ' [A-Za-z. ]*,'                                // Brunswick Court,/
  451.                                + ' [A-Za-z ]*,'                                 // Houston,/
  452.                                + ' [A-Z]\{2\},'                                 // TX,/
  453.                                + ' [0-9]\{5\}-[0-9]\{4\}$')                    ;// 77008-1234$
  454.        //
  455.        // catch-all - leaving this out will cause an index error in getMatchType()
  456.        //
  457.        @regexp@(3) = cp1400_load('^.*$')                                       ;
  458.  
  459.  
  460.        //
  461.        // initialization of dynamic data structure array @heap
  462.        //
  463.        addrCtl.@heap# = #ADDRECSIZE                                            ;// intial allocation
  464.        addrCtl.@heap$ = 0                                                      ;// number of entries
  465.        addrCtl.heapSz = %Len(addrRec)                                          ;// length of array element
  466.  
  467.        Return                                                                  ;
  468.        End-Proc                                                                ;
  469.       //--------------------------------------------------------------------------------------------------------------//
  470.       // ... end of job - print out reports and house-keeping ...                                                     //
  471.       //--------------------------------------------------------------------------------------------------------------//
  472.        Dcl-Proc eoj                                                            ;
  473.        Dcl-S  $I            Uns(10)                                            ;// Utility variable
  474.        Dcl-S  $J            Uns(10)                                            ;// Utility variable
  475.        Dcl-S  svText        Like(inp_TEXT)                                     ;// only print once
  476.        //
  477.        // ... print reports ...
  478.        //
  479.        For $I = 1 to %Elem(@qsortcomp)                                         ;
  480.          qsort( addrCtl.@heap@
  481.               : addrCtl.@heap$
  482.               : #POINTERSIZE
  483.               : @qsortcomp($I)
  484.               )                                                                ;
  485.          Open qsysprt                                                          ;
  486.          svTEXT = *Blanks                                                      ;
  487.          addrCtl.heap@@ = addrCtl.@heap@                                       ;
  488.          For $J = 1 to addrCtl.@heap$                                          ;
  489.            If ( addrRec.text <> svTEXT )                                       ;// print if not duplicate
  490.              Except                                                            ;
  491.              svTEXT = addrRec.text                                             ;
  492.            EndIf                                                               ;
  493.            addrCtl.heap@@ += #POINTERSIZE                                      ;// @heap@ + ($I-1)*#POINTERSIZE
  494.          EndFor                                                                ;
  495.          Close qsysprt                                                         ;
  496.        EndFor                                                                  ;
  497.  
  498.        Close cp1400f                                                           ;
  499.  
  500.        cp1402_dealloc( addrCtl )                                               ;
  501.  
  502.        For $I = 1 to %Elem(@regexp@)                                           ;
  503.          cp1400_cleanup( @regexp@($I) )                                        ;
  504.        EndFor                                                                  ;
  505.  
  506.        Return                                                                  ;
  507.        End-Proc                                                                ;
  508.       //--------------------------------------------------------------------------------------------------------------//
  509.       // ... comparison for qsort ...                                                                                 //
  510.       //--------------------------------------------------------------------------------------------------------------//
  511.        Dcl-Proc qsortComp1                                                     ;
  512.          Dcl-PI   *n        Int(10)                                            ;
  513.            ds1@@            Pointer         Value                              ;
  514.            ds2@@            Pointer         Value                              ;
  515.          End-PI                                                                ;
  516.  
  517.        Dcl-DS ds1           LikeDS(addrRec) Based(ds1@)                        ;
  518.        Dcl-DS ds2           LikeDS(addrRec) Based(ds2@)                        ;
  519.        Dcl-S  ds1@          Pointer         Based(ds1@@)                       ;
  520.        Dcl-S  ds2@          Pointer         Based(ds2@@)                       ;
  521.  
  522.        Select                                                                  ;
  523.        When ( ds1.TEXT   < ds2.TEXT   )                                        ;
  524.          Return -1                                                             ;
  525.        When ( ds1.TEXT   > ds2.TEXT   )                                        ;
  526.          Return  1                                                             ;
  527.        Other                                                                   ;
  528.          Return 0                                                              ;
  529.        EndSl                                                                   ;
  530.  
  531.        End-Proc                                                                ;
  532.       //--------------------------------------------------------------------------------------------------------------//
  533.        Dcl-Proc qsortComp2                                                     ;
  534.          Dcl-PI *n          Int(10)                                            ;
  535.            ds1@@            Pointer         Value                              ;
  536.            ds2@@            Pointer         Value                              ;
  537.          End-PI                                                                ;
  538.  
  539.        Dcl-S  ds1@          Pointer         Based(ds1@@)                       ;
  540.        Dcl-S  ds2@          Pointer         Based(ds2@@)                       ;
  541.  
  542.        Return  memcmp( ds1@ : ds2@ : addrCtl.heapSz )                          ;
  543.  
  544.        End-Proc                                                                ;
  545. CLLE                                                     cpsrc.cp1402c
  546.  PGM
  547.  
  548.        OVRPRTF    FILE(QSYSPRT) MAXRCDS(*NOMAX)
  549.        CALL       PGM(CP1402R)
  550.  
  551.  ENDPGM
  552. File Source:
  553. CLLE                                                     cpsrc.cp1400f
  554.       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  555.       *                                                                   *
  556.       *  regular expression (caching) - test data                         *
  557.       *                                                                   *
  558.       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  559.      A          R CP1400
  560.      A            TEXT         128A
  561.  
© 2004-2019 by midrange.com generated in 0.012s valid xhtml & css