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