Nife version Beta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

215 lines
5.0 KiB

  1. /* Copyright (C) 2011-2024 Patrick H. E. Foubet - S.E.R.I.A.N.E.
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or any
  5. later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>
  12. *******************************************************************/
  13. #include "conf.h"
  14. /* err.c */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include "nife.h"
  19. #include "mth.h"
  20. #include "err.h"
  21. #include "debug.h"
  22. #include "histo.h"
  23. #include "stackF.h"
  24. #include "stackN.h"
  25. #include "stackL.h"
  26. #include "stackC.h"
  27. char * InExec;
  28. static int ERROR=0, LASTERR=0;
  29. static void *ADDRERR=VIDE, *ADDRONE=VIDE;
  30. void tellOnErr (void*A)
  31. {
  32. ADDRONE=A;
  33. if (A != VIDE) LASTERR=0;
  34. }
  35. void majLastErr(void*A)
  36. {
  37. /* if (LASTERR != ERROR) {*/
  38. LASTERR=ERROR;
  39. ADDRERR=A;
  40. /* }*/
  41. }
  42. void razErr(void)
  43. {
  44. ERROR=0;
  45. }
  46. int noErr(void)
  47. {
  48. return ERROR;
  49. }
  50. static char *TabErr[] = {
  51. "No error",
  52. "no such error",
  53. "empty stack",
  54. "sizes are differents",
  55. "not enought elements on the stack",
  56. "empty logical stack",
  57. "empty character stack",
  58. "empty function stack",
  59. "function code is present",
  60. "string too long",
  61. "command not found", /* 10 */
  62. "code type invalid",
  63. "need one array on top",
  64. "only allowed in a function code",
  65. "IF instruction missing",
  66. "already in function",
  67. "loading error",
  68. "no comedilib",
  69. "invalid argument",
  70. "not enought elements on the character stack",
  71. "not enought elements on the logical stack", /* 20 */
  72. "function not found",
  73. "BEGIN instruction missing",
  74. "empty variable stack",
  75. "variable not found",
  76. "not possible in function code",
  77. "no more task possible",
  78. "task is running",
  79. "task not exists",
  80. "value must be greater than zero",
  81. "value must be greater than 1", /* 30 */
  82. "create socket error",
  83. "net is off",
  84. "gethostbyname error, server not found",
  85. "start server error",
  86. "net message error",
  87. "need a scalar on the top",
  88. "not possible with Universal NetKey",
  89. "not a Sister Chip System",
  90. "DO instruction missing",
  91. "net protocol error", /* 40 */
  92. "network system unknown",
  93. "gnuplot not found",
  94. "file open error",
  95. "back compile limit missing",
  96. "too many loads",
  97. "label onerr: already found",
  98. "label end: already found",
  99. "inside compilation aborted",
  100. "I2C is not available",
  101. "invalid I2C bus", /* 50 */
  102. "error open I2C device",
  103. "could not get I2C adapter functionality matrix",
  104. "bad I2C address",
  105. "bad I2C offset",
  106. "value out of range",
  107. "I2C write failed",
  108. "I2C read failed",
  109. "binary dump error",
  110. "binary restore error",
  111. "meta-stack size limit reached", /* 60 */
  112. "no previous stack",
  113. "-"
  114. };
  115. #define ERR_MAX 61
  116. void stopErr(char *M, char *F)
  117. {
  118. fprintf(stderr,"ERREUR : %s !!\n",M);
  119. if (F != NULL) perror(F);
  120. if (inSonProc) exit(1);
  121. termReset();
  122. exit(1);
  123. }
  124. static void ErrPrintf(char *M)
  125. {
  126. printf(M);
  127. if (InDebugFct==0) fprintf(stderr,M);
  128. }
  129. static void traiteErr(int n, char * L)
  130. {
  131. int v;
  132. ERROR=n;
  133. if (D_Cod==0) {
  134. if (ECHOOFF) printf("\n");
  135. /* if (InDebugFct==0) fprintf(stderr,"\n"); A VOIR ! */
  136. printf("%s : %s !!\a\n",L,TabErr[n]);
  137. if (InDebugFct==0) fprintf(stderr,"%s : %s !!\a\n",L,TabErr[n]);
  138. }
  139. if (inSonProc) exit(1);
  140. if (fctEnCours) {
  141. if (D_Cod==0) ErrPrintf("Compilation aborted !\n");
  142. else
  143. if (ADDRONE == VIDE) ErrPrintf("Inside compilation aborted !\n");
  144. _MODIF_fctEnCours_(0);
  145. rmLastFct();
  146. }
  147. if (ADDRONE != VIDE) return;
  148. if (FD_IN) {
  149. printf("In loading file %s : line %d !\n", getFDname(),getFDlig());
  150. if (InDebugFct==0) fprintf(stderr, "In loading file %s : line %d !\n", getFDname(),getFDlig());
  151. closeFD();
  152. }
  153. if (iTERM) {
  154. printf("In loading stdin : line %d !\n", getFDlig());
  155. if (InDebugFct==0) fprintf(stderr,"In loading stdin : line %d !\n", getFDlig());
  156. close(FD_IN); /* pipe ou autre */
  157. v = dup(iTERM); /* stdin on term */
  158. iTERM = 0;
  159. }
  160. }
  161. void messErr(int n)
  162. {
  163. char M[50];
  164. if ((n < 0) || (n > ERR_MAX)) n = 1;
  165. sprintf(M,"Error in '%s'",InExec);
  166. traiteErr(n,M);
  167. }
  168. void messErr2(int n, char * M)
  169. {
  170. if ((n < 0) || (n > ERR_MAX)) n = 1;
  171. traiteErr(n,M);
  172. }
  173. void IF_NoError(void)
  174. {
  175. putLong((long)LASTERR);
  176. }
  177. void IF_LibError(void)
  178. {
  179. long P;
  180. if (getParLong(&P)) putString(TabErr[(int)P]);
  181. }
  182. void IF_IsError(void)
  183. {
  184. if (LASTERR) putBool(TRUE);
  185. else putBool(FALSE);
  186. }
  187. void IF_showError(void)
  188. {
  189. if (ERROR)
  190. printf("%s : %s !!\n",InExec,TabErr[ERROR]);
  191. else
  192. printf("%s : %s.\n",codByAddr(ADDRERR),TabErr[LASTERR]);
  193. }