POSIX.1 National Language Support API for MinGW
Revisión | c3620f65047fbf7b97f14348b45523f61da42196 (tree) |
---|---|
Tiempo | 2007-05-12 07:48:17 |
Autor | Keith Marshall <keithmarshall@user...> |
Commiter | Keith Marshall |
Miscellaneous comment and layout improvements.
@@ -1,5 +1,20 @@ | ||
1 | 1 | 2007-05-11 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 2 | |
3 | + * mcsource.c: Miscellaneous comment and layout improvements; | |
4 | + improved formatting of some debugging/tracing messages. | |
5 | + (add_escape): Static function renamed... | |
6 | + (mc_add_escape): ...to this. | |
7 | + (wanted): Static function renamed... | |
8 | + (mc_workspace_wanted): ...to this. | |
9 | + (update_workspace): Static function renamed... | |
10 | + (mc_update_workspace): ...to this. | |
11 | + (errout): Static function renamed... | |
12 | + (mc_errout): ...to this. | |
13 | + | |
14 | + * include/debug.h (DCODEFMT): Redundant macro; deleted. | |
15 | + | |
16 | +2007-05-11 Keith Marshall <keithmarshall@users.sourceforge.net> | |
17 | + | |
3 | 18 | Avoid attempt to read input again, after EOF detected; this caused |
4 | 19 | strange behaviour if processing an interactive input stream. |
5 | 20 |
@@ -3,7 +3,7 @@ | ||
3 | 3 | * debug.h |
4 | 4 | * |
5 | 5 | * Written by Keith Marshall <keithmarshall@users.sourceforge.net> |
6 | - * Last modification: 02-Apr-2007 | |
6 | + * Last modification: 11-May-2007 | |
7 | 7 | * |
8 | 8 | * THIS SOFTWARE IS NOT COPYRIGHTED |
9 | 9 | * |
@@ -25,7 +25,6 @@ | ||
25 | 25 | # define dinvoke(x) x |
26 | 26 | # define dfprintf(x) fprintf x |
27 | 27 | # define dfputc(x) fputc x |
28 | -# define DCODEFMT "<escape: %#4.4x>" | |
29 | 28 | #else |
30 | 29 | /* |
31 | 30 | * ...or, to do nothing, if not building for debugging |
@@ -35,4 +34,4 @@ | ||
35 | 34 | # define dfputc(x) |
36 | 35 | #endif |
37 | 36 | |
38 | -#endif /* !defined( DEBUG_H ): $RCSfile$Revision$: end of file */ | |
37 | +#endif /* !defined( DEBUG_H ): $RCSfile$Revision: 1.1.1.1 $: end of file */ |
@@ -9,7 +9,7 @@ | ||
9 | 9 | * used internally by `gencat', to compile message dictionaries. |
10 | 10 | * |
11 | 11 | * Written by Keith Marshall <keithmarshall@users.sourceforge.net> |
12 | - * Last modification: 27-Mar-2007 | |
12 | + * Last modification: 11-May-2007 | |
13 | 13 | * |
14 | 14 | * |
15 | 15 | * This is free software. It is provided AS IS, in the hope that it may |
@@ -95,7 +95,6 @@ int mc_directive( int status, const char *keyword ) | ||
95 | 95 | /* Identify a GENCAT directive, based on a specified keyword, |
96 | 96 | * and activate the appropriate parser attribute bits to process it. |
97 | 97 | */ |
98 | - | |
99 | 98 | static struct directives |
100 | 99 | { |
101 | 100 | /* Defines the dictionary of known directives, |
@@ -149,8 +148,11 @@ char *mc_default_codeset( void ) | ||
149 | 148 | } |
150 | 149 | |
151 | 150 | static |
152 | -int errout( const char *src, long linenum, const char *fmt, ... ) | |
151 | +int mc_errout( const char *src, long linenum, const char *fmt, ... ) | |
153 | 152 | { |
153 | + /* Message dispatcher for error messages, | |
154 | + * used when `gencat_errno' is to be set to indicate `EXIT_FAILURE'. | |
155 | + */ | |
154 | 156 | va_list args; |
155 | 157 | va_start( args, fmt ); |
156 | 158 | fprintf( stderr, "%s:%ld:", src, linenum ); |
@@ -160,7 +162,7 @@ int errout( const char *src, long linenum, const char *fmt, ... ) | ||
160 | 162 | } |
161 | 163 | |
162 | 164 | static |
163 | -off_t wanted( int fd ) | |
165 | +off_t mc_workspace_wanted( int fd ) | |
164 | 166 | { |
165 | 167 | struct stat info; |
166 | 168 | # ifndef DEBUG |
@@ -175,17 +177,17 @@ off_t wanted( int fd ) | ||
175 | 177 | } |
176 | 178 | |
177 | 179 | static |
178 | -size_t add_escape( iconv_t *iconv_map, char *msgbuf, wchar_t code ) | |
180 | +size_t mc_add_escape( iconv_t *iconv_map, char *msgbuf, wchar_t code ) | |
179 | 181 | { |
180 | 182 | /* A trivial helper function, for encoding an escape sequence into the |
181 | 183 | * compiled message stream. |
182 | 184 | */ |
183 | - dfprintf(( stderr, DCODEFMT, code )); | |
185 | + dfprintf(( stderr, "add escape code: %0#4.4x", code )); | |
184 | 186 | return iconv_wctomb( msgbuf, code ); |
185 | 187 | } |
186 | 188 | |
187 | 189 | static |
188 | -char *update_workspace( char *buf, char *cache, unsigned int count ) | |
190 | +char *mc_update_workspace( char *buf, char *cache, unsigned int count ) | |
189 | 191 | { |
190 | 192 | # ifdef DEBUG |
191 | 193 | unsigned int xcount = count; |
@@ -238,7 +240,7 @@ struct msgdict *mc_source( const char *input ) | ||
238 | 240 | return NULL; |
239 | 241 | |
240 | 242 | dfprintf(( stderr, "\n%s:new source file\n%s:", input, input )); |
241 | - if( (messages = mc_malloc( headroom = wanted( fd ))) == NULL ) | |
243 | + if( (messages = mc_malloc( headroom = mc_workspace_wanted( fd ))) == NULL ) | |
242 | 244 | return NULL; |
243 | 245 | |
244 | 246 | msgloc = (off_t)(0); |
@@ -291,7 +293,6 @@ struct msgdict *mc_source( const char *input ) | ||
291 | 293 | * Increment the line number, reset the parser context, |
292 | 294 | * and clear the set/message number accumulator. |
293 | 295 | */ |
294 | - | |
295 | 296 | ++linenum; |
296 | 297 | status &= ~( DIRECTIVE | NUMERIC | CATEGORY ); |
297 | 298 | accumulator = 0; |
@@ -301,7 +302,6 @@ struct msgdict *mc_source( const char *input ) | ||
301 | 302 | /* When this new line is NOT simply a logical continuation |
302 | 303 | * of the previous line... |
303 | 304 | */ |
304 | - | |
305 | 305 | status &= ~MSGTEXT; |
306 | 306 | dfprintf(( stderr, "\n\n%s:%d:new input record", input, linenum )); |
307 | 307 | if( c == '$' ) |
@@ -310,7 +310,6 @@ struct msgdict *mc_source( const char *input ) | ||
310 | 310 | * means that this line is either a `gencat' directive, |
311 | 311 | * or it's a comment. |
312 | 312 | */ |
313 | - | |
314 | 313 | status |= DIRECTIVE; |
315 | 314 | id = keyword; |
316 | 315 | } |
@@ -320,7 +319,6 @@ struct msgdict *mc_source( const char *input ) | ||
320 | 319 | /* This is a message definition line, |
321 | 320 | * with a the message identified by an explicit numeric key. |
322 | 321 | */ |
323 | - | |
324 | 322 | status |= NUMERIC; |
325 | 323 | accumulator = c - L'0'; |
326 | 324 | } |
@@ -333,7 +331,6 @@ struct msgdict *mc_source( const char *input ) | ||
333 | 331 | * then we need to include the current input character |
334 | 332 | * as part of the message definition. |
335 | 333 | */ |
336 | - | |
337 | 334 | if( c == quote ) |
338 | 335 | { |
339 | 336 | dfprintf(( stderr, "\n%s:%u:%s quoted context", input, linenum, (status & QUOTED) ? "end" : "begin" )); |
@@ -350,7 +347,6 @@ struct msgdict *mc_source( const char *input ) | ||
350 | 347 | /* Now, we dealt with the new line conditions, |
351 | 348 | * so clear the related NEWLINE and CONTINUATION flags. |
352 | 349 | */ |
353 | - | |
354 | 350 | status &= ~( NEWLINE | CONTINUED ); |
355 | 351 | } |
356 | 352 |
@@ -360,12 +356,10 @@ struct msgdict *mc_source( const char *input ) | ||
360 | 356 | * which persists until a space character marks the end of the |
361 | 357 | * directive identifying keyword. |
362 | 358 | */ |
363 | - | |
364 | 359 | if( isspace( c ) ) |
365 | 360 | { |
366 | 361 | /* We found the keyword delimiting space ... |
367 | 362 | */ |
368 | - | |
369 | 363 | if( id == keyword ) |
370 | 364 | { |
371 | 365 | /* But, we didn't find any keyword... |
@@ -374,7 +368,6 @@ struct msgdict *mc_source( const char *input ) | ||
374 | 368 | * a codeset declaration comment, so we can't simply ignore it; |
375 | 369 | * set the comment state, to parse any codeset assignment. |
376 | 370 | */ |
377 | - | |
378 | 371 | status = (status & ~CATEGORY) | DEFCONV; |
379 | 372 | dfprintf(( stderr, "\n%s:%u:record type: comment", input, linenum )); |
380 | 373 | } |
@@ -419,7 +412,6 @@ struct msgdict *mc_source( const char *input ) | ||
419 | 412 | * We have identified a possible match for a directive keyword; |
420 | 413 | * identify it, and establish its associated parser state. |
421 | 414 | */ |
422 | - | |
423 | 415 | *id = '\0'; |
424 | 416 | status = mc_directive( status, keyword ); |
425 | 417 | dfprintf(( stderr, "\n%s:%u:record type: directive: %s", input, linenum, keyword )); |
@@ -432,7 +424,6 @@ struct msgdict *mc_source( const char *input ) | ||
432 | 424 | /* We are still parsing a potential directive keyword; |
433 | 425 | * add the current character to the keyword parse buffer. |
434 | 426 | */ |
435 | - | |
436 | 427 | if( (id - keyword) < (sizeof( keyword ) - 1) ) |
437 | 428 | *id++ = c; |
438 | 429 | } |
@@ -442,13 +433,11 @@ struct msgdict *mc_source( const char *input ) | ||
442 | 433 | { |
443 | 434 | /* We are parsing a numeric value... |
444 | 435 | */ |
445 | - | |
446 | 436 | if( isdigit( c ) ) |
447 | 437 | { |
448 | 438 | /* ...and the current character is part of the number, |
449 | 439 | * so add it into the accumulator. |
450 | 440 | */ |
451 | - | |
452 | 441 | accumulator = accumulator * 10 + c - L'0'; |
453 | 442 | } |
454 | 443 |
@@ -458,16 +447,13 @@ struct msgdict *mc_source( const char *input ) | ||
458 | 447 | * so hand it off as a set number, or a message number, |
459 | 448 | * and process as appropriate. |
460 | 449 | */ |
461 | - | |
462 | 450 | switch( status & CATEGORY ) |
463 | 451 | { |
464 | 452 | case ADDSET: |
465 | 453 | /* |
466 | 454 | * Invoked by a "set" directive, |
467 | 455 | * open a new numbered message set within the catalogue ... |
468 | - * | |
469 | 456 | */ |
470 | - | |
471 | 457 | dfprintf(( stderr, ": add set with id = %ld", accumulator )); |
472 | 458 | if( accumulator > setnum ) |
473 | 459 | { |
@@ -479,7 +465,6 @@ struct msgdict *mc_source( const char *input ) | ||
479 | 465 | * so we can simply create a new message set with this "setnum", |
480 | 466 | * and reset the "msgnum", for the start of a new set. |
481 | 467 | */ |
482 | - | |
483 | 468 | setnum = accumulator; |
484 | 469 | msgnum = 0; |
485 | 470 | } |
@@ -489,9 +474,8 @@ struct msgdict *mc_source( const char *input ) | ||
489 | 474 | /* This "setnum" entry DOESN'T satisfy the ascending order rule, |
490 | 475 | * so complain, and bail out. |
491 | 476 | */ |
492 | - | |
493 | 477 | dfputc(( '\n', stderr )); |
494 | - gencat_errno = errout( FATAL( MSG_SETNUM_NOT_INCR ), setnum, accumulator ); | |
478 | + gencat_errno = mc_errout( FATAL( MSG_SETNUM_NOT_INCR ), setnum, accumulator ); | |
495 | 479 | return NULL; |
496 | 480 | } |
497 | 481 | break; |
@@ -500,7 +484,6 @@ struct msgdict *mc_source( const char *input ) | ||
500 | 484 | /* |
501 | 485 | * Invoked by a "delset" directive, |
502 | 486 | * mark a numbered message set for deletion from the catalogue. |
503 | - * | |
504 | 487 | */ |
505 | 488 | dfprintf(( stderr, ": delete set with id = %ld", accumulator )); |
506 | 489 | if( (accumulator > 0) && (accumulator <= NL_SETMAX) ) |
@@ -511,7 +494,6 @@ struct msgdict *mc_source( const char *input ) | ||
511 | 494 | /* We successfully created an empty dictionary slot, |
512 | 495 | * so fill it in as a `delset' request entry. |
513 | 496 | */ |
514 | - | |
515 | 497 | this->src = input; |
516 | 498 | this->lineno = linenum; |
517 | 499 | this->base = NULL; |
@@ -522,7 +504,6 @@ struct msgdict *mc_source( const char *input ) | ||
522 | 504 | /* The catalogue currently contains no records, |
523 | 505 | * so simply insert this as the first one. |
524 | 506 | */ |
525 | - | |
526 | 507 | head = tail = this; |
527 | 508 | this->link = NULL; |
528 | 509 | } |
@@ -532,7 +513,6 @@ struct msgdict *mc_source( const char *input ) | ||
532 | 513 | /* We've already added some message records, |
533 | 514 | * so the new one must be added at the end. |
534 | 515 | */ |
535 | - | |
536 | 516 | this->link = tail->link; |
537 | 517 | tail->link = this; |
538 | 518 | tail = this; |
@@ -549,7 +529,6 @@ struct msgdict *mc_source( const char *input ) | ||
549 | 529 | * message defined in the current set; this declaration satisfies |
550 | 530 | * this requirement, so add a new message to the catalogue. |
551 | 531 | */ |
552 | - | |
553 | 532 | struct msgdict *this; |
554 | 533 | if( (this = mc_malloc( sizeof( struct msgdict ))) != NULL ) |
555 | 534 | { |
@@ -559,14 +538,12 @@ struct msgdict *mc_source( const char *input ) | ||
559 | 538 | * first check that one has been opened; if not, we |
560 | 539 | * simply open the default set. |
561 | 540 | */ |
562 | - | |
563 | 541 | if( setnum == 0 ) |
564 | 542 | setnum = NL_SETD; |
565 | 543 | |
566 | 544 | /* We may now complete the message details in the new |
567 | 545 | * dictionary slot, and commit the record to the catalogue. |
568 | 546 | */ |
569 | - | |
570 | 547 | this->src = input; |
571 | 548 | this->base = messages; |
572 | 549 | this->lineno = linenum; |
@@ -578,7 +555,6 @@ struct msgdict *mc_source( const char *input ) | ||
578 | 555 | /* The catalogue currently contains no records, |
579 | 556 | * so simply insert this as the first one. |
580 | 557 | */ |
581 | - | |
582 | 558 | head = tail = this; |
583 | 559 | this->link = NULL; |
584 | 560 | } |
@@ -588,7 +564,6 @@ struct msgdict *mc_source( const char *input ) | ||
588 | 564 | /* We've already added some message records, |
589 | 565 | * so the new one must be added at the end. |
590 | 566 | */ |
591 | - | |
592 | 567 | this->link = tail->link; |
593 | 568 | tail->link = this; |
594 | 569 | tail = this; |
@@ -601,9 +576,8 @@ struct msgdict *mc_source( const char *input ) | ||
601 | 576 | /* This doesn't satisfy the requirement for incrementing "msgnum", |
602 | 577 | * so complain, and bail out. |
603 | 578 | */ |
604 | - | |
605 | 579 | dfputc(( '\n', stderr )); |
606 | - gencat_errno = errout( FATAL( MSG_MSGNUM_NOT_INCR ), msgnum, accumulator ); | |
580 | + gencat_errno = mc_errout( FATAL( MSG_MSGNUM_NOT_INCR ), msgnum, accumulator ); | |
607 | 581 | return NULL; |
608 | 582 | } |
609 | 583 | status |= ( MSGTEXT | ENCODED ); |
@@ -625,7 +599,6 @@ struct msgdict *mc_source( const char *input ) | ||
625 | 599 | * defining the "quote" character to be used, or "none" if no other |
626 | 600 | * character appears before end of line. |
627 | 601 | */ |
628 | - | |
629 | 602 | quote = (c == L'\n') ? L'\0' : c; |
630 | 603 | dfprintf(( stderr, quote ? ": assigned as %#4.4x" : ": none assigned", quote )); |
631 | 604 | status &= ~( CATEGORY | ENCODED ); |
@@ -637,34 +610,32 @@ struct msgdict *mc_source( const char *input ) | ||
637 | 610 | * Continue scanning the current input line, |
638 | 611 | * until we find the end-of-line marker. |
639 | 612 | */ |
640 | - | |
641 | 613 | if( c != L'\n' ) |
642 | 614 | { |
643 | 615 | /* We haven't reached end-of-line yet... |
644 | 616 | * Check for other characters with special significance. |
645 | 617 | */ |
646 | - | |
647 | 618 | if( status & ESCAPE ) |
648 | 619 | { |
649 | 620 | /* The current input character was escaped... |
650 | 621 | * Clear the ESCAPE flag, and interpret this case. |
651 | 622 | */ |
652 | - | |
653 | 623 | size_t len = 0; |
654 | 624 | status &= ~ESCAPE; |
625 | + dfprintf(( stderr, "%s:%u:", input, linenum )); | |
655 | 626 | switch ( c ) |
656 | 627 | { |
657 | 628 | case L'r': /* embed a carriage return */ |
658 | - len = add_escape( iconv_map, messages + msgloc, L'\r' ); | |
629 | + len = mc_add_escape( iconv_map, messages + msgloc, L'\r' ); | |
659 | 630 | break; |
660 | 631 | |
661 | 632 | case L'n': /* embed a newline */ |
662 | - len = add_escape( iconv_map, messages + msgloc, L'\n' ); | |
633 | + len = mc_add_escape( iconv_map, messages + msgloc, L'\n' ); | |
663 | 634 | break; |
664 | 635 | |
665 | 636 | default: /* not a special case; just pass it through */ |
666 | 637 | xcount += skip; |
667 | - dfputc(( c, stderr )); | |
638 | + dfprintf(( stderr, "pass through escape code: %0#4.4x", c )); | |
668 | 639 | } |
669 | 640 | if( len > (size_t)(0) ) |
670 | 641 | { |
@@ -679,7 +650,6 @@ struct msgdict *mc_source( const char *input ) | ||
679 | 650 | * Set the parser flags, so that any cached message data is flushed, |
680 | 651 | * and switch to ESCAPE mode, to interpret the next character. |
681 | 652 | */ |
682 | - | |
683 | 653 | status |= FLUSH | ESCAPE; |
684 | 654 | } |
685 | 655 |
@@ -708,19 +678,16 @@ struct msgdict *mc_source( const char *input ) | ||
708 | 678 | * and schedule any pending message data from this line |
709 | 679 | * for flushing to the message collection buffer. |
710 | 680 | */ |
711 | - | |
712 | 681 | status |= NEWLINE | FLUSH; |
713 | 682 | |
714 | 683 | /* If "QUOTED" context remains active, at the end of this line, |
715 | 684 | * then we have an implicit continuation, so force it. |
716 | 685 | */ |
717 | - | |
718 | 686 | if( (status & QUOTED) == QUOTED ) |
719 | 687 | status |= CONTINUED; |
720 | 688 | |
721 | 689 | /* Clean up the context of any pending directive processing. |
722 | 690 | */ |
723 | - | |
724 | 691 | switch( status & CATEGORY ) |
725 | 692 | { |
726 | 693 | case DEFQUOTE: |
@@ -729,7 +696,6 @@ struct msgdict *mc_source( const char *input ) | ||
729 | 696 | * then there was no defining character with the "quote" directive, |
730 | 697 | * so we must disable "quote" character recognition. |
731 | 698 | */ |
732 | - | |
733 | 699 | quote = L'\0'; |
734 | 700 | dfprintf(( stderr, ": none assigned" )); |
735 | 701 | break; |
@@ -754,13 +720,14 @@ struct msgdict *mc_source( const char *input ) | ||
754 | 720 | dfprintf(( stderr, "<grow allocation to %u bytes>", (unsigned)(msgloc + headroom) )); |
755 | 721 | if( (messages = realloc( messages, msgloc + headroom )) == NULL ) |
756 | 722 | { |
757 | - gencat_errno = errout( FATAL( MSG_OUT_OF_MEMORY )); | |
723 | + gencat_errno = mc_errout( FATAL( MSG_OUT_OF_MEMORY )); | |
758 | 724 | return NULL; |
759 | 725 | } |
760 | 726 | } |
761 | 727 | headroom -= xcount; |
762 | 728 | dfprintf(( stderr, "\n%s:%u:", input, linenum )); |
763 | - msgloc = update_workspace( messages + msgloc, p - xcount - skip, xcount ) - messages; | |
729 | + msgloc = mc_update_workspace( messages + msgloc, p - xcount - skip, xcount ) | |
730 | + - messages; | |
764 | 731 | dfprintf(( stderr, "; %u byte%s free\n", headroom, headroom == 1 ? "" : "s" )); |
765 | 732 | if( (status & (MSGTEXT | NEWLINE | CONTINUED)) == (MSGTEXT | NEWLINE) ) |
766 | 733 | { |
@@ -882,4 +849,4 @@ struct msgdict *mc_source( const char *input ) | ||
882 | 849 | return head; |
883 | 850 | } |
884 | 851 | |
885 | -/* $RCSfile$Revision: 1.3 $: end of file */ | |
852 | +/* $RCSfile$Revision: 1.4 $: end of file */ |