errcode.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**********************************************************************
  2. * File: errcode.h (Formerly error.h)
  3. * Description: Header file for generic error handler class
  4. * Author: Ray Smith
  5. *
  6. * (C) Copyright 1990, Hewlett-Packard Ltd.
  7. ** Licensed under the Apache License, Version 2.0 (the "License");
  8. ** you may not use this file except in compliance with the License.
  9. ** You may obtain a copy of the License at
  10. ** http://www.apache.org/licenses/LICENSE-2.0
  11. ** Unless required by applicable law or agreed to in writing, software
  12. ** distributed under the License is distributed on an "AS IS" BASIS,
  13. ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ** See the License for the specific language governing permissions and
  15. ** limitations under the License.
  16. *
  17. **********************************************************************/
  18. #ifndef ERRCODE_H
  19. #define ERRCODE_H
  20. #include "platform.h" // for TESS_API
  21. /*Control parameters for error()*/
  22. enum TessErrorLogCode {
  23. DBG = -1, /*log without alert */
  24. TESSLOG = 0, /*alert user */
  25. TESSEXIT = 1, /*exit after erro */
  26. ABORT = 2 /*abort after error */
  27. };
  28. /* Explicit Error Abort codes */
  29. #define NO_ABORT_CODE 0
  30. #define LIST_ABORT 1
  31. #define MEMORY_ABORT 2
  32. #define FILE_ABORT 3
  33. /* Location of code at error codes Reserve 0..2 (status codes 0..23 for UNLV)*/
  34. #define LOC_UNUSED0 0
  35. #define LOC_UNUSED1 1
  36. #define LOC_UNUSED2 2
  37. #define LOC_INIT 3
  38. #define LOC_EDGE_PROG 4
  39. #define LOC_TEXT_ORD_ROWS 5
  40. #define LOC_TEXT_ORD_WORDS 6
  41. #define LOC_PASS1 7
  42. #define LOC_PASS2 8
  43. /* Reserve up to 8..13 for adding subloc 0/3 plus subsubloc 0/1/2 */
  44. #define LOC_FUZZY_SPACE 14
  45. /* Reserve up to 14..20 for adding subloc 0/3 plus subsubloc 0/1/2 */
  46. #define LOC_MM_ADAPT 21
  47. #define LOC_DOC_BLK_REJ 22
  48. #define LOC_WRITE_RESULTS 23
  49. #define LOC_ADAPTIVE 24
  50. /* DON'T DEFINE ANY LOCATION > 31 !!! */
  51. /* Sub locatation determines whether pass2 was in normal mode or fix xht mode*/
  52. #define SUBLOC_NORM 0
  53. #define SUBLOC_FIX_XHT 3
  54. /* Sub Sub locatation determines whether match_word_pass2 was in Tess
  55. matcher, NN matcher or somewhere else */
  56. #define SUBSUBLOC_OTHER 0
  57. #define SUBSUBLOC_TESS 1
  58. #define SUBSUBLOC_NN 2
  59. class TESS_API ERRCODE { // error handler class
  60. const char *message; // error message
  61. public:
  62. void error( // error print function
  63. const char *caller, // function location
  64. TessErrorLogCode action, // action to take
  65. const char *format, ... // fprintf format
  66. ) const;
  67. constexpr ERRCODE(const char *string) : message(string) {
  68. } // initialize with string
  69. };
  70. constexpr ERRCODE ASSERT_FAILED("Assert failed");
  71. #if defined __cplusplus
  72. # define DO_NOTHING static_cast<void>(0)
  73. #else
  74. # define DO_NOTHING (void)(0)
  75. #endif
  76. #define ASSERT_HOST(x) (x) \
  77. ? DO_NOTHING \
  78. : ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__)
  79. #define ASSERT_HOST_MSG(x, ...) \
  80. if (!(x)) { \
  81. tprintf(__VA_ARGS__); \
  82. ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__); \
  83. }
  84. void signal_exit(int signal_code);
  85. void set_global_loc_code(int loc_code);
  86. void set_global_subloc_code(int loc_code);
  87. void set_global_subsubloc_code(int loc_code);
  88. #endif