osfuns.cc revision 1.1.1.3 1 1.1 mrg /* Support for operator<< routines.
2 1.1 mrg
3 1.1 mrg THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 1.1 mrg CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 1.1 mrg FUTURE GNU MP RELEASES.
6 1.1 mrg
7 1.1 mrg Copyright 2001 Free Software Foundation, Inc.
8 1.1 mrg
9 1.1 mrg This file is part of the GNU MP Library.
10 1.1 mrg
11 1.1 mrg The GNU MP Library is free software; you can redistribute it and/or modify
12 1.1.1.2 mrg it under the terms of either:
13 1.1.1.2 mrg
14 1.1.1.2 mrg * the GNU Lesser General Public License as published by the Free
15 1.1.1.2 mrg Software Foundation; either version 3 of the License, or (at your
16 1.1.1.2 mrg option) any later version.
17 1.1.1.2 mrg
18 1.1.1.2 mrg or
19 1.1.1.2 mrg
20 1.1.1.2 mrg * the GNU General Public License as published by the Free Software
21 1.1.1.2 mrg Foundation; either version 2 of the License, or (at your option) any
22 1.1.1.2 mrg later version.
23 1.1.1.2 mrg
24 1.1.1.2 mrg or both in parallel, as here.
25 1.1 mrg
26 1.1 mrg The GNU MP Library is distributed in the hope that it will be useful, but
27 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 1.1.1.2 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 1.1.1.2 mrg for more details.
30 1.1 mrg
31 1.1.1.2 mrg You should have received copies of the GNU General Public License and the
32 1.1.1.2 mrg GNU Lesser General Public License along with the GNU MP Library. If not,
33 1.1.1.2 mrg see https://www.gnu.org/licenses/. */
34 1.1 mrg
35 1.1 mrg #include <iostream>
36 1.1 mrg #include <stdarg.h> /* for va_list and hence doprnt_funs_t */
37 1.1 mrg #include <string.h>
38 1.1 mrg
39 1.1 mrg #include "gmp-impl.h"
40 1.1 mrg
41 1.1 mrg using namespace std;
42 1.1 mrg
43 1.1 mrg
44 1.1 mrg /* Don't need "format" for operator<< routines, just "memory" and "reps".
45 1.1 mrg Omitting gmp_asprintf_format lets us avoid dragging vsnprintf into the
46 1.1 mrg link. __gmp_asprintf_final will be called directly and doesn't need to
47 1.1 mrg be in the struct. */
48 1.1 mrg
49 1.1 mrg const struct doprnt_funs_t __gmp_asprintf_funs_noformat = {
50 1.1 mrg NULL,
51 1.1 mrg (doprnt_memory_t) __gmp_asprintf_memory,
52 1.1 mrg (doprnt_reps_t) __gmp_asprintf_reps,
53 1.1 mrg NULL
54 1.1 mrg };
55 1.1 mrg
56 1.1 mrg
57 1.1 mrg void
58 1.1 mrg __gmp_doprnt_params_from_ios (struct doprnt_params_t *p, ios &o)
59 1.1 mrg {
60 1.1 mrg if ((o.flags() & ios::basefield) == ios::hex)
61 1.1 mrg {
62 1.1 mrg p->expfmt = "@%c%02d";
63 1.1 mrg p->base = (o.flags() & ios::uppercase ? -16 : 16);
64 1.1 mrg }
65 1.1 mrg else
66 1.1 mrg {
67 1.1 mrg p->expfmt = (o.flags() & ios::uppercase ? "E%c%02d" : "e%c%02d");
68 1.1 mrg if ((o.flags() & ios::basefield) == ios::oct)
69 1.1 mrg p->base = 8;
70 1.1 mrg else
71 1.1 mrg p->base = 10;
72 1.1 mrg }
73 1.1 mrg
74 1.1 mrg /* "general" if none or more than one bit set */
75 1.1 mrg if ((o.flags() & ios::floatfield) == ios::fixed)
76 1.1 mrg p->conv = DOPRNT_CONV_FIXED;
77 1.1 mrg else if ((o.flags() & ios::floatfield) == ios::scientific)
78 1.1 mrg p->conv = DOPRNT_CONV_SCIENTIFIC;
79 1.1 mrg else
80 1.1 mrg p->conv = DOPRNT_CONV_GENERAL;
81 1.1 mrg
82 1.1 mrg p->exptimes4 = 0;
83 1.1 mrg
84 1.1 mrg p->fill = o.fill();
85 1.1 mrg
86 1.1 mrg /* "right" if more than one bit set */
87 1.1 mrg if ((o.flags() & ios::adjustfield) == ios::left)
88 1.1 mrg p->justify = DOPRNT_JUSTIFY_LEFT;
89 1.1 mrg else if ((o.flags() & ios::adjustfield) == ios::internal)
90 1.1 mrg p->justify = DOPRNT_JUSTIFY_INTERNAL;
91 1.1 mrg else
92 1.1 mrg p->justify = DOPRNT_JUSTIFY_RIGHT;
93 1.1 mrg
94 1.1 mrg /* ios::fixed allows prec==0, others take 0 as the default 6.
95 1.1 mrg Don't allow negatives (they do bad things to __gmp_doprnt_float_cxx). */
96 1.1 mrg p->prec = MAX (0, o.precision());
97 1.1 mrg if (p->prec == 0 && p->conv != DOPRNT_CONV_FIXED)
98 1.1 mrg p->prec = 6;
99 1.1 mrg
100 1.1 mrg /* for hex showbase is always, for octal only non-zero */
101 1.1 mrg if (o.flags() & ios::showbase)
102 1.1 mrg p->showbase = ((o.flags() & ios::basefield) == ios::hex
103 1.1 mrg ? DOPRNT_SHOWBASE_YES : DOPRNT_SHOWBASE_NONZERO);
104 1.1 mrg else
105 1.1 mrg p->showbase = DOPRNT_SHOWBASE_NO;
106 1.1 mrg
107 1.1 mrg p->showpoint = ((o.flags() & ios::showpoint) != 0);
108 1.1 mrg
109 1.1 mrg /* in fixed and scientific always show trailing zeros, in general format
110 1.1 mrg show them if showpoint is set (or so it seems) */
111 1.1 mrg if ((o.flags() & ios::floatfield) == ios::fixed
112 1.1 mrg || (o.flags() & ios::floatfield) == ios::scientific)
113 1.1 mrg p->showtrailing = 1;
114 1.1 mrg else
115 1.1 mrg p->showtrailing = p->showpoint;
116 1.1 mrg
117 1.1 mrg p->sign = (o.flags() & ios::showpos ? '+' : '\0');
118 1.1 mrg
119 1.1 mrg p->width = o.width();
120 1.1 mrg
121 1.1 mrg /* reset on each output */
122 1.1 mrg o.width (0);
123 1.1 mrg }
124