| 251 | //#define FILENAMESALLLOWERCASE |
| 252 | |
| 253 | bool validmapname(const char *s) // checks for length, allowed chars and special DOS filenames |
| 254 | { |
| 255 | int len = strlen(s); |
| 256 | if(len > MAXMAPNAMELEN) return false; |
| 257 | if(len == 3 || len == 4) |
| 258 | { |
| 259 | char uc[4]; |
| 260 | loopi(3) uc[i] = toupper(s[i]); |
| 261 | uc[3] = '\0'; |
| 262 | const char *resd = "COMLPTCONPRNAUXNUL", *fnd = strstr(resd, uc); |
| 263 | if(fnd) |
| 264 | { |
| 265 | int pos = (int) (fnd - resd); |
| 266 | if(pos == 0 || pos == 3) |
| 267 | { |
| 268 | if(isdigit(s[3])) return false; // COMx, LPTx |
| 269 | } |
| 270 | else if(pos % 3 == 0) return false; // CON, PRN, AUX, NUL |
| 271 | } |
| 272 | } |
| 273 | while(*s != '\0') |
| 274 | { |
| 275 | #ifdef FILENAMESALLLOWERCASE |
| 276 | if(!islower(*s) && !isdigit(*s) && *s != '_' && *s != '-' && *s != '.') return false; |
| 277 | #else |
| 278 | if(!isalnum(*s) && *s != '_' && *s != '-' && *s != '.') return false; |
| 279 | #endif |
| 280 | ++s; |
| 281 | } |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | |
| 286 | // filter text according to rules |
no test coverage detected