midrange.com code scratchpad
Name:
WordWrap-RPG Version
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
09/19/2008 12:00:37 pm
IP:
Logged
Description:
The user was to lazy to give a description
Code:
  1.      H BNDDIR('QC2LE') DFTACTGRP(*NO)
  2.  
  3.      D regex_t         DS                  qualified  dim(1) align
  4.      D  re_nsub                      10U 0
  5.      D  re_comp                        *   inz(*NULL)
  6.      D  re_cflags                    10I 0
  7.      D  re_erroff                    10U 0
  8.      D  re_len                       10U 0
  9.      D  re_ucoll                     10I 0 Dim(2)
  10.      D  re_lsub                        *   Inz(*NULL)
  11.      D  lsub_ar                      10I 0 Dim(16)
  12.      D  esub_ar                      10I 0 Dim(16)
  13.      D  reserved1                      *   Inz(*NULL)
  14.      D  re_esub                        *   Inz(*NULL)
  15.      D  re_specchar                    *   Inz(*NULL)
  16.      D  re_phdl                        *   Inz(*NULL)
  17.      D  comp_spc                      1A   Dim(112)
  18.      D  re_map                        1A   Dim(256)
  19.      D  re_shift                      5I 0
  20.      D  re_dbcs                       5I 0
  21.  
  22.      D regmatch_t      DS                  occurs(maxEntry) align               start offset
  23.      D  rm_so                        10I 0
  24.      D  rm_ss                         5I 0
  25.      D  rm_eo                        10I 0                                      end offset
  26.      D  rm_es                         5I 0
  27.  
  28.      D regcomp         PR            10I 0 extproc('regcomp')
  29.      D   preg                          *   value
  30.      D   pattern                       *   value options(*string)
  31.      D   cflags                      10I 0 value
  32.  
  33.      D regexec         PR            10I 0 extproc('regexec')
  34.      D   preg                          *   value
  35.      D   string                        *   value options(*string)
  36.      D   nmatch                      10U 0 value
  37.      d   pmatch                        *   value
  38.      D   eflags                      10I 0 value
  39.  
  40.      D regerror        PR            10U 0 extproc('regerror')
  41.      D   errcode                     10I 0 value
  42.      D   preg                          *   value
  43.      D   errbuf                        *   value
  44.      D   errbuf_size                 10I 0 const
  45.  
  46.      D regfree         PR                  extproc('regfree')
  47.      D   preg                          *   value
  48.  
  49.      D REG_BASIC       C                   const(X'00')
  50.      D REG_EXTENDED    C                   const(X'01')
  51.      D REG_ICASE       C                   const(X'02')
  52.      D REG_ICASEX      C                   const(X'03')
  53.      D REG_NEWLINE     C                   const(X'04')
  54.      D REG_NOSUB       C                   const(X'08')
  55.      D REG_ALT_NL      C                   const(X'10')
  56.  
  57.  
  58.      D maxEntry        c                   const(10)
  59.      D preg            S               *
  60.      D pmatch          S               *
  61.      D string          S            256A
  62.      D len             S             10I 0
  63.      D rc              S             10I 0
  64.      D nmatch          S             10U 0 inz(maxEntry)
  65.      D buf             S            256A
  66.      D pattern         S             50A
  67.      D temp            s            100a   varying
  68.      D x               s             10i 0
  69.       /free
  70.  
  71.        *inlr = *on;
  72.  
  73.        string = 'This is a line of text 111111. T2his i2s al2so a2 lin2e' +
  74.          'will eventuallyrunoverats  string is longer than normal. Somwer' +
  75.          'some more text'+ x'0D25' + 'over at some point simple stri.'+
  76.          'This is the last sentence in the paragraph.';
  77.  
  78.        pattern = '(\S\S{40,}|.{1,40})(\s+|$)';
  79.  
  80.        %occur(regmatch_t) = 1;
  81.        preg = %addr(regex_t);
  82.        pmatch = %addr(regmatch_t);
  83.  
  84.        // Compile RE
  85.        rc = regcomp(preg: %trim(pattern): REG_ICASEX);
  86.        if rc <> 0;
  87.          regerror(rc: preg: %addr(buf): %size(buf));
  88.          temp = 'comp() failed with: ' + %str(%addr(buf));
  89.          return;
  90.        endif;
  91.  
  92.        // Execute RE
  93.        rc = regexec(preg: %trim(string): nmatch: pmatch: 0);
  94.        if rc <> 0;
  95.          regerror(rc: preg: %addr(buf): %size(buf));
  96.          regfree(preg);
  97.          temp = 'regexec() failed with: ' + %str(%addr(buf));
  98.          return;
  99.        endif;
  100.  
  101.        for x = 1 to nmatch;
  102.          %occur(regmatch_t) = x;
  103.  
  104.          // Done processing if these are negative
  105.          if rm_eo = -1 or rm_so = -1;
  106.            leave;
  107.          endif;
  108.  
  109.          len = rm_eo - rm_so;
  110.          rm_so = rm_so + 1;
  111.          temp = %subst(string: rm_so: len);
  112.        endfor;
  113.  
  114.        regfree(preg);
  115.  
  116.        return;
  117.       /END-FREE 
© 2004-2019 by midrange.com generated in 0.005s valid xhtml & css