commit e49a3bc027fc5ef929d9460323b6b654b9886284
parent dfc3dc8bd05e0e61b13f459587326828a74b7a9b
Author: Naveen Narayanan <zerous@nocebo.space>
Date: Sun, 26 Sep 2021 18:47:55 +0200
Report error on stderr & parse shall return -1
Diffstat:
M | main.c | | | 3 | ++- |
M | parser.c | | | 49 | +++++++++++++++++++++++++++++-------------------- |
2 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/main.c b/main.c
@@ -29,8 +29,9 @@ main(int argc, char **argv)
*line++ = c;
}
- if (!parse(buf))
+ if (parse(buf) == -1) {
fprintf(stderr, "parse failed\n");
+
if (c == EOF)
break;
}
diff --git a/parser.c b/parser.c
@@ -334,26 +334,35 @@ parse(char *line)
lp = line;
tp = token;
- if (!timestamp())
- return 0;
-
- if (!hostname())
- return 0;
-
- if (!procid())
- return 0;
-
- if (!constat())
- return 0;
-
- if (!ipaddr())
- return 0;
-
- if (!portnum())
- return 0;
-
- if (!misc())
- return 0;
+ printf("parse: line: %s\n", lp);
+ if (!timestamp()) {
+ fprintf(stderr, "timestamp not found\n");
+ return -1;
+ }
+ if (!hostname()) {
+ fprintf(stderr, "hostname not found\n");
+ return -1;
+ }
+ if (!procid()) {
+ fprintf(stderr, "procid not found\n");
+ return -1;
+ }
+ if (!constat()) {
+ fprintf(stderr, "constat not found\n");
+ return -1;
+ }
+ if (!ipaddr()) {
+ fprintf(stderr, "ipaddr not found\n");
+ return -1;
+ }
+ if (!portnum()) {
+ fprintf(stderr, "portnum not found\n");
+ return -1;
+ }
+ if (!misc()) {
+ fprintf(stderr, "misc not found\n");
+ return -1;
+ }
return 1;
}