⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int_error_result.c

📁 LastWave
💻 C
📖 第 1 页 / 共 2 页
字号:
/*..........................................................................*//*                                                                          *//*      L a s t W a v e   K e r n e l   3 . 0                               *//*                                                                          *//*      Copyright (C) 1998-2002 Emmanuel Bacry.                             *//*      email : lastwave@cmap.polytechnique.fr                              *//*                                                                          *//*..........................................................................*//*                                                                          *//*      This program is a free software, you can redistribute it and/or     *//*      modify it under the terms of the GNU General Public License as      *//*      published by the Free Software Foundation; either version 2 of the  *//*      License, or (at your option) any later version                      *//*                                                                          *//*      This program is distributed in the hope that it will be useful,     *//*      but WITHOUT ANY WARRANTY; without even the implied warranty of      *//*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *//*      GNU General Public License for more details.                        *//*                                                                          *//*      You should have received a copy of the GNU General Public License   *//*      along with this program (in a file named COPYRIGHT);                *//*      if not, write to the Free Software Foundation, Inc.,                *//*      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             *//*                                                                          *//*..........................................................................*/#include "lastwave.h"#include "signals.h"#include <stdarg.h>#define ErrorLineLength 38/******************************************************** * * Managing errors * ********************************************************/#define MessageLength 10000/* * The corresponding error Msge */static char msge0[MessageLength];static char msge1[MessageLength];static char msge2[MessageLength];static char *errorMsge = msge0;/* * Two useful strings */ static char tempStr[MessageLength];static char tempStr1[MessageLength]; /* Init the error message */void InitError(){  *errorMsge = '\0';}/* * Should the error be saved ? */char ShouldSaveError(void){  return(toplevelCur->flagSaveError);}/* * Is there an error msge ?  */char IsErrorMsge(void){  return(errorMsge[0] != '\0');}/* * Set the error msge */void SetErrorf(char *format,...){  va_list ap;    if (!ShouldSaveError()) return;    va_start(ap,format);  vsprintf(errorMsge,format,ap);  va_end(ap);}/* * Append a msge to the existing error msge */void AppendErrorf(char *format,...){  va_list ap;  if (!ShouldSaveError()) return;  va_start(ap,format);  vsprintf(tempStr,format,ap);  va_end(ap);  strcat(errorMsge,tempStr);}/* * Append a string to the existing error msge */void AppendStrError(char *str,char *end){  int l;    if (!ShouldSaveError()) return;  if (end == NULL) strcat(errorMsge,str);  else {    l = strlen(errorMsge);    strncpy(errorMsge+l,str,end-str);    errorMsge[l+end-str] = '\0';  }}  /* * Prints a syntax error in the 'line' and at the position 'ptr' */void SyntaxError(char msge[],char *line, char *ptr){  char *ptr1;  int n;  if (!ShouldSaveError()) return;  if (msge == NULL) strcpy(msge2,errorMsge);  else strcpy(msge2,msge);  msge = msge2;    InitError();  n = 0;    if (ptr<line) ptr = line;    for (ptr1 = MAX(ptr-1,line); ptr1>line && ptr1 >= ptr-ErrorLineLength && *ptr1 != '\n';ptr1--);    if (*ptr1 != '\n' && ptr1 != line)  {    AppendErrorf("...");    n+=3;  }  if (*ptr1 == '\n' && ptr1 != ptr) ptr1++;  while (*ptr1 == ' ' &&  ptr1 != ptr) ptr1++;  AppendStrError(ptr1,ptr);  n += ptr-ptr1;   for (ptr1 = ptr; *ptr1 != '\0' && ptr1 <= ptr+ErrorLineLength/2 && *ptr1 != '\n';ptr1++);  AppendStrError(ptr,ptr1);    if (*ptr1 != '\0' && *ptr1 != '\n' && *ptr1 != '\r') AppendErrorf("...");       AppendErrorf("\n**        ");  if (toplevelCur->sourceFilename) n+= strlen(toplevelCur->sourceFilename)+3;  while (n != 0) {AppendErrorf(" "); n--;}  AppendErrorf(".^.\n");    AppendErrorf("** --> %s",msge);}  /* * Generate an error (after appending a new msge) */static void PrintCmdLines(void){  static char c = ' ';  char line[ErrorLineLength+1];  char *str,*str1,c1;  int i;    c1 = '\0';    for (i=toplevelCur->nLevel-1;i>=0;i--) {        if (toplevelCur->levels[i].scriptline == NULL) return;    if (toplevelCur->levels[i].scriptline->line == NULL) {      str = TList2Str(toplevelCur->levels[i].scriptline->words,&c);  /* ???? Separateur pas terrible il faut {} */    }    else str = toplevelCur->levels[i].scriptline->line;        str1 = strchr(str,'\n');    if (str1 != NULL && str1[1] == '\0') str1 = NULL;    if (str1) {      c1 = *str1;      *str1 = '\0';    }    if (strlen(str) <= ErrorLineLength) {      if (!str1) PrintfErr("---> %s\n",str);      else PrintfErr("---> %s...\n",str);    }    else {      strncpy(line,str,ErrorLineLength-3);      line[ErrorLineLength-3] = '\0';      PrintfErr("---> %s...\n",line);    }    if (str1) *str1 = c1;  }}static void MakeError(void){  struct event event;  char flagInPromptScript;   // Notify windows that an error occured  ErrorWindow();     /* Print the error message */  if (toplevelCur->sourceFilename == NULL)  PrintfErr("** Error : %s\n",errorMsge);  else PrintfErr("** Error [%s] : %s\n",toplevelCur->sourceFilename,errorMsge);  toplevelCur->flagStoreResult = YES;  toplevelCur->flagSaveError = YES;  toplevelCur->packageName = NULL;  toplevelCur->sourceFilename = NULL;    PrintCmdLines();  Flush();      /* Do Error bindings if there are any */  if (errorMsge == msge0) {    errorMsge = msge1;    event.type = ErrorEvent;    event.object = NULL;    SendEvent(&event);  }    errorMsge = msge0;   flagInPromptScript = GetPrompt(NULL);  if (flagInPromptScript) longjmp(toplevelCur->environment,2);  else     longjmp(toplevelCur->environment,1);}void Errorf1(char *format,...){  va_list ap; if (errorMsge == msge1) PrintfErr("\n**** Error in error handler\n");        va_start(ap,format);  vsprintf(tempStr,format,ap);  va_end(ap);  strcat(errorMsge,tempStr);  MakeError();}  void Errorf(char *format,...){  va_list ap; if (errorMsge == msge1) PrintfErr("\n**** Error in error handler\n");   InitError();         va_start(ap,format);  vsprintf(tempStr,format,ap);  va_end(ap);  strcat(errorMsge,tempStr);  MakeError();}  /* * Prints a warning message  */   void Warningf(char *format,...){  va_list ap;    va_start(ap,format);  vsprintf(tempStr,format,ap);  va_end(ap);    PrintfErr("** Warning : %s\n",tempStr);  Flush();  }void Warningf1(char *format,...){  va_list ap;    va_start(ap,format);  vsprintf(tempStr,format,ap);  va_end(ap);    PrintfErr("\n%s** Error : %s\n\n",tempStr,errorMsge+1); /* ????????????? */  Flush();  }/* * Simulate an error and print the usage of the current command  */void ErrorUsage(void){  InitError();  ErrorUsage1();}/* * Same as above but call Errorf1 instead of Errorf */void ErrorProcUsage(LWPROC c){  char *name;  char **list1,**list;  extern void GetVarListProc(LWPROC);    if (c == NULL) Errorf1("");    list = c->description;  name = c->name;    AppendErrorf("** Usage");  AppendErrorf(" : ");  if (list == NULL) {    toplevelCur->flagStoreResult = YES;    GetVarListProc (c);    AppendErrorf(" %s {%s}", name,GetResultStr());    Errorf1("");  }    if (*list == NULL) {    AppendErrorf(" %s",name);    Errorf1("");    return;  }  ParseWordList(*list,&list1);  if (*list1 == NULL) {    AppendErrorf(" %s",name);    Errorf1("");    return;  }    list1[0]++;  list1[0][strlen(list1[0])-1] = '\0';  AppendErrorf("%s %s",name,*list1);      list++;  while (*list != NULL) {    ParseWordList(*list,&list1);    if (*list1 == NULL) break;    list1[0]++;    list1[0][strlen(list1[0])-1] = '\0';    AppendErrorf("\n           %s %s",name,*list1);    list++;  }  Errorf1("");}void ErrorUsage1(void){  if (levelCur->scriptline && levelCur->scriptline->proc)    ErrorProcUsage(levelCur->scriptline->proc);    ErrorProcUsage(levelCur->scommand);}/* Simulate an error and print the char 'c'   as being a bad option for the current command */void ErrorOption(char c){  Errorf("invalid option or argument (-%c)",c);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -