tidy things up

This commit is contained in:
Kyryl Melekhin
2021-07-13 21:07:53 +00:00
parent 6ea4f0f7ed
commit a7ee926770
3 changed files with 7 additions and 6 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
a.out

8
pike.c
View File

@@ -1,6 +1,5 @@
// Copyright 2007-2009 Russ Cox. All Rights Reserved. // Copyright 2007-2009 Russ Cox. All Rights Reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -201,7 +200,7 @@ void re_dumpcode(rcode *prog)
printf("any\n"); printf("any\n");
break; break;
case CLASS: case CLASS:
case CLASSNOT: { case CLASSNOT:;
int num = code[pc]; int num = code[pc];
printf("class%s %d", (code[pc - 1] == CLASSNOT ? "not" : ""), num); printf("class%s %d", (code[pc - 1] == CLASSNOT ? "not" : ""), num);
pc++; pc++;
@@ -211,7 +210,6 @@ void re_dumpcode(rcode *prog)
} }
printf("\n"); printf("\n");
break; break;
}
case NAMEDCLASS: case NAMEDCLASS:
printf("namedclass %c\n", code[pc++]); printf("namedclass %c\n", code[pc++]);
break; break;
@@ -632,6 +630,10 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (argc < 2) {
printf("usage: <regex> <str...> <str...> ...\n");
return 0;
}
int sz = re_sizecode(argv[1]) * sizeof(int); int sz = re_sizecode(argv[1]) * sizeof(int);
printf("Precalculated size: %d\n", sz); printf("Precalculated size: %d\n", sz);
char code[sizeof(rcode)+sz]; char code[sizeof(rcode)+sz];

View File

@@ -1,3 +1,4 @@
#!/bin/sh
regex="\ regex="\
abc abc
@@ -38,7 +39,6 @@ a{5}
(abc+){5}|[0-9]{1,} (abc+){5}|[0-9]{1,}
b[^c]* b[^c]*
" "
input="\ input="\
abcdef abcdef
abcdef abcdef
@@ -78,7 +78,6 @@ abcabcabcabcabcabchsdfhsdh
62374623 62374623
djfjgjsdfjbshdhfhshd djfjgjsdfjbshdhfhshd
" "
expect="\ expect="\
(0,3) (0,3)
(2,5) (2,5)
@@ -119,7 +118,6 @@ expect="\
(10,20) (10,20)
(0,0) (0,0)
" "
c=1 c=1
echo "$regex" | tr '\n' | while read re; do echo "$regex" | tr '\n' | while read re; do
inp=$(echo "$input" | awk -v c=$c 'BEGIN{ RS = "" ; FS = "\n" }{print $c}') inp=$(echo "$input" | awk -v c=$c 'BEGIN{ RS = "" ; FS = "\n" }{print $c}')