📄 errors.c
字号:
nErrors [ErrorClass] ++; (* HandleMessage) (rfalse, MakeIdent (ErrorText, strlen (ErrorText)), ErrorClass, Position, InfoClass, Info);}static void WriteHead#if defined __STDC__ | defined __cplusplus (tPosition Position, int ErrorClass)#else (Position, ErrorClass) tPosition Position; int ErrorClass;#endif{#ifndef _USRDLL if (Out == NULL) Out = stderr;#endif if (Position.Line != 0) { WritePosition (Out, Position); (void) fputs (": ", Out); } switch (ErrorClass) { case xxFatal : (void) fputs ("Fatal ", Out); break; case xxRestriction : (void) fputs ("Restriction ", Out); break; case xxError : (void) fputs ("Error ", Out); break; case xxWarning : (void) fputs ("Warning ", Out); break; case xxRepair : (void) fputs ("Repair ", Out); break; case xxNote : (void) fputs ("Note ", Out); break; case xxInformation : (void) fputs ("Information ", Out); break; default : (void) fprintf (Out, "Error class: %d ", ErrorClass); }}static void WriteCode#if defined __STDC__ | defined __cplusplus (long ErrorCode)#else (ErrorCode) long ErrorCode;#endif{ switch (ErrorCode) { case xxNoText : break; case xxSyntaxError : (void) fputs ("syntax error" , Out); break; case xxExpectedTokens: (void) fputs ("expected tokens" , Out); break; case xxRestartPoint : (void) fputs ("restart point" , Out); break; case xxTokenInserted : (void) fputs ("token inserted " , Out); break; case xxTooManyErrors : (void) fputs ("too many messages" , Out); break; case xxTokenFound : (void) fputs ("token found " , Out); break; case xxFoundExpected : (void) fputs ("found/expected " , Out); break; default : (void) fprintf (Out, " error code: %ld", ErrorCode); }}static void WriteInfo#if defined __STDC__ | defined __cplusplus (int InfoClass, char * Info)#else (InfoClass, Info) int InfoClass; char * Info;#endif{ int i; if (InfoClass == xxNone) return; (void) fputs (": ", Out); switch (InfoClass) { case xxInteger : (void) fprintf (Out, "%d", * (int *) Info); break; case xxShort : i = * (short *) Info; (void) fprintf (Out, "%d", i); break; case xxLong : (void) fprintf (Out, "%ld", * (long *) Info); break; case xxReal : (void) fprintf (Out, "%e", * (float *) Info); break; case xxBoolean : (void) fprintf (Out, "%c", * (rbool *) Info ? 'T' : 'F'); break; case xxCharacter : (void) fprintf (Out, "%c", * Info); break; case xxString : #ifdef TRUNCATE { register int i = 0; while (i <= 25 && Info [i] != '\0') (void) fputc (Info [i ++], Out); if (Info [i] != '\0') { while (Info [i] != ' ' && Info [i] != '\0') (void) fputc (Info [i ++], Out); if (Info [i] != '\0') (void) fputs (" ...", Out); } }#else (void) fputs (Info, Out);#endif break; case xxSet : WriteSet (Out, (tSet *) Info); break; case xxIdent : WriteIdent (Out, * (tIdent *) Info); break; case xxPosition : WritePosition (Out, * (tPosition *) Info); break; default : (void) fprintf (Out, "info class: %d", InfoClass); }}static void WriteMessage#if defined __STDC__ | defined __cplusplus (rbool IsErrorCode, long ErrorCode, int ErrorClass, tPosition Position, int InfoClass, char * Info)#else (IsErrorCode, ErrorCode, ErrorClass, Position, InfoClass, Info) rbool IsErrorCode; long ErrorCode, ErrorClass; tPosition Position; int InfoClass; char * Info;#endif{ if (IsErrorCode) {#ifdef BRIEF switch (ErrorCode) { case xxTokenFound : (void) strcpy (FoundString, Info); (void) strcat (FoundString, "/"); case xxSyntaxError : case xxRestartPoint : case xxTokenInserted : return; case xxExpectedTokens : ErrorCode = xxFoundExpected; ErrorClass = xxError; Info = strcat (FoundString, Info); }#endif#ifdef FIRST if (Position.Line == PrevLine) return; else PrevLine = Position.Line;#endif } WriteHead (Position, ErrorClass); if (IsErrorCode) WriteCode (ErrorCode); else WriteIdent (Out, (tIdent) ErrorCode); WriteInfo (InfoClass, Info); (void) fputc ('\n', Out); (void) fflush (Out); if (ErrorClass == xxFatal && ! IsStore) (* Errors_Exit) ();}void WriteMessages#if defined __STDC__ | defined __cplusplus (FILE * File)#else (File) FILE * File;#endif{ int i; char * Info = NULL; int length; char string1 [256]; char * string2; qsort ((char *) & ErrorTable [1], MessageCount, sizeof (tError),#ifdef _MSC_VER (int (*) (const void *, const void *)) IsLess);#else (int (*) ARGS ((const void *, const void *))) IsLess);#endif PrevLine = 0; Out = File; for (i = 1; i <= MessageCount; i ++) { register tError * With = & ErrorTable [i]; switch (With->InfoClass) { case xxInteger : Info = (char *) & With->Info.vInteger ; break; case xxShort : Info = (char *) & With->Info.vShort ; break; case xxLong : Info = (char *) & With->Info.vLong ; break; case xxReal : Info = (char *) & With->Info.vReal ; break; case xxBoolean : Info = (char *) & With->Info.vBoolean ; break; case xxCharacter : Info = (char *) & With->Info.vCharacter; break; case xxString : length = LengthSt (With->Info.vString); if (length < 256) { StGetString (With->Info.vString, string1); Info = string1; } else { string2 = (char *) Alloc ((unsigned long) ++ length); StGetString (With->Info.vString, string2); Info = string2; } break; case xxSet : Info = (char *) With->Info.vSet ; break; case xxIdent : Info = (char *) & With->Info.vIdent ; break; case xxPosition : Info = (char *) & With->Info.vPosition; break; } WriteMessage (With->IsErrorCode, With->ErrorCode, With->ErrorClass, With->Position, With->InfoClass, Info); if (With->InfoClass == xxString && length >= 256) Free ((unsigned long) length, (char *) string2); }#ifndef _USRDLL Out = stderr;#endif}static void StoreMessage#if defined __STDC__ | defined __cplusplus (rbool IsErrorCode, long ErrorCode, int ErrorClass, tPosition Position, int InfoClass, char * Info)#else (IsErrorCode, ErrorCode, ErrorClass, Position, InfoClass, Info) rbool IsErrorCode; long ErrorCode, ErrorClass; tPosition Position; int InfoClass; char * Info;#endif{ if (MessageCount < MaxError) { MessageCount ++; { register tError * With = & ErrorTable [MessageCount]; With->Position = Position; With->IsErrorCode = IsErrorCode; With->ErrorNumber = MessageCount; With->ErrorCode = ErrorCode; With->ErrorClass = ErrorClass; With->InfoClass = InfoClass; switch (With->InfoClass) { case xxInteger : With->Info.vInteger = * (int *) Info; break; case xxShort : With->Info.vShort = * (short *) Info; break; case xxLong : With->Info.vLong = * (long *) Info; break; case xxReal : With->Info.vReal = * (float *) Info; break; case xxBoolean : With->Info.vBoolean = * (rbool *) Info; break; case xxCharacter : With->Info.vCharacter = * (char *) Info; break; case xxString : With->Info.vString = PutString (Info, strlen (Info)); break; case xxSet : With->Info.vSet = (tSet *) Alloc ((unsigned long) sizeof (tSet)); MakeSet (With->Info.vSet, Size ((tSet *) Info)); Assign (With->Info.vSet, (tSet *) Info); break; case xxIdent : With->Info.vIdent = * (tIdent *) Info; break; case xxPosition : With->Info.vPosition = * (tPosition *) Info; break; } } } else { { register tError * With = & ErrorTable [MessageCount]; With->IsErrorCode = rtrue; With->ErrorCode = xxTooManyErrors; With->ErrorClass = xxRestriction; With->InfoClass = xxNone; } } if (ErrorClass == xxFatal) {#ifndef _USRDLL WriteMessages (stderr);#endif (* Errors_Exit) (); }}static int IsLess#if defined __STDC__ | defined __cplusplus (tError * i, tError * j)#else (i, j) tError * i, * j;#endif{ register int r = Compare (i->Position, j->Position); return r != 0 ? r : i->ErrorNumber - j->ErrorNumber;}void StoreMessages#if defined __STDC__ | defined __cplusplus (rbool Store)#else (Store) rbool Store;#endif{ if (Store) { HandleMessage = StoreMessage; MessageCount = 0; } else { HandleMessage = WriteMessage; } IsStore = Store;}int GetCount#if defined __STDC__ | defined __cplusplus (int ErrorClass)#else (ErrorClass) int ErrorClass;#endif{ return nErrors [ErrorClass];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -