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

Function match_sym

src/symbols.c:851–901  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

849}
850
851const struct symparse *
852match_sym(char *buf)
853{
854 static struct alternate_parse {
855 const char *altnm;
856 const char *nm;
857 } alternates[] = {
858 { "S_armour", "S_armor" },
859 /* alt explosion names are numbered in phone key/button layout */
860 { "S_explode1", "S_expl_tl" },
861 { "S_explode2", "S_expl_tc" }, { "S_explode3", "S_expl_tr" },
862 { "S_explode4", "S_expl_ml" }, { "S_explode5", "S_expl_mc" },
863 { "S_explode6", "S_expl_mr" }, { "S_explode7", "S_expl_bl" },
864 { "S_explode8", "S_expl_bc" }, { "S_explode9", "S_expl_br" },
865 };
866 int i;
867 size_t len = strlen(buf);
868 const char *p = strchr(buf, ':'), *q = strchr(buf, '=');
869 const struct symparse *sp = loadsyms;
870
871 /* G_ lines will never match here */
872 if ((buf[0] == 'G' || buf[0] == 'g') && buf[1] == '_')
873 return (struct symparse *) 0;
874
875 if (!p || (q && q < p))
876 p = q;
877 if (p) {
878 /* note: there will be at most one space before the '='
879 because caller has condensed buf[] with mungspaces() */
880 if (p > buf && p[-1] == ' ')
881 p--;
882 len = (int) (p - buf);
883 }
884 while (sp->range) {
885 if ((len >= strlen(sp->name)) && !strncmpi(buf, sp->name, len))
886 return sp;
887 sp++;
888 }
889 for (i = 0; i < SIZE(alternates); ++i) {
890 if ((len >= strlen(alternates[i].altnm))
891 && !strncmpi(buf, alternates[i].altnm, len)) {
892 sp = loadsyms;
893 while (sp->range) {
894 if (!strcmp(alternates[i].nm, sp->name))
895 return sp;
896 sp++;
897 }
898 }
899 }
900 return (struct symparse *) 0;
901}
902
903DISABLE_WARNING_FORMAT_NONLITERAL
904

Callers 2

parse_sym_lineFunction · 0.85
parsesymbolsFunction · 0.85

Calls 1

strncmpiFunction · 0.70

Tested by

no test coverage detected