diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-04-09 19:24:30 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-04-09 19:28:29 +0200 |
commit | 6f12d32de35ab1d0589db157e0fbc8e56727e138 (patch) | |
tree | 6f0243654f9eae076035556d231477712ebd470f | |
parent | ee68a0baf2f8ec82b758d1dcaf3d71cb5b633b3d (diff) |
Let the replacement file be stdin
-rw-r--r-- | fsub.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -46,7 +46,7 @@ static void fsub(char *, pcre2_match_data *, pcre2_code *, char *); int main(int argc, char *argv[]) { - int fd, fd2, ec, opt; + int fd = 0, fd2, ec, opt; char *needle, *haystack, *repl, *argv0 = argv[0], *optstr = "dim", @@ -89,7 +89,10 @@ main(int argc, char *argv[]) } needle = argv[0]; - fd = loadfile(&repl, argv[1]); + if (streq(argv[1], "-")) + repl = stdio_to_string(); + else + fd = loadfile(&repl, argv[1]); rx = pcre2_compile((PCRE2_SPTR) needle, PCRE2_ZERO_TERMINATED, rx_opts, &ec, &eo, NULL); if (rx == NULL) { @@ -115,7 +118,9 @@ main(int argc, char *argv[]) pcre2_match_data_free(mdata); pcre2_code_free(rx); - close(fd); + + if (!streq(argv[1], "-")) + close(fd); return rv; } |