Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
fmt_bits.cpp
Go to the documentation of this file.
1
29// expand _TEST_EXPORT macros
30#define _RWSTD_TEST_SRC
31
32#include "fmt_defs.h"
33
34#include <rw_printf.h>
35
36#include <ctype.h> // for isalnum(), ...
37#include <errno.h> // for errno, errno constants
38#include <locale.h>
39#include <signal.h> // for signal constant
40#include <stddef.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h> // memcpy(), memmove(), strcat(), ...
44
45#ifndef _RWSTD_NO_WCHAR_H
46# include <wchar.h>
47#endif // _RWSTD_NO_WCHAR_H
48
49#ifndef _RWSTD_NO_WCTYPE_H
50# include <wctype.h> // for iswalpha(), ...
51#endif // _RWSTD_NO_WCTYPE_H
52
53#ifdef _WIN32
54# include <windows.h> // for FormatMessage()
55#endif // _WIN32
56
57#include <ios>
58#include <iostream>
59#include <locale>
60
61
64{
65 const char *longname;
66 const char *name;
67 int bits;
68};
69
70#define BITNAME(qual, name) { #qual "::" #name, #name, qual::name }
71
72static int
73_rw_bmpfmt (const FmtSpec &spec, Buffer &buf,
74 const Bitnames bmap[],
75 size_t size,
76 int bits)
77{
78 RW_ASSERT (0 != buf.pbuf);
79
80 char buffer [1024];
81 *buffer = '\0';
82
83 // string to use when no bits are set
84 const char* all_clear = "0";
85
86 for (size_t i = 0; i != size; ++i) {
87 if (bmap [i].bits) {
88 if ((bits & bmap [i].bits) == bmap [i].bits) {
89
90 const char* const name = spec.fl_pound ?
91 bmap [i].longname : bmap [i].name;
92
93 strcat (*buffer ? strcat (buffer, " | ") : buffer, name);
94
95 bits &= ~bmap [i].bits;
96 }
97 }
98 else {
99 // save the name of the constant to use for 0
100 all_clear = spec.fl_pound ? bmap [i].longname : bmap [i].name;
101 }
102 }
103
104 size_t buffersize;
105
106 if ('\0' == *buffer) {
107 // no constant matched, format teh value either as a number
108 // or, when 0, using the all_clear name (see above)
109 if (bits)
110 sprintf (buffer, "%#x", bits);
111 else
112 strcpy (buffer, all_clear);
113
114 buffersize = strlen (buffer);
115 }
116 else if (bits) {
117 buffersize = strlen (buffer);
118
119 // verify that buffer wasn't overflowed
120 RW_ASSERT (buffersize <= sizeof buffer);
121
122 char bitstr [32];
123 const int n = sprintf (bitstr, "%#x | ", bits);
124
125 RW_ASSERT (0 < n);
126
127 memmove (buffer + n, buffer, buffersize);
128 memcpy (buffer, bitstr, size_t (n));
129
130 buffersize += n;
131 }
132 else {
133 buffersize = strlen (buffer);
134 }
135
136 // verify that buffer wasn't overflowed
137 RW_ASSERT (buffersize <= sizeof buffer);
138
139 // NUL-terminate string so that it can be appended to using
140 // the %{+} directive, taking care not to make the NUL a part
141 // of the formatted string
142 FmtSpec newspec (spec);
143 newspec.fl_pound = 0;
144
145 const int len = _rw_fmtstr (newspec, buf, buffer, buffersize + 1);
146 --buf.endoff;
147
148 return 0 < len ? len - 1 : len;
149}
150
151
153/* extern */ int
154_rw_fmtflags (const FmtSpec &spec, Buffer &buf, int bits)
155{
156 static const Bitnames names [] = {
157 BITNAME (std::ios, adjustfield),
158 BITNAME (std::ios, basefield),
159 BITNAME (std::ios, boolalpha),
160 BITNAME (std::ios, dec),
161 BITNAME (std::ios, fixed),
162 BITNAME (std::ios, hex),
163 BITNAME (std::ios, internal),
164 BITNAME (std::ios, left),
165 BITNAME (std::ios, oct),
166 BITNAME (std::ios, right),
167 BITNAME (std::ios, scientific),
168 BITNAME (std::ios, showbase),
169 BITNAME (std::ios, showpoint),
170 BITNAME (std::ios, showpos),
171 BITNAME (std::ios, skipws),
172 BITNAME (std::ios, unitbuf),
173 BITNAME (std::ios, uppercase),
174
175#ifndef _RWSTD_NO_EXT_BIN_IO
176
177 // extension: produce binary output (similar to oct, dec, and hex)
178 BITNAME (std::ios, bin),
179
180#endif // _RWSTD_NO_EXT_BIN_IO
181
182#ifndef _RWSTD_NO_EXT_REENTRANT_IO
183
184 // extension: allow unsychronized access to stream and/or its buffer
185 BITNAME (std::ios, nolock),
186 BITNAME (std::ios, nolockbuf),
187
188#endif // _RWSTD_NO_EXT_REENTRANT_IO
189
190 { "std::ios::fmtflags(0)", "fmtflags(0)", std::ios::fmtflags () }
191
192 };
193
194 static const size_t count = sizeof names / sizeof *names;
195
196 const int base = (bits >> _RWSTD_IOS_BASEOFF) & _RWSTD_IOS_BASEMASK;
197
198 // zero out bits representingthe numeric base
200
201 int len = _rw_bmpfmt (spec, buf, names, count, bits);
202
203 if (0 < len && base && base != 8 && base != 10 && base != 16) {
204
205 // for numeric bases other than those required by the standard,
206 // use the text "base (%d)" to show the extended numeric base
207
208#ifndef _RWSTD_NO_EXT_BIN_IO
209
210 if (bits & std::ios::bin)
211 return len;
212
213#endif // _RWSTD_NO_EXT_BIN_IO
214
215 const int n = rw_asnprintf (buf.pbuf, buf.pbufsize,
216 "%{+} | %{?}std::ios::%{;}base(%d)",
217 spec.fl_pound, base);
218
219 if (0 < n) {
220 // adjust length and the end offset after appending above
221 len += n;
222 buf.endoff += n;
223 }
224 else {
225 // error (most likely ENOMEM)
226 len = n;
227 }
228 }
229
230 return len;
231}
232
233
235/* extern */ int
236_rw_fmtiostate (const FmtSpec &spec, Buffer &buf, int bits)
237{
238 static const Bitnames names [] = {
239 BITNAME (std::ios, goodbit),
240 BITNAME (std::ios, badbit),
241 BITNAME (std::ios, eofbit),
242 BITNAME (std::ios, failbit)
243 };
244
245 static const size_t count = sizeof names / sizeof *names;
246
247 return _rw_bmpfmt (spec, buf, names, count, bits);
248}
249
250
252/* extern */ int
253_rw_fmtopenmode (const FmtSpec &spec, Buffer &buf, int bits)
254{
255 static const Bitnames names [] = {
256
257#ifndef _RWSTD_NO_EXTENSIONS
258
259 { "std::ios::nocreate", "nocreate", std::ios::nocreate },
260 { "std::ios::noreplace", "noreplace", std::ios::noreplace },
261
262#else // if defined (_RWSTD_NO_EXTENSIONS)
263
264 { "__rw:::__rw_nocreate", "__rw_nocreate", _RW::__rw_nocreate },
265 { "__rw::__rw_noreplace", "__rw_noreplace", _RW::__rw_noreplace },
266
267#endif // _RWSTD_NO_EXTENSIONS
268
269#ifndef _RWSTD_NO_EXT_STDIO
270
271 { "std::ios::stdio", "stdio", std::ios::stdio },
272 { "std::ios::native", "native", std::ios::native },
273
274#else // if defined (_RWSTD_NO_EXT_STDIO)
275
276 { "__rw::__rw_stdio", "__rw_stdio", _RW::__rw_stdio },
277 { "__rw::__rw_native", "__rw_native", _RW::__rw_native },
278
279#endif // _RWSTD_NO_EXT_STDIO
280
281 BITNAME (std::ios, app),
282 BITNAME (std::ios, binary),
283 BITNAME (std::ios, in),
284 BITNAME (std::ios, out),
285 BITNAME (std::ios, trunc),
286 BITNAME (std::ios, ate),
287
288 { "std::ios::openmode(0)", "openmode(0)", std::ios::openmode () }
289 };
290
291 static const size_t count = sizeof names / sizeof *names;
292
293 return _rw_bmpfmt (spec, buf, names, count, bits);
294}
295
296
298/* extern */ int
299_rw_fmtseekdir (const FmtSpec &spec, Buffer &buf, int bits)
300{
301 static const Bitnames names [] = {
302
303 BITNAME (std::ios, beg),
304 BITNAME (std::ios, cur),
305 BITNAME (std::ios, end)
306 };
307
308 static const size_t count = sizeof names / sizeof *names;
309
310 return _rw_bmpfmt (spec, buf, names, count, bits);
311}
312
313
315/* extern */ int
316_rw_fmtevent (const FmtSpec& spec, Buffer &buf, int event)
317{
318 const char* const str =
319 std::ios::copyfmt_event == event ? "copyfmt_event"
320 : std::ios::imbue_event == event ? "imbue_event"
321 : std::ios::erase_event == event ? "erase_event"
322 : 0;
323
324 // NUL-terminate before appending below
325 FmtSpec newspec (spec);
326 newspec.fl_pound = 0;
327
328 int len = _rw_fmtstr (newspec, buf, "", 1);
329
330 if (1 == len) {
331 // back up before the terminating NUL
332 buf.endoff -= 1;
333
334 // append name of event
335 len = rw_asnprintf (buf.pbuf, buf.pbufsize,
336 "%{+}%{?}std::ios::%{;}%{?}%s%{:}event(%d)%{;}",
337 spec.fl_pound, 0 != str, str, event);
338
339 if (0 < len)
340 buf.endoff += len;
341 }
342
343 return len;
344}
345
346
348/* extern */ int
349_rw_fmtlc (const FmtSpec &spec, Buffer &buf, int val)
350{
351 const char *str = 0;
352
353 switch (val) {
354 case LC_ALL: str = "LC_ALL"; break;
355 case LC_COLLATE: str = "LC_COLLATE"; break;
356 case LC_CTYPE: str = "LC_CTYPE"; break;
357 case LC_MONETARY: str = "LC_MONETARY"; break;
358 case LC_NUMERIC: str = "LC_NUMERIC"; break;
359 case LC_TIME: str = "LC_TIME"; break;
360
361#ifdef LC_MESSAGES
362 case LC_MESSAGES: str = "LC_MESSAGES"; break;
363#endif // LC_MESSAGES
364
365 }
366
367 if (str) {
368 // NUL-terminate before appending below
369 FmtSpec newspec (spec);
370 newspec.fl_pound = 0;
371
372 int len = _rw_fmtstr (newspec, buf, "", 1);
373
374 if (1 == len) {
375 // back up before the terminating NUL
376 buf.endoff -= 1;
377
378 len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str);
379
380 if (0 < len)
381 buf.endoff += len;
382 }
383
384 return len;
385 }
386
387 static const Bitnames names [] = {
388 BITNAME (std::locale, all),
389 BITNAME (std::locale, none),
390 BITNAME (std::locale, collate),
391 BITNAME (std::locale, ctype),
392 BITNAME (std::locale, monetary),
393 BITNAME (std::locale, numeric),
394 BITNAME (std::locale, messages),
395 BITNAME (std::locale, time)
396 };
397
398 static const size_t count = sizeof names / sizeof *names;
399
400 return _rw_bmpfmt (spec, buf, names, count, val);
401}
402
403
405/* extern */ int
406_rw_fmtmonpat (const FmtSpec &spec, Buffer &buf, const char pat [4])
407{
408 static const char qual[] = "std::money_base::";
409
410 char buffer [256];
411
412 buffer [0] = '\0';
413
414 for (int i = 0; i != 4; ++i) {
415 switch (pat [i]) {
416 case std::money_base::symbol:
417 if (spec.fl_pound)
418 strcat (buffer, qual);
419 strcat (buffer, "symbol ");
420 break;
421
422 case std::money_base::sign:
423 if (spec.fl_pound)
424 strcat (buffer, qual);
425 strcat (buffer, "sign ");
426 break;
427
428 case std::money_base::none:
429 if (spec.fl_pound)
430 strcat (buffer, qual);
431 strcat (buffer, "none ");
432 break;
433
434 case std::money_base::value:
435 if (spec.fl_pound)
436 strcat (buffer, qual);
437 strcat (buffer, "value ");
438 break;
439
440 case std::money_base::space:
441 if (spec.fl_pound)
442 strcat (buffer, qual);
443 strcat (buffer, "space ");
444 break;
445
446 default:
447 sprintf (buffer + strlen (buffer), "\\%03o", pat [i]);
448 break;
449 }
450 }
451
452 FmtSpec newspec (spec);
453 newspec.fl_pound = 0;
454
455 return _rw_fmtstr (newspec, buf, buffer, _RWSTD_SIZE_MAX);
456}
457
458
460/* extern */ int
461_rw_fmtsignal (const FmtSpec &spec, Buffer &buf, int val)
462{
463 static const struct {
464 int val;
465 const char* str;
466 } names[] = {
467
468#undef SIGNAL
469#define SIGNAL(val) { val, #val }
470
471#ifdef SIGABRT
472 SIGNAL (SIGABRT),
473#endif // SIGABRT
474#ifdef SIGALRM
475 SIGNAL (SIGALRM),
476#endif // SIGALRM
477#ifdef SIGBUS
478 SIGNAL (SIGBUS),
479#endif // SIGBUS
480#ifdef SIGCANCEL
481 SIGNAL (SIGCANCEL),
482#endif // SIGCANCEL
483#ifdef SIGCHLD
484 SIGNAL (SIGCHLD),
485#endif // SIGCHLD
486#ifdef SIGCKPT
487 SIGNAL (SIGCKPT),
488#endif // SIGCKPT
489#ifdef SIGCLD
490 SIGNAL (SIGCLD),
491#endif // SIGCLD
492#ifdef SIGCONT
493 SIGNAL (SIGCONT),
494#endif // SIGCONT
495#ifdef SIGDIL
496 SIGNAL (SIGDIL),
497#endif // SIGDIL
498#ifdef SIGEMT
499 SIGNAL (SIGEMT),
500#endif // SIGEMT
501#ifdef SIGFPE
502 SIGNAL (SIGFPE),
503#endif // SIGFPE
504#ifdef SIGFREEZE
505 SIGNAL (SIGFREEZE),
506#endif // SIGFREEZE
507#ifdef SIGGFAULT
508 SIGNAL (SIGGFAULT),
509#endif // SIGGFAULT
510#ifdef SIGHUP
511 SIGNAL (SIGHUP),
512#endif // SIGHUP
513#ifdef SIGILL
514 SIGNAL (SIGILL),
515#endif // SIGILL
516#ifdef SIGINFO
517 SIGNAL (SIGINFO),
518#endif // SIGINFO
519#ifdef SIGINT
520 SIGNAL (SIGINT),
521#endif // SIGINT
522#ifdef SIGIO
523 SIGNAL (SIGIO),
524#endif // SIGIO
525#ifdef SIGIOT
526 SIGNAL (SIGIOT),
527#endif // SIGIOT
528#ifdef SIGK32
529 SIGNAL (SIGK32),
530#endif // SIGK32
531#ifdef SIGKILL
532 SIGNAL (SIGKILL),
533#endif // SIGKILL
534#ifdef SIGLOST
535 SIGNAL (SIGLOST),
536#endif // SIGLOST
537#ifdef SIGLWP
538 SIGNAL (SIGLWP),
539#endif // SIGLWP
540#ifdef SIGPIPE
541 SIGNAL (SIGPIPE),
542#endif // SIGPIPE
543#ifdef SIGPOLL
544 SIGNAL (SIGPOLL),
545#endif // SIGPOLL
546#ifdef SIGPROF
547 SIGNAL (SIGPROF),
548#endif // SIGPROF
549#ifdef SIGPTINTR
550 SIGNAL (SIGPTINTR),
551#endif // SIGPTINTR
552#ifdef SIGPTRESCHED
553 SIGNAL (SIGPTRESCHED),
554#endif // SIGPTRESCHED
555#ifdef SIGPWR
556 SIGNAL (SIGPWR),
557#endif // SIGPWR
558#ifdef SIGQUIT
559 SIGNAL (SIGQUIT),
560#endif // SIGQUIT
561#ifdef SIGRESTART
562 SIGNAL (SIGRESTART),
563#endif // SIGRESTART
564#ifdef SIGRESV
565 SIGNAL (SIGRESV),
566#endif // SIGRESV
567#ifdef SIGSEGV
568 SIGNAL (SIGSEGV),
569#endif // SIGSEGV
570#ifdef SIGSTKFLT
571 SIGNAL (SIGSTKFLT),
572#endif // SIGSTKFLT
573#ifdef SIGSTOP
574 SIGNAL (SIGSTOP),
575#endif // SIGSTOP
576#ifdef SIGSYS
577 SIGNAL (SIGSYS),
578#endif // SIGSYS
579#ifdef SIGTERM
580 SIGNAL (SIGTERM),
581#endif // SIGTERM
582#ifdef SIGTHAW
583 SIGNAL (SIGTHAW),
584#endif // SIGTHAW
585#ifdef SIGTRAP
586 SIGNAL (SIGTRAP),
587#endif // SIGTRAP
588#ifdef SIGTSTP
589 SIGNAL (SIGTSTP),
590#endif // SIGTSTP
591#ifdef SIGTTIN
592 SIGNAL (SIGTTIN),
593#endif // SIGTTIN
594#ifdef SIGTTOU
595 SIGNAL (SIGTTOU),
596#endif // SIGTTOU
597#ifdef SIGUNUSED
598 SIGNAL (SIGUNUSED),
599#endif // SIGUNUSED
600#ifdef SIGURG
601 SIGNAL (SIGURG),
602#endif // SIGURG
603#ifdef SIGUSR1
604 SIGNAL (SIGUSR1),
605#endif // SIGUSR1
606#ifdef SIGUSR2
607 SIGNAL (SIGUSR2),
608#endif // SIGUSR2
609#ifdef SIGVTALRM
610 SIGNAL (SIGVTALRM),
611#endif // SIGVTALRM
612#ifdef SIGWAITING
613 SIGNAL (SIGWAITING),
614#endif // SIGWAITING
615#ifdef SIGWINCH
616 SIGNAL (SIGWINCH),
617#endif // SIGWINCH
618#ifdef SIGWINDOW
619 SIGNAL (SIGWINDOW),
620#endif // SIGWINDOW
621#ifdef SIGXCPU
622 SIGNAL (SIGXCPU),
623#endif // SIGXCPU
624#ifdef SIGXFSZ
625 SIGNAL (SIGXFSZ),
626#endif // SIGXFSZ
627#ifdef SIGXRES
628 SIGNAL (SIGXRES),
629#endif // SIGXRES
630 { -1, 0 }
631 };
632
633 const char *name = 0;
634
635 for (size_t i = 0; i != sizeof names / sizeof *names; ++i) {
636 if (names [i].val == val) {
637 name = names [i].str;
638 break;
639 }
640 }
641
642 char smallbuf [32];
643 if (0 == name) {
644 sprintf (smallbuf, "SIG#%d", val);
645 name = smallbuf;
646 }
647
648 FmtSpec newspec (spec);
649 newspec.fl_pound = 0;
650
651 return _rw_fmtstr (newspec, buf, name, _RWSTD_SIZE_MAX);
652}
653
654
656/* extern */ int
657_rw_fmterrno (const FmtSpec &spec, Buffer &buf, int val)
658{
659 static const struct {
660 int val;
661 const char* str;
662 } names[] = {
663
664#undef ERRNO
665#define ERRNO(val) { val, #val }
666
667#ifdef EPERM
668 ERRNO (EPERM),
669#endif // EPERM
670#ifdef ENOENT
671 ERRNO (ENOENT),
672#endif // ENOENT
673#ifdef ESRCH
674 ERRNO (ESRCH),
675#endif // ESRCH
676#ifdef EINTR
677 ERRNO (EINTR),
678#endif // EINTR
679#ifdef EIO
680 ERRNO (EIO),
681#endif // EIO
682#ifdef ENXIO
683 ERRNO (ENXIO),
684#endif // ENXIO
685#ifdef E2BIG
686 ERRNO (E2BIG),
687#endif // E2BIG
688#ifdef ENOEXEC
689 ERRNO (ENOEXEC),
690#endif // ENOEXEC
691#ifdef EBADF
692 ERRNO (EBADF),
693#endif // EBADF
694#ifdef ECHILD
695 ERRNO (ECHILD),
696#endif // ECHILD
697#ifdef EAGAIN
698 ERRNO (EAGAIN),
699#endif // EAGAIN
700#ifdef ENOMEM
701 ERRNO (ENOMEM),
702#endif // ENOMEM
703#ifdef EACCES
704 ERRNO (EACCES),
705#endif // EACCES
706#ifdef EFAULT
707 ERRNO (EFAULT),
708#endif // EFAULT
709#ifdef ENOTBLK
710 ERRNO (ENOTBLK),
711#endif // ENOTBLK
712#ifdef EBUSY
713 ERRNO (EBUSY),
714#endif // EBUSY
715#ifdef EEXIST
716 ERRNO (EEXIST),
717#endif // EEXIST
718#ifdef EXDEV
719 ERRNO (EXDEV),
720#endif // EXDEV
721#ifdef ENODEV
722 ERRNO (ENODEV),
723#endif // ENODEV
724#ifdef ENOTDIR
725 ERRNO (ENOTDIR),
726#endif // ENOTDIR
727#ifdef EISDIR
728 ERRNO (EISDIR),
729#endif // EISDIR
730#ifdef EINVAL
731 ERRNO (EINVAL),
732#endif // EINVAL
733#ifdef ENFILE
734 ERRNO (ENFILE),
735#endif // ENFILE
736#ifdef EMFILE
737 ERRNO (EMFILE),
738#endif // EMFILE
739#ifdef ENOTTY
740 ERRNO (ENOTTY),
741#endif // ENOTTY
742#ifdef ETXTBSY
743 ERRNO (ETXTBSY),
744#endif // ETXTBSY
745#ifdef EFBIG
746 ERRNO (EFBIG),
747#endif // EFBIG
748#ifdef ENOSPC
749 ERRNO (ENOSPC),
750#endif // ENOSPC
751#ifdef ESPIPE
752 ERRNO (ESPIPE),
753#endif // ESPIPE
754#ifdef EROFS
755 ERRNO (EROFS),
756#endif // EROFS
757#ifdef EMLINK
758 ERRNO (EMLINK),
759#endif // EMLINK
760#ifdef EPIPE
761 ERRNO (EPIPE),
762#endif // EPIPE
763#ifdef EDOM
764 ERRNO (EDOM),
765#endif // EDOM
766#ifdef ERANGE
767 ERRNO (ERANGE),
768#endif // ERANGE
769#ifdef ENOMSG
770 ERRNO (ENOMSG),
771#endif // ENOMSG
772#ifdef EIDRM
773 ERRNO (EIDRM),
774#endif // EIDRM
775#ifdef ECHRNG
776 ERRNO (ECHRNG),
777#endif // ECHRNG
778#ifdef EL2NSYNC
779 ERRNO (EL2NSYNC),
780#endif // EL2NSYNC
781#ifdef EL3HLT
782 ERRNO (EL3HLT),
783#endif // EL3HLT
784#ifdef EL3RST
785 ERRNO (EL3RST),
786#endif // EL3RST
787#ifdef ELNRNG
788 ERRNO (ELNRNG),
789#endif // ELNRNG
790#ifdef EUNATCH
791 ERRNO (EUNATCH),
792#endif // EUNATCH
793#ifdef ENOCSI
794 ERRNO (ENOCSI),
795#endif // ENOCSI
796#ifdef EL2HLT
797 ERRNO (EL2HLT),
798#endif // EL2HLT
799#ifdef EDEADLK
800 ERRNO (EDEADLK),
801#endif // EDEADLK
802#ifdef ENOLCK
803 ERRNO (ENOLCK),
804#endif // ENOLCK
805#ifdef ECANCELED
806 ERRNO (ECANCELED),
807#endif // ECANCELED
808#ifdef ENOTSUP
809 ERRNO (ENOTSUP),
810#endif // ENOTSUP
811#ifdef EDQUOT
812 ERRNO (EDQUOT),
813#endif // EDQUOT
814#ifdef EBADE
815 ERRNO (EBADE),
816#endif // EBADE
817#ifdef EBADR
818 ERRNO (EBADR),
819#endif // EBADR
820#ifdef EXFULL
821 ERRNO (EXFULL),
822#endif // EXFULL
823#ifdef ENOANO
824 ERRNO (ENOANO),
825#endif // ENOANO
826#ifdef EBADRQC
827 ERRNO (EBADRQC),
828#endif // EBADRQC
829#ifdef EBADSLT
830 ERRNO (EBADSLT),
831#endif // EBADSLT
832#ifdef EDEADLOCK
833 ERRNO (EDEADLOCK),
834#endif // EDEADLOCK
835#ifdef EBFONT
836 ERRNO (EBFONT),
837#endif // EBFONT
838#ifdef EOWNERDEAD
839 ERRNO (EOWNERDEAD),
840#endif // EOWNERDEAD
841#ifdef ENOTRECOVERABLE
842 ERRNO (ENOTRECOVERABLE),
843#endif // ENOTRECOVERABLE
844#ifdef ENOSTR
845 ERRNO (ENOSTR),
846#endif // ENOSTR
847#ifdef ENODATA
848 ERRNO (ENODATA),
849#endif // ENODATA
850#ifdef ETIME
851 ERRNO (ETIME),
852#endif // ETIME
853#ifdef ENOSR
854 ERRNO (ENOSR),
855#endif // ENOSR
856#ifdef ENONET
857 ERRNO (ENONET),
858#endif // ENONET
859#ifdef ENOPKG
860 ERRNO (ENOPKG),
861#endif // ENOPKG
862#ifdef EREMOTE
863 ERRNO (EREMOTE),
864#endif // EREMOTE
865#ifdef ENOLINK
866 ERRNO (ENOLINK),
867#endif // ENOLINK
868#ifdef EADV
869 ERRNO (EADV),
870#endif // EADV
871#ifdef ESRMNT
872 ERRNO (ESRMNT),
873#endif // ESRMNT
874#ifdef ECOMM
875 ERRNO (ECOMM),
876#endif // ECOMM
877#ifdef ELOCKUNMAPPED
878 ERRNO (ELOCKUNMAPPED),
879#endif // ELOCKUNMAPPED
880#ifdef ENOTACTIVE
881 ERRNO (ENOTACTIVE),
882#endif // ENOTACTIVE
883#ifdef EMULTIHOP
884 ERRNO (EMULTIHOP),
885#endif // EMULTIHOP
886#ifdef EBADMSG
887 ERRNO (EBADMSG),
888#endif // EBADMSG
889#ifdef ENAMETOOLONG
890 ERRNO (ENAMETOOLONG),
891#endif // ENAMETOOLONG
892#ifdef EOVERFLOW
893 ERRNO (EOVERFLOW),
894#endif // EOVERFLOW
895#ifdef ENOTUNIQ
896 ERRNO (ENOTUNIQ),
897#endif // ENOTUNIQ
898#ifdef EBADFD
899 ERRNO (EBADFD),
900#endif // EBADFD
901#ifdef EREMCHG
902 ERRNO (EREMCHG),
903#endif // EREMCHG
904#ifdef ELIBACC
905 ERRNO (ELIBACC),
906#endif // ELIBACC
907#ifdef ELIBBAD
908 ERRNO (ELIBBAD),
909#endif // ELIBBAD
910#ifdef ELIBSCN
911 ERRNO (ELIBSCN),
912#endif // ELIBSCN
913#ifdef ELIBMAX
914 ERRNO (ELIBMAX),
915#endif // ELIBMAX
916#ifdef ELIBEXEC
917 ERRNO (ELIBEXEC),
918#endif // ELIBEXEC
919#ifdef EILSEQ
920 ERRNO (EILSEQ),
921#endif // EILSEQ
922#ifdef ENOSYS
923 ERRNO (ENOSYS),
924#endif // ENOSYS
925#ifdef ELOOP
926 ERRNO (ELOOP),
927#endif // ELOOP
928#ifdef ERESTART
929 ERRNO (ERESTART),
930#endif // ERESTART
931#ifdef ESTRPIPE
932 ERRNO (ESTRPIPE),
933#endif // ESTRPIPE
934#ifdef ENOTEMPTY
935 ERRNO (ENOTEMPTY),
936#endif // ENOTEMPTY
937#ifdef EUSERS
938 ERRNO (EUSERS),
939#endif // EUSERS
940#ifdef ENOTSOCK
941 ERRNO (ENOTSOCK),
942#endif // ENOTSOCK
943#ifdef EDESTADDRREQ
944 ERRNO (EDESTADDRREQ),
945#endif // EDESTADDRREQ
946#ifdef EMSGSIZE
947 ERRNO (EMSGSIZE),
948#endif // EMSGSIZE
949#ifdef EPROTOTYPE
950 ERRNO (EPROTOTYPE),
951#endif // EPROTOTYPE
952#ifdef ENOPROTOOPT
953 ERRNO (ENOPROTOOPT),
954#endif // ENOPROTOOPT
955#ifdef EPROTONOSUPPORT
956 ERRNO (EPROTONOSUPPORT),
957#endif // EPROTONOSUPPORT
958#ifdef ESOCKTNOSUPPORT
959 ERRNO (ESOCKTNOSUPPORT),
960#endif // ESOCKTNOSUPPORT
961#ifdef EOPNOTSUPP
962 ERRNO (EOPNOTSUPP),
963#endif // EOPNOTSUPP
964#ifdef EPFNOSUPPORT
965 ERRNO (EPFNOSUPPORT),
966#endif // EPFNOSUPPORT
967#ifdef EAFNOSUPPORT
968 ERRNO (EAFNOSUPPORT),
969#endif // EAFNOSUPPORT
970#ifdef EADDRINUSE
971 ERRNO (EADDRINUSE),
972#endif // EADDRINUSE
973#ifdef EADDRNOTAVAIL
974 ERRNO (EADDRNOTAVAIL),
975#endif // EADDRNOTAVAIL
976#ifdef ENETDOWN
977 ERRNO (ENETDOWN),
978#endif // ENETDOWN
979#ifdef ENETUNREACH
980 ERRNO (ENETUNREACH),
981#endif // ENETUNREACH
982#ifdef ENETRESET
983 ERRNO (ENETRESET),
984#endif // ENETRESET
985#ifdef ECONNABORTED
986 ERRNO (ECONNABORTED),
987#endif // ECONNABORTED
988#ifdef ECONNRESET
989 ERRNO (ECONNRESET),
990#endif // ECONNRESET
991#ifdef ENOBUFS
992 ERRNO (ENOBUFS),
993#endif // ENOBUFS
994#ifdef EISCONN
995 ERRNO (EISCONN),
996#endif // EISCONN
997#ifdef ENOTCONN
998 ERRNO (ENOTCONN),
999#endif // ENOTCONN
1000#ifdef ESHUTDOWN
1001 ERRNO (ESHUTDOWN),
1002#endif // ESHUTDOWN
1003#ifdef ETOOMANYREFS
1004 ERRNO (ETOOMANYREFS),
1005#endif // ETOOMANYREFS
1006#ifdef ETIMEDOUT
1007 ERRNO (ETIMEDOUT),
1008#endif // ETIMEDOUT
1009#ifdef ECONNREFUSED
1010 ERRNO (ECONNREFUSED),
1011#endif // ECONNREFUSED
1012#ifdef EHOSTDOWN
1013 ERRNO (EHOSTDOWN),
1014#endif // EHOSTDOWN
1015#ifdef EHOSTUNREACH
1016 ERRNO (EHOSTUNREACH),
1017#endif // EHOSTUNREACH
1018#ifdef EWOULDBLOCK
1019 ERRNO (EWOULDBLOCK),
1020#endif // EWOULDBLOCK
1021#ifdef EALREADY
1022 ERRNO (EALREADY),
1023#endif // EALREADY
1024#ifdef EINPROGRESS
1025 ERRNO (EINPROGRESS),
1026#endif // EINPROGRESS
1027#ifdef ESTALE
1028 ERRNO (ESTALE),
1029#endif // ESTALE
1030 { -1, 0 }
1031 };
1032
1033 const char* str = strerror (val);
1034
1035 char smallbuf [32];
1036
1037 if (spec.fl_pound || 0 == str) {
1038
1039 const char *name = 0;
1040
1041 for (size_t i = 0; i != sizeof names / sizeof *names; ++i) {
1042 if (names [i].val == val) {
1043 name = names [i].str;
1044 break;
1045 }
1046 }
1047
1048 if (0 == name) {
1049 sprintf (smallbuf, "E#%d", val);
1050 str = smallbuf;
1051 }
1052 else
1053 str = name;
1054 }
1055
1056 FmtSpec newspec (spec);
1057 newspec.width = 0;
1058 newspec.fl_pound = 0;
1059
1060 return _rw_fmtstr (newspec, buf, str, _RWSTD_SIZE_MAX);
1061}
1062
1063
1065/* extern */ int
1067{
1068#ifdef _WIN32
1069
1070 LPVOID pmsg;
1071 FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER
1072 | FORMAT_MESSAGE_FROM_SYSTEM
1073 | FORMAT_MESSAGE_IGNORE_INSERTS,
1074 0, (DWORD)val,
1075 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
1076 (LPTSTR)&pmsg,
1077 0, 0);
1078
1079 FmtSpec newspec (spec);
1080 newspec.width = 0;
1081 newspec.fl_pound = 0;
1082
1083 const int result = _rw_fmtstr (newspec, buf,
1084 _RWSTD_STATIC_CAST (const char*, pmsg),
1085 _RWSTD_SIZE_MAX);
1086
1087 LocalFree (pmsg);
1088
1089 return result;
1090
1091#else // if !defined (_WIN32)
1092
1093 return _rw_fmterrno (spec, buf, val);
1094
1095#endif // _WIN32
1096
1097}
1098
1099
1101/* extern */ int
1102_rw_fmtmask (const FmtSpec &spec, Buffer &buf, int bits)
1103{
1104 static const Bitnames names [] = {
1105 BITNAME (std::ctype_base, alnum),
1106 BITNAME (std::ctype_base, alpha),
1107 BITNAME (std::ctype_base, cntrl),
1108 BITNAME (std::ctype_base, digit),
1109 BITNAME (std::ctype_base, graph),
1110 BITNAME (std::ctype_base, lower),
1111 BITNAME (std::ctype_base, print),
1112 BITNAME (std::ctype_base, punct),
1113 BITNAME (std::ctype_base, space),
1114 BITNAME (std::ctype_base, upper),
1115 BITNAME (std::ctype_base, xdigit)
1116 };
1117
1118 static const size_t count = sizeof names / sizeof *names;
1119
1120 return _rw_bmpfmt (spec, buf, names, count, bits);
1121}
1122
1123
1125/* extern */ int
1126_rw_fmtcharmask (const FmtSpec &spec, Buffer &buf, int c)
1127{
1128 enum {
1129 bit_alnum = 1,
1130 bit_alpha = 1 << 1,
1131 bit_cntrl = 1 << 2,
1132 bit_digit = 1 << 3,
1133 bit_graph = 1 << 4,
1134 bit_lower = 1 << 5,
1135 bit_print = 1 << 6,
1136 bit_punct = 1 << 7,
1137 bit_space = 1 << 8,
1138 bit_upper = 1 << 9,
1139 bit_xdigit = 1 << 10
1140 };
1141
1142 int mask = 0;
1143
1144 if (spec.fl_pound) {
1145
1146#ifndef _RWSTD_NO_WCHAR_H
1147
1148 mask |= iswalnum (c) ? bit_alnum : 0;
1149 mask |= iswalpha (c) ? bit_alpha : 0;
1150 mask |= iswcntrl (c) ? bit_cntrl : 0;
1151 mask |= iswdigit (c) ? bit_digit : 0;
1152 mask |= iswgraph (c) ? bit_graph : 0;
1153 mask |= iswlower (c) ? bit_lower : 0;
1154 mask |= iswprint (c) ? bit_print : 0;
1155 mask |= iswpunct (c) ? bit_punct : 0;
1156 mask |= iswspace (c) ? bit_space : 0;
1157 mask |= iswupper (c) ? bit_upper : 0;
1158 mask |= iswxdigit (c) ? bit_xdigit : 0;
1159
1160#endif // _RWSTD_NO_WCHAR_H
1161
1162 }
1163 else {
1164 const unsigned char uc = c;
1165
1166 mask |= isalnum (uc) ? bit_alnum : 0;
1167 mask |= isalpha (uc) ? bit_alpha : 0;
1168 mask |= iscntrl (uc) ? bit_cntrl : 0;
1169 mask |= isdigit (uc) ? bit_digit : 0;
1170 mask |= isgraph (uc) ? bit_graph : 0;
1171 mask |= islower (uc) ? bit_lower : 0;
1172 mask |= isprint (uc) ? bit_print : 0;
1173 mask |= ispunct (uc) ? bit_punct : 0;
1174 mask |= isspace (uc) ? bit_space : 0;
1175 mask |= isupper (uc) ? bit_upper : 0;
1176 mask |= isxdigit (uc) ? bit_xdigit : 0;
1177 }
1178
1179 char mask_str [80];
1180 char *str = mask_str;
1181
1182 str [0] = '\0';
1183
1184#define APPEND(bit) \
1185 if (mask & bit_ ## bit) \
1186 strcat (strcat (str, #bit), "|"); \
1187 else (void)0
1188
1189 APPEND (alnum);
1190 APPEND (alpha);
1191 APPEND (cntrl);
1192 APPEND (digit);
1193 APPEND (graph);
1194 APPEND (lower);
1195 APPEND (print);
1196 APPEND (punct);
1197 APPEND (space);
1198 APPEND (upper);
1199 APPEND (xdigit);
1200
1201 if (str == mask_str)
1202 *str = '\0';
1203 else
1204 str [-1] = '\0';
1205
1206 FmtSpec newspec (spec);
1207 newspec.fl_pound = 0;
1208
1209 return _rw_fmtstr (newspec, buf, str, _RWSTD_SIZE_MAX);
1210}
1211
1212
1214/* extern */ int
1216 const void *pelems, size_t elemsize)
1217{
1218 const size_t nbits = spec.prec;
1219
1220 char bitbuf [256];
1221 char *pbits = nbits < sizeof bitbuf ? bitbuf : new char [nbits + 1];
1222
1223 for (size_t bitno = 0; bitno != nbits; ++bitno) {
1224
1225 if (bitno && 0 == (bitno % (elemsize * _RWSTD_CHAR_BIT)))
1226 pelems = _RWSTD_STATIC_CAST (const UChar*, pelems) + elemsize;
1227
1228 size_t bit = 1 << (bitno & (_RWSTD_CHAR_BIT * elemsize - 1));
1229
1230 switch (elemsize) {
1231 case _RWSTD_CHAR_SIZE:
1232 bit = *_RWSTD_STATIC_CAST (const UChar*, pelems) & bit;
1233 break;
1234
1235#if _RWSTD_CHAR_SIZE < _RWSTD_SHRT_SIZE
1236 case _RWSTD_SHRT_SIZE:
1237 bit = *_RWSTD_STATIC_CAST (const UShrt*, pelems) & bit;
1238 break;
1239#endif // sizeof (char) < sizeof (short)
1240
1241#if _RWSTD_SHRT_SIZE < _RWSTD_INT_SIZE
1242 case _RWSTD_INT_SIZE:
1243 bit = *_RWSTD_STATIC_CAST (const UInt*, pelems) & bit;
1244 break;
1245#endif // sizeof (short) < sizeof (int)
1246
1247#if _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
1248 case _RWSTD_LONG_SIZE:
1249 bit = *_RWSTD_STATIC_CAST (const ULong*, pelems) & bit;
1250 break;
1251#endif // sizeof (int) < sizeof (long)
1252
1253#if _RWSTD_LONG_SIZE < _RWSTD_LLONG_SIZE
1254 case _RWSTD_LLONG_SIZE:
1255 bit = *_RWSTD_STATIC_CAST (const ULLong*, pelems) & bit;
1256 break;
1257#endif // sizeof (long) < sizeof (long long)
1258
1259 default:
1260 RW_ASSERT (!"logic error: bad element size");
1261 }
1262
1263 pbits [bitno] = bit ? '1' : '0';
1264 }
1265
1266 const int res = _rw_fmtstr (spec, buf, pbits, nbits);
1267
1268 if (pbits != bitbuf)
1269 delete[] pbits;
1270
1271 return res;
1272}
const char lower[]
const char graph[]
const char upper[]
const char cntrl[]
const char print[]
const char punct[]
void count(T, T, const U &,...)
#define i
Definition 17.names.cpp:126
#define res
Definition 17.names.cpp:531
#define buf
Definition 17.names.cpp:452
#define buffer
Definition 17.names.cpp:453
#define c
Definition 17.names.cpp:111
#define len
Definition 17.names.cpp:488
#define n
Definition 17.names.cpp:130
#define val
Definition 17.names.cpp:570
volatile int result
#define EDOM
#define EILSEQ
@ bit_graph
@ bit_cntrl
@ bit_upper
@ bit_digit
@ bit_alpha
@ bit_alnum
@ bit_xdigit
@ bit_lower
@ bit_print
@ bit_space
@ bit_punct
#define showbase
#define failbit
#define badbit
#define adjustfield
#define unitbuf
#define scientific
#define uppercase
#define left
#define nolock
#define nolockbuf
#define showpoint
#define goodbit
#define dec
#define skipws
#define oct
#define hex
#define bin
#define eofbit
#define boolalpha
#define internal
#define right
#define basefield
#define showpos
#define fixed
#define SIGPIPE
@ ULLong
const int end
const int out
const int ate
const int cur
const int in
#define ERANGE
#define LC_CTYPE
#define LC_NUMERIC
#define LC_MONETARY
#define LC_ALL
#define LC_TIME
#define LC_COLLATE
#define SIGINT
#define SIGILL
#define SIGTERM
#define SIGFPE
#define SIGABRT
#define SIGSEGV
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_IOS_BASEOFF
Definition _defs.h:805
#define _RWSTD_IOS_BASEMASK
Definition _defs.h:804
#define SIGALRM
Definition alarm.cpp:132
const char * name
Definition codecvt1.cpp:72
#define ENOENT
Definition exec.cpp:93
#define ESRCH
Definition exec.cpp:96
#define ECHILD
Definition exec.cpp:102
const char * str
Definition exec.cpp:170
int _rw_fmtcharmask(const FmtSpec &spec, Buffer &buf, int c)
#define APPEND(bit)
int _rw_fmtmonpat(const FmtSpec &spec, Buffer &buf, const char pat[4])
Definition fmt_bits.cpp:406
int _rw_fmtlasterror(const FmtSpec &spec, Buffer &buf, int val)
int _rw_fmtbits(const FmtSpec &spec, Buffer &buf, const void *pelems, size_t elemsize)
int _rw_fmtmask(const FmtSpec &spec, Buffer &buf, int bits)
#define ERRNO(val)
int _rw_fmtiostate(const FmtSpec &spec, Buffer &buf, int bits)
Definition fmt_bits.cpp:236
int _rw_fmtevent(const FmtSpec &spec, Buffer &buf, int event)
Definition fmt_bits.cpp:316
int _rw_fmtflags(const FmtSpec &spec, Buffer &buf, int bits)
Definition fmt_bits.cpp:154
int _rw_fmtlc(const FmtSpec &spec, Buffer &buf, int val)
Definition fmt_bits.cpp:349
#define SIGNAL(val)
int _rw_fmterrno(const FmtSpec &spec, Buffer &buf, int val)
Definition fmt_bits.cpp:657
int _rw_fmtseekdir(const FmtSpec &spec, Buffer &buf, int bits)
Definition fmt_bits.cpp:299
#define BITNAME(qual, name)
Definition fmt_bits.cpp:70
int _rw_fmtopenmode(const FmtSpec &spec, Buffer &buf, int bits)
Definition fmt_bits.cpp:253
int _rw_fmtsignal(const FmtSpec &spec, Buffer &buf, int val)
Definition fmt_bits.cpp:461
unsigned long ULong
Definition fmt_defs.h:43
unsigned int UInt
Definition fmt_defs.h:42
int _rw_fmtstr(const FmtSpec &, Buffer &, const char *, size_t)
Definition printf.cpp:2316
unsigned short UShrt
Definition fmt_defs.h:41
#define EFAULT
Definition memattr.cpp:36
#define ENOMEM
Definition memattr.cpp:78
#define SIGCHLD
Definition process.cpp:65
#define SIGHUP
Definition process.cpp:75
#define EINTR
Definition process.cpp:54
#define SIGQUIT
Definition process.cpp:79
#define E2BIG
Definition process.cpp:50
#define SIGKILL
Definition process.cpp:83
_TEST_EXPORT int rw_asnprintf(char **pbuf, _RWSTD_SIZE_T *pbufsize, const char *fmt,...)
#define RW_ASSERT(expr)
unsigned char UChar
Definition collate.cpp:122
#define LC_MESSAGES
Definition time_put.cpp:60
const char * longname
Definition fmt_bits.cpp:65
const char * name
Definition fmt_bits.cpp:66
unsigned fl_pound
Definition fmt_defs.h:72
int prec
Definition fmt_defs.h:112
int width
Definition fmt_defs.h:111
A local time-of-day.
#define EINVAL
Definition cmdopt.cpp:40
#define ENOTSUP
Definition thread.cpp:374