err.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* This file is part of nit.
  2. *
  3. * Nit is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * Nit is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with nit. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef ERR_H
  17. #define ERR_H
  18. #include <stdlib.h>
  19. typedef enum {
  20. NIT_ERROR_FINE = 0,
  21. NIT_ERROR_MEMORY,
  22. NIT_ERROR_EMPTY,
  23. NIT_ERROR_NO_NEXT,
  24. NIT_ERROR_ALREADY,
  25. NIT_ERROR_NOT_FOUND,
  26. NIT_ERROR_NOT_DOABLE,
  27. NIT_ERROR_NOT_UNDOABLE,
  28. NIT_ERROR_NOT_DIFF,
  29. NIT_ERROR_FAILED,
  30. NIT_ERROR_ROI,
  31. NIT_ERROR_REDO_PAST,
  32. } Nit_error;
  33. typedef struct Err Err;
  34. typedef void (*Err_log)(Err *err);
  35. struct Err {
  36. Err_log log;
  37. const char *custom;
  38. int errnum;
  39. char *where;
  40. char *what;
  41. size_t where_len;
  42. size_t what_len;
  43. size_t under;
  44. size_t line;
  45. size_t pos;
  46. unsigned print_under : 1;
  47. unsigned print_where : 1;
  48. unsigned print_what : 1;
  49. unsigned print_line : 1;
  50. unsigned print_pos : 1;
  51. unsigned occured : 1;
  52. };
  53. void
  54. err_init(Err *err, Err_log log);
  55. void
  56. err_dispose(Err *err);
  57. void
  58. err_std(Err *err);
  59. void
  60. err_nit(Err *err, Nit_error error);
  61. void
  62. err_cust(Err *err, const char *msg);
  63. void
  64. err_under(Err *err, size_t under);
  65. int
  66. err_where(Err *err, const char *where);
  67. int
  68. err_what(Err *err, const char *what);
  69. void
  70. err_line(Err *err, size_t line);
  71. void
  72. err_pos(Err *err, size_t pos);
  73. void
  74. err_log(Err *err);
  75. #endif