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> |
---|
11 | #include "misc/auxiliary.h" |
---|
12 | #include "resources/feFopen.h" |
---|
13 | |
---|
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; |
---|
20 | extern const char feNotImplemented[]; |
---|
21 | EXTERN_VAR int feProt; |
---|
22 | EXTERN_VAR BOOLEAN feWarn; |
---|
23 | EXTERN_VAR BOOLEAN feOut; |
---|
24 | EXTERN_VAR int traceit ; |
---|
25 | EXTERN_VAR int traceit_stop ; |
---|
26 | EXTERN_VAR void (*WarnS_callback)(const char *s); |
---|
27 | |
---|
28 | // show entering/leaving proc: |
---|
29 | #define TRACE_SHOW_PROC 1 |
---|
30 | // show current line-no: |
---|
31 | #define TRACE_SHOW_LINENO 2 |
---|
32 | // show current line and wait for <RET>: |
---|
33 | #define TRACE_SHOW_LINE 4 |
---|
34 | // show basering for all levels of the proc-stack at enteringing/leaving proc, |
---|
35 | // requires RDEBUG to be defined: |
---|
36 | #define TRACE_SHOW_RINGS 8 |
---|
37 | // show current line and do not wait for <RET>: |
---|
38 | #define TRACE_SHOW_LINE1 16 |
---|
39 | // |
---|
40 | #define TRACE_BREAKPOINT 32 |
---|
41 | // |
---|
42 | #define TRACE_TMP_BREAKPOINT 64 |
---|
43 | // show all calls to kernel routines (via iparith): |
---|
44 | #define TRACE_CALL 128 |
---|
45 | // show all assigns (via ipassign): |
---|
46 | #define TRACE_ASSIGN 256 |
---|
47 | // show all automtic type conversions (via ipconv): |
---|
48 | #define TRACE_CONV 512 |
---|
49 | // profiling: print line-no to smon.out: |
---|
50 | #define TRACE_PROFILING 1024 |
---|
51 | |
---|
52 | |
---|
53 | #define SI_PROT_I 1 |
---|
54 | #define SI_PROT_O 2 |
---|
55 | #define SI_PROT_IO 3 |
---|
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))); |
---|
65 | void WerrorS_batch(const char *s); |
---|
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 | |
---|
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) |
---|
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, ...); |
---|
89 | |
---|
90 | const char * eati(const char *s, int *i); |
---|
91 | |
---|
92 | // Prints resources into string with StringAppend, etc |
---|
93 | void feStringAppendResources(int warn = -1); |
---|
94 | #endif /* c++ only */ |
---|
95 | |
---|
96 | /* everything in between calls to these procedures is printed into a string |
---|
97 | * which is returned by SprintEnd() |
---|
98 | * Shall ONLY be used for a temporary redirection of the standard output |
---|
99 | * (i.e. if Singular runs as a server) |
---|
100 | */ |
---|
101 | // unlike the StringSet/StringEndS stuff: |
---|
102 | // only one SPrintStart/SPrintEnd buffer may be active |
---|
103 | // the returned string must be free via omFree |
---|
104 | void SPrintStart(); |
---|
105 | char* SPrintEnd(); |
---|
106 | |
---|
107 | /* error reporting */ |
---|
108 | #ifdef __cplusplus |
---|
109 | extern "C" |
---|
110 | { |
---|
111 | #endif |
---|
112 | extern int dReportError(const char* fmt, ...); |
---|
113 | #define dReportBug(s) \ |
---|
114 | dReportError("Bug reported: %s\n occurred at %s,%d\n", s, __FILE__, __LINE__) |
---|
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 | |
---|
124 | #ifdef SING_NDEBUG |
---|
125 | #define assume(x) do {} while (0) |
---|
126 | #define r_assume(x) do {} while (0) |
---|
127 | #else /* !SING_NDEBUG */ |
---|
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) |
---|
155 | #endif /* !SING_NDEBUG */ |
---|
156 | |
---|
157 | #endif /* ifndef OUTPUT_H */ |
---|