My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
libpolys
reporter
reporter.cc
Go to the documentation of this file.
1
2
/****************************************
3
* Computer Algebra System SINGULAR *
4
****************************************/
5
/*
6
* ABSTRACT: output system
7
*/
8
9
#include "
misc/auxiliary.h
"
10
11
#include "
reporter/reporter.h
"
12
#include "
resources/feResource.h
"
13
#include "
resources/feFopen.h
"
14
//#include "options.h"
15
#include "
omalloc/omalloc.h
"
16
17
#include <stdlib.h>
18
#include <stdio.h>
19
#include "
misc/mylimits.h
"
20
#include <stdarg.h>
21
#include <sys/stat.h>
22
#include <ctype.h>
23
#include <unistd.h>
24
25
#ifdef HAVE_PWD_H
26
#include <pwd.h>
27
#endif
28
29
30
#define fePutChar(c) fputc((unsigned char)(c),stdout)
31
/*0 implementation */
32
33
// output/print buffer:
34
#define INITIAL_PRINT_BUFFER 24*1024L
35
// line buffer for reading:
36
// minimal value for MAX_FILE_BUFFER: 4*4096 - see Tst/Long/gcd0_l.tst
37
// this is an upper limit for the size of monomials/numbers read via the interpreter
38
#define MAX_FILE_BUFFER 4*4096
39
STATIC_VAR
long
feBufferLength
=0;
40
STATIC_VAR
char
*
feBuffer
=
NULL
;
41
STATIC_VAR
long
feBufferLength_save
[8];
42
STATIC_VAR
char
*
feBuffer_save
[8];
43
STATIC_VAR
int
feBuffer_cnt
=0;
44
STATIC_VAR
char
*
feBufferStart_save
[8];
45
46
47
VAR
char
*
feErrors
=
NULL
;
48
VAR
int
feErrorsLen
=0;
49
VAR
BOOLEAN
feWarn
=
TRUE
;
50
VAR
BOOLEAN
feOut
=
TRUE
;
51
52
//void (*WerrorS_callback)(const char *s) = NULL;
53
54
const
char
feNotImplemented
[]=
"not implemented"
;
55
56
VAR
int
feProt
=
FALSE
;
57
VAR
FILE*
feProtFile
;
58
59
STATIC_VAR
char
*
feBufferStart
;
60
/* only used in StringSet(S)/StringAppend(S)*/
61
void
StringAppend
(
const
char
*fmt, ...)
62
{
63
va_list
ap
;
64
char
*
s
=
feBufferStart
;
/*feBuffer + strlen(feBuffer);*/
65
int
vs;
66
long
more;
67
va_start(
ap
, fmt);
68
if
((more=
feBufferStart
-
feBuffer
+strlen(fmt)+100)>
feBufferLength
)
69
{
70
more = ((more + (8*1024-1))/(8*1024))*(8*1024);
71
int
l
=
s
-
feBuffer
;
72
feBuffer
=(
char
*)
omReallocSize
((
void
*)
feBuffer
,
feBufferLength
,
73
more);
74
#if (!defined(SING_NDEBUG)) && (!defined(OM_NDEBUG))
75
omMarkAsStaticAddr
(
feBuffer
);
76
#endif
77
feBufferLength
=more;
78
s
=
feBuffer
+
l
;
79
#ifndef BSD_SPRINTF
80
feBufferStart
=
s
;
81
#endif
82
}
83
//#ifdef BSD_SPRINTF
84
// vsprintf(s, fmt, ap);
85
// while (*s!='\0') s++;
86
// feBufferStart =s;
87
//#else
88
#ifdef HAVE_VSNPRINTF
89
vs = vsnprintf(
s
,
feBufferLength
- (
feBufferStart
-
feBuffer
), fmt,
ap
);
90
if
(vs == -1)
91
{
92
assume
(0);
93
feBufferStart
=
feBuffer
+
feBufferLength
-1;
94
}
95
else
96
{
97
feBufferStart
+= vs;
98
}
99
#else
100
feBufferStart
+= vsprintf(
s
, fmt,
ap
);
101
#endif
102
//#endif
103
omCheckAddrSize
(
feBuffer
,
feBufferLength
);
104
va_end(
ap
);
105
}
106
107
void
StringAppendS
(
const
char
*st)
108
{
109
if
(*st!=
'\0'
)
110
{
111
/* feBufferStart is feBuffer + strlen(feBuffer);*/
112
int
l
=strlen(st);
113
long
more;
114
int
ll=
feBufferStart
-
feBuffer
;
115
if
((more=ll+2+
l
)>
feBufferLength
)
116
{
117
more = ((more + (8*1024-1))/(8*1024))*(8*1024);
118
feBuffer
=(
char
*)
omreallocSize
((
void
*)
feBuffer
,
feBufferLength
,
119
more);
120
feBufferLength
=more;
121
feBufferStart
=
feBuffer
+ll;
122
}
123
strncat(
feBufferStart
, st,
l
);
124
feBufferStart
+=
l
;
125
}
126
}
127
128
void
StringSetS
(
const
char
*st)
129
{
130
feBuffer_save
[
feBuffer_cnt
]=
feBuffer
;
131
feBuffer
=(
char
*)
omAlloc0
(
INITIAL_PRINT_BUFFER
);
132
feBufferLength_save
[
feBuffer_cnt
]=
feBufferLength
;
133
feBufferLength
=
INITIAL_PRINT_BUFFER
;
134
feBufferStart_save
[
feBuffer_cnt
]=
feBufferStart
;
135
feBufferStart
=
feBuffer
;
136
feBuffer_cnt
++;
137
assume
(
feBuffer_cnt
<8);
138
int
l
=strlen(st);
139
long
more;
140
if
(
l
>
feBufferLength
)
141
{
142
more = ((
l
+ (4*1024-1))/(4*1024))*(4*1024);
143
feBuffer
=(
char
*)
omReallocSize
((
ADDRESS
)
feBuffer
,
feBufferLength
,
144
more);
145
feBufferLength
=more;
146
}
147
strcpy(
feBuffer
,st);
148
feBufferStart
=
feBuffer
+
l
;
149
}
150
151
char
*
StringEndS
()
152
{
153
char
*r=
feBuffer
;
154
feBuffer_cnt
--;
155
assume
(
feBuffer_cnt
>=0);
156
feBuffer
=
feBuffer_save
[
feBuffer_cnt
];
157
feBufferLength
=
feBufferLength_save
[
feBuffer_cnt
];
158
feBufferStart
=
feBufferStart_save
[
feBuffer_cnt
];
159
if
(strlen(r)<1024)
160
{
161
// if the used buffer is a "small block",
162
// substitute the "large" initial block by a small one
163
char
*
s
=
omStrDup
(r);
omFree
(r); r=
s
;
164
}
165
return
r;
166
}
167
168
void
WerrorS_batch
(
const
char
*
s
)
169
{
170
if
(
feErrors
==
NULL
)
171
{
172
feErrors
=(
char
*)
omAlloc
(256);
173
feErrorsLen
=256;
174
*
feErrors
=
'\0'
;
175
}
176
else
177
{
178
if
(((
int
)(strlen((
char
*)
s
)+ 20 +strlen(
feErrors
)))>=
feErrorsLen
)
179
{
180
feErrors
=(
char
*)
omReallocSize
(
feErrors
,
feErrorsLen
,
feErrorsLen
+256);
181
feErrorsLen
+=256;
182
}
183
}
184
strcat(
feErrors
,
"Singular error: "
);
185
strcat(
feErrors
, (
char
*)
s
);
186
errorreported
=
TRUE
;
187
}
188
189
void
Werror
(
const
char
*fmt, ...)
190
{
191
va_list
ap
;
192
va_start(
ap
, fmt);
193
char
*
s
=(
char
*)
omAlloc
(256);
194
#ifdef HAVE_VSNPRINTF
195
vsnprintf(
s
,256, fmt,
ap
);
196
#else
197
vsprintf(
s
, fmt,
ap
);
198
#endif
199
WerrorS
(
s
);
200
omFreeSize
(
s
,256);
201
va_end(
ap
);
202
}
203
204
VAR
void (*
WarnS_callback
)(
const
char
*
s
) =
NULL
;
205
206
void
WarnS
(
const
char
*
s
)
207
{
208
#define warn_str "// ** "
209
if
(
feWarn
)
/* ignore warnings if option --no-warn was given */
210
{
211
if
(
WarnS_callback
==
NULL
)
212
{
213
fwrite(
warn_str
,1,6,stdout);
214
fwrite(
s
,1,strlen(
s
),stdout);
215
fwrite(
"\n"
,1,1,stdout);
216
fflush(stdout);
217
if
(
feProt
&
SI_PROT_O
)
218
{
219
fwrite(
warn_str
,1,6,
feProtFile
);
220
fwrite(
s
,1,strlen(
s
),
feProtFile
);
221
fwrite(
"\n"
,1,1,
feProtFile
);
222
}
223
}
224
else
225
{
226
WarnS_callback
(
s
);
227
}
228
}
229
}
230
231
void
Warn
(
const
char
*fmt, ...)
232
{
233
va_list
ap
;
234
va_start(
ap
, fmt);
235
char
*
s
=(
char
*)
omAlloc
(256);
236
#ifdef HAVE_VSNPRINTF
237
vsnprintf(
s
, 256, fmt,
ap
);
238
#else
239
vsprintf(
s
, fmt,
ap
);
240
#endif
241
WarnS
(
s
);
242
omFreeSize
(
s
,256);
243
va_end(
ap
);
244
}
245
246
247
// some routines which redirect the output of print to a string
248
STATIC_VAR
char
*
sprint
=
NULL
;
249
STATIC_VAR
char
*
sprint_backup
=
NULL
;
250
void
SPrintStart
()
251
{
252
if
(
sprint
!=
NULL
)
253
{
254
if
(
sprint_backup
!=
NULL
)
WerrorS
(
"internal error: SPrintStart"
);
255
else
sprint_backup
=
sprint
;
256
}
257
sprint
=
omStrDup
(
""
);
258
}
259
260
static
inline
void
SPrintS
(
const
char
*
s
)
261
{
262
omCheckAddr
(
sprint
);
263
if
((
s
==
NULL
)||(*
s
==
'\0'
))
return
;
264
int
ls = strlen(
s
);
265
266
char
* ns;
267
int
l
= strlen(
sprint
);
268
ns = (
char
*)
omAlloc
((
l
+ ls + 1)*
sizeof
(
char
));
269
if
(
l
> 0) strcpy(ns,
sprint
);
270
271
strcpy(&(ns[
l
]),
s
);
272
omFree
(
sprint
);
273
sprint
= ns;
274
omCheckAddr
(
sprint
);
275
}
276
277
char
*
SPrintEnd
()
278
{
279
char
* ns =
sprint
;
280
sprint
=
sprint_backup
;
281
sprint_backup
=
NULL
;
282
omCheckAddr
(ns);
283
return
ns;
284
}
285
286
// Print routines
287
extern
"C"
{
288
void
PrintS
(
const
char
*
s
)
289
{
290
if
(
sprint
!=
NULL
)
291
{
292
SPrintS
(
s
);
293
return
;
294
}
295
else
if
(
feOut
)
/* do not print when option --no-out was given */
296
{
297
298
if
(
PrintS_callback
!=
NULL
)
299
{
300
PrintS_callback
(
s
);
301
}
302
else
303
{
304
fwrite(
s
,1,strlen(
s
),stdout);
305
fflush(stdout);
306
if
(
feProt
&
SI_PROT_O
)
307
{
308
fwrite(
s
,1,strlen(
s
),
feProtFile
);
309
}
310
}
311
}
312
}
313
314
void
PrintLn
()
315
{
316
PrintS
(
"\n"
);
317
}
318
319
void
Print
(
const
char
*fmt, ...)
320
{
321
if
(
sprint
!=
NULL
)
322
{
323
va_list
ap
;
324
va_start(
ap
, fmt);
325
omCheckAddr
(
sprint
);
326
int
ls = strlen(fmt);
327
if
(fmt !=
NULL
&& ls > 0)
328
{
329
char
* ns;
330
int
l
= strlen(
sprint
);
331
ns = (
char
*)
omAlloc
(
sizeof
(
char
)*(ls +
l
+ 512));
332
if
(
l
> 0) strcpy(ns,
sprint
);
333
334
#ifdef HAVE_VSNPRINTF
335
l
= vsnprintf(&(ns[
l
]), ls+511, fmt,
ap
);
336
assume
(
l
!= -1);
337
#else
338
vsprintf(&(ns[
l
]), fmt,
ap
);
339
#endif
340
omCheckAddr
(ns);
341
omFree
(
sprint
);
342
sprint
= ns;
343
}
344
va_end(
ap
);
345
return
;
346
}
347
else
if
(
feOut
)
348
{
349
va_list
ap
;
350
va_start(
ap
, fmt);
351
int
l
=0;
352
long
ls=strlen(fmt);
353
char
*
s
=(
char
*)
omAlloc0
(ls+512);
354
#ifdef HAVE_VSNPRINTF
355
l
= vsnprintf(
s
, ls+511, fmt,
ap
);
356
if
((
l
==-1)||(
s
[
l
]!=
'\0'
)||(
l
!=(
int
)strlen(
s
)))
357
{
358
printf(
"Print problem: l=%d, fmt=>>%s<<\n"
,
l
,fmt);
359
}
360
#else
361
vsprintf(
s
, fmt,
ap
);
362
#endif
363
PrintS
(
s
);
364
omFree
(
s
);
365
va_end(
ap
);
366
}
367
}
368
void
PrintNSpaces
(
const
int
n)
369
{
370
int
l
=n-1;
371
while
(
l
>=0) {
PrintS
(
" "
);
l
--; }
372
}
373
374
/* end extern "C" */
375
}
376
377
const
char
*
eati
(
const
char
*
s
,
int
*
i
)
378
{
379
int
l
=0;
380
381
if
(*
s
>=
'0'
&& *
s
<=
'9'
)
382
{
383
*
i
= 0;
384
while
(*
s
>=
'0'
&& *
s
<=
'9'
)
385
{
386
*
i
*= 10;
387
*
i
+= *
s
++ -
'0'
;
388
l
++;
389
if
((
l
>=
MAX_INT_LEN
)||((*
i
) <0))
390
{
391
s
-=
l
;
392
Werror
(
"`%s` greater than %d(max. integer representation)"
,
393
s
,
MAX_INT_VAL
);
394
return
s
;
395
}
396
}
397
}
398
else
*
i
= 1;
399
return
s
;
400
}
401
402
void
feStringAppendResources
(
int
warn)
403
{
404
int
i
= 0;
405
char
* r;
406
StringAppend
(
"%-10s:\t%s\n"
,
"argv[0]"
,
feArgv0
);
407
while
(
feResourceConfigs
[
i
].key !=
NULL
)
408
{
409
r =
feResource
(
feResourceConfigs
[
i
].key, warn);
410
StringAppend
(
"%-10s:\t%s\n"
,
feResourceConfigs
[
i
].key,
411
(r !=
NULL
? r :
""
));
412
i
++;
413
}
414
}
auxiliary.h
All the auxiliary stuff.
BOOLEAN
int BOOLEAN
Definition
auxiliary.h:88
TRUE
#define TRUE
Definition
auxiliary.h:101
FALSE
#define FALSE
Definition
auxiliary.h:97
ADDRESS
void * ADDRESS
Definition
auxiliary.h:120
l
int l
Definition
cfEzgcd.cc:100
i
int i
Definition
cfEzgcd.cc:132
Print
#define Print
Definition
emacs.cc:80
Warn
#define Warn
Definition
emacs.cc:77
WarnS
#define WarnS
Definition
emacs.cc:78
StringAppend
#define StringAppend
Definition
emacs.cc:79
s
const CanonicalForm int s
Definition
facAbsFact.cc:51
errorreported
VAR short errorreported
Definition
feFopen.cc:23
WerrorS
void WerrorS(const char *s)
Definition
feFopen.cc:24
PrintS_callback
VAR void(* PrintS_callback)(const char *s)
Definition
feFopen.cc:22
feFopen.h
feArgv0
VAR char * feArgv0
Definition
feResource.cc:19
feResourceConfigs
VAR feResourceConfig_s feResourceConfigs[]
Definition
feResource.cc:41
feResource
static char * feResource(feResourceConfig config, int warn)
Definition
feResource.cc:244
feResource.h
STATIC_VAR
#define STATIC_VAR
Definition
globaldefs.h:7
VAR
#define VAR
Definition
globaldefs.h:5
assume
#define assume(x)
Definition
mod2.h:389
mylimits.h
MAX_INT_VAL
const int MAX_INT_VAL
Definition
mylimits.h:12
MAX_INT_LEN
const int MAX_INT_LEN
Definition
mylimits.h:13
ap
Definition
ap.h:40
omStrDup
#define omStrDup(s)
Definition
omAllocDecl.h:263
omFreeSize
#define omFreeSize(addr, size)
Definition
omAllocDecl.h:260
omCheckAddr
#define omCheckAddr(addr)
Definition
omAllocDecl.h:328
omAlloc
#define omAlloc(size)
Definition
omAllocDecl.h:210
omreallocSize
#define omreallocSize(addr, o_size, size)
Definition
omAllocDecl.h:231
omReallocSize
#define omReallocSize(addr, o_size, size)
Definition
omAllocDecl.h:220
omCheckAddrSize
#define omCheckAddrSize(addr, size)
Definition
omAllocDecl.h:327
omFree
#define omFree(addr)
Definition
omAllocDecl.h:261
omAlloc0
#define omAlloc0(size)
Definition
omAllocDecl.h:211
NULL
#define NULL
Definition
omList.c:12
omalloc.h
feBufferStart_save
STATIC_VAR char * feBufferStart_save[8]
Definition
reporter.cc:44
feBuffer
STATIC_VAR char * feBuffer
Definition
reporter.cc:40
SPrintStart
void SPrintStart()
Definition
reporter.cc:250
feBuffer_save
STATIC_VAR char * feBuffer_save[8]
Definition
reporter.cc:42
WerrorS_batch
void WerrorS_batch(const char *s)
Definition
reporter.cc:168
StringSetS
void StringSetS(const char *st)
Definition
reporter.cc:128
feBufferLength_save
STATIC_VAR long feBufferLength_save[8]
Definition
reporter.cc:41
eati
const char * eati(const char *s, int *i)
Definition
reporter.cc:377
StringAppendS
void StringAppendS(const char *st)
Definition
reporter.cc:107
feBufferStart
STATIC_VAR char * feBufferStart
Definition
reporter.cc:59
feBufferLength
STATIC_VAR long feBufferLength
Definition
reporter.cc:39
PrintNSpaces
void PrintNSpaces(const int n)
Definition
reporter.cc:368
feNotImplemented
const char feNotImplemented[]
Definition
reporter.cc:54
feErrorsLen
VAR int feErrorsLen
Definition
reporter.cc:48
PrintS
void PrintS(const char *s)
Definition
reporter.cc:288
feProt
VAR int feProt
Definition
reporter.cc:56
feStringAppendResources
void feStringAppendResources(int warn)
Definition
reporter.cc:402
WarnS_callback
VAR void(* WarnS_callback)(const char *s)
Definition
reporter.cc:204
SPrintS
static void SPrintS(const char *s)
Definition
reporter.cc:260
feBuffer_cnt
STATIC_VAR int feBuffer_cnt
Definition
reporter.cc:43
sprint
STATIC_VAR char * sprint
Definition
reporter.cc:248
feErrors
VAR char * feErrors
Definition
reporter.cc:47
feWarn
VAR BOOLEAN feWarn
Definition
reporter.cc:49
StringEndS
char * StringEndS()
Definition
reporter.cc:151
SPrintEnd
char * SPrintEnd()
Definition
reporter.cc:277
PrintLn
void PrintLn()
Definition
reporter.cc:314
feProtFile
VAR FILE * feProtFile
Definition
reporter.cc:57
warn_str
#define warn_str
sprint_backup
STATIC_VAR char * sprint_backup
Definition
reporter.cc:249
INITIAL_PRINT_BUFFER
#define INITIAL_PRINT_BUFFER
Definition
reporter.cc:34
feOut
VAR BOOLEAN feOut
Definition
reporter.cc:50
Werror
void Werror(const char *fmt,...)
Definition
reporter.cc:189
reporter.h
SI_PROT_O
#define SI_PROT_O
Definition
reporter.h:54
omMarkAsStaticAddr
#define omMarkAsStaticAddr(A)
Definition
xalloc.h:245
Generated on
for My Project by
doxygen 1.17.0
for
Singular