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

Function alt_color_spec

src/coloratt.c:1110–1165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1108}
1109
1110staticfn int32
1111alt_color_spec(const char *str)
1112{
1113 static NEARDATA const char oct[] = "01234567", dec[] = "0123456789";
1114 /* hexdd[] is defined in decl.c */
1115
1116 const char *dp, *cp = str;
1117 int32 cval = -1;
1118 int dcount, dlimit = 6;
1119 boolean hexescape = FALSE, octescape = FALSE;
1120
1121 dcount = 0; /* for decimal, octal, hexadecimal cases */
1122 hexescape =
1123 (*cp == '\\' && cp[1] && (cp[1] == 'x' || cp[1] == 'X') && cp[2]);
1124 if (!hexescape) {
1125 octescape =
1126 (*cp == '\\' && cp[1] && (cp[1] == 'o' || cp[1] == 'O') && cp[2]);
1127 }
1128
1129 if (hexescape || octescape) {
1130 cval = 0;
1131 cp += 2;
1132 if (octescape)
1133 dlimit = 8;
1134 } else if (*cp == '#' && cp[1]) {
1135 hexescape = TRUE;
1136 cval = 0;
1137 cp += 1;
1138 } else if (cp[1]) {
1139 cval = 0;
1140 dlimit = 8;
1141 } else if (!cp[1]) {
1142 if (strchr(dec, *cp) != 0) {
1143 /* simple val, or nothing left for \ to escape */
1144 cval = (*cp - '0');
1145 }
1146 dlimit = 1;
1147 cp++;
1148 }
1149
1150 while (*cp) {
1151 if (!hexescape && !octescape && strchr(dec, *cp)) {
1152 cval = (cval * 10) + (*cp - '0');
1153 } else if (octescape && strchr(oct, *cp)) {
1154 cval = (cval * 8) + (*cp - '0');
1155 } else if (hexescape && (dp = strchr(hexdd, *cp)) != 0) {
1156 cval = (cval * 16) + ((int) (dp - hexdd) / 2);
1157 }
1158 ++cp;
1159 if (++dcount > dlimit) {
1160 cval = -1;
1161 break;
1162 }
1163 }
1164 return cval;
1165}
1166#endif /* CHANGE_COLOR */
1167

Callers 1

alternative_paletteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected