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

📄 int_error_result.c

📁 LastWave
💻 C
📖 第 1 页 / 共 2 页
字号:
}/******************************************************** * * * *      Managing results * * * ********************************************************/ /* Init result */void InitResult(){  toplevelCur->resultType = NULL;  toplevelCur->nResult = 0;  toplevelCur->nResultList = 0;  if (toplevelCur->resultContent != NULL) {    DeleteValue(toplevelCur->resultContent);    toplevelCur->resultContent = NULL;  }}/******************************************* * * Routines to set the result * *******************************************//* If it is a formatted string */void SetResultf(char *format,...){  va_list ap;  /* Delete old result */    InitResult();    /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;    /* Store it */  va_start(ap,format);    vsprintf(toplevelCur->result,format,ap);  va_end(ap);     toplevelCur->nResult = strlen(toplevelCur->result);  toplevelCur->resultType = strType;  }/* If it is a string */void SetResultStr(char *str){  int n;  STRVALUE sc;    /* Delete old result */    InitResult();    /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;    n = strlen(str);  if (n >= MaxLengthResult-1) {    sc = TNewStrValue();    SetStrValue(sc,str);    SetResultValue(sc);    return;  }    toplevelCur->nResult = n;      /* Store it */  strcpy(toplevelCur->result,str);  toplevelCur->resultType = strType;}void SetResultList(char **list){  while(*list) {AppendListResultStr(*list); list++;}}/*  * static routine to append a string to the existing result  * WARNING : Not to be used outside of this file  */static void AppendResultStr_(char *str){  int l = strlen(str);    if (toplevelCur->nResult + l >= MaxLengthResult-1)     Errorf("AppendResultStr_() : string is too long (%d characters) --> change 'MaxLengthResult' in kernel/include/int_toplevel.h and recompile",toplevelCur->nResult+l);  strcpy(toplevelCur->result+toplevelCur->nResult,str);  toplevelCur->nResult += l;  toplevelCur->resultType = strType;}/* Append a string to the existing result */void AppendResultStr(char *str){  /* Some inits */  if (toplevelCur->resultType != strType && toplevelCur->resultType != NULL) InitResult();    /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;  /* store it */  AppendResultStr_(str);}/* Append a formatted string to the existing result */void AppendResultf(char *format,...){  va_list ap;  /* Some inits */  if (toplevelCur->resultType != strType && toplevelCur->resultType != NULL) InitResult();    /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;  /* store it */  va_start(ap,format);  vsprintf(tempStr,format,ap);  va_end(ap);  AppendResultStr_(tempStr);}/* The result is supposed to contain a list and we just want to append a string */static void AppendListResultStr_(char *str){  char flagBraces;     /* Test if not too many elements */  if (toplevelCur->nResultList >= MaxLengthResultList-1)     Errorf("AppendListResultStr_() : list is too long (%d words) --> change 'MaxLengthResultList' in kernel/include/int_toplevel.h and recompile",MaxLengthResultList);  /* If it is not the beginning of the result then we print a ' ' */  if (toplevelCur->nResult != 0) AppendResultStr_(" ");    /* Should we put braces around the result ? */  flagBraces = IsList(str);  if (*str == '\0') flagBraces = YES;    /* Let's do it */  if (!flagBraces) {    toplevelCur->begResultList[toplevelCur->nResultList] = toplevelCur->result+toplevelCur->nResult;    AppendResultStr_(str);    toplevelCur->endResultList[toplevelCur->nResultList] = toplevelCur->result+toplevelCur->nResult-1;  }  else {    AppendResultStr_("{");    toplevelCur->begResultList[toplevelCur->nResultList] = toplevelCur->result+toplevelCur->nResult;    AppendResultStr_(str);    toplevelCur->endResultList[toplevelCur->nResultList] = toplevelCur->result+toplevelCur->nResult-1;    AppendResultStr_("}");  }  toplevelCur->nResultList++;}/* The result is supposed to contain a list and we just want to append a string */void AppendListResultStr(char *str){  /* Some inits */  if (toplevelCur->resultType != strType && toplevelCur->resultType != NULL) InitResult();  /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;  AppendListResultStr_(str);  }/* The result is supposed to contain a list and we just want to append a string */void AppendListResultf(char *format,...){  va_list ap;     /* Some inits */  if (toplevelCur->resultType != strType && toplevelCur->resultType != NULL) InitResult();  /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;  va_start(ap,format);  vsprintf(tempStr1,format,ap);  va_end(ap);  AppendListResultStr_(tempStr1);  }/* If it is an VALUE */void SetResultContent_(VALUE val){  SIGNAL signal;    /* Delete old result */    InitResult();    /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;  /* Store it */  val = ValueOf(val);  toplevelCur->resultType = GetTypeValue(val);    if (toplevelCur->resultType == numType)    toplevelCur->resultNum = CastValue(val,NUMVALUE)->f;    else if (toplevelCur->resultType == signaliType || toplevelCur->resultType == signalType) {    signal = CastValue(val,SIGNAL);    if (signal->size == 1 && signal->type == YSIG) {      toplevelCur->resultNum = signal->Y[0];      toplevelCur->resultType = numType;      return;    }    toplevelCur->resultContent = val;    AddRefValue(val);  }      else {    toplevelCur->resultContent = val;    AddRefValue(val);  }   }/* If it is a LWFLOAT */void SetResultFloat(LWFLOAT f){  /* Delete old result */    InitResult();    /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;  /* Store it */  toplevelCur->resultNum = f;  toplevelCur->resultType = numType;}/* If it is an int */void SetResultInt(int i){  /* Delete old result */    InitResult();    /* Should we store the result ? */  if (!toplevelCur->flagStoreResult) return;  /* Store it */  toplevelCur->resultNum = i;  toplevelCur->resultType = numType;}/******************************************* * * Routines to get the result * *******************************************//* Get the result Type */char *GetResultType(void){  if (toplevelCur->resultType == NULL) return(NULL);  return(toplevelCur->resultType);}  /* Function to get the string result */char *GetResultStr(void){  if (toplevelCur->resultType == NULL) Errorf("GetResultStr() : Sorry no result to get");  if (toplevelCur->resultType != strType)    Errorf("GetResultStr() : Sorry the result is not a string, it is of type '%s'",toplevelCur->resultType);      if (toplevelCur->resultContent == NULL) return(toplevelCur->result);    return(CastValue(toplevelCur->resultContent,STRVALUE)->str);}/* Function to get the VALUE result which is neither a string nor a number */VALUE GetResultValue(void){  VALUE val;  if (toplevelCur->resultContent != NULL) {    val = toplevelCur->resultContent;    return(val);  }   if (toplevelCur->resultType == NULL) return(nullValue);    if (toplevelCur->resultType == strType) {    val = (VALUE) TNewStrValue();    SetStrValue((STRVALUE) val, toplevelCur->result);    if (toplevelCur->nResultList != 0) {      toplevelCur->begResultList[toplevelCur->nResultList] = NULL;      toplevelCur->endResultList[toplevelCur->nResultList] = NULL;      ((STRVALUE) val)->list = BegEndStr2List(toplevelCur->begResultList,toplevelCur->endResultList);    }    return(val);  }    if (toplevelCur->resultType == numType) {    val = (VALUE) TNewNumValue();    SetNumValue((NUMVALUE) val, toplevelCur->resultNum);    return(val);  }  Errorf("GetResultValue() : Weird error");    return(NULL);}  /* Get the result as an integer */int GetResultInt(void){  LWFLOAT f;    if (toplevelCur->resultType == NULL) Errorf("GetResultInt() : Sorry no result to get");  if (toplevelCur->resultType != numType)    Errorf("GetResultInt() : Sorry the result is not a number, it is of type '%s'",toplevelCur->resultType);    if (toplevelCur->resultContent != NULL) f = CastValue(toplevelCur->resultContent,NUMVALUE)->f;  else f = toplevelCur->resultNum;  if (f != (int) f) Errorf("GetResultInt() : Sorry the result is not an integer it is a foat (%g)",f);    return((int) f);}/* Get the result as a LWFLOAT */LWFLOAT GetResultFloat(void){  if (toplevelCur->resultType == NULL) Errorf("GetResultInt() : Sorry no result to get");  if (toplevelCur->resultType != numType)    Errorf("GetResultInt() : Sorry the result is not a number, it is of type '%s'",toplevelCur->resultType);    if (toplevelCur->resultContent != NULL) return(CastValue(toplevelCur->resultContent,NUMVALUE)->f);  return(toplevelCur->resultNum);}/******************************************* * * Routines to print the result * *******************************************//* A simple print */void PrintResult(void){  static STRVALUE sc = NULL;  static NUMVALUE nc = NULL;  VALUE val;  char *type;    if (sc == NULL) sc = NewStrValue();  if (nc == NULL) nc = NewNumValue();    type = GetResultType();  if (type == NULL) {    return;  }    if (type == strType) {    SetStrValue(sc,GetResultStr());    val = (VALUE) sc;  }  else if (type == numType) {    SetNumValue(nc,GetResultFloat());    val = (VALUE) nc;  }  else val = GetResultValue();    DeleteVariableIfExist("ans");  SetVariable("ans",val);    Printf("ans = %s\n",ToStrValue(val,NO));}

⌨️ 快捷键说明

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