aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-09-12 18:43:19 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-09-12 18:43:19 +0200
commit14eb9b46326f70d6c14ee82614b8107941b04dbe (patch)
treeabdc993c5979d52c2cdae86fd2e2a93b4745b502
parent63ef5c4f6ed5997be1135189f6bb5872daafa93a (diff)
Use yy_scan_string() instead of fmemopen();HEADmaster
-rw-r--r--src/main.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index c301fdf..d4af50c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -138,17 +138,18 @@ usage:
interactive = sflag == NULL && argc == 0 && isatty(STDIN_FILENO);
if (argc == 0) {
- if (sflag != NULL &&
- (yyin = fmemopen((char *)sflag, strlen(sflag), "r")) == NULL)
- {
- err(1, "fmemopen");
- }
-
- current_file = "-";
- for (;;) {
- if (yyparse() == 0)
- break;
- rv = EXIT_FAILURE;
+ if (sflag == NULL) {
+ current_file = "-";
+ for (;;) {
+ if (yyparse() == 0)
+ break;
+ rv = EXIT_FAILURE;
+ }
+ } else {
+ current_file = "-s";
+ YY_BUFFER_STATE buf = yy_scan_string(sflag);
+ (void)yyparse();
+ yy_delete_buffer(buf);
}
} else for (int i = 0; i < argc; i++) {
if (streq(argv[i], "-"))
@@ -160,7 +161,7 @@ usage:
}
current_file = argv[i];
- yyparse();
+ (void)yyparse();
fclose(yyin);
}