mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-20 01:46:26 +00:00
todo
This commit is contained in:
parent
cce9e4e65d
commit
bdb5f395fd
2 changed files with 42 additions and 4 deletions
|
|
@ -19,7 +19,7 @@
|
|||
// pmatch[9].rm_so= -1 pmatch[9].rm_eo= -1
|
||||
|
||||
static void usage(char* argv0, FILE* o, int exit_code) {
|
||||
fprintf(o, "Usage: %s {regex} {string}\n", argv0);
|
||||
fprintf(o, "Usage: %s {string} {regex}\n", argv0);
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
|
|
@ -32,8 +32,8 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
regex_t reg;
|
||||
|
||||
char* sregex = argv[1];
|
||||
char* sstr = argv[2];
|
||||
char* sstr = argv[1];
|
||||
char* sregex = argv[2];
|
||||
int cflags = REG_EXTENDED;
|
||||
const size_t nmatchmax = 10;
|
||||
regmatch_t pmatch[nmatchmax];
|
||||
|
|
@ -51,11 +51,29 @@ int main(int argc, char** argv) {
|
|||
|
||||
rc = regexec(®, sstr, nmatchmax, pmatch, eflags);
|
||||
printf("rc=%d\n", rc);
|
||||
int len = strlen(sstr);
|
||||
if (rc == 0) {
|
||||
for (int i = 0; i < nmatchmax; i++) {
|
||||
if (pmatch[i].rm_so == -1)
|
||||
break;
|
||||
printf("pmatch[%i].rm_so=%4lld pmatch[%d].rm_eo=%4lld\n",
|
||||
i, (long long)pmatch[i].rm_so,
|
||||
i, (long long)pmatch[i].rm_eo);
|
||||
|
||||
printf(" ");
|
||||
for (int j = 0; j < len; j++) {
|
||||
fputc(sstr[j], stdout);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf(" ");
|
||||
for (int j = 0; j < len; j++) {
|
||||
if (j >= pmatch[i].rm_so && j < pmatch[i].rm_eo)
|
||||
fputc('^', stdout);
|
||||
else
|
||||
fputc('.', stdout);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
} else if (rc == REG_NOMATCH) {
|
||||
printf("no match\n");
|
||||
|
|
|
|||
22
c/todo.txt
22
c/todo.txt
|
|
@ -11,7 +11,27 @@ BUGFIXES
|
|||
echo 'x=a\tb'| mlr put '$x=gsub($x,"\\t","\t")'
|
||||
x=a\ b
|
||||
|
||||
* reg_test/dev material
|
||||
-> try w/ regex lib directly
|
||||
|
||||
experimental/regexes.c:
|
||||
|
||||
$ a.out 'a@tb' '@t'
|
||||
rc=0
|
||||
pmatch[0].rm_so= 1 pmatch[0].rm_eo= 3
|
||||
a@tb
|
||||
.^^.
|
||||
|
||||
$ a.out 'a\tb' '\t'
|
||||
rc=0
|
||||
pmatch[0].rm_so= 2 pmatch[0].rm_eo= 3
|
||||
a\tb
|
||||
..^.
|
||||
|
||||
$ a.out 'a\tb' '\\t'
|
||||
rc=0
|
||||
pmatch[0].rm_so= 1 pmatch[0].rm_eo= 3
|
||||
a\tb
|
||||
.^^.
|
||||
|
||||
================================================================
|
||||
TOP-OF-LIST SUMMARY
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue