Either set this file's input language explicitly via a string or use the filename extension to determine the language. If neither works out, use the default language C. Uses global filename (maybe stdin). Once the language is known, configs for that language are applied, e.g. the correct keyword table to use. */
| 413 | e.g. the correct keyword table to use. |
| 414 | */ |
| 415 | Language set_or_detect_lang(const char *source) |
| 416 | { |
| 417 | int i; |
| 418 | Language lang = C; // default language |
| 419 | |
| 420 | if (source) { |
| 421 | /* Check if explicit language is known: */ |
| 422 | for (i = 0; i < sizeof(langs)/sizeof(langs[0]); i++) |
| 423 | if (!strcmp(source, langs[i].name)) { |
| 424 | lang = langs[i].lang; |
| 425 | goto done; |
| 426 | } |
| 427 | fprintf(stderr, "(E): No support for language `%s'.\n", source); |
| 428 | } |
| 429 | |
| 430 | char *p; |
| 431 | if (p = strrchr(filename, '.')) { |
| 432 | for (i = 0; i < sizeof(langs)/sizeof(langs[0]); i++) |
| 433 | if (!strcmp(p, langs[i].ext)) { |
| 434 | lang = langs[i].lang; |
| 435 | goto done; |
| 436 | } |
| 437 | fprintf(stderr, "(E): Unknown filename extension `%s'.\n", p); |
| 438 | } |
| 439 | if (!nowarn) |
| 440 | fprintf(stderr, "(W): Assuming default language C.\n"); |
| 441 | |
| 442 | done: |
| 443 | is_keyword = lang_configs[lang].is_keyword; |
| 444 | return lang; |
| 445 | } |
| 446 | |
| 447 | // Dynamically sized token buffer: |
| 448 | static char *token_buf = 0; |
no outgoing calls
no test coverage detected