|
@@ -7,7 +7,47 @@ regex_t regex;
|
|
|
// This is the number of capture groups + 1
|
|
|
#define RESET "\x1b[0m"
|
|
|
|
|
|
-void test( const char * trythis) {
|
|
|
+int regmatch( regex_t *preg, const char * string, size_t nmatch, regmatch_t pmatch[], int eflags) {
|
|
|
+ // returns number of matches found. (Max nmatch)
|
|
|
+ int matches = 0;
|
|
|
+ int offset = 0;
|
|
|
+ int ret;
|
|
|
+
|
|
|
+ while (matches < nmatch) {
|
|
|
+ ret = regexec( preg, string + offset, nmatch - matches, pmatch + matches, eflags);
|
|
|
+ if (!ret) {
|
|
|
+ int current = offset;
|
|
|
+ offset += pmatch[matches].rm_eo;
|
|
|
+ pmatch[matches].rm_so += current;
|
|
|
+ pmatch[matches].rm_eo += current;
|
|
|
+ matches++;
|
|
|
+ } else if (ret == REG_NOMATCH ) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return matches;
|
|
|
+}
|
|
|
+
|
|
|
+void test(const char * trythis) {
|
|
|
+ regmatch_t regmatches[MAX_MATCH];
|
|
|
+ int matches, x;
|
|
|
+ printf("TEST (%s)\n", trythis);
|
|
|
+
|
|
|
+ matches = regmatch(®ex, trythis, MAX_MATCH, regmatches, 0);
|
|
|
+ if (matches == 0) {
|
|
|
+ printf("No matches.\n");
|
|
|
+ } else {
|
|
|
+ printf("%d matches:\n", matches);
|
|
|
+ for( x = 0; x < matches; x++) {
|
|
|
+ printf("%d (%d - %d)\n", x, regmatches[x].rm_so, regmatches[x].rm_eo);
|
|
|
+ printf("[%.*s]\n", regmatches[x].rm_eo - regmatches[x].rm_so, trythis + regmatches[x].rm_so);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void test_( const char * trythis) {
|
|
|
int ret;
|
|
|
char msgbuf[100];
|
|
|
const char * p = trythis;
|