clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name comp_scan.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/lib/libcurses/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -I /usr/src/lib/libcurses -D PIC -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libcurses/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/lib/libcurses/tinfo/comp_scan.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | #include <curses.priv.h> |
| 51 | |
| 52 | #include <ctype.h> |
| 53 | #include <term_entry.h> |
| 54 | #include <tic.h> |
| 55 | |
| 56 | MODULE_ID("$Id: comp_scan.c,v 1.15 2010/01/12 23:22:06 nicm Exp $") |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | #define MAXCAPLEN 600 |
| 63 | |
| 64 | #define iswhite(ch) (ch == ' ' || ch == '\t') |
| 65 | |
| 66 | NCURSES_EXPORT_VAR(int) |
| 67 | _nc_syntax = 0; |
| 68 | NCURSES_EXPORT_VAR(long) |
| 69 | _nc_curr_file_pos = 0; |
| 70 | NCURSES_EXPORT_VAR(long) |
| 71 | _nc_comment_start = 0; |
| 72 | NCURSES_EXPORT_VAR(long) |
| 73 | _nc_comment_end = 0; |
| 74 | NCURSES_EXPORT_VAR(long) |
| 75 | _nc_start_line = 0; |
| 76 | |
| 77 | NCURSES_EXPORT_VAR(struct token) |
| 78 | _nc_curr_token = |
| 79 | { |
| 80 | 0, 0, 0 |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | static bool first_column; |
| 90 | static bool had_newline; |
| 91 | static char separator; |
| 92 | static int pushtype; |
| 93 | static char *pushname; |
| 94 | |
| 95 | #if NCURSES_EXT_FUNCS |
| 96 | NCURSES_EXPORT_VAR(bool) |
| 97 | _nc_disable_period = FALSE; |
| 98 | #endif |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | #define LEXBUFSIZ 1024 |
| 107 | |
| 108 | static char *bufptr; |
| 109 | static char *bufstart; |
| 110 | static FILE *yyin; |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | NCURSES_EXPORT(void) |
| 121 | _nc_reset_input(FILE *fp, char *buf) |
| 122 | { |
| 123 | pushtype = NO_PUSHBACK; |
| 124 | if (pushname != 0) |
| 125 | pushname[0] = '\0'; |
| 126 | yyin = fp; |
| 127 | bufstart = bufptr = buf; |
| 128 | _nc_curr_file_pos = 0L; |
| 129 | if (fp != 0) |
| 130 | _nc_curr_line = 0; |
| 131 | _nc_curr_col = 0; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | static int |
| 140 | last_char(void) |
| 141 | { |
| 142 | size_t len = strlen(bufptr); |
| 143 | while (len--) { |
| 144 | if (!isspace(UChar(bufptr[len]))) |
| 145 | return bufptr[len]; |
| 146 | } |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | static int |
| 165 | next_char(void) |
| 166 | { |
| 167 | static char *result; |
| 168 | static size_t allocated; |
| 169 | int the_char; |
| 170 | |
| 171 | if (!yyin) { |
| |
| |
| 172 | if (result != 0) { |
| 173 | FreeAndNull(result); |
| 174 | FreeAndNull(pushname); |
| 175 | allocated = 0; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | if (bufptr == 0 || *bufptr == '\0') |
| 182 | return (EOF); |
| 183 | if (*bufptr == '\n') { |
| 184 | _nc_curr_line++; |
| 185 | _nc_curr_col = 0; |
| 186 | } else if (*bufptr == '\t') { |
| 187 | _nc_curr_col = (_nc_curr_col | 7); |
| 188 | } |
| 189 | } else if (!bufptr || !*bufptr) { |
| 15 | | Assuming 'bufptr' is non-null, which participates in a condition later | |
|
| 16 | | Assuming the condition is false | |
|
| |
| 34 | | Assuming the condition is false | |
|
| |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | size_t used; |
| 197 | size_t len; |
| 198 | |
| 199 | do { |
| 200 | bufstart = 0; |
| 201 | used = 0; |
| 202 | do { |
| 203 | if (used + (LEXBUFSIZ / 4) >= allocated) { |
| 204 | allocated += (allocated + LEXBUFSIZ); |
| 205 | result = typeRealloc(char, allocated, result); |
| 206 | if (result == 0) |
| 207 | return (EOF); |
| 208 | bufstart = result; |
| 209 | } |
| 210 | if (used == 0) |
| 211 | _nc_curr_file_pos = ftell(yyin); |
| 212 | |
| 213 | if (fgets(result + used, (int) (allocated - used), yyin) != 0) { |
| 214 | bufstart = result; |
| 215 | if (used == 0) { |
| 216 | _nc_curr_line++; |
| 217 | _nc_curr_col = 0; |
| 218 | } |
| 219 | } else { |
| 220 | if (used != 0) |
| 221 | strlcat(result, "\n", allocated); |
| 222 | } |
| 223 | if ((bufptr = bufstart) != 0) { |
| 224 | used = strlen(bufptr); |
| 225 | while (iswhite(*bufptr)) { |
| 226 | if (*bufptr == '\t') { |
| 227 | _nc_curr_col = (_nc_curr_col | 7) + 1; |
| 228 | } else { |
| 229 | _nc_curr_col++; |
| 230 | } |
| 231 | bufptr++; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | if ((len = strlen(bufptr)) > 1) { |
| 239 | if (bufptr[len - 1] == '\n' |
| 240 | && bufptr[len - 2] == '\r') { |
| 241 | len--; |
| 242 | bufptr[len - 1] = '\n'; |
| 243 | bufptr[len] = '\0'; |
| 244 | } |
| 245 | } |
| 246 | } else { |
| 247 | return (EOF); |
| 248 | } |
| 249 | } while (bufptr[len - 1] != '\n'); |
| 250 | } while (result[0] == '#'); |
| 251 | } else if (*bufptr == '\t') { |
| 18 | | Assuming the condition is false | |
|
| |
| 36 | | Assuming the condition is false | |
|
| |
| 252 | _nc_curr_col = (_nc_curr_col | 7); |
| 253 | } |
| 254 | |
| 255 | first_column = (bufptr == bufstart); |
| 20 | | Assuming 'bufptr' is not equal to 'bufstart', which participates in a condition later | |
|
| 38 | | Value assigned to 'first_column', which participates in a condition later | |
|
| 256 | if (first_column) |
| |
| 39 | | Assuming 'first_column' is true, which participates in a condition later | |
|
| |
| 257 | had_newline = FALSE; |
| 258 | |
| 259 | _nc_curr_col++; |
| 260 | the_char = *bufptr++; |
| 261 | return UChar(the_char); |
| 262 | } |
| 263 | |
| 264 | static void |
| 265 | push_back(char c) |
| 266 | |
| 267 | { |
| 268 | if (bufptr == bufstart) |
| 269 | _nc_syserr_abort("Can't backspace off beginning of line"); |
| 270 | *--bufptr = c; |
| 271 | _nc_curr_col--; |
| 272 | } |
| 273 | |
| 274 | static long |
| 275 | stream_pos(void) |
| 276 | |
| 277 | { |
| 278 | return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0)); |
| 279 | } |
| 280 | |
| 281 | static bool |
| 282 | end_of_stream(void) |
| 283 | |
| 284 | { |
| 285 | return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0')) |
| 4 | | Assuming 'yyin' is non-null, which participates in a condition later | |
|
| |
| 6 | | Assuming '__isthreaded' is not equal to 0 | |
|
| |
| 8 | | Assuming the condition is false | |
|
| |
| 10 | | Returning zero, which participates in a condition later | |
|
| 286 | ? TRUE : FALSE); |
| 287 | } |
| 288 | |
| 289 | |
| 290 | static NCURSES_INLINE int |
| 291 | eat_escaped_newline(int ch) |
| 292 | { |
| 293 | if (ch == '\\') |
| 294 | while ((ch = next_char()) == '\n' || iswhite(ch)) |
| 295 | continue; |
| 296 | return ch; |
| 297 | } |
| 298 | |
| 299 | #define TOK_BUF_SIZE MAX_ENTRY_SIZE |
| 300 | |
| 301 | #define OkToAdd() \ |
| 302 | ((tok_ptr - tok_buf) < (TOK_BUF_SIZE - 2)) |
| 303 | |
| 304 | #define AddCh(ch) \ |
| 305 | *tok_ptr++ = (char) ch; \ |
| 306 | *tok_ptr = '\0' |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | NCURSES_EXPORT(int) |
| 342 | _nc_get_token(bool silent) |
| 343 | { |
| 344 | static const char terminfo_punct[] = "@%&*!#"; |
| 345 | static char *tok_buf; |
| 346 | |
| 347 | char *after_list; |
| 348 | char *after_name; |
| 349 | char *numchk; |
| 350 | char *tok_ptr; |
| 351 | char *s; |
| 352 | char numbuf[80]; |
| 353 | int ch; |
| 354 | int dot_flag = FALSE; |
| 355 | int type; |
| 356 | long number; |
| 357 | long token_start; |
| 358 | unsigned found; |
| 359 | #ifdef TRACE |
| 360 | int old_line; |
| 361 | int old_col; |
| 362 | #endif |
| 363 | |
| 364 | if (pushtype != NO_PUSHBACK) { |
| 1 | Assuming the condition is false | |
|
| |
| 365 | int retval = pushtype; |
| 366 | |
| 367 | _nc_set_type(pushname != 0 ? pushname : ""); |
| 368 | DEBUG(3, ("pushed-back token: `%s', class %d", |
| 369 | _nc_curr_token.tk_name, pushtype)); |
| 370 | |
| 371 | pushtype = NO_PUSHBACK; |
| 372 | if (pushname != 0) |
| 373 | pushname[0] = '\0'; |
| 374 | |
| 375 | |
| 376 | return (retval); |
| 377 | } |
| 378 | |
| 379 | if (end_of_stream()) { |
| |
| 11 | | Returning from 'end_of_stream' | |
|
| |
| 380 | yyin = 0; |
| 381 | next_char(); |
| 382 | if (tok_buf != 0) { |
| 383 | if (_nc_curr_token.tk_name == tok_buf) |
| 384 | _nc_curr_token.tk_name = 0; |
| 385 | FreeAndNull(tok_buf); |
| 386 | } |
| 387 | return (EOF); |
| 388 | } |
| 389 | |
| 390 | start_token: |
| 391 | token_start = stream_pos(); |
| 392 | while ((ch = next_char()) == '\n' || iswhite(ch)) { |
| |
| 22 | | Returning from 'next_char' | |
|
| 23 | | Assuming the condition is false | |
|
| 24 | | Assuming the condition is false | |
|
| 25 | | Loop condition is false. Execution continues on line 398 | |
|
| 393 | if (ch == '\n') |
| 394 | had_newline = TRUE; |
| 395 | continue; |
| 396 | } |
| 397 | |
| 398 | ch = eat_escaped_newline(ch); |
| 399 | |
| 400 | #ifdef TRACE |
| 401 | old_line = _nc_curr_line; |
| 402 | old_col = _nc_curr_col; |
| 403 | #endif |
| 404 | if (ch == EOF) |
| 26 | | Assuming the condition is false | |
|
| |
| 405 | type = EOF; |
| 406 | else { |
| 407 | |
| 408 | if (separator == ':' && ch == ':') |
| 28 | | Assuming the condition is false | |
|
| 409 | ch = next_char(); |
| 410 | |
| 411 | if (ch == '.' |
| 29 | | Assuming the condition is true | |
|
| |
| 412 | #if NCURSES_EXT_FUNCS |
| 413 | && !_nc_disable_period |
| 30 | | Assuming '_nc_disable_period' is false | |
|
| 414 | #endif |
| 415 | ) { |
| 416 | dot_flag = TRUE; |
| 417 | DEBUG(8, ("dot-flag set")); |
| 418 | |
| 419 | while ((ch = next_char()) == '.' || iswhite(ch)) |
| |
| 41 | | Returning from 'next_char' | |
|
| 42 | | Assuming the condition is false | |
|
| 43 | | Assuming the condition is false | |
|
| 44 | | Loop condition is false. Execution continues on line 423 | |
|
| 420 | continue; |
| 421 | } |
| 422 | |
| 423 | if (ch == EOF) { |
| 45 | | Assuming the condition is false | |
|
| |
| 424 | type = EOF; |
| 425 | goto end_of_token; |
| 426 | } |
| 427 | |
| 428 | |
| 429 | if (!isalnum(UChar(ch)) |
| 430 | #if NCURSES_EXT_FUNCS |
| 431 | && !(ch == '.' && _nc_disable_period) |
| 432 | #endif |
| 433 | && !strchr(terminfo_punct, (char) ch)) { |
| 434 | if (!silent) |
| 435 | _nc_warning("Illegal character (expected alphanumeric or %s) - '%s'", |
| 436 | terminfo_punct, unctrl((chtype) ch)); |
| 437 | _nc_panic_mode(separator); |
| 438 | goto start_token; |
| 439 | } |
| 440 | |
| 441 | if (tok_buf == 0) |
| |
| 442 | tok_buf = typeMalloc(char, TOK_BUF_SIZE); |
| 48 | | Storing uninitialized value | |
|
| 443 | |
| 444 | #ifdef TRACE |
| 445 | old_line = _nc_curr_line; |
| 446 | old_col = _nc_curr_col; |
| 447 | #endif |
| 448 | tok_ptr = tok_buf; |
| 449 | AddCh(ch); |
| 450 | |
| 451 | if (first_column) { |
| |
| 452 | _nc_comment_start = token_start; |
| 453 | _nc_comment_end = _nc_curr_file_pos; |
| 454 | _nc_start_line = _nc_curr_line; |
| 455 | |
| 456 | _nc_syntax = ERR; |
| 457 | after_name = 0; |
| 458 | after_list = 0; |
| 459 | while ((ch = next_char()) != '\n') { |
| 50 | | Assuming the condition is false | |
|
| 51 | | Loop condition is false. Execution continues on line 496 | |
|
| 460 | if (ch == EOF) { |
| 461 | _nc_err_abort(MSG_NO_INPUTS); |
| 462 | } else if (ch == '|') { |
| 463 | after_list = tok_ptr; |
| 464 | if (after_name == 0) |
| 465 | after_name = tok_ptr; |
| 466 | } else if (ch == ':' && last_char() != ',') { |
| 467 | _nc_syntax = SYN_TERMCAP; |
| 468 | separator = ':'; |
| 469 | break; |
| 470 | } else if (ch == ',') { |
| 471 | _nc_syntax = SYN_TERMINFO; |
| 472 | separator = ','; |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | if (after_name == 0) |
| 478 | break; |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | } else |
| 487 | ch = eat_escaped_newline(ch); |
| 488 | |
| 489 | if (OkToAdd()) { |
| 490 | AddCh(ch); |
| 491 | } else { |
| 492 | ch = EOF; |
| 493 | break; |
| 494 | } |
| 495 | } |
| 496 | *tok_ptr = '\0'; |
| 497 | if (_nc_syntax == ERR) { |
| 52 | | Assuming the condition is false | |
|
| |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | _nc_syntax = SYN_TERMCAP; |
| 505 | separator = ':'; |
| 506 | } else if (_nc_syntax == SYN_TERMINFO) { |
| 54 | | Assuming '_nc_syntax' is not equal to SYN_TERMINFO | |
|
| |
| 507 | |
| 508 | for (--tok_ptr; |
| 509 | iswhite(*tok_ptr) || *tok_ptr == ','; |
| 510 | tok_ptr--) |
| 511 | continue; |
| 512 | tok_ptr[1] = '\0'; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | if (after_name != 0) { |
| |
| 521 | ch = *after_name; |
| 522 | *after_name = '\0'; |
| 523 | _nc_set_type(tok_buf); |
| 524 | *after_name = (char) ch; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | if (after_list != 0) { |
| |
| 532 | if (!silent) { |
| 533 | if (*after_list == '\0') |
| 534 | _nc_warning("empty longname field"); |
| 535 | else if (strchr(after_list, ' ') == 0) |
| 536 | _nc_warning("older tic versions may treat the description field as an alias"); |
| 537 | } |
| 538 | } else { |
| 539 | after_list = tok_buf + strlen(tok_buf); |
| 540 | DEBUG(1, ("missing description")); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | for (s = tok_buf; s < after_list; ++s) { |
| 58 | | Assuming 's' is < 'after_list' | |
|
| 59 | | Loop condition is true. Entering loop body | |
|
| 64 | | Assuming 's' is < 'after_list' | |
|
| 65 | | Loop condition is true. Entering loop body | |
|
| 70 | | Assuming 's' is < 'after_list' | |
|
| 71 | | Loop condition is true. Entering loop body | |
|
| 549 | if (isspace(UChar(*s))) { |
| |
| |
| 72 | | 1st function call argument is an uninitialized value |
|
| 550 | if (!silent) |
| 551 | _nc_warning("whitespace in name or alias field"); |
| 552 | break; |
| 553 | } else if (*s == '/') { |
| |
| |
| 554 | if (!silent) |
| 555 | _nc_warning("slashes aren't allowed in names or aliases"); |
| 556 | break; |
| 557 | } else if (strchr("$[]!*?", *s)) { |
| 62 | | Assuming the condition is false | |
|
| |
| 68 | | Assuming the condition is false | |
|
| |
| 558 | if (!silent) |
| 559 | _nc_warning("dubious character `%c' in name or alias field", *s); |
| 560 | break; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | _nc_curr_token.tk_name = tok_buf; |
| 565 | type = NAMES; |
| 566 | } else { |
| 567 | if (had_newline && _nc_syntax == SYN_TERMCAP) { |
| 568 | _nc_warning("Missing backslash before newline"); |
| 569 | had_newline = FALSE; |
| 570 | } |
| 571 | while ((ch = next_char()) != EOF) { |
| 572 | if (!isalnum(UChar(ch))) { |
| 573 | if (_nc_syntax == SYN_TERMINFO) { |
| 574 | if (ch != '_') |
| 575 | break; |
| 576 | } else { |
| 577 | if (ch != ';') |
| 578 | break; |
| 579 | } |
| 580 | } |
| 581 | if (OkToAdd()) { |
| 582 | AddCh(ch); |
| 583 | } else { |
| 584 | ch = EOF; |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | *tok_ptr++ = '\0'; |
| 590 | switch (ch) { |
| 591 | case ',': |
| 592 | case ':': |
| 593 | if (ch != separator) |
| 594 | _nc_err_abort("Separator inconsistent with syntax"); |
| 595 | _nc_curr_token.tk_name = tok_buf; |
| 596 | type = BOOLEAN; |
| 597 | break; |
| 598 | case '@': |
| 599 | if ((ch = next_char()) != separator && !silent) |
| 600 | _nc_warning("Missing separator after `%s', have %s", |
| 601 | tok_buf, unctrl((chtype) ch)); |
| 602 | _nc_curr_token.tk_name = tok_buf; |
| 603 | type = CANCEL; |
| 604 | break; |
| 605 | |
| 606 | case '#': |
| 607 | found = 0; |
| 608 | while (isalnum(ch = next_char())) { |
| 609 | numbuf[found++] = (char) ch; |
| 610 | if (found >= sizeof(numbuf) - 1) |
| 611 | break; |
| 612 | } |
| 613 | numbuf[found] = '\0'; |
| 614 | number = strtol(numbuf, &numchk, 0); |
| 615 | if (!silent) { |
| 616 | if (numchk == numbuf) |
| 617 | _nc_warning("no value given for `%s'", tok_buf); |
| 618 | if ((*numchk != '\0') || (ch != separator)) |
| 619 | _nc_warning("Missing separator"); |
| 620 | } |
| 621 | _nc_curr_token.tk_name = tok_buf; |
| 622 | _nc_curr_token.tk_valnumber = number; |
| 623 | type = NUMBER; |
| 624 | break; |
| 625 | |
| 626 | case '=': |
| 627 | ch = _nc_trans_string(tok_ptr, tok_buf + TOK_BUF_SIZE); |
| 628 | if (!silent && ch != separator) |
| 629 | _nc_warning("Missing separator"); |
| 630 | _nc_curr_token.tk_name = tok_buf; |
| 631 | _nc_curr_token.tk_valstring = tok_ptr; |
| 632 | type = STRING; |
| 633 | break; |
| 634 | |
| 635 | case EOF: |
| 636 | type = EOF; |
| 637 | break; |
| 638 | default: |
| 639 | |
| 640 | type = UNDEF; |
| 641 | if (!silent) |
| 642 | _nc_warning("Illegal character - '%s'", unctrl((chtype) ch)); |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | end_of_token: |
| 648 | |
| 649 | #ifdef TRACE |
| 650 | if (dot_flag == TRUE) |
| 651 | DEBUG(8, ("Commented out ")); |
| 652 | |
| 653 | if (_nc_tracing >= DEBUG_LEVEL(8)) { |
| 654 | _tracef("parsed %d.%d to %d.%d", |
| 655 | old_line, old_col, |
| 656 | _nc_curr_line, _nc_curr_col); |
| 657 | } |
| 658 | if (_nc_tracing >= DEBUG_LEVEL(7)) { |
| 659 | switch (type) { |
| 660 | case BOOLEAN: |
| 661 | _tracef("Token: Boolean; name='%s'", |
| 662 | _nc_curr_token.tk_name); |
| 663 | break; |
| 664 | |
| 665 | case NUMBER: |
| 666 | _tracef("Token: Number; name='%s', value=%d", |
| 667 | _nc_curr_token.tk_name, |
| 668 | _nc_curr_token.tk_valnumber); |
| 669 | break; |
| 670 | |
| 671 | case STRING: |
| 672 | _tracef("Token: String; name='%s', value=%s", |
| 673 | _nc_curr_token.tk_name, |
| 674 | _nc_visbuf(_nc_curr_token.tk_valstring)); |
| 675 | break; |
| 676 | |
| 677 | case CANCEL: |
| 678 | _tracef("Token: Cancel; name='%s'", |
| 679 | _nc_curr_token.tk_name); |
| 680 | break; |
| 681 | |
| 682 | case NAMES: |
| 683 | |
| 684 | _tracef("Token: Names; value='%s'", |
| 685 | _nc_curr_token.tk_name); |
| 686 | break; |
| 687 | |
| 688 | case EOF: |
| 689 | _tracef("Token: End of file"); |
| 690 | break; |
| 691 | |
| 692 | default: |
| 693 | _nc_warning("Bad token type"); |
| 694 | } |
| 695 | } |
| 696 | #endif |
| 697 | |
| 698 | if (dot_flag == TRUE) |
| 699 | type = _nc_get_token(silent); |
| 700 | |
| 701 | DEBUG(3, ("token: `%s', class %d", |
| 702 | ((_nc_curr_token.tk_name != 0) |
| 703 | ? _nc_curr_token.tk_name |
| 704 | : "<null>"), |
| 705 | type)); |
| 706 | |
| 707 | return (type); |
| 708 | } |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | NCURSES_EXPORT(int) |
| 730 | _nc_trans_string(char *ptr, char *last) |
| 731 | { |
| 732 | int count = 0; |
| 733 | int number = 0; |
| 734 | int i, c; |
| 735 | chtype ch, last_ch = '\0'; |
| 736 | bool ignored = FALSE; |
| 737 | bool long_warning = FALSE; |
| 738 | |
| 739 | while ((ch = c = next_char()) != (chtype) separator && c != EOF) { |
| 740 | if (ptr >= (last - 1)) { |
| 741 | if (c != EOF) { |
| 742 | while ((c = next_char()) != separator && c != EOF) { |
| 743 | ; |
| 744 | } |
| 745 | ch = c; |
| 746 | } |
| 747 | break; |
| 748 | } |
| 749 | if ((_nc_syntax == SYN_TERMCAP) && c == '\n') |
| 750 | break; |
| 751 | if (ch == '^' && last_ch != '%') { |
| 752 | ch = c = next_char(); |
| 753 | if (c == EOF) |
| 754 | _nc_err_abort(MSG_NO_INPUTS); |
| 755 | |
| 756 | if (!(is7bits(ch) && isprint(ch))) { |
| 757 | _nc_warning("Illegal ^ character - '%s'", unctrl(ch)); |
| 758 | } |
| 759 | if (ch == '?') { |
| 760 | *(ptr++) = '\177'; |
| 761 | if (_nc_tracing) |
| 762 | _nc_warning("Allow ^? as synonym for \\177"); |
| 763 | } else { |
| 764 | if ((ch &= 037) == 0) |
| 765 | ch = 128; |
| 766 | *(ptr++) = (char) (ch); |
| 767 | } |
| 768 | } else if (ch == '\\') { |
| 769 | ch = c = next_char(); |
| 770 | if (c == EOF) |
| 771 | _nc_err_abort(MSG_NO_INPUTS); |
| 772 | |
| 773 | if (ch >= '0' && ch <= '7') { |
| 774 | number = ch - '0'; |
| 775 | for (i = 0; i < 2; i++) { |
| 776 | ch = c = next_char(); |
| 777 | if (c == EOF) |
| 778 | _nc_err_abort(MSG_NO_INPUTS); |
| 779 | |
| 780 | if (c < '0' || c > '7') { |
| 781 | if (isdigit(c)) { |
| 782 | _nc_warning("Non-octal digit `%c' in \\ sequence", c); |
| 783 | |
| 784 | } else { |
| 785 | push_back((char) c); |
| 786 | break; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | number = number * 8 + c - '0'; |
| 791 | } |
| 792 | |
| 793 | if (number == 0) |
| 794 | number = 0200; |
| 795 | *(ptr++) = (char) number; |
| 796 | } else { |
| 797 | switch (c) { |
| 798 | case 'E': |
| 799 | case 'e': |
| 800 | *(ptr++) = '\033'; |
| 801 | break; |
| 802 | |
| 803 | case 'a': |
| 804 | *(ptr++) = '\007'; |
| 805 | break; |
| 806 | |
| 807 | case 'l': |
| 808 | case 'n': |
| 809 | *(ptr++) = '\n'; |
| 810 | break; |
| 811 | |
| 812 | case 'r': |
| 813 | *(ptr++) = '\r'; |
| 814 | break; |
| 815 | |
| 816 | case 'b': |
| 817 | *(ptr++) = '\010'; |
| 818 | break; |
| 819 | |
| 820 | case 's': |
| 821 | *(ptr++) = ' '; |
| 822 | break; |
| 823 | |
| 824 | case 'f': |
| 825 | *(ptr++) = '\014'; |
| 826 | break; |
| 827 | |
| 828 | case 't': |
| 829 | *(ptr++) = '\t'; |
| 830 | break; |
| 831 | |
| 832 | case '\\': |
| 833 | *(ptr++) = '\\'; |
| 834 | break; |
| 835 | |
| 836 | case '^': |
| 837 | *(ptr++) = '^'; |
| 838 | break; |
| 839 | |
| 840 | case ',': |
| 841 | *(ptr++) = ','; |
| 842 | break; |
| 843 | |
| 844 | case ':': |
| 845 | *(ptr++) = ':'; |
| 846 | break; |
| 847 | |
| 848 | case '\n': |
| 849 | continue; |
| 850 | |
| 851 | default: |
| 852 | _nc_warning("Illegal character '%s' in \\ sequence", |
| 853 | unctrl(ch)); |
| 854 | |
| 855 | case '|': |
| 856 | *(ptr++) = (char) ch; |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) { |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | ignored = TRUE; |
| 867 | } else { |
| 868 | *(ptr++) = (char) ch; |
| 869 | } |
| 870 | |
| 871 | if (!ignored) { |
| 872 | if (_nc_curr_col <= 1) { |
| 873 | push_back((char) ch); |
| 874 | ch = '\n'; |
| 875 | break; |
| 876 | } |
| 877 | last_ch = ch; |
| 878 | count++; |
| 879 | } |
| 880 | ignored = FALSE; |
| 881 | |
| 882 | if (count > MAXCAPLEN && !long_warning) { |
| 883 | _nc_warning("Very long string found. Missing separator?"); |
| 884 | long_warning = TRUE; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | *ptr = '\0'; |
| 889 | |
| 890 | return (ch); |
| 891 | } |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | NCURSES_EXPORT(void) |
| 901 | _nc_push_token(int tokclass) |
| 902 | { |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | pushtype = tokclass; |
| 910 | if (pushname == 0) |
| 911 | pushname = typeMalloc(char, MAX_NAME_SIZE + 1); |
| 912 | _nc_get_type(pushname); |
| 913 | |
| 914 | DEBUG(3, ("pushing token: `%s', class %d", |
| 915 | ((_nc_curr_token.tk_name != 0) |
| 916 | ? _nc_curr_token.tk_name |
| 917 | : "<null>"), |
| 918 | pushtype)); |
| 919 | } |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | NCURSES_EXPORT(void) |
| 925 | _nc_panic_mode(char ch) |
| 926 | { |
| 927 | int c; |
| 928 | |
| 929 | for (;;) { |
| 930 | c = next_char(); |
| 931 | if (c == ch) |
| 932 | return; |
| 933 | if (c == EOF) |
| 934 | return; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | #if NO_LEAKS |
| 939 | NCURSES_EXPORT(void) |
| 940 | _nc_comp_scan_leaks(void) |
| 941 | { |
| 942 | if (pushname != 0) { |
| 943 | FreeAndNull(pushname); |
| 944 | } |
| 945 | } |
| 946 | #endif |