Source code of Windows XP (NT5)
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.

360 lines
7.6 KiB

  1. /* errstr.c - error codes
  2. *
  3. * Matt Saettler. 06-09-88 Created
  4. * Kevyn C-T 88-07-25 Warnings 1,2,3 no longer cause non-zero ret. code
  5. *
  6. * Matt Saettler 89-10-09 Placed into Autodoc Sources and modified for DOCFMT
  7. * Matt Saettler 89-10-15 Create Autodoc style comment blocks.
  8. */
  9. #include <stdio.h>
  10. #include <stdarg.h>
  11. #include "types.h"
  12. #include "docfmt.h"
  13. #define FATAL -1
  14. #define INTERNAL -2
  15. #define INFO -3
  16. #define SYSTEM -4
  17. #define COMMAND -5
  18. #define EOFILE -6
  19. #define WARNING0 0
  20. #define WARNING1 1
  21. #define WARNING2 2
  22. #define WARNING3 3
  23. #if 0
  24. #include "tools.h"
  25. #endif
  26. #include "errstr.h"
  27. extern int warninglevel;
  28. extern int prlineno;
  29. extern int prinfo;
  30. extern long haderror;
  31. extern int therewaserror;
  32. FILE *errfp; /* where the error messages are sent */
  33. struct errormsg {
  34. int errno;
  35. int errlevel;
  36. char *errtxt;
  37. int errcnt;
  38. };
  39. struct errormsg errorlist[]=
  40. {
  41. /* error messages */
  42. ERROR1, FATAL, "Unable to open file.\n", 0,
  43. ERROR3, FATAL, "Memory Allocation Failure.\n", 0,
  44. ERROR4, FATAL, "Unexpected End of File.\n", 0,
  45. ERROR7, FATAL, "Unknown Error.\n", 0,
  46. ERROR8, FATAL, "Out of Memory.\n", 0,
  47. ERROR9, FATAL, "Could not open file %s.\n", 0,
  48. ERROR10, FATAL, "Could not create file %s\n.", 0,
  49. ERR_FILE_OPTION, FATAL, "No file specified for -%c option.\n", 0,
  50. ERR_NAME_OPTION, FATAL, "No name specified for -%c option.\n", 0,
  51. ERR_XOPTION, FATAL, "Unrecognized %c option: %c.\n", 0,
  52. ERR_OPTION, FATAL, "Illegal option flag '-%c'\n", 0,
  53. ERR_UNKNOWN_FILE, FATAL, "Unknown file type: %s\n", 0,
  54. ERROR5, WARNING0, "Improper tag or tag sequence.\n", 0,
  55. ERROR6, WARNING0, "Missing @ENDBLOCK.\n", 0,
  56. WARN1, WARNING1, "FLAGS are not currently allowed on Return Values.\n", 0,
  57. WARN2, WARNING1, "Improper tag or tag sequence.\nFile %s. Line %d\n", 0,
  58. LOGON, INFO, "Source Code Documentation Formatting Tool\n %s\n", 0,
  59. INFO_LOGFILEDEFAULT, INFO, "Log file defaults to: %s\n", 0,
  60. INFO_OUTFILEDEFAULT, INFO, "Output file defaults to: %s\n", 0,
  61. 0, 0, "\n\n***DUMMY ERROR****\n\n", 0
  62. };
  63. #if 0
  64. extern long curlineno;
  65. extern long curoffset;
  66. #endif
  67. #ifdef TEST
  68. long curlineno=0L;
  69. long curoffset=0L;
  70. main()
  71. {
  72. int line = 1;
  73. int no=0;
  74. char *filename = "EXAMPLE";
  75. while(errorlist[no].errno!=0)
  76. {
  77. error(no);
  78. no++;
  79. }
  80. }
  81. #endif
  82. /*
  83. * @doc INTERNAL ERRSTR
  84. *
  85. * @func int | initerror | This function initializes the error handling
  86. * system. It must be called before any calls to <f error>.
  87. *
  88. * @rdesc The return value is zero if no errors have occured during
  89. * initialization, non-zero otherwise.
  90. */
  91. int
  92. initerror()
  93. {
  94. int errno;
  95. for(errno=0;errorlist[errno].errno!=0; errno++)
  96. errorlist[errno].errcnt=0;
  97. return(0); /* success */
  98. }
  99. /*
  100. * @doc INTERNAL ERRSTR
  101. *
  102. * @func void | dumperrorlist | This function prints the error
  103. * list logs to the specified file.
  104. *
  105. * @parm FILE * | fpout | Specifies the output file.
  106. *
  107. */
  108. void
  109. dumperrorlist(fpout)
  110. FILE *fpout;
  111. {
  112. int errno;
  113. for(errno=0;errorlist[errno].errno!=0; errno++)
  114. {
  115. if(errorlist[errno].errcnt!=0)
  116. {
  117. switch(errorlist[errno].errlevel)
  118. {
  119. case FATAL :
  120. case EOFILE :
  121. case INTERNAL :
  122. case INFO :
  123. case SYSTEM :
  124. case COMMAND :
  125. break; /* these errors are not counted */
  126. case WARNING0 : /* is actually an error */
  127. fprintf(errfp,"Error %d: ",errorlist[errno].errno);
  128. fprintf(errfp,"Occured %d times.\n",errorlist[errno].errcnt);
  129. break;
  130. case WARNING1 :
  131. case WARNING2 :
  132. case WARNING3 :
  133. fprintf(errfp,"Warning %d: ",errorlist[errno].errno);
  134. fprintf(errfp,"Occured %d times.\n",errorlist[errno].errcnt);
  135. break;
  136. default:
  137. fprintf(errfp," -----> UHOH:\n\n");
  138. break;
  139. }
  140. }
  141. }
  142. }
  143. /*
  144. * @doc INTERNAL ERRSTR
  145. *
  146. * @func int | error | Prints the specified error on the file errfp.
  147. *
  148. * @parm int | errno | Specifies the error number.
  149. *
  150. * @comm This is a variable argument function like printf.
  151. *
  152. */
  153. int
  154. error(int no, ...)
  155. {
  156. int errno,no,thelevel,ret;
  157. va_list arg_ptr;
  158. /* initiliaze "arg_ptr" */
  159. va_start(arg_ptr,no);
  160. no=va_arg(arg_ptr,int);
  161. for(errno=0;errorlist[errno].errno!=0; errno++)
  162. if(errorlist[errno].errno==no)
  163. break;
  164. thelevel=errorlist[errno].errlevel;
  165. if(errorlist[errno].errno==0)
  166. {
  167. fprintf(stderr,"Bad errno to error()!\n");
  168. exit(1);
  169. }
  170. ret=TRUE; /* we printed the error */
  171. switch(thelevel)
  172. {
  173. case FATAL :
  174. #if 0
  175. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  176. if(prlineno)
  177. fprintf(errfp,", Line %ld",curlineno);
  178. #endif
  179. fprintf(errfp,": FATAL Error %d: ",errorlist[errno].errno);
  180. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  181. haderror++;
  182. therewaserror = TRUE;
  183. break;
  184. case EOFILE :
  185. fprintf(errfp,"General File Error %d: ",errorlist[errno].errno);
  186. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  187. therewaserror = TRUE;
  188. haderror++;
  189. break;
  190. case INTERNAL :
  191. #if 0
  192. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  193. if(prlineno)
  194. fprintf(errfp,", Line %ld",curlineno);
  195. #endif
  196. fprintf(errfp,": Internal FATAL Error %d: ",errorlist[errno].errno);
  197. therewaserror = TRUE;
  198. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  199. break;
  200. case INFO :
  201. if(prinfo)
  202. {
  203. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  204. }
  205. else
  206. ret=FALSE;
  207. break;
  208. case SYSTEM :
  209. #if 0
  210. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  211. if(prlineno)
  212. fprintf(errfp,", Line %ld",curlineno);
  213. #endif
  214. fprintf(errfp,": SYSTEM Error %d: ",errorlist[errno].errno);
  215. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  216. therewaserror = TRUE;
  217. break;
  218. case COMMAND :
  219. #if 0
  220. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  221. if(prlineno)
  222. fprintf(errfp,", Line %ld",curlineno);
  223. #endif
  224. fprintf(errfp,": Command Line Error %d: ",errorlist[errno].errno);
  225. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  226. therewaserror = TRUE;
  227. break;
  228. case WARNING0 : /* is actually an error */
  229. #if 0
  230. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  231. if(prlineno)
  232. fprintf(errfp,", Line %ld",curlineno);
  233. #endif
  234. fprintf(errfp,": Error %d: ",errorlist[errno].errno);
  235. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  236. errorlist[errno].errcnt++;
  237. haderror++;
  238. therewaserror = TRUE;
  239. break;
  240. case WARNING1 :
  241. if(warninglevel>=thelevel)
  242. {
  243. #if 0
  244. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  245. if(prlineno)
  246. fprintf(errfp,", Line %ld",curlineno);
  247. #endif
  248. fprintf(errfp,": Warning %d: ",errorlist[errno].errno);
  249. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  250. errorlist[errno].errcnt++;
  251. }
  252. else
  253. ret=FALSE;
  254. break;
  255. case WARNING2 :
  256. if(warninglevel>=thelevel)
  257. {
  258. #if 0
  259. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  260. if(prlineno)
  261. fprintf(errfp,", Line %ld",curlineno);
  262. #endif
  263. fprintf(errfp,": Warning %d: ",errorlist[errno].errno);
  264. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  265. errorlist[errno].errcnt++;
  266. }
  267. else
  268. ret=FALSE;
  269. break;
  270. case WARNING3 :
  271. if(warninglevel>=thelevel)
  272. {
  273. #if 0
  274. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  275. if(prlineno)
  276. fprintf(errfp,", Line %ld",curlineno);
  277. #endif
  278. fprintf(errfp,": Warning %d: ",errorlist[errno].errno);
  279. vfprintf(errfp,errorlist[errno].errtxt, arg_ptr);
  280. errorlist[errno].errcnt++;
  281. }
  282. else
  283. ret=FALSE;
  284. break;
  285. default:
  286. #if 0
  287. fprintf(errfp,"Offset %ld",curoffset + (oldcurpos - curline));
  288. #endif
  289. fprintf(errfp," -----> UHOH:\n\n");
  290. ret=TRUE;
  291. therewaserror = TRUE;
  292. break;
  293. }
  294. #ifdef TEST
  295. fprintf(errfp,"%s",errorlist[errno].errtxt);
  296. #endif
  297. va_end(arg_ptr);
  298. return(ret);
  299. }