Debian Codegraph @

lib/sfio/sfhdr.h

raw
1 /*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11 #pragma once
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #include <inttypes.h>
18
19 /* Internal definitions for sfio.
20 ** Written by Kiem-Phong Vo
21 */
22
23 #include <sfio/sfio.h>
24 #include "config.h"
25
26 #include <limits.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdint.h>
30 #include <stddef.h>
31
32 #include <fcntl.h>
33
34 #include <unistd.h>
35
36 #include <errno.h>
37 #include <ctype.h>
38
39 /* short-hands */
40 #ifndef uchar
41 #define uchar unsigned char
42 #endif
43 #ifndef ulong
44 #define ulong uint64_t
45 #endif
46 #ifndef ushort
47 #define ushort unsigned short
48 #endif
49
50 /* function to get the decimal point for local environment */
51 #include <locale.h>
52 #define SFSETLOCALE(decimal,thousand) \
53 { struct lconv* lv_; \
54 if((decimal) == 0) \
55 { (decimal) = '.'; \
56 if((lv_ = localeconv())) \
57 { if(lv_->decimal_point && lv_->decimal_point[0]) \
58 (decimal) = lv_->decimal_point[0]; \
59 if(lv_->thousands_sep && lv_->thousands_sep[0]) \
60 (thousand) = lv_->thousands_sep[0]; \
61 } \
62 } \
63 }
64
65 typedef union {
66 int i, *ip;
67 long l, *lp;
68 short h, *hp;
69 unsigned ui;
70 ulong ul;
71 ushort uh;
72 long long ll, *llp;
73 unsigned long long lu;
74 long double ld;
75 double d;
76 float f;
77 char c, *s, **sp;
78 void *vp;
79 Sffmt_t *ft;
80 } Argv_t;
81
82 #define LEFTP '('
83 #define RIGHTP ')'
84 #define QUOTE '\''
85
86 #define FMTSET(ft, frm, fv, sz, flgs, wid,pr,bs, ts,ns) \
87 ((ft->form = (char*)frm), \
88 (ft->fmt = fv), (ft->size = sz), \
89 (ft->flags = (flgs&SFFMT_SET)), \
90 (ft->width = wid), (ft->precis = pr), (ft->base = bs), \
91 (ft->t_str = ts), (ft->n_str = ns) )
92 #define FMTGET(ft, frm, fv, sz, flgs, wid,pr,bs) \
93 ((frm = ft->form), (fv = ft->fmt), (sz = ft->size), \
94 (flgs = (flgs&~(SFFMT_SET))|(ft->flags&SFFMT_SET)), \
95 (wid = ft->width), (pr = ft->precis), (bs = ft->base) )
96 #define FMTCMP(sz, type, maxtype) \
97 (sz == sizeof(type) || (sz == 0 && sizeof(type) == sizeof(maxtype)) || \
98 (sz == 64 && sz == sizeof(type)*CHAR_BIT) )
99
100 /* format flags&types, must coexist with those in sfio.h */
101 #define SFFMT_EFORMAT 01000000000 /* sfcvt converting %e */
102 #define SFFMT_MINUS 02000000000 /* minus sign */
103
104 #define SFFMT_TYPES (SFFMT_SHORT|SFFMT_SSHORT | SFFMT_LONG|SFFMT_LLONG|\
105 SFFMT_LDOUBLE | SFFMT_IFLAG|SFFMT_JFLAG| \
106 SFFMT_TFLAG | SFFMT_ZFLAG )
107
108 /* type of elements to be converted */
109 #define SFFMT_INT 001 /* %d,%i */
110 #define SFFMT_UINT 002 /* %u,o,x etc. */
111 #define SFFMT_FLOAT 004 /* %f,e,g etc. */
112 #define SFFMT_BYTE 010 /* %c */
113 #define SFFMT_POINTER 020 /* %p, %n */
114 #define SFFMT_CLASS 040 /* %[ */
115
116 #define SF_RADIX 64 /* maximum integer conversion base */
117
118 /* floating point to ascii conversion */
119 #define SF_MAXEXP10 6
120 #define SF_FDIGITS 256 /* max allowed fractional digits */
121 #define SF_IDIGITS 1024 /* max number of digits in int part */
122 #define SF_MAXDIGITS (((SF_FDIGITS+SF_IDIGITS)/sizeof(int) + 1)*sizeof(int))
123
124 /* tables for numerical translation */
125 #define _Sfpos10 (_Sftable.sf_pos10)
126 #define _Sfneg10 (_Sftable.sf_neg10)
127 #define _Sfdec (_Sftable.sf_dec)
128 #define _Sfdigits (_Sftable.sf_digits)
129 #define _Sffmtintf (_Sftable.sf_fmtintf)
130 #define _Sfcv36 (_Sftable.sf_cv36)
131 #define _Sfcv64 (_Sftable.sf_cv64)
132 #define _Sftype (_Sftable.sf_type)
133 typedef struct _sftab_ {
134 long double sf_pos10[SF_MAXEXP10]; ///< positive powers of 10
135 long double sf_neg10[SF_MAXEXP10]; ///< negative powers of 10
136 uchar sf_dec[200]; /* ascii reps of values < 100 */
137 char *sf_digits; /* digits for general bases */
138 const char *(*sf_fmtintf)(const char *);
139 uchar sf_cv36[UCHAR_MAX + 1]; /* conversion for base [2-36] */
140 uchar sf_cv64[UCHAR_MAX + 1]; /* conversion for base [37-64] */
141 uchar sf_type[UCHAR_MAX + 1]; /* conversion formats&types */
142 } Sftab_t;
143
144 extern Sftab_t _Sftable;
145
146 extern char *_sfcvt(void *, int, int *, int *, int);
147
148 #ifdef __cplusplus
149 }
150 #endif