Macaulay2 Engine
Loading...
Searching...
No Matches
text-io.cpp
Go to the documentation of this file.
1
// (c) 1994 Michael E. Stillman
2
3
#include "
text-io.hpp
"
4
#include "
newdelete.hpp
"
5
#include <cstdio>
6
#include <cstring>
7
#include <atomic>
8
9
int
MAX_LINE_LENGTH
= 75;
10
std::atomic_int
emit_line_len
= 0;
11
12
void
bignum_text_out
(
buffer
&o, mpz_srcptr a)
13
{
14
char
s
[1000];
15
char
*str;
16
17
int
size =
static_cast<
int
>
(mpz_sizeinbase(a, 10) + 2);
18
char
*allocstr = (size > 1000 ?
newarray_atomic
(
char
, size) :
s
);
19
20
str = mpz_get_str(allocstr, 10, a);
21
o << str;
22
23
if
(size > 1000)
freemem
(allocstr);
24
}
25
26
void
clear_emit_size
() {
emit_line_len
= 0; }
27
void
emit_wrapped
(
const
char
*
s
)
28
{
29
// We wish verbose display to wrap at some reasonable length.
30
emit_line_len
-=
static_cast<
int
>
(strlen(
s
));
31
if
(
emit_line_len
<= 0)
32
{
33
emit_line_len
=
MAX_LINE_LENGTH
;
34
fprintf(stdout,
"\n"
);
35
fprintf(stdout,
wrapping_prefix
);
36
}
37
fputs(
s
, stdout);
38
fflush(stdout);
39
}
40
41
void
emit
(
const
char
*
s
)
42
{
43
fputs(
s
, stdout);
44
fflush(stdout);
45
}
46
47
void
emit_line
(
const
char
*
s
)
48
{
49
while
(*
s
!= 0)
50
{
51
while
(*
s
!=
'\n'
&& *
s
!= 0) putchar(*
s
++);
52
putchar(
'\n'
);
53
if
(*
s
!= 0)
s
++;
54
fputs(
wrapping_prefix
, stdout);
55
}
56
fflush(stdout);
57
}
58
59
// Local Variables:
60
// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
61
// indent-tabs-mode: nil
62
// End:
buffer
Definition
buffer.hpp:55
freemem
void freemem(void *s)
Definition
m2-mem.cpp:103
s
void size_t s
Definition
m2-mem.cpp:271
newarray_atomic
#define newarray_atomic(T, len)
Definition
newdelete.hpp:91
newdelete.hpp
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
emit_wrapped
void emit_wrapped(const char *s)
Definition
text-io.cpp:27
bignum_text_out
void bignum_text_out(buffer &o, mpz_srcptr a)
Definition
text-io.cpp:12
emit_line
void emit_line(const char *s)
Definition
text-io.cpp:47
emit
void emit(const char *s)
Definition
text-io.cpp:41
MAX_LINE_LENGTH
int MAX_LINE_LENGTH
Definition
text-io.cpp:9
clear_emit_size
void clear_emit_size()
Definition
text-io.cpp:26
emit_line_len
std::atomic_int emit_line_len
Definition
text-io.cpp:10
wrapping_prefix
#define wrapping_prefix
Definition
text-io.hpp:41
text-io.hpp
Text-formatting helpers layered on buffer: bignum print, line wrapping, M2_gbTrace-gated emit.
Macaulay2
e
text-io.cpp
Generated on
for Macaulay2 Engine by
1.15.0