MCPcopy Create free account
hub / github.com/NetHack/NetHack / grep0

Function grep0

util/makedefs.c:926–997  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

924}
925
926static void
927grep0(FILE *inputfp0, FILE* outputfp0, int flg)
928{
929#ifndef HAS_NO_MKSTEMP
930 /* if grep0 is passed FLG_TEMPFILE flag, it will
931 leave the output file open when it returns.
932 The caller will have to take care of calling
933 fclose() when it is done with the file */
934 boolean istemp = (flg & FLG_TEMPFILE) != 0;
935#else
936 flg; // unused
937#endif
938 char buf[16384]; /* looong, just in case */
939
940 while (!feof(inputfp0) && !ferror(inputfp0)) {
941 char *tmp;
942 char *buf1;
943
944 if (fgets(buf, sizeof(buf), inputfp0) == 0)
945 break;
946 if ((tmp = strchr(buf, '\n')))
947 *tmp = '\0';
948 grep_lineno++;
949 if (grep_trace) {
950 Fprintf(outputfp0, "%04d %c >%s\n", grep_lineno,
951 grep_writing ? ' ' : '#', buf);
952 }
953
954 if (buf[0] == GREP_MAGIC) {
955 buf1 = do_grep_control(&buf[1]);
956 if (!buf1)
957 continue;
958 } else {
959 buf1 = buf;
960 }
961#ifdef notyet
962 if (grep_rewrite)
963 do_grep_rewrite(buf1);
964#endif
965 if (grep_writing)
966 Fprintf(outputfp0, "%s\n", buf1);
967 }
968 if (ferror(inputfp0)) {
969 Fprintf(stderr, "read error!\n");
970 makedefs_exit(EXIT_FAILURE);
971 /*NOTREACHED*/
972 }
973 if (ferror(outputfp0)) {
974 Fprintf(stderr, "write error!\n");
975 makedefs_exit(EXIT_FAILURE);
976 /*NOTREACHED*/
977 }
978 fclose(inputfp0);
979#ifndef HAS_NO_MKSTEMP
980 if (istemp)
981 rewind(outputfp0);
982 else
983#endif

Callers 3

do_grepFunction · 0.85
do_rnd_access_fileFunction · 0.85
do_dungeonFunction · 0.85

Calls 6

feofFunction · 0.85
fgetsFunction · 0.85
do_grep_controlFunction · 0.85
do_grep_rewriteFunction · 0.85
makedefs_exitFunction · 0.85
fcloseFunction · 0.85

Tested by

no test coverage detected