| 953 | } |
| 954 | |
| 955 | static int file_callback(const struct option *opt, const char *arg, int unset) |
| 956 | { |
| 957 | struct grep_opt *grep_opt = opt->value; |
| 958 | int from_stdin; |
| 959 | const char *filename = arg; |
| 960 | FILE *patterns; |
| 961 | int lno = 0; |
| 962 | struct strbuf sb = STRBUF_INIT; |
| 963 | |
| 964 | BUG_ON_OPT_NEG(unset); |
| 965 | |
| 966 | if (!*filename) |
| 967 | ; /* leave it as-is */ |
| 968 | else |
| 969 | filename = prefix_filename_except_for_dash(grep_prefix, filename); |
| 970 | |
| 971 | from_stdin = !strcmp(filename, "-"); |
| 972 | patterns = from_stdin ? stdin : fopen(filename, "r"); |
| 973 | if (!patterns) |
| 974 | die_errno(_("cannot open '%s'"), arg); |
| 975 | while (strbuf_getline(&sb, patterns) == 0) { |
| 976 | /* ignore empty line like grep does */ |
| 977 | if (sb.len == 0) |
| 978 | continue; |
| 979 | |
| 980 | append_grep_pat(grep_opt, sb.buf, sb.len, arg, ++lno, |
| 981 | GREP_PATTERN); |
| 982 | } |
| 983 | if (!from_stdin) |
| 984 | fclose(patterns); |
| 985 | strbuf_release(&sb); |
| 986 | if (filename != arg) |
| 987 | free((void *)filename); |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static int not_callback(const struct option *opt, const char *arg, int unset) |
| 992 | { |
nothing calls this directly
no test coverage detected