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

Function do_grep_control

util/makedefs.c:821–895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

819}
820
821static char *
822do_grep_control(char *buf)
823{
824 int isif = 1;
825 char *buf0 = buf;
826#if 1
827 if (isspace((uchar) buf[0]))
828 return &buf[-1]; /* XXX see docs above */
829#else
830 while (buf[0] && isspace((uchar) buf[0]))
831 buf++;
832#endif
833 switch (buf[0]) {
834 case '#': /* comment */
835 break;
836 case '.': /* end of if level */
837 if (grep_sp == 0) {
838 Fprintf(stderr, "unmatched ^. (endif) at line %d.\n",
839 grep_lineno);
840 grep_errors++;
841 } else {
842 grep_writing = ST_OLD(grep_stack[grep_sp--]);
843 grep_show_wstack("pop");
844 }
845 break;
846 case '!': /* if not ID */
847 isif = 0;
848 FALLTHROUGH;
849 /* FALLTHRU */
850 case '?': /* if ID */
851 if (grep_sp == GREP_STACK_SIZE - 2) {
852 Fprintf(stderr, "stack overflow at line %d.", grep_lineno);
853 makedefs_exit(EXIT_FAILURE);
854 /*NOTREACHED*/
855 }
856 if (grep_writing) {
857 isif = grep_check_id(&buf[1]) ? isif : !isif;
858 grep_stack[++grep_sp] = ST_LD(grep_writing, !isif);
859 grep_writing = isif;
860 } else {
861 grep_stack[++grep_sp] = ST_LD(0, 0);
862 /* grep_writing = 0; */
863 }
864 grep_show_wstack("push");
865 break;
866 case ':': /* else */
867 if (ST_ELSE & grep_stack[grep_sp]) {
868 Fprintf(stderr, "multiple : for same conditional at line %d.\n",
869 grep_lineno);
870 grep_errors++;
871 }
872 grep_writing = ST_OPP(grep_stack[grep_sp]);
873 grep_stack[grep_sp] |= ST_ELSE;
874 break;
875#if defined(notyet)
876 case '(': /* start of expression */
877#endif
878 case GREP_MAGIC: /* ^^ -> ^ */

Callers 1

grep0Function · 0.85

Calls 5

isspaceFunction · 0.85
grep_show_wstackFunction · 0.85
makedefs_exitFunction · 0.85
grep_check_idFunction · 0.85
isprintFunction · 0.85

Tested by

no test coverage detected