[ebcfee3] | 1 | #ifndef OUTPUT_H |
---|
| 2 | #define OUTPUT_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
| 6 | /* |
---|
| 7 | * ABSTRACT: basic output |
---|
| 8 | */ |
---|
| 9 | #include <stdio.h> |
---|
| 10 | #include <string.h> |
---|
[aadd638] | 11 | #include "misc/auxiliary.h" |
---|
| 12 | #include "resources/feFopen.h" |
---|
[3a4bda] | 13 | |
---|
[a3f0fea] | 14 | EXTERN_VAR char* feErrors; |
---|
| 15 | EXTERN_VAR int feErrorsLen; |
---|
| 16 | EXTERN_VAR FILE* feProtFile; |
---|
| 17 | EXTERN_VAR int pagelength, colmax; |
---|
| 18 | EXTERN_VAR int yy_blocklineno; |
---|
| 19 | EXTERN_VAR int yy_noeof; |
---|
[ebcfee3] | 20 | extern const char feNotImplemented[]; |
---|
[a3f0fea] | 21 | EXTERN_VAR int feProt; |
---|
| 22 | EXTERN_VAR BOOLEAN feWarn; |
---|
| 23 | EXTERN_VAR BOOLEAN feOut; |
---|
| 24 | EXTERN_VAR int traceit ; |
---|
[c5bae4] | 25 | EXTERN_VAR int traceit_stop ; |
---|
[a3f0fea] | 26 | EXTERN_VAR void (*WarnS_callback)(const char *s); |
---|
[3e4cb1] | 27 | |
---|
[802996] | 28 | // show entering/leaving proc: |
---|
[ebcfee3] | 29 | #define TRACE_SHOW_PROC 1 |
---|
[802996] | 30 | // show current line-no: |
---|
[ebcfee3] | 31 | #define TRACE_SHOW_LINENO 2 |
---|
[802996] | 32 | // show current line and wait for <RET>: |
---|
[ebcfee3] | 33 | #define TRACE_SHOW_LINE 4 |
---|
[b9d42e] | 34 | // show basering for all levels of the proc-stack at enteringing/leaving proc, |
---|
[802996] | 35 | // requires RDEBUG to be defined: |
---|
[ebcfee3] | 36 | #define TRACE_SHOW_RINGS 8 |
---|
[802996] | 37 | // show current line and do not wait for <RET>: |
---|
[ebcfee3] | 38 | #define TRACE_SHOW_LINE1 16 |
---|
[802996] | 39 | // |
---|
[ebcfee3] | 40 | #define TRACE_BREAKPOINT 32 |
---|
[802996] | 41 | // |
---|
[ebcfee3] | 42 | #define TRACE_TMP_BREAKPOINT 64 |
---|
[802996] | 43 | // show all calls to kernel routines (via iparith): |
---|
[a97ac0] | 44 | #define TRACE_CALL 128 |
---|
[802996] | 45 | // show all assigns (via ipassign): |
---|
[a97ac0] | 46 | #define TRACE_ASSIGN 256 |
---|
[b9d42e] | 47 | // show all automtic type conversions (via ipconv): |
---|
[a97ac0] | 48 | #define TRACE_CONV 512 |
---|
[802996] | 49 | // profiling: print line-no to smon.out: |
---|
| 50 | #define TRACE_PROFILING 1024 |
---|
[a97ac0] | 51 | |
---|
[ebcfee3] | 52 | |
---|
[e5ecb5] | 53 | #define SI_PROT_I 1 |
---|
| 54 | #define SI_PROT_O 2 |
---|
| 55 | #define SI_PROT_IO 3 |
---|
[ebcfee3] | 56 | |
---|
| 57 | /* the C-part: */ |
---|
| 58 | #define mflush() fflush(stdout) |
---|
| 59 | |
---|
| 60 | #ifdef __cplusplus |
---|
| 61 | extern "C" { |
---|
| 62 | #endif |
---|
| 63 | |
---|
| 64 | void Werror(const char *fmt, ...) __attribute__((format(printf,1,2))); |
---|
[854405] | 65 | void WerrorS_batch(const char *s); |
---|
[ebcfee3] | 66 | void WarnS(const char *s); |
---|
| 67 | void Print(const char* fmt, ...) __attribute__((format(printf,1,2))); |
---|
| 68 | /* Print should not produce more than strlen(fmt)+510 characters! */ |
---|
| 69 | |
---|
| 70 | void PrintNSpaces(const int n); |
---|
| 71 | void PrintLn(); |
---|
| 72 | void PrintS(const char* s); |
---|
| 73 | |
---|
| 74 | #ifdef __cplusplus |
---|
| 75 | } |
---|
| 76 | /* the C++-part: */ |
---|
| 77 | |
---|
[91dd8a5] | 78 | // a new output buffer will be allocated by StringSetS, |
---|
| 79 | // used by several calls to StringAppend/StringAppendS |
---|
| 80 | // and closed by StringEndS: |
---|
| 81 | // StringEndS() returns this buffer which must be freed by omFree |
---|
| 82 | // several buffer may be active at the same time |
---|
| 83 | // (for example in subroutines) |
---|
[538512] | 84 | void StringAppend(const char *fmt, ...); |
---|
| 85 | void StringAppendS(const char *s); |
---|
| 86 | void StringSetS(const char* s); |
---|
| 87 | char * StringEndS(); |
---|
| 88 | void Warn(const char *fmt, ...); |
---|
[ebcfee3] | 89 | |
---|
[9c83f2] | 90 | const char * eati(const char *s, int *i); |
---|
| 91 | |
---|
[f323dd1] | 92 | // Prints resources into string with StringAppend, etc |
---|
| 93 | void feStringAppendResources(int warn = -1); |
---|
[ebcfee3] | 94 | #endif /* c++ only */ |
---|
| 95 | |
---|
| 96 | /* everything in between calls to these procedures is printed into a string |
---|
| 97 | * which is returned by SprintEnd() |
---|
[31cbb08] | 98 | * Shall ONLY be used for a temporary redirection of the standard output |
---|
| 99 | * (i.e. if Singular runs as a server) |
---|
[ebcfee3] | 100 | */ |
---|
[fea494] | 101 | // unlike the StringSet/StringEndS stuff: |
---|
[91dd8a5] | 102 | // only one SPrintStart/SPrintEnd buffer may be active |
---|
| 103 | // the returned string must be free via omFree |
---|
[ebcfee3] | 104 | void SPrintStart(); |
---|
| 105 | char* SPrintEnd(); |
---|
| 106 | |
---|
[508610a] | 107 | /* error reporting */ |
---|
| 108 | #ifdef __cplusplus |
---|
| 109 | extern "C" |
---|
| 110 | { |
---|
| 111 | #endif |
---|
| 112 | extern int dReportError(const char* fmt, ...); |
---|
| 113 | #define dReportBug(s) \ |
---|
[80f8f6c] | 114 | dReportError("Bug reported: %s\n occurred at %s,%d\n", s, __FILE__, __LINE__) |
---|
[508610a] | 115 | |
---|
| 116 | // this is just a dummy procedure which is called after the error |
---|
| 117 | // has been reported. Within the debugger, set a breakpoint on this |
---|
| 118 | // proc. |
---|
| 119 | extern void dErrorBreak(); |
---|
| 120 | #ifdef __cplusplus |
---|
| 121 | } |
---|
| 122 | #endif |
---|
| 123 | |
---|
[caf8c6] | 124 | #ifdef SING_NDEBUG |
---|
[d101b1] | 125 | #define assume(x) do {} while (0) |
---|
| 126 | #define r_assume(x) do {} while (0) |
---|
[caf8c6] | 127 | #else /* !SING_NDEBUG */ |
---|
[8948da] | 128 | |
---|
| 129 | #define assume_violation(s,f,l) \ |
---|
| 130 | dReportError("assume violation at %s:%d condition: %s", f,l,s) |
---|
| 131 | |
---|
| 132 | #define assume(x) _assume(x, __FILE__, __LINE__) |
---|
| 133 | #define r_assume(x) _r_assume(x, __FILE__, __LINE__) |
---|
| 134 | |
---|
| 135 | #define _assume(x, f, l) \ |
---|
| 136 | do \ |
---|
| 137 | { \ |
---|
| 138 | if (! (x)) \ |
---|
| 139 | { \ |
---|
| 140 | assume_violation(#x, f, l); \ |
---|
| 141 | } \ |
---|
| 142 | } \ |
---|
| 143 | while (0) |
---|
| 144 | |
---|
| 145 | #define _r_assume(x, f, l) \ |
---|
| 146 | do \ |
---|
| 147 | { \ |
---|
| 148 | if (! (x)) \ |
---|
| 149 | { \ |
---|
| 150 | assume_violation(#x, f, l); \ |
---|
| 151 | return 0; \ |
---|
| 152 | } \ |
---|
| 153 | } \ |
---|
| 154 | while (0) |
---|
[caf8c6] | 155 | #endif /* !SING_NDEBUG */ |
---|
[ebcfee3] | 156 | |
---|
| 157 | #endif /* ifndef OUTPUT_H */ |
---|