[pcre-dev] Pcre2-10.32 return code -51?

Página superior
Eliminar este mensaje
Autor: BEYER Mark
Fecha:  
A: pcre-dev@exim.org
Asunto: [pcre-dev] Pcre2-10.32 return code -51?
Thank you in advance if you are able to help me. Ultimately, I hope to create Fortran wrapper methods for Pcre2 to replace my POSIX regular expression interface methods.

Demo.c is a stripped down version of pcre2demo.c and works with no issue:

> demo '(abc|be)' 'abcdefg'

pattern:(abc|be)
compile rc:1
subject:abcdefg
execute rc: 2

Demo2.c is my attempt to group demo.c into functions, however, I get a return code of -51 in the execute step:

> demo2 '(abc|be)' 'abcdefg'

pattern:(abc|be)
compile:1
subject:abcdefg
execute rc:-51

What am I doing wrong?

Best Regards,

Mark Beyer

Mark.Beyer@???

This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email and all attachments,

(iii) Dassault Systèmes does not accept or assume any liability or responsibility for any use of or reliance on this email.


Please be informed that your personal data are processed according to our data privacy policy as described on our website. Should you have any questions related to personal data protection, please contact 3DS Data Protection Officer at 3DS.compliance-privacy@???<mailto:3DS.compliance-privacy@3ds.com>


For other languages, go to https://www.3ds.com/terms/email-disclaimer
#define PCRE2_STATIC
#define PCRE2_CODE_UNIT_WIDTH 8
#include <stdio.h>
#include <string.h>
#include <pcre2.h>

int main(int argc, char **argv) {
  pcre2_code *re;
  int rc;
  int errornumber;
  size_t subject_length;
  PCRE2_SIZE erroroffset;
  pcre2_match_data *match_data;
  PCRE2_SPTR pattern=(PCRE2_SPTR)argv[1];
  PCRE2_SPTR subject=(PCRE2_SPTR)argv[2];
  
  subject_length = strlen((char *)subject);
  
  /* Compile pattern */
  re = pcre2_compile(
    pattern,               /* the pattern */
    PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
    0,                     /* default options */
    &errornumber,          /* for error number */
    &erroroffset,          /* for error offset */
    NULL);                 /* use default compile context */
  
  rc=1;
  if(re == NULL) rc=-1;

  printf("pattern:%s\n",pattern);
  printf("compile rc:%d\n",rc);

  if(re == NULL)return rc;

  /* ensures that the block is exactly the right size for the number of 
   * capturing parentheses in the pattern. */
  match_data = pcre2_match_data_create_from_pattern(re, NULL);

  /* Test for match */
  rc = pcre2_match(
    re,                   /* the compiled pattern */
    subject,              /* the subject string */
    subject_length,       /* the length of the subject */
    0,                    /* start at offset 0 in the subject */
    0,                    /* default options */
    match_data,           /* block for storing the result */
    NULL);                /* use default match context */
  
  printf("subject:%s\n",subject);
  printf("execute rc: %d\n",rc);

  pcre2_match_data_free(match_data); /* release memory for the match */
  pcre2_code_free(re);               /* data and the compiled pattern */
  return rc;
}

#define PCRE2_STATIC
#define PCRE2_CODE_UNIT_WIDTH 8
#include <stdio.h>
#include <string.h>
#include <pcre2.h>

// --------------------------------------------------------- function prototypes
int C_compile(pcre2_code *, pcre2_match_data *, const char *);
int C_execute(pcre2_code *, pcre2_match_data *, const char *);
void C_free(pcre2_code *, pcre2_match_data *); 

int main(int argc, char **argv) {
  pcre2_code *re;
  pcre2_match_data *match_data;
  int rc;
  rc=C_compile(re, match_data, argv[1]);
  if(rc < 0)return rc;
  rc=C_execute(re, match_data, argv[2]);
  C_free(re, match_data);
  return rc;
}

// ------------------------------------------------------------- compile pattern
int C_compile(pcre2_code *re, pcre2_match_data *match_data, 
  const char *string) {
  int rc;
  int errornumber;
  PCRE2_SIZE erroroffset;
  PCRE2_SPTR pattern=(PCRE2_SPTR)string;
  
  re = pcre2_compile(
    pattern,               /* the pattern */
    PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
    0,                     /* default options */
    &errornumber,          /* for error number */
    &erroroffset,          /* for error offset */
    NULL);                 /* use default compile context */
  
  rc=1;
  if(re == NULL) rc=-1; 

  printf("pattern:%s\n",pattern);
  printf("compile:%d\n",rc);

  if(re == NULL) return rc;

  /* Ensures that the block is exactly the right size for the number of 
   * Capturing parentheses in the pattern. */
  match_data = pcre2_match_data_create_from_pattern(re, NULL);

  return rc;
}

// -------------------------------------------------------------- test for match
int C_execute(pcre2_code *re, pcre2_match_data *match_data,
  const char *string) {
  int rc;
  size_t subject_length;
  PCRE2_SPTR subject=(PCRE2_SPTR)string;
  subject_length = strlen((char *)subject);

  rc = pcre2_match(
    re,                   /* the compiled pattern */
    subject,              /* the subject string */
    subject_length,       /* the length of the subject */
    0,                    /* start at offset 0 in the subject */
    0,                    /* default options */
    match_data,           /* block for storing the result */
    NULL);                /* use default match context */

  printf("subject:%s\n",subject);
  printf("execute rc:%d\n",rc);
  return rc;
} 

// -------------------------------------------------------------- release memory
void C_free(pcre2_code *re, pcre2_match_data *match_data) {
  pcre2_match_data_free(match_data); /* release memory for the match */
  pcre2_code_free(re);               /* data and the compiled pattern */
}