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.
 
 
 
 

200 lines
4.5 KiB

  1. /* Copyright (C) 2011-2014 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 "histo.h"
  22. #include "stackF.h"
  23. #include "stackN.h"
  24. #include "stackL.h"
  25. #include "stackC.h"
  26. char * InExec;
  27. static int ERROR=0, LASTERR=0;
  28. static void *ADDRERR=VIDE, *ADDRONE=VIDE;
  29. void tellOnErr (void*A)
  30. {
  31. ADDRONE=A;
  32. if (A != VIDE) LASTERR=0;
  33. }
  34. void majLastErr(void*A)
  35. {
  36. /* if (LASTERR != ERROR) {*/
  37. LASTERR=ERROR;
  38. ADDRERR=A;
  39. /* }*/
  40. }
  41. void razErr(void)
  42. {
  43. ERROR=0;
  44. }
  45. int noErr(void)
  46. {
  47. return ERROR;
  48. }
  49. static char *TabErr[] = {
  50. "No error",
  51. "no such error",
  52. "empty stack",
  53. "sizes are differents",
  54. "not enought elements on the stack",
  55. "empty logical stack",
  56. "empty character stack",
  57. "empty function stack",
  58. "function code is present",
  59. "string too long",
  60. "command not found", /* 10 */
  61. "code type invalid",
  62. "need one array on top",
  63. "only allowed in a function code",
  64. "IF instruction missing",
  65. "already in function",
  66. "loading error",
  67. "no comedilib",
  68. "invalid argument",
  69. "not enought elements on the character stack",
  70. "not enought elements on the logical stack", /* 20 */
  71. "function not found",
  72. "BEGIN instruction missing",
  73. "empty variable stack",
  74. "variable not found",
  75. "not possible in function code",
  76. "no more task possible",
  77. "task is running",
  78. "task not exists",
  79. "value must be greater than zero",
  80. "value must be greater than 1", /* 30 */
  81. "create socket error",
  82. "net is off",
  83. "gethostbyname error, server not found",
  84. "start server error",
  85. "net message error",
  86. "need a scalar on the top",
  87. "not possible with Universal NetKey",
  88. "not a Sister Chip System",
  89. "DO instruction missing",
  90. "net protocol error", /* 40 */
  91. "network system unknown",
  92. "gnuplot not found",
  93. "file open error",
  94. "back compile limit missing",
  95. "too many loads",
  96. "label onerr: already found",
  97. "label end: already found",
  98. "inside compilation aborted",
  99. "I2C is not available",
  100. "invalid I2C bus", /* 50 */
  101. "error open I2C device",
  102. "could not get I2C adapter functionality matrix",
  103. "bad I2C address",
  104. "bad I2C offset",
  105. "value out of range",
  106. "I2C write failed",
  107. "I2C read failed",
  108. "-"
  109. };
  110. #define ERR_MAX 57
  111. void stopErr(char *M, char *F)
  112. {
  113. fprintf(stderr,"ERREUR : %s !!\n",M);
  114. if (F != NULL) perror(F);
  115. if (inSonProc) exit(1);
  116. termReset();
  117. exit(1);
  118. }
  119. static void traiteErr(int n, char * L)
  120. {
  121. ERROR=n;
  122. if (D_Cod==0) {
  123. if (ECHOOFF) printf("\n");
  124. printf("%s : %s !!\a\n",L,TabErr[n]);
  125. }
  126. if (inSonProc) exit(1);
  127. if (fctEnCours) {
  128. if (D_Cod==0) printf("Compilation aborted !\n");
  129. else
  130. if (ADDRONE == VIDE) printf("Inside compilation aborted !\n");
  131. _MODIF_fctEnCours_(0);
  132. rmLastFct();
  133. }
  134. if (ADDRONE != VIDE) return;
  135. if (FD_IN) {
  136. printf("In loading file %s : line %d !\n", getFDname(),getFDlig());
  137. closeFD();
  138. }
  139. if (iTERM) {
  140. printf("In loading stdin : line %d !\n", getFDlig());
  141. close(FD_IN); /* pipe ou autre */
  142. dup(iTERM); /* stdin on term */
  143. iTERM = 0;
  144. }
  145. }
  146. void messErr(int n)
  147. {
  148. char M[50];
  149. if ((n < 0) || (n > ERR_MAX)) n = 1;
  150. sprintf(M,"Error in '%s'",InExec);
  151. traiteErr(n,M);
  152. }
  153. void messErr2(int n, char * M)
  154. {
  155. if ((n < 0) || (n > ERR_MAX)) n = 1;
  156. traiteErr(n,M);
  157. }
  158. void IF_NoError(void)
  159. {
  160. putLong((long)LASTERR);
  161. }
  162. void IF_LibError(void)
  163. {
  164. long P;
  165. getParLong(&P);
  166. putString(TabErr[(int)P]);
  167. }
  168. void IF_IsError(void)
  169. {
  170. if (LASTERR) putBool(TRUE);
  171. else putBool(FALSE);
  172. }
  173. void IF_showError(void)
  174. {
  175. if (ERROR)
  176. printf("%s : %s !!\n",InExec,TabErr[ERROR]);
  177. else
  178. printf("%s : %s.\n",codByAddr(ADDRERR),TabErr[LASTERR]);
  179. }