./ ADD NAME=PCOBDEMO
       IDENTIFICATION DIVISION.
       PROGRAM-ID. 'PCOBDEMO'.
       AUTHOR. Ze'ev Atlas.
       DATE-WRITTEN. September 2012.
      *************************************************
      *           PCRE DEMONSTRATION PROGRAM          *
      *************************************************
      * This is a direct port to COBOL from pcredemo.c in the PCRE
      * package 8.31.  Port doen by Ze'ev Alas
      * This is a demonstration program to illustrate the most
      * straightforward ways of calling the PCRE regular expression
      * library from a C program. See the pcresample documentation for
      * a short discussion ("man pcresample" if you have the PCRE man
      * pages installed).
      *
      * Copyright (c) 2012 Ze'ev Atlas
      * Please refer to the LICENSE document to see all other
      * applicable copyrights.
      *
      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------
      * While the original UNIX/Windows program now supports the
      *testing of both the 8-bit and 16-bit PCRE libraries in a single
      *program, the z/OS COBOL (and C) versions support only 8 bit
      *EBCDIC.  Modules such as COMPLIE8 (originally pcre_compile.c)
      *in the library itself, are also specifically compiled for 8 bit
      *EBCDIC.  It does, however, make use of SUPPORT_PCRE8 to ensure
      *that it calls only supported library functions.

      *****************************************************************
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       Special-Names.
           SYSIN is Parms-Input.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
      *    SELECT INFILE ASSIGN TO SYSIN.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.

      *     FD  INFILE
      *         RECORDING MODE IS F
      *         BLOCK CONTAINS 0 RECORDS
      *         LABEL RECORDS ARE STANDARD.
      *     01  INPUT-RECORD.
      *         05  FILLER                PIC X(80).
       WORKING-STORAGE SECTION.

       COPY    pcre.

      * should be a multiple of 3 */

       01 display-comp              PIC -(10)9.
       01 RE                        USAGE POINTER VALUE NULL.
       01 re-i                      redefines re pic 9(9) comp.
      * pointer to pcre
       01 FILLER.
           05 pattern               PIC X(80).
           05 filler                PIC X VALUE X'00'.
       01 FILLER.
           05 subject               PIC X(80).
           05 filler                PIC X VALUE X'00'.
       01 find-all                  PIC S9(8) COMP.
       01 crlf-is-newline           PIC S9(8) COMP.
       01 subject-length            PIC S9(8) COMP.
       01 rc                        PIC S9(8) COMP.
       01 i                         PIC S9(8) COMP.
       01 j                         PIC S9(8) COMP.
       01  d                        PIC S9(9) BINARY.
       01  n                        PIC S9(8) COMP.
       01  filler                   redefines n.
           05 filler                pic xx.
           05 n-x                   pic xx.
       01  options                  pic s9(9) binary value 0.
       01  optint                   pic s9(9) binary value 0.
       01  optint-x                 redefines optint
                                    pic x(4).
       01  start-offset             pic s9(9) binary value 0.
       01  always-zero              pic s9(9) binary value zero.
       COPY PCREWS.

      *****************************************************************
       LINKAGE SECTION.
       01  PARM-BUFFER.
           05  PARM-LENGTH         pic S9(4)   comp.
           05  PARM-DATA           pic X(256).
       COPY PCREPCRE REPLACING ==:PREFIX:== BY ==LS==.
       copy pcrels.
      *****************************************************************
       PROCEDURE DIVISION USING PARM-BUFFER.

      *****************************************************************
      * First, sort out the input parameters. using command line in
      * z/OS batch JCL is pretty limited so instead we read sysin.
      * in this version of the demo I limit the input to two records
      * of the traditional 80 characters each.
      *---------------------------------------------------------------
      * There is only one possible option in the command line at the
      * moment, "-g" to request repeated matching to find
      * all occurrences, like Perl's /g option. We set the variable
      * find_all to a non-zero value if the -g option is present. Apart
      * from that, there must be exactly two arguments.
      *****************************************************************

           MOVE 0 TO find-all
           if  PARM-LENGTH = 2
               if PARM-DATA(1:2) = '-g'
                  MOVE 1 TO find-all
               end-if
           end-if
      * we require exactly two argument records, which are the pattern,
      * and the subject string. I assume both records are present.
      * Since z/OS records do not have NL in the end, nor do strings
      * have NULL character in the end, I will force null character
      * character after 80 characters.  However I also demonstrate
      * here the use of one of the pcrz function that converts a space
      * terminated string into a null terminated.
      * In this version I do not actually check whether I really have
      * two parm cards.
           ACCEPT PATTERN from Parms-Input
           ACCEPT SUBJECT from Parms-Input
           display
           "----+----1----+----2----+----3----+----4----+----5----+--"
           display pattern
           display subject
      *    call 'pcrz_space_to_null_term_str' using
           call 'ZSPC2NUL' using
                                by reference pattern
                                by value 80
           end-call
      * note the returning clause to get the length
      *    call 'pcrz_space_to_null_term_str' using
           call 'ZSPC2NUL' using
                                by reference subject
                                by value 80
                                returning subject-length
           end-call
      *****************************************************************
      * Now we are going to compile the regular expression pattern, and
      * handle and errors that are detected.
      *****************************************************************
      *     SET pcrews-erroffset-ptr to ADDRESS of offset
      *     SET pcrews-error-ptr to ADDRESS of orror
           SET pcrews-error-ptr to address of pcrews-error-str
           SET pcrews-pattern-ptr to address of pattern
      *    call 'COMPILE8' using by reference pattern
           call 'COMPILE8' using by value     pcrews-pattern-ptr
                BY VALUE 0
                BY reference pcrews-error-ptr
                BY reference pcrews-erroffset
                BY VALUE pcrews-null-ptr
                RETURNING RE
           end-call
      * the pattern */
      * default options */
      * for error message */
      * for error offset */
      * use default character tables */

      * Compilation failed: print the error message and exit

           if re = NULL
              move pcrews-erroffset to display-comp
              display "PCRE compilation failed at offset "
                      display-comp " " pcrews-error-str
              move 1 to return-code
              goback
           end-if
           SET ADDRESS OF LS-PCRE TO re

      *****************************************************************
      * If the compilation succeeded, we call PCRE again, in order to
      * do a pattern match against the subject string. This does just
      * ONE match. If further matching is needed, it will be done below
      *****************************************************************

           SET pcrews-subject-ptr to address of subject
           call 'PCREXEC8' using by value     re
                BY VALUE pcrews-null-ptr
      *         BY REFERENCE subject
                BY value     pcrews-subject-ptr
                BY value subject-length
                BY VALUE 0
                by value 0
                by reference pcrews-ovec
                by value pcrews-oveccount
                RETURNING rc
           end-call
      * the compiled pattern */
      * no extra data - we didn't study the pattern */
      * the subject string */
      * the length of the subject */
      * start at offset 0 in the subject */
      * default options */
      * output vector for substring information */
      * number of elements in the output vector */

      * Matching failed: handle error cases */

           if rc < 0
              evaluate rc
                 when PCRE-ERROR-NOMATCH
                      display "No match"
      * Handle other special cases if you like
                 when OTHER
                      move rc to display-comp
                      display "Matching error "  display-comp
              end-evaluate
              call 'pcre_free' using by value re
      * Release memory used for the compiled pattern */
              move 1 to return-code
              goback
           end-if

      * Match succeded */

           move pcrews-ovector(1) to display-comp
           display "Match succeeded at offset "  display-comp

      ****************************************************************
      * We have found the first match within the subject string. If
      * the output vector wasn't big enough, say so. Then output any
      * substrings that were captured.
      ****************************************************************

      * The output vector wasn't big enough */

           if rc = 0
              compute rc = pcrews-ovecCOUNT / 3
              compute i = rc - 1
              move i to display-comp
              display "pcrews-ovector only has room for " display-comp
                      " captured substrings"
           end-if

      * Show substrings stored in the output vector by number.
      * Obviously, in a real application you might want to do things
      * other than print them. */

           perform with test after
                   varying i from 1 by 1 until i = rc
              compute j = 2 * (i - 1) + 1
              compute pcrews-substring-start = pcrews-ovector (j)
              compute j = 2 * (i - 1) + 2
              compute pcrews-substring-length = pcrews-ovector (j) -
                      pcrews-substring-start
      * change offset to column number
              add 1 to pcrews-substring-start giving
                       pcrews-substring-start
              move i to display-comp
              display display-comp ":"
                      subject (pcrews-substring-start:
                               pcrews-substring-length)

           end-perform
      *****************************************************************
      * That concludes the basic part of this demonstration program. We
      * have compiled a pattern, and performed a single match. The code
      * that follows shows first how to access named substrings, and
      * then how to code for repeated matches on the same subject.
      *****************************************************************

      * See if there are any named substrings, and if so, show them by
      * name. First we have to extract the count of named parentheses
      * from the pattern.

      * change al s9(4) to s9(9) in pcre.h
           set pcrews-apiptr to address of pcrews-namecount
           call 'FULLINF8' using by value re
                                by value pcrews-null-ptr
                                by value PCRE-INFO-NAMECOUNT
                                by value pcrews-apiptr
           end-call
      * the compiled pattern */
      * no extra data - we didn't study the pattern */
      * number of named substrings */
      * where to put the answer */

           if pcrews-namecount not > 0
              display "No named substrings"
           else
              move pcrews-namecount to display-comp
              display "Named substrings " display-comp

      * Before we can access the substrings, we must extract the table
      * for translating names to numbers, and the size of each entry in
      * the table.

              set pcrews-apiptr to address of pcrews-name-table
              call 'FULLINF8' using by value re
                                   by value pcrews-null-ptr
                                   by value PCRE-INFO-NAMETABLE
                                   by value pcrews-apiptr
              end-call
      * the compiled pattern */
      * no extra data - we didn't study the pattern */
      * address of the table */
      * where to put the answer */

              set pcrews-apiptr to address of pcrews-name-entry-size
              call 'FULLINF8' using by value re
                                   by value pcrews-null-ptr
                                   by value PCRE-INFO-NAMEENTRYSIZE
                                   by value pcrews-apiptr
              end-call
      * the compiled pattern */
      * no extra data - we didn't study the pattern */
      * size of each entry in the table */
      * where to put the answer */

      * Now we can scan the table and, for each entry, print the
      * number, the name, and the substring itself. */

              set pcrews-tabptr to pcrews-name-table
              set address of pcrels-name-to-number-map to pcrews-tabptr
              perform with test after
                 varying i from 1 by 1 until i = pcrews-namecount
                 move zero to n
                 move pcrels-capturing-parenthesis-x
                      (PCRELS-LSINDEX)  to n-x
                 subtract 2 from pcrews-name-entry-size giving
                                 pcrews-name-entry-size-2
                 set pcrews-apiptr to address of pcrels-name-tab-name
                                      (PCRELS-LSINDEX)
      *          call 'pcrz_is_null_term_str' using by value
                 call 'ZISNLTRM' using by value
                                      pcrews-apiptr
                                 by value pcrews-name-entry-size-2
                                 returning pcrews-substring-length
                 end-call
                 display "name table: "
                            pcrels-name-tab-name
                            (PCRELS-LSINDEX)
                            (1:pcrews-substring-length)
                 compute j = 2 * (n - 1) + 1
                 compute pcrews-substring-start = pcrews-ovector (j)
                 compute j = 2 * (n - 1) + 2
                 compute pcrews-substring-length = pcrews-ovector (j) -
                         pcrews-substring-start
                 add 1 to pcrews-substring-start giving
                          pcrews-substring-start
                 move n to display-comp
                 display display-comp ":"
                 subject
                    (pcrews-substring-start:pcrews-substring-length)
                 set pcrews-tabptr to address of pcrels-next-tab-grp
      *          set pcrews-tabptr up by name-entry-size
                 set address of pcrels-name-to-number-map to
                                pcrews-tabptr
             end-perform
           end-if

      *****************************************************************
      * If the "-g" option was given on the command line, we want to
      * continue to search for additional matches in the subject
      * string, in a similar way to the /g option in Perl. This turns
      * out to be trickier than you might think because of the
      * possibility of matching an empty string. What happens is as
      * follows:
      *
      * If the previous match was NOT for an empty string, we can just
      * start the next match at the end of the previous one.
      *
      * If the previous match WAS for an empty string, we can't do
      * that, as it would lead to an infinite loop. Instead, a special
      * call of pcre_exec() is made with the PCRE_NOTEMPTY_ATSTART and
      * PCRE_ANCHORED flags set. The first of these tells PCRE that an
      * empty string at the start of the subject is not a valid match;
      * other possibilities must be tried. The second flag restricts
      * PCRE to one match attempt at the initial string position. If
      * this  succeeds, an alternative to the empty string match has
      * then found, and we can print it and proceed round the loop,
      * advancing by the length of whatever was found. If this match
      * does not succeed, we still stay in the loop, advancing by just
      * one character. In UTF-8 mode, which can be set by (*UTF8) in
      * the pattern, this may be more than one byte.
      *
      * However, there is a complication concerned with newlines. When
      * the newline convention is such that CRLF is a valid newline, we
      * must advance by two characters rather than one. The newline
      * convention can be set in the regex by (*CR), etc.; if not, we
      * must find the default.
      *****************************************************************

           if   find-all NOT = 1
      * Check for -g */
              call 'pcre_free' using by value re
      * Release the memory used for the compiled pattern */
              move 0 to return-code
              goback
      * Finish unless -g was given */
           end-if

      * Before running the loop, check for UTF-8 and whether CRLF is a
      * valid newline sequence. First, find the options with which the
      * regex was compiled; extract the UTF-8 state, and mask off all
      * but the newline options. */

           set pcrews-apiptr to address of pcrews-option-bits
           call 'FULLINF8' using by value re
                                by value pcrews-null-ptr
                                by value PCRE-INFO-OPTIONS
                                by value pcrews-apiptr
           end-call
           move pcrews-option-bits to display-comp
           display "OPTION BITS IS: " display-comp
      *    utf8 = option_bits & PCRE_UTF8;
      *    option_bits &= PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|
      *                   PCRE_NEWLINE_CRLF|
      *                   PCRE_NEWLINE_ANY|PCRE_NEWLINE_ANYCRLF;
      * In this EBCDIC z/OS platform it should be ignored as it is
      * EBCDIC and not UTF8
      *
      * If no newline options were set, find the default newline
      * convention from the build configuration. */

      * ZA: Run this for compatibility with the C.  There is no use
      * for newline in COBOL
           if pcrews-option-bits = 0
              set pcrews-apiptr to address of d
              call 'CONFIG8' using by value PCRE-CONFIG-NEWLINE
                                by value pcrews-apiptr
              end-call
              move d to display-comp
              display "NEWLINE IS: " display-comp
      * Note that these values are always the ASCII ones, even in
      * EBCDIC environments. CR = 13, NL = 10. */
      * ZA: The comment above is not entirely true. The newline
      * would be as it is defined in config.h. in the z/OS port
      * it is defined as x'15' (=21):
      * #define NEWLINE 21
              evaluate d
                 when 13
                    move  PCRE-NEWLINE-CR      to pcrews-option-bits-x
                 when 10
                    move  PCRE-NEWLINE-LF      to pcrews-option-bits-x
      * CRLF = x'0d0a' = 3338
                 when 3338
                    move  PCRE-NEWLINE-CRLF    to pcrews-option-bits-x
                 when -2
                    move  PCRE-NEWLINE-ANYCRLF to pcrews-option-bits-x
                 when -2
                    move  PCRE-NEWLINE-ANY     to pcrews-option-bits-x
                 when OTHER
                    move        0              to pcrews-option-bits
              end-evaluate
           end-if

      * See if CRLF is a valid newline sequence. */

           if   pcrews-option-bits-x = PCRE-NEWLINE-ANY or
                pcrews-option-bits-x = PCRE-NEWLINE-CRLF or
                pcrews-option-bits-x = PCRE-NEWLINE-ANYCRLF
                move 1 to crlf-is-newline
           end-if

      * Loop for second and subsequent matches */
           perform until  always-zero  NOT = 0
              move zero to options
      * Normally no options */
              move pcrews-ovector (2) to start-offset
      * Start at end of previous match

      * If the previous match was for an empty string, we are finished
      * if we are at the end of the subject. Otherwise, arrange to run
      * another match at the same point to see if a non-empty match can
      * be found. */

              compute j = pcrews-ovector(1) + 1
      *       if pcrews-ovector(1) = pcrews-ovector (2)
              if pcrews-ovector(1) = pcrews-ovector (2)
                 if pcrews-ovector(1) = subject-length
      *             next sentence
                    go to after-perform
                 end-if
                 move 0 to options
                 move PCRE-NOTEMPTY-ATSTART to optint-x
                 add optint to options giving options
                 move PCRE-ANCHORED to optint-x
                 add optint to options giving options
              end-if

      * Run the next matching operation */

              call 'PCREXEC8' using by value re
                       BY VALUE pcrews-null-ptr
                       BY REFERENCE subject
                       BY value subject-length
                       BY VALUE start-offset
                       by value options
                       by reference pcrews-ovec
                       by value pcrews-oveccount
                       RETURNING rc
              end-call
      * the compiled pattern */
      * no extra data - we didn't study the pattern */
      * the subject string */
      * the length of the subject */
      * starting offset in the subject */
      * options */
      * output vector for substring information */
      * number of elements in the output vector */

      * This time, a result of NOMATCH isn't an error. If the value
      * in "options" is zero, it just means we have found all possible
      * matches, so the loop ends. Otherwise, it means we have failed
      * to find a non-empty-string match at a point where there was a
      * previous empty-string match. In this case, we do what Perl
      * does: advance the matching position by one character, and
      * continue. We do this by setting the "end of previous match"
      * offset, because that is picked up at the top of the loop as
      * the point at which to start again.

      * There are two complications: (a) When CRLF is a valid newline
      * sequence, and the current position is just before it, advance
      * by an extra byte. (b) Otherwise we must ensure that we skip an
      * entire UTF-8 character if we are in UTF-8 mode. */

              if rc = PCRE-ERROR-NOMATCH
                 if options = 0
      *             next sentence
                    go to after-perform
      * All matches found */
                 end-if
                 compute pcrews-ovector(2) = start-offset + 1
      * Advance one byte */
      * If CRLF is newline & we are at CRLF, */
      * ZA: This cannot happen in z/OS COBOL
      *          if  crlf-is-newline = 1 and
      * Advance by one more. Otherwise, ensure we advance a whole
      * UTF-8 character. */
      *              start-offset < subject-length - 1 and
      *              subject (start-offset + 1) = '\r' and
      *              subject (start-offset + 2) = '\n'
      *              add 1 to ovector(2)
      *          else if (utf8)
      * ZA: This also cannot happen in z/OS COBOL
      *                  perform until ovector (2)
      *                     NOT < subject-length
      *                     if ((subject[ovector[1]] & 0xc0) NOT =
      *                        x'00' then  break
      *                     add 1 to ovector(2)
      *                  end-perform
      *               end-if
      *          continue
      * Go round the loop again */
              else

      * Other matching errors are not recoverable. */

              if rc < 0
                 move rc to display-comp
                 display "Matching error "  display-comp
                 call 'pcre_free' using by value re
      * Release memory used for the compiled pattern */
                 move 1 to return-code
                 goback
              end-if

      * Match succeded */

              display " "
              move pcrews-ovector(1) to display-comp
              display "Match succeeded again at offset "
                      display-comp

      * The match succeeded, but the output vector wasn't big
      * enough. */

              if rc = 0
                 compute rc = pcrews-ovecCOUNT / 3
                 compute i = rc - 1
                 move i to display-comp
                 display
                 "ovector only has room for " display-comp
                        " captured substrings"
              end-if

      * As before, show substrings stored in the output vector by
      * number, and then also any named substrings. */

              perform with test after
                      varying i from 1 by 1 until i = rc
                 compute j = 2 * (i - 1) + 1
                 compute pcrews-substring-start =
                         pcrews-ovector (j)
                 compute j = 2 * (i - 1) + 2
                 compute pcrews-substring-length =
                         pcrews-ovector (j) -
                         pcrews-substring-start
      * change offset to column number
                 add 1 to pcrews-substring-start giving
                          pcrews-substring-start
                 move i to display-comp
                 display display-comp ":"
                         subject (pcrews-substring-start:
                                  pcrews-substring-length)
              end-perform

              if pcrews-namecount <= 0
                 display "No named substringsn"
              else
                 set pcrews-tabptr to pcrews-name-table
                 set address of pcrels-name-to-number-map to
                     pcrews-tabptr
                 display "Named substrings"
                 set PCRELS-LSINDEX to 1
                 perform varying i from 1 by 1 until i >
                         pcrews-namecount
                    move zero to n
                    move pcrels-capturing-parenthesis-x
                         (PCRELS-LSINDEX)  to n-x
                    subtract 2 from pcrews-name-entry-size giving
                                    pcrews-name-entry-size-2
                    set pcrews-apiptr to address of
                                      pcrels-name-tab-name
                                      (PCRELS-LSINDEX)
      *             call 'pcrz_is_null_term_str' using by value
                    call 'ZISNLTRM' using by value
                                         pcrews-apiptr
                                    by value pcrews-name-entry-size-2
                                    returning pcrews-substring-length
                    end-call
                    display "name table: "
                               pcrels-name-tab-name
                               (PCRELS-LSINDEX)
                               (1:pcrews-substring-length)
                    compute j = 2 * (n - 1) + 1
                    compute pcrews-substring-start = pcrews-ovector (j)
                    compute j = 2 * (n - 1) + 2
                    compute pcrews-substring-length = pcrews-ovector (j)
                            - pcrews-substring-start
                    add 1 to pcrews-substring-start giving
                             pcrews-substring-start
                    move n to display-comp
                    display display-comp ":"
                    subject
                       (pcrews-substring-start:pcrews-substring-length)
      *             set pcrews-tabptr to address of pcrels-next-tab-grp
                    set PCRELS-LSINDEX up by 1
                    set pcrews-tabptr to address of
                        pcrels-NAME-TAB-GRP (pcreLs-lsindex)
      *          set pcrews-tabptr up by name-entry-size
                    set address of pcrels-name-to-number-map to
                                   pcrews-tabptr
                 end-perform
              end-if
              end-if
           end-perform.
      * End of loop to find second and subsequent matches */
      * ZA: note that the period is here for a reason.
       after-perform.

           display " "
      *    call 'pcre_free' using by value re
      * Release memory used for the compiled pattern */
           move 0 to return-code
           goback
           .
      * End of pcredemo.c */
        end-program.
./ ADD NAME=PCRE
      **************************************************
      *       Perl-Compatible Regular Expressions      *
      **************************************************

      * This is a port of the public header (pcre.h) file for the PCRE
      * library to COBOL.  It is to be COPIED by applications that call
      * the PCRE functions.
      * Version 0.1
      * Contributed by:   Ze'ev Atlas  2012.
      * Copyright (c) 2012, Ze'ev Atlas.
      * All rights reserved.

      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------

      * The current PCRE version information.

       01 PCRE-MAJOR       PIC S9(9) COMP VALUE  8.
       01 PCRE-MINOR       PIC S9(9) COMP VALUE  31.
       01 PCRE-PRERELEASE  PIC X VALUE  ' '.
       01 PCRE-DATE        PIC X(10) VALUE  '2012-07-06'.

      * Options. Some are compile-time only, some are run-time only,
      * and some are both, so we keep them all distinct. However,
      * almost all the bits in the options word are now used. In the
      * long run, we may have to re-use some of the compile-time only
      * bits for runtime options, or vice versa. In the comments below,
      * "compile", "exec", and "DFA exec" mean that the option is
      * permitted to be set for those functions; "used in" means that
      * an option may be set only for compile, but is subsequently
      * referenced in exec and/or DFA exec. Any of the compile-time
      * options may be inspected during studying (and therefore JIT
      * compiling).

      * Compile */
      * Compile */
      * Compile */
      * Compile */
      * Compile, exec, DFA exec */
      * Compile, used in exec, DFA exec */
      * Compile */
      * Exec, DFA exec */
      * Exec, DFA exec */
      * Compile */
      * Exec, DFA exec */
       01 PCRE-CASELESS       PIC X(4) VALUE    x'00000001'.
       01 PCRE-MULTILINE      PIC X(4) VALUE    x'00000002'.
       01 PCRE-DOTALL         PIC X(4) VALUE    x'00000004'.
       01 PCRE-EXTENDED       PIC X(4) VALUE    x'00000008'.
       01 PCRE-ANCHORED       PIC X(4) VALUE    x'00000010'.
       01 PCRE-DOLLAR-ENDONLY PIC X(4) VALUE    x'00000020'.
       01 PCRE-EXTRA          PIC X(4) VALUE    x'00000040'.
       01 PCRE-NOTBOL         PIC X(4) VALUE    x'00000080'.
       01 PCRE-NOTEOL         PIC X(4) VALUE    x'00000100'.
       01 PCRE-UNGREEDY       PIC X(4) VALUE    x'00000200'.
       01 PCRE-NOTEMPTY       PIC X(4) VALUE    x'00000400'.
      * The next two are also used in exec and DFA exec
      * Compile (same as PCRE_UTF16) */
      * Compile (same as PCRE_UTF8) */
       01 PCRE-UTF8            PIC X(4) VALUE   x'00000800'.
       01 PCRE-UTF16           PIC X(4) VALUE   x'00000800'.
      * Compile */
        01 PCRE-NO-AUTO-CAPTURE PIC X(4) VALUE   x'00001000'.
      * The next two are also used in exec and DFA exec */
      * Compile (same as PCRE_NO_UTF16_CHECK) */
      * Compile (same as PCRE_NO_UTF8_CHECK) */
       01 PCRE-NO-UTF8-CHECK     PIC X(4) VALUE x'00002000'.
       01 PCRE-NO-UTF16-CHECK    PIC X(4) VALUE x'00002000'.
      * Compile */
      * Exec, DFA exec */
      * Backwards compatible synonym */
      * DFA exec */
      * DFA exec */
      * Compile, used in exec, DFA exec */
      * Compile */
      * Compile, exec, DFA exec */
      * Compile, exec, DFA exec */
      * Compile, exec, DFA exec */
      * Compile, exec, DFA exec */
      * Compile, exec, DFA exec */
      * Compile, exec, DFA exec */
      * Compile, exec, DFA exec */
      * Compile, used in exec */
      * Compile, exec, DFA exec */
      * Synonym */
      * Exec, DFA exec */
      * Exec, DFA exec */
      * Compile, used in exec, DFA exec */
       01 PCRE-AUTO-CALLOUT      PIC X(4) VALUE x'00004000'.
       01 PCRE-PARTIAL-SOFT      PIC X(4) VALUE x'00008000'.
       01 PCRE-PARTIAL           PIC X(4) VALUE x'00008000'.
       01 PCRE-DFA-SHORTEST      PIC X(4) VALUE x'00010000'.
       01 PCRE-DFA-RESTART       PIC X(4) VALUE x'00020000'.
       01 PCRE-FIRSTLINE         PIC X(4) VALUE x'00040000'.
       01 PCRE-DUPNAMES          PIC X(4) VALUE x'00080000'.
       01 PCRE-NEWLINE-CR        PIC X(4) VALUE x'00100000'.
       01 PCRE-NEWLINE-LF        PIC X(4) VALUE x'00200000'.
       01 PCRE-NEWLINE-CRLF      PIC X(4) VALUE x'00300000'.
       01 PCRE-NEWLINE-ANY       PIC X(4) VALUE x'00400000'.
       01 PCRE-NEWLINE-ANYCRLF   PIC X(4) VALUE x'00500000'.
       01 PCRE-BSR-ANYCRLF       PIC X(4) VALUE x'00800000'.
       01 PCRE-BSR-UNICODE       PIC X(4) VALUE x'01000000'.
       01 PCRE-JAVASCRIPT-COMPAT PIC X(4) VALUE x'02000000'.
       01 PCRE-NO-START-OPTIMIZE PIC X(4) VALUE x'04000000'.
       01 PCRE-NO-START-OPTIMISE PIC X(4) VALUE x'04000000'.
       01 PCRE-PARTIAL-HARD      PIC X(4) VALUE x'08000000'.
       01 PCRE-NOTEMPTY-ATSTART  PIC X(4) VALUE x'10000000'.
       01 PCRE-UCP               PIC X(4) VALUE x'20000000'.

       01  PCRE-COB-ERROR-CODES.
      * Exec-time and get/set-time error codes */

           05 PCRE-ERROR-NOMATCH          PIC s9(9) COMP VALUE -1.
           05 PCRE-ERROR-NULL             PIC s9(9) COMP VALUE -2.
           05 PCRE-ERROR-BADOPTION        PIC s9(9) COMP VALUE -3.
           05 PCRE-ERROR-BADMAGIC         PIC s9(9) COMP VALUE -4.
           05 PCRE-ERROR-UNKNOWN-OPCODE   PIC s9(9) COMP VALUE -5.
           05 PCRE-ERROR-UNKNOWN-NODE     PIC s9(9) COMP VALUE -5.
      * For backward compatibility */
           05 PCRE-ERROR-NOMEMORY         PIC s9(9) COMP VALUE -6.
           05 PCRE-ERROR-NOSUBSTRING      PIC s9(9) COMP VALUE -7.
           05 PCRE-ERROR-MATCHLIMIT       PIC s9(9) COMP VALUE -8.
           05 PCRE-ERROR-CALLOUT          PIC s9(9) COMP VALUE -9.
      * Never used by PCRE itself */
           05 PCRE-ERROR-BADUTF8         PIC s9(9) COMP VALUE -10.
      * Same for 8/16 */
           05 PCRE-ERROR-BADUTF16        PIC s9(9) COMP VALUE -10.
      * Same for 8/16 */
           05 PCRE-ERROR-BADUTF8-OFFSET  PIC s9(9) COMP VALUE -11.
      * Same for 8/16 */
           05 PCRE-ERROR-BADUTF16-OFFSET PIC s9(9) COMP VALUE -11.
      * Same for 8/16 */
           05 PCRE-ERROR-PARTIAL         PIC s9(9) COMP VALUE -12.
           05 PCRE-ERROR-BADPARTIAL      PIC s9(9) COMP VALUE -13.
           05 PCRE-ERROR-INTERNAL        PIC s9(9) COMP VALUE -14.
           05 PCRE-ERROR-BADCOUNT        PIC s9(9) COMP VALUE -15.
           05 PCRE-ERROR-DFA-UITEM       PIC s9(9) COMP VALUE -16.
           05 PCRE-ERROR-DFA-UCOND       PIC s9(9) COMP VALUE -17.
           05 PCRE-ERROR-DFA-UMLIMIT     PIC s9(9) COMP VALUE -18.
           05 PCRE-ERROR-DFA-WSSIZE      PIC s9(9) COMP VALUE -19.
           05 PCRE-ERROR-DFA-RECURSE     PIC s9(9) COMP VALUE -20.
           05 PCRE-ERROR-RECURSIONLIMIT  PIC s9(9) COMP VALUE -21.
           05 PCRE-ERROR-NULLWSLIMIT     PIC s9(9) COMP VALUE -22.
      * No longer actually used */
           05 PCRE-ERROR-BADNEWLINE      PIC s9(9) COMP VALUE -23.
           05 PCRE-ERROR-BADOFFSET       PIC s9(9) COMP VALUE -24.
           05 PCRE-ERROR-SHORTUTF8       PIC s9(9) COMP VALUE -25.
           05 PCRE-ERROR-SHORTUTF16      PIC s9(9) COMP VALUE -25.
      * Same for 8/16 */
           05 PCRE-ERROR-RECURSELOOP     PIC s9(9) COMP VALUE -26.
           05 PCRE-ERROR-JIT-STACKLIMIT  PIC s9(9) COMP VALUE -27.
           05 PCRE-ERROR-BADMODE         PIC s9(9) COMP VALUE -28.
           05 PCRE-ERROR-BADENDIANNESS   PIC s9(9) COMP VALUE -29.
           05 PCRE-ERROR-DFA-BADRESTART  PIC s9(9) COMP VALUE -30.

      * Specific error codes for UTF-8 validity checks */

           05 PCRE-UTF8-ERR0             PIC S9(9) COMP VALUE 0.
           05 PCRE-UTF8-ERR1             PIC S9(9) COMP VALUE 1.
           05 PCRE-UTF8-ERR2             PIC S9(9) COMP VALUE 2.
           05 PCRE-UTF8-ERR3             PIC S9(9) COMP VALUE 3.
           05 PCRE-UTF8-ERR4             PIC S9(9) COMP VALUE 4.
           05 PCRE-UTF8-ERR5             PIC S9(9) COMP VALUE 5.
           05 PCRE-UTF8-ERR6             PIC S9(9) COMP VALUE 6.
           05 PCRE-UTF8-ERR7             PIC S9(9) COMP VALUE 7.
           05 PCRE-UTF8-ERR8             PIC S9(9) COMP VALUE 8.
           05 PCRE-UTF8-ERR9             PIC S9(9) COMP VALUE 9.
           05 PCRE-UTF8-ERR10            PIC S9(9) COMP VALUE 10.
           05 PCRE-UTF8-ERR11            PIC S9(9) COMP VALUE 11.
           05 PCRE-UTF8-ERR12            PIC S9(9) COMP VALUE 12.
           05 PCRE-UTF8-ERR13            PIC S9(9) COMP VALUE 13.
           05 PCRE-UTF8-ERR14            PIC S9(9) COMP VALUE 14.
           05 PCRE-UTF8-ERR15            PIC S9(9) COMP VALUE 15.
           05 PCRE-UTF8-ERR16            PIC S9(9) COMP VALUE 16.
           05 PCRE-UTF8-ERR17            PIC S9(9) COMP VALUE 17.
           05 PCRE-UTF8-ERR18            PIC S9(9) COMP VALUE 18.
           05 PCRE-UTF8-ERR19            PIC S9(9) COMP VALUE 19.
           05 PCRE-UTF8-ERR20            PIC S9(9) COMP VALUE 20.
           05 PCRE-UTF8-ERR21            PIC S9(9) COMP VALUE 21.

      * Specific error codes for UTF-16 validity checks */

           05 PCRE-UTF16-ERR0            PIC S9(9) COMP VALUE 0.
           05 PCRE-UTF16-ERR1            PIC S9(9) COMP VALUE 1.
           05 PCRE-UTF16-ERR2            PIC S9(9) COMP VALUE 2.
           05 PCRE-UTF16-ERR3            PIC S9(9) COMP VALUE 3.
           05 PCRE-UTF16-ERR4            PIC S9(9) COMP VALUE 4.

       01  PCRE-COB-REQUEST-TYPES.
      * Request types for pcre-fullinfo()

           05 PCRE-INFO-OPTIONS           PIC S9(9) COMP VALUE 0.
           05 PCRE-INFO-SIZE              PIC S9(9) COMP VALUE 1.
           05 PCRE-INFO-CAPTURECOUNT      PIC S9(9) COMP VALUE 2.
           05 PCRE-INFO-BACKREFMAX        PIC S9(9) COMP VALUE 3.
           05 PCRE-INFO-FIRSTBYTE         PIC S9(9) COMP VALUE 4.
           05 PCRE-INFO-FIRSTCHAR         PIC S9(9) COMP VALUE 4.
      * For backwards compatibility
           05 PCRE-INFO-FIRSTTABLE        PIC S9(9) COMP VALUE 5.
           05 PCRE-INFO-LASTLITERAL       PIC S9(9) COMP VALUE 6.
           05 PCRE-INFO-NAMEENTRYSIZE     PIC S9(9) COMP VALUE 7.
           05 PCRE-INFO-NAMECOUNT         PIC S9(9) COMP VALUE 8.
           05 PCRE-INFO-NAMETABLE         PIC S9(9) COMP VALUE 9.
           05 PCRE-INFO-STUDYSIZE         PIC S9(9) COMP VALUE 10.
           05 PCRE-INFO-DEFAULT-TABLES    PIC S9(9) COMP VALUE 11.
           05 PCRE-INFO-OKPARTIAL         PIC S9(9) COMP VALUE 12.
           05 PCRE-INFO-JCHANGED          PIC S9(9) COMP VALUE 13.
           05 PCRE-INFO-HASCRORLF         PIC S9(9) COMP VALUE 14.
           05 PCRE-INFO-MINLENGTH         PIC S9(9) COMP VALUE 15.
           05 PCRE-INFO-JIT               PIC S9(9) COMP VALUE 16.
           05 PCRE-INFO-JITSIZE           PIC S9(9) COMP VALUE 17.
           05 PCRE-INFO-MAXLOOKBEHIND     PIC S9(9) COMP VALUE 18.

      * Request types for pcre-config(). Do not re-arrange, in
      * order to remain compatible.

           05 PCRE-CONFIG-UTF8                  PIC S9(9) COMP VALUE 0.
           05 PCRE-CONFIG-NEWLINE               PIC S9(9) COMP VALUE 1.
           05 PCRE-CONFIG-LINK-SIZE             PIC S9(9) COMP VALUE 2.
           05 PCRE-CONFIG-POSIX-MALLOC-THRES
                                              PIC S9(9) COMP VALUE 3.
           05 PCRE-CONFIG-MATCH-LIMIT           PIC S9(9) COMP VALUE 4.
           05 PCRE-CONFIG-STACKRECURSE          PIC S9(9) COMP VALUE 5.
           05 PCRE-CONFIG-UNICODE-PROPERTIES    PIC S9(9) COMP VALUE 6.
           05 PCRE-CONFIG-MATCH-LIMIT-RECURS    PIC S9(9) COMP VALUE 7.
           05 PCRE-CONFIG-BSR                   PIC S9(9) COMP VALUE 8.
           05 PCRE-CONFIG-JIT                   PIC S9(9) COMP VALUE 9.
           05 PCRE-CONFIG-UTF16                 PIC S9(9) COMP VALUE 10.
           05 PCRE-CONFIG-JITTARGET             PIC S9(9) COMP VALUE 11.

      * Request types for pcre-study(). Do not re-arrange, in order
      * to remain compatible.

           05 PCRE-STUDY-JIT-COMPILE          PIC x(2) value x'0001'.
           05 PCRE-STUDY-JIT-PARTIAL-SOFT-C
                                            PIC x(2) value x'0002'.
           05 PCRE-STUDY-JIT-PARTIAL-HARD-C
                                            PIC x(2) value x'0004'.

      * Bit flags for the pcre[16]-extra structure. Do not re-arrange
      * or redefine these bits, just add new ones on the end, in order
      * to remain compatible.

           05 PCRE-EXTRA-STUDY-DATA            PIC x(2) value x'0001'.
           05 PCRE-EXTRA-MATCH-LIMIT           PIC x(2) value x'0002'.
           05 PCRE-EXTRA-CALLOUT-DATA          PIC x(2) value x'0004'.
           05 PCRE-EXTRA-TABLES                PIC x(2) value x'0008'.
           05 PCRE-EXTRA-MATCH-LIMIT-RECURS    PIC x(2) value x'0010'.
           05 PCRE-EXTRA-MARK                  PIC x(2) value x'0020'.
           05 PCRE-EXTRA-EXECUTABLE-JIT        PIC x(2) value x'0040'.

      * Types *
      *  typedef unsigned char pcre_uint8 => X.
      *  typedef unsigned int pcre_uint32 => 9(9) BINARY.
      *  typedef int pcre_int32 => S9(9) Binary.
      *  typedef unsigned short pcre_uint16 => 9(4) BINARY.
      *  typedef short pcre_int16 => S9(4) BINARY.

      * When PCRE is compiled as a C++ library, the subject pointer
      * type can be replaced with a custom type. For conventional use,
      * the public interface is a const char *.
       01 PCRE-SPTR                            USAGE POINTER.

      * COBOL COPYBOOK DOES NOT CONTAIN FUNCTION DEFINITIONS
      * structure types delegated to specific copybooks
./ ADD NAME=PCRECALL
      * This is a partial port of the public header (pcre.h) file for
      * the PCRE library to COBOL.  It is to be COPIED by applications
      * that call the PCRE functions.
      * Version 0.1
      * Contributed by:   Ze'ev Atlas  2012.
      * Copyright (c) 2012, Ze'ev Atlas.
      * All rights reserved.

      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------
      * The structure for passing out data via the
      * pcre_callout_function. We use a structure so that new fields
      * can be added on the end in future versions, without changing
      * the API of the function, thereby allowing old clients to work
      * without modification.
       01 pcre-callout-block.
           05 :PREFIX:-version;          PIC S9(4) BINARY.
      * Identifies version of block
      * ------------------------ Version 0 -------------------------- *
           05 :PREFIX:-callout-number    PIC S9(4) BINARY.
      * Number compiled into pattern
           05 :PREFIX:-offset-vector     USAGE POINTER.
      * int * The offset vector
           05 :PREFIX:-subject           USAGE POINTER.
      * PCRE-SPTR The subject being matched
           05 :PREFIX:-subject-length;   PIC S9(4) BINARY.
      * The length of the subject
           05 :PREFIX:-start-match;      PIC S9(4) BINARY.
      * Offset to start of this match attempt
           05 :PREFIX:-current-position  PIC S9(4) BINARY.
      * Where we currently are in the subject
           05 :PREFIX:-capture-top       PIC S9(4) BINARY.
      * Max current capture
           05 :PREFIX:-capture-last      PIC S9(4) BINARY.
      * Most recently closed capture
           05 :PREFIX:-callout-data      USAGE POINTER.
      * void * Data passed in with the call
      * ------------------- Added for Version 1 --------------------- *
           05 :PREFIX:-pattern-position  PIC S9(4) BINARY.
      * Offset to next item in the pattern
           05 :PREFIX:-next-item-length  PIC S9(4) BINARY.
      * Length of next item in the pattern
      * ------------------- Added for Version 2 --------------------- *
           05 :PREFIX:-mark              USAGE POINTER.
      * const unsigned char * Pointer to current mark or NULL
      * ------------------------------------------------------------- *
./ ADD NAME=PCRELS
      * this is a description of the linkage section structure for
      * pattern name table
      *
      * Copyright (c) 2012 Ze'ev Atlas
      * Please refer to the LICENSE document to see all other
      * applicable copyrights.
      *
      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------
      * While the original UNIX/Windows program now supports the
      *testing of both the 8-bit and 16-bit PCRE libraries in a single
      *program, the z/OS COBOL (and C) versions support only 8 bit
      *EBCDIC.  Modules such as COMPLIE8 (originally pcre_compile.c)
      *in the library itself, are also specifically compiled for 8 bit
      *EBCDIC.  It does, however, make use of SUPPORT_PCRE8 to ensure
      *that it calls only supported library functions.

      *****************************************************************
       01 PCRELS-NAME-TO-NUMBER-MAP.
           05 PCRELS-NAME-TAB-GRP OCCURS 2 INDEXED BY PCRELS-LSINDEX.
              10 PCRELS-CAPTURING-PARENTHESIS-X PIC XX.
              10 PCRELS-CAPTURING-PARENTHESIS   REDEFINES
                 PCRELS-CAPTURING-PARENTHESIS-X PIC S9(4) COMP.
              10 PCRELS-NAME-TAB-NAME.
                 15 FILLER PIC X
                           OCCURS 1 TO 2046
                           DEPENDING ON PCREWS-NAME-ENTRY-SIZE-2.
           05 PCRELS-NEXT-TAB-GRP PIC X.
./ ADD NAME=PCREPCRE
      * This is a partial port of the public header (pcre.h) file for
      * the PCRE library to COBOL.  It is to be COPIED by applications
      * that call the PCRE functions.
      * Version 0.1
      * Contributed by:   Ze'ev Atlas  2012.
      * Copyright (c) 2012, Ze'ev Atlas.
      * All rights reserved.

      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------
       01  :PREFIX:-PCRE.
           05 :PREFIX:-magic-number          PIC 9(9) BINARY.
           05 :PREFIX:-size                  PIC 9(9) BINARY.
      * Total that was malloced
           05 :PREFIX:-options               PIC 9(9) BINARY.
      * Public options
           05 :PREFIX:-flags                 PIC 9(4) BINARY.
      * Private flags
           05 :PREFIX:-max-lookbehind        PIC 9(4) BINARY.
      * Longest lookbehind (characters)
           05 :PREFIX:-top-bracket           PIC 9(4) BINARY.
      * Highest numbered group
           05 :PREFIX:-top-backref           PIC 9(4) BINARY.
      * Highest numbered back reference
           05 :PREFIX:-first-char            PIC 9(4) BINARY.
      * Starting character
           05 :PREFIX:-req-char              PIC 9(4) BINARY.
      * This character must be seen
           05 :PREFIX:-name-table-offset     PIC 9(4) BINARY.
      * Offset to name table that follows
           05 :PREFIX:-name-entry-size       PIC 9(4) BINARY.
      * Size of any name items
           05 :PREFIX:-name-count            PIC 9(4) BINARY.
      * Number of name items
           05 :PREFIX:-ref-count             PIC 9(4) BINARY.
      * Reference count
           05 :PREFIX:-tables                USAGE POINTER.
      * const pcre-uint8 * Pointer to tables or NULL for std
           05 :PREFIX:-nullpad               USAGE POINTER.
      * const pcre-uint8 * NULL padding
./ ADD NAME=PCREWS
      * this is a description of the working-storage section, common
      * needed variables.
      *
      * Copyright (c) 2012 Ze'ev Atlas
      * Please refer to the LICENSE document to see all other
      * applicable copyrights.
      *
      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------
      * While the original UNIX/Windows program now supports the
      *testing of both the 8-bit and 16-bit PCRE libraries in a single
      *program, the z/OS COBOL (and C) versions support only 8 bit
      *EBCDIC.  Modules such as COMPLIE8 (originally pcre_compile.c)
      *in the library itself, are also specifically compiled for 8 bit
      *EBCDIC.  It does, however, make use of SUPPORT_PCRE8 to ensure
      *that it calls only supported library functions.

      *****************************************************************
       01   PCREWS-NULL-PTR         USAGE POINTER VALUE NULL.
       01   PCREWS-PATTERN-PTR      USAGE POINTER VALUE NULL.
       01   PCREWS-SUBJECT-PTR      USAGE POINTER VALUE NULL.
       01   PCREWS-NAME-TABLE       USAGE POINTER VALUE NULL.
       01   PCREWS-TABPTR           USAGE POINTER.
       01   PCREWS-APIPTR           USAGE POINTER.
       01   PCREWS-OPTION-BITS      PIC 9(8) COMP.
       01   PCREWS-OPTION-BITS-X    REDEFINES
                                    PCREWS-OPTION-BITS PIC X(4).
       01   PCREWS-ERROR-STR        PIC X(1024) VALUE SPACES.
       01   PCREWS-ERROR-PTR        USAGE POINTER VALUE NULL.
       01   PCREWS-ERROFFSET        PIC S9(8) COMP.
       01   PCREWS-UTF8             PIC S9(8) COMP.
       01   PCREWS-NAMECOUNT        PIC S9(8) COMP.
       01   PCREWS-NAME-ENTRY-SIZE  PIC S9(8) COMP.
       01   PCREWS-NAME-ENTRY-SIZE-2 PIC S9(9) BINARY.
       01   PCREWS-OVECCOUNT        PIC S9(4) COMP VALUE 30.
       01   PCREWS-OVEC.
            05 PCREWS-OVECTOR              PIC S9(8) COMP
              OCCURS 1 TO 1000      TIMES
              DEPENDING ON          PCREWS-OVECCOUNT.
       01   PCREWS-SUBSTRING-START  PIC S9(9) BINARY.
       01   PCREWS-SUBSTRING-LENGTH PIC S9(9) BINARY.
./ ADD NAME=PCREXTRA
      * This is a partial port of the public header (pcre.h) file for
      * the PCRE library to COBOL.  It is to be COPIED by applications
      * that call the PCRE functions.
      * Version 0.1
      * Contributed by:   Ze'ev Atlas  2012.
      * Copyright (c) 2012, Ze'ev Atlas.
      * All rights reserved.

      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------

      * The structure for passing additional data to pcre-exec(). This
      * is defined in such as way as to be extensible. Always add new
      * fields at the end, in order to remain compatible.
       01  :PREFIX:-pcre-extra.
           05 :PREFIX:-flags                      PIC 9(9) BINARY.
      * Bits for which fields are set
           05 :PREFIX:-study-data                 USAGE POINTER.
      * Opaque data from pcre-study()
           05 :PREFIX:-match-limit                PIC 9(9) BINARY.
      * Maximum number of calls to match()
           05 :PREFIX:-callout-data               USAGE POINTER.
      * Data passed back in callouts
           05 :PREFIX:-tables                     USAGE POINTER.
      * const unsigned char * Pointer to character tables
           05 :PREFIX:-match-limit-recursion      PIC 9(9) BINARY.
      * Max recursive calls to match()
           05 :PREFIX:-mark                       USAGE POINTER.
      * unsigned char ** For passing back a mark pointer
           05 :PREFIX:-executable-jit             USAGE POINTER.
      * void * Contains a pointer to a compiled jit code
./ ADD NAME=REALPCRE
      * This is a partial port of the public header (pcre.h) file for
      * the PCRE library to COBOL.  It is to be COPIED by applications
      * that call the PCRE functions.
      * Version 0.1
      * Contributed by:   Ze'ev Atlas   2012.
      * Copyright (c) 2012, Ze'ev Atlas.
      * All rights reserved.

      *---------------------------------------------------------------
      *Redistribution and use in source and binary forms, with or
      *without modification, are permitted provided that the following
      *conditions are met:

      * 1. Redistributions of source code must retain the above
      * copyright notice, this list of conditions and the following
      * disclaimer.

      * 2. Redistributions in binary form must reproduce the above
      * copyright notice, this list of conditions and the following
      * disclaimer in the documentation and/or other materials
      * provided with the distribution.

      * 3. Neither the name of the University of Cambridge nor the
      * names of its contributors may be used to endorse or promote
      * products derived from this software without specific prior
      * written permission.

      *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
      *CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
      *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      *CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      *LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      *OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
      *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      *---------------------------------------------------------------
       01  :PREFIX:-REAL-PCRE.
           05 :PREFIX:-magic-number          PIC 9(9) BINARY.
           05 :PREFIX:-size                  PIC 9(9) BINARY.
      * Total that was malloced
           05 :PREFIX:-options               PIC 9(9) BINARY.
      * Public options
           05 :PREFIX:-flags                 PIC 9(4) BINARY.
      * Private flags
           05 :PREFIX:-max-lookbehind        PIC 9(4) BINARY.
      * Longest lookbehind (characters)
           05 :PREFIX:-top-bracket           PIC 9(4) BINARY.
      * Highest numbered group
           05 :PREFIX:-top-backref           PIC 9(4) BINARY.
      * Highest numbered back reference
           05 :PREFIX:-first-char            PIC 9(4) BINARY.
      * Starting character
           05 :PREFIX:-req-char              PIC 9(4) BINARY.
      * This character must be seen
           05 :PREFIX:-name-table-offset     PIC 9(4) BINARY.
      * Offset to name table that follows
           05 :PREFIX:-name-entry-size       PIC 9(4) BINARY.
      * Size of any name items
           05 :PREFIX:-name-count            PIC 9(4) BINARY.
      * Number of name items
           05 :PREFIX:-ref-count             PIC 9(4) BINARY.
      * Reference count
           05 :PREFIX:-tables                USAGE POINTER.
      * const pcre-uint8 * Pointer to tables or NULL for std
           05 :PREFIX:-nullpad               USAGE POINTER.
      * const pcre-uint8 * NULL padding
