summaryrefslogtreecommitdiffstats
path: root/rubbos/app/httpd-2.0.64/srclib/pcre/pcredemo.c
diff options
context:
space:
mode:
authorhongbotian <hongbo.tianhongbo@huawei.com>2015-11-30 01:45:08 -0500
committerhongbotian <hongbo.tianhongbo@huawei.com>2015-11-30 01:45:08 -0500
commite8ec7aa8e38a93f5b034ac74cebce5de23710317 (patch)
treeaa031937bf856c1f8d6ad7877b8d2cb0224da5ef /rubbos/app/httpd-2.0.64/srclib/pcre/pcredemo.c
parentcc40af334e619bb549038238507407866f774f8f (diff)
upload http
JIRA: BOTTLENECK-10 Change-Id: I7598427ff904df438ce77c2819ee48ac75ffa8da Signed-off-by: hongbotian <hongbo.tianhongbo@huawei.com>
Diffstat (limited to 'rubbos/app/httpd-2.0.64/srclib/pcre/pcredemo.c')
-rw-r--r--rubbos/app/httpd-2.0.64/srclib/pcre/pcredemo.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/rubbos/app/httpd-2.0.64/srclib/pcre/pcredemo.c b/rubbos/app/httpd-2.0.64/srclib/pcre/pcredemo.c
new file mode 100644
index 00000000..cb4e46f1
--- /dev/null
+++ b/rubbos/app/httpd-2.0.64/srclib/pcre/pcredemo.c
@@ -0,0 +1,94 @@
+#include <stdio.h>
+#include <string.h>
+#include <pcre.h>
+
+/* Compile thuswise:
+ gcc -Wall pcredemo.c -I/opt/local/include -L/opt/local/lib \
+ -R/opt/local/lib -lpcre
+*/
+
+#define OVECCOUNT 30 /* should be a multiple of 3 */
+
+int main(int argc, char **argv)
+{
+pcre *re;
+const char *error;
+int erroffset;
+int ovector[OVECCOUNT];
+int rc, i;
+
+if (argc != 3)
+ {
+ printf("Two arguments required: a regex and a subject string\n");
+ return 1;
+ }
+
+/* Compile the regular expression in the first argument */
+
+re = pcre_compile(
+ argv[1], /* the pattern */
+ 0, /* default options */
+ &error, /* for error message */
+ &erroffset, /* for error offset */
+ NULL); /* use default character tables */
+
+/* Compilation failed: print the error message and exit */
+
+if (re == NULL)
+ {
+ printf("PCRE compilation failed at offset %d: %s\n", erroffset, error);
+ return 1;
+ }
+
+/* Compilation succeeded: match the subject in the second argument */
+
+rc = pcre_exec(
+ re, /* the compiled pattern */
+ NULL, /* no extra data - we didn't study the pattern */
+ argv[2], /* the subject string */
+ (int)strlen(argv[2]), /* the length of the subject */
+ 0, /* start at offset 0 in the subject */
+ 0, /* default options */
+ ovector, /* output vector for substring information */
+ OVECCOUNT); /* number of elements in the output vector */
+
+/* Matching failed: handle error cases */
+
+if (rc < 0)
+ {
+ switch(rc)
+ {
+ case PCRE_ERROR_NOMATCH: printf("No match\n"); break;
+ /*
+ Handle other special cases if you like
+ */
+ default: printf("Matching error %d\n", rc); break;
+ }
+ return 1;
+ }
+
+/* Match succeded */
+
+printf("Match succeeded\n");
+
+/* The output vector wasn't big enough */
+
+if (rc == 0)
+ {
+ rc = OVECCOUNT/3;
+ printf("ovector only has room for %d captured substrings\n", rc - 1);
+ }
+
+/* Show substrings stored in the output vector */
+
+for (i = 0; i < rc; i++)
+ {
+ char *substring_start = argv[2] + ovector[2*i];
+ int substring_length = ovector[2*i+1] - ovector[2*i];
+ printf("%2d: %.*s\n", i, substring_length, substring_start);
+ }
+
+return 0;
+}
+
+