• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

POSIX.1 National Language Support API for MinGW


Commit MetaInfo

Revisionc3620f65047fbf7b97f14348b45523f61da42196 (tree)
Zeit2007-05-12 07:48:17
AutorKeith Marshall <keithmarshall@user...>
CommiterKeith Marshall

Log Message

Miscellaneous comment and layout improvements.

Ändern Zusammenfassung

Diff

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
11 2007-05-11 Keith Marshall <keithmarshall@users.sourceforge.net>
22
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+
318 Avoid attempt to read input again, after EOF detected; this caused
419 strange behaviour if processing an interactive input stream.
520
--- a/include/debug.h
+++ b/include/debug.h
@@ -3,7 +3,7 @@
33 * debug.h
44 *
55 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
6- * Last modification: 02-Apr-2007
6+ * Last modification: 11-May-2007
77 *
88 * THIS SOFTWARE IS NOT COPYRIGHTED
99 *
@@ -25,7 +25,6 @@
2525 # define dinvoke(x) x
2626 # define dfprintf(x) fprintf x
2727 # define dfputc(x) fputc x
28-# define DCODEFMT "<escape: %#4.4x>"
2928 #else
3029 /*
3130 * ...or, to do nothing, if not building for debugging
@@ -35,4 +34,4 @@
3534 # define dfputc(x)
3635 #endif
3736
38-#endif /* !defined( DEBUG_H ): $RCSfile$Revision$: end of file */
37+#endif /* !defined( DEBUG_H ): $RCSfile$Revision: 1.1.1.1 $: end of file */
--- a/mcsource.c
+++ b/mcsource.c
@@ -9,7 +9,7 @@
99 * used internally by `gencat', to compile message dictionaries.
1010 *
1111 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
12- * Last modification: 27-Mar-2007
12+ * Last modification: 11-May-2007
1313 *
1414 *
1515 * 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 )
9595 /* Identify a GENCAT directive, based on a specified keyword,
9696 * and activate the appropriate parser attribute bits to process it.
9797 */
98-
9998 static struct directives
10099 {
101100 /* Defines the dictionary of known directives,
@@ -149,8 +148,11 @@ char *mc_default_codeset( void )
149148 }
150149
151150 static
152-int errout( const char *src, long linenum, const char *fmt, ... )
151+int mc_errout( const char *src, long linenum, const char *fmt, ... )
153152 {
153+ /* Message dispatcher for error messages,
154+ * used when `gencat_errno' is to be set to indicate `EXIT_FAILURE'.
155+ */
154156 va_list args;
155157 va_start( args, fmt );
156158 fprintf( stderr, "%s:%ld:", src, linenum );
@@ -160,7 +162,7 @@ int errout( const char *src, long linenum, const char *fmt, ... )
160162 }
161163
162164 static
163-off_t wanted( int fd )
165+off_t mc_workspace_wanted( int fd )
164166 {
165167 struct stat info;
166168 # ifndef DEBUG
@@ -175,17 +177,17 @@ off_t wanted( int fd )
175177 }
176178
177179 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 )
179181 {
180182 /* A trivial helper function, for encoding an escape sequence into the
181183 * compiled message stream.
182184 */
183- dfprintf(( stderr, DCODEFMT, code ));
185+ dfprintf(( stderr, "add escape code: %0#4.4x", code ));
184186 return iconv_wctomb( msgbuf, code );
185187 }
186188
187189 static
188-char *update_workspace( char *buf, char *cache, unsigned int count )
190+char *mc_update_workspace( char *buf, char *cache, unsigned int count )
189191 {
190192 # ifdef DEBUG
191193 unsigned int xcount = count;
@@ -238,7 +240,7 @@ struct msgdict *mc_source( const char *input )
238240 return NULL;
239241
240242 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 )
242244 return NULL;
243245
244246 msgloc = (off_t)(0);
@@ -291,7 +293,6 @@ struct msgdict *mc_source( const char *input )
291293 * Increment the line number, reset the parser context,
292294 * and clear the set/message number accumulator.
293295 */
294-
295296 ++linenum;
296297 status &= ~( DIRECTIVE | NUMERIC | CATEGORY );
297298 accumulator = 0;
@@ -301,7 +302,6 @@ struct msgdict *mc_source( const char *input )
301302 /* When this new line is NOT simply a logical continuation
302303 * of the previous line...
303304 */
304-
305305 status &= ~MSGTEXT;
306306 dfprintf(( stderr, "\n\n%s:%d:new input record", input, linenum ));
307307 if( c == '$' )
@@ -310,7 +310,6 @@ struct msgdict *mc_source( const char *input )
310310 * means that this line is either a `gencat' directive,
311311 * or it's a comment.
312312 */
313-
314313 status |= DIRECTIVE;
315314 id = keyword;
316315 }
@@ -320,7 +319,6 @@ struct msgdict *mc_source( const char *input )
320319 /* This is a message definition line,
321320 * with a the message identified by an explicit numeric key.
322321 */
323-
324322 status |= NUMERIC;
325323 accumulator = c - L'0';
326324 }
@@ -333,7 +331,6 @@ struct msgdict *mc_source( const char *input )
333331 * then we need to include the current input character
334332 * as part of the message definition.
335333 */
336-
337334 if( c == quote )
338335 {
339336 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 )
350347 /* Now, we dealt with the new line conditions,
351348 * so clear the related NEWLINE and CONTINUATION flags.
352349 */
353-
354350 status &= ~( NEWLINE | CONTINUED );
355351 }
356352
@@ -360,12 +356,10 @@ struct msgdict *mc_source( const char *input )
360356 * which persists until a space character marks the end of the
361357 * directive identifying keyword.
362358 */
363-
364359 if( isspace( c ) )
365360 {
366361 /* We found the keyword delimiting space ...
367362 */
368-
369363 if( id == keyword )
370364 {
371365 /* But, we didn't find any keyword...
@@ -374,7 +368,6 @@ struct msgdict *mc_source( const char *input )
374368 * a codeset declaration comment, so we can't simply ignore it;
375369 * set the comment state, to parse any codeset assignment.
376370 */
377-
378371 status = (status & ~CATEGORY) | DEFCONV;
379372 dfprintf(( stderr, "\n%s:%u:record type: comment", input, linenum ));
380373 }
@@ -419,7 +412,6 @@ struct msgdict *mc_source( const char *input )
419412 * We have identified a possible match for a directive keyword;
420413 * identify it, and establish its associated parser state.
421414 */
422-
423415 *id = '\0';
424416 status = mc_directive( status, keyword );
425417 dfprintf(( stderr, "\n%s:%u:record type: directive: %s", input, linenum, keyword ));
@@ -432,7 +424,6 @@ struct msgdict *mc_source( const char *input )
432424 /* We are still parsing a potential directive keyword;
433425 * add the current character to the keyword parse buffer.
434426 */
435-
436427 if( (id - keyword) < (sizeof( keyword ) - 1) )
437428 *id++ = c;
438429 }
@@ -442,13 +433,11 @@ struct msgdict *mc_source( const char *input )
442433 {
443434 /* We are parsing a numeric value...
444435 */
445-
446436 if( isdigit( c ) )
447437 {
448438 /* ...and the current character is part of the number,
449439 * so add it into the accumulator.
450440 */
451-
452441 accumulator = accumulator * 10 + c - L'0';
453442 }
454443
@@ -458,16 +447,13 @@ struct msgdict *mc_source( const char *input )
458447 * so hand it off as a set number, or a message number,
459448 * and process as appropriate.
460449 */
461-
462450 switch( status & CATEGORY )
463451 {
464452 case ADDSET:
465453 /*
466454 * Invoked by a "set" directive,
467455 * open a new numbered message set within the catalogue ...
468- *
469456 */
470-
471457 dfprintf(( stderr, ": add set with id = %ld", accumulator ));
472458 if( accumulator > setnum )
473459 {
@@ -479,7 +465,6 @@ struct msgdict *mc_source( const char *input )
479465 * so we can simply create a new message set with this "setnum",
480466 * and reset the "msgnum", for the start of a new set.
481467 */
482-
483468 setnum = accumulator;
484469 msgnum = 0;
485470 }
@@ -489,9 +474,8 @@ struct msgdict *mc_source( const char *input )
489474 /* This "setnum" entry DOESN'T satisfy the ascending order rule,
490475 * so complain, and bail out.
491476 */
492-
493477 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 );
495479 return NULL;
496480 }
497481 break;
@@ -500,7 +484,6 @@ struct msgdict *mc_source( const char *input )
500484 /*
501485 * Invoked by a "delset" directive,
502486 * mark a numbered message set for deletion from the catalogue.
503- *
504487 */
505488 dfprintf(( stderr, ": delete set with id = %ld", accumulator ));
506489 if( (accumulator > 0) && (accumulator <= NL_SETMAX) )
@@ -511,7 +494,6 @@ struct msgdict *mc_source( const char *input )
511494 /* We successfully created an empty dictionary slot,
512495 * so fill it in as a `delset' request entry.
513496 */
514-
515497 this->src = input;
516498 this->lineno = linenum;
517499 this->base = NULL;
@@ -522,7 +504,6 @@ struct msgdict *mc_source( const char *input )
522504 /* The catalogue currently contains no records,
523505 * so simply insert this as the first one.
524506 */
525-
526507 head = tail = this;
527508 this->link = NULL;
528509 }
@@ -532,7 +513,6 @@ struct msgdict *mc_source( const char *input )
532513 /* We've already added some message records,
533514 * so the new one must be added at the end.
534515 */
535-
536516 this->link = tail->link;
537517 tail->link = this;
538518 tail = this;
@@ -549,7 +529,6 @@ struct msgdict *mc_source( const char *input )
549529 * message defined in the current set; this declaration satisfies
550530 * this requirement, so add a new message to the catalogue.
551531 */
552-
553532 struct msgdict *this;
554533 if( (this = mc_malloc( sizeof( struct msgdict ))) != NULL )
555534 {
@@ -559,14 +538,12 @@ struct msgdict *mc_source( const char *input )
559538 * first check that one has been opened; if not, we
560539 * simply open the default set.
561540 */
562-
563541 if( setnum == 0 )
564542 setnum = NL_SETD;
565543
566544 /* We may now complete the message details in the new
567545 * dictionary slot, and commit the record to the catalogue.
568546 */
569-
570547 this->src = input;
571548 this->base = messages;
572549 this->lineno = linenum;
@@ -578,7 +555,6 @@ struct msgdict *mc_source( const char *input )
578555 /* The catalogue currently contains no records,
579556 * so simply insert this as the first one.
580557 */
581-
582558 head = tail = this;
583559 this->link = NULL;
584560 }
@@ -588,7 +564,6 @@ struct msgdict *mc_source( const char *input )
588564 /* We've already added some message records,
589565 * so the new one must be added at the end.
590566 */
591-
592567 this->link = tail->link;
593568 tail->link = this;
594569 tail = this;
@@ -601,9 +576,8 @@ struct msgdict *mc_source( const char *input )
601576 /* This doesn't satisfy the requirement for incrementing "msgnum",
602577 * so complain, and bail out.
603578 */
604-
605579 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 );
607581 return NULL;
608582 }
609583 status |= ( MSGTEXT | ENCODED );
@@ -625,7 +599,6 @@ struct msgdict *mc_source( const char *input )
625599 * defining the "quote" character to be used, or "none" if no other
626600 * character appears before end of line.
627601 */
628-
629602 quote = (c == L'\n') ? L'\0' : c;
630603 dfprintf(( stderr, quote ? ": assigned as %#4.4x" : ": none assigned", quote ));
631604 status &= ~( CATEGORY | ENCODED );
@@ -637,34 +610,32 @@ struct msgdict *mc_source( const char *input )
637610 * Continue scanning the current input line,
638611 * until we find the end-of-line marker.
639612 */
640-
641613 if( c != L'\n' )
642614 {
643615 /* We haven't reached end-of-line yet...
644616 * Check for other characters with special significance.
645617 */
646-
647618 if( status & ESCAPE )
648619 {
649620 /* The current input character was escaped...
650621 * Clear the ESCAPE flag, and interpret this case.
651622 */
652-
653623 size_t len = 0;
654624 status &= ~ESCAPE;
625+ dfprintf(( stderr, "%s:%u:", input, linenum ));
655626 switch ( c )
656627 {
657628 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' );
659630 break;
660631
661632 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' );
663634 break;
664635
665636 default: /* not a special case; just pass it through */
666637 xcount += skip;
667- dfputc(( c, stderr ));
638+ dfprintf(( stderr, "pass through escape code: %0#4.4x", c ));
668639 }
669640 if( len > (size_t)(0) )
670641 {
@@ -679,7 +650,6 @@ struct msgdict *mc_source( const char *input )
679650 * Set the parser flags, so that any cached message data is flushed,
680651 * and switch to ESCAPE mode, to interpret the next character.
681652 */
682-
683653 status |= FLUSH | ESCAPE;
684654 }
685655
@@ -708,19 +678,16 @@ struct msgdict *mc_source( const char *input )
708678 * and schedule any pending message data from this line
709679 * for flushing to the message collection buffer.
710680 */
711-
712681 status |= NEWLINE | FLUSH;
713682
714683 /* If "QUOTED" context remains active, at the end of this line,
715684 * then we have an implicit continuation, so force it.
716685 */
717-
718686 if( (status & QUOTED) == QUOTED )
719687 status |= CONTINUED;
720688
721689 /* Clean up the context of any pending directive processing.
722690 */
723-
724691 switch( status & CATEGORY )
725692 {
726693 case DEFQUOTE:
@@ -729,7 +696,6 @@ struct msgdict *mc_source( const char *input )
729696 * then there was no defining character with the "quote" directive,
730697 * so we must disable "quote" character recognition.
731698 */
732-
733699 quote = L'\0';
734700 dfprintf(( stderr, ": none assigned" ));
735701 break;
@@ -754,13 +720,14 @@ struct msgdict *mc_source( const char *input )
754720 dfprintf(( stderr, "<grow allocation to %u bytes>", (unsigned)(msgloc + headroom) ));
755721 if( (messages = realloc( messages, msgloc + headroom )) == NULL )
756722 {
757- gencat_errno = errout( FATAL( MSG_OUT_OF_MEMORY ));
723+ gencat_errno = mc_errout( FATAL( MSG_OUT_OF_MEMORY ));
758724 return NULL;
759725 }
760726 }
761727 headroom -= xcount;
762728 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;
764731 dfprintf(( stderr, "; %u byte%s free\n", headroom, headroom == 1 ? "" : "s" ));
765732 if( (status & (MSGTEXT | NEWLINE | CONTINUED)) == (MSGTEXT | NEWLINE) )
766733 {
@@ -882,4 +849,4 @@ struct msgdict *mc_source( const char *input )
882849 return head;
883850 }
884851
885-/* $RCSfile$Revision: 1.3 $: end of file */
852+/* $RCSfile$Revision: 1.4 $: end of file */