Graphviz 13.0.0~dev.20241222.1117
Loading...
Searching...
No Matches
sfhdr.h
Go to the documentation of this file.
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
14extern "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/* extensions to sfvprintf/sfvscanf */
66#define FP_SET(fp,fn) (fp < 0 ? (fn += 1) : (fn = fp) )
67
68 typedef union {
69 int i, *ip;
70 long l, *lp;
71 short h, *hp;
72 unsigned ui;
75 long long ll, *llp;
76 unsigned long long lu;
77 long double ld;
78 double d;
79 float f;
80 char c, *s, **sp;
81 void *vp;
83 } Argv_t;
84
85#define LEFTP '('
86#define RIGHTP ')'
87#define QUOTE '\''
88
89#define FMTSET(ft, frm, fv, sz, flgs, wid,pr,bs, ts,ns) \
90 ((ft->form = (char*)frm), \
91 (ft->fmt = fv), (ft->size = sz), \
92 (ft->flags = (flgs&SFFMT_SET)), \
93 (ft->width = wid), (ft->precis = pr), (ft->base = bs), \
94 (ft->t_str = ts), (ft->n_str = ns) )
95#define FMTGET(ft, frm, fv, sz, flgs, wid,pr,bs) \
96 ((frm = ft->form), (fv = ft->fmt), (sz = ft->size), \
97 (flgs = (flgs&~(SFFMT_SET))|(ft->flags&SFFMT_SET)), \
98 (wid = ft->width), (pr = ft->precis), (bs = ft->base) )
99#define FMTCMP(sz, type, maxtype) \
100 (sz == sizeof(type) || (sz == 0 && sizeof(type) == sizeof(maxtype)) || \
101 (sz == 64 && sz == sizeof(type)*CHAR_BIT) )
102
103/* format flags&types, must coexist with those in sfio.h */
104#define SFFMT_EFORMAT 01000000000 /* sfcvt converting %e */
105#define SFFMT_MINUS 02000000000 /* minus sign */
106
107#define SFFMT_TYPES (SFFMT_SHORT|SFFMT_SSHORT | SFFMT_LONG|SFFMT_LLONG|\
108 SFFMT_LDOUBLE | SFFMT_IFLAG|SFFMT_JFLAG| \
109 SFFMT_TFLAG | SFFMT_ZFLAG )
110
111/* type of elements to be converted */
112#define SFFMT_INT 001 /* %d,%i */
113#define SFFMT_UINT 002 /* %u,o,x etc. */
114#define SFFMT_FLOAT 004 /* %f,e,g etc. */
115#define SFFMT_BYTE 010 /* %c */
116#define SFFMT_POINTER 020 /* %p, %n */
117#define SFFMT_CLASS 040 /* %[ */
118
119#define SF_RADIX 64 /* maximum integer conversion base */
120
121/* floating point to ascii conversion */
122#define SF_MAXEXP10 6
123#define SF_FDIGITS 256 /* max allowed fractional digits */
124#define SF_IDIGITS 1024 /* max number of digits in int part */
125#define SF_MAXDIGITS (((SF_FDIGITS+SF_IDIGITS)/sizeof(int) + 1)*sizeof(int))
126
127/* tables for numerical translation */
128#define _Sfpos10 (_Sftable.sf_pos10)
129#define _Sfneg10 (_Sftable.sf_neg10)
130#define _Sfdec (_Sftable.sf_dec)
131#define _Sfdigits (_Sftable.sf_digits)
132#define _Sfcvinit (_Sftable.sf_cvinit)
133#define _Sffmtintf (_Sftable.sf_fmtintf)
134#define _Sfcv36 (_Sftable.sf_cv36)
135#define _Sfcv64 (_Sftable.sf_cv64)
136#define _Sftype (_Sftable.sf_type)
137 typedef struct _sftab_ {
138 long double sf_pos10[SF_MAXEXP10];
139 long double sf_neg10[SF_MAXEXP10];
140 uchar sf_dec[200]; /* ascii reps of values < 100 */
141 char *sf_digits; /* digits for general bases */
142 int sf_cvinit; /* initialization state */
143 char *(*sf_fmtintf) (const char *, int *);
144 uchar sf_cv36[UCHAR_MAX + 1]; /* conversion for base [2-36] */
145 uchar sf_cv64[UCHAR_MAX + 1]; /* conversion for base [37-64] */
146 uchar sf_type[UCHAR_MAX + 1]; /* conversion formats&types */
148
149/* sfucvt() converts decimal integers to ASCII */
150#define SFDIGIT(v,scale,digit) \
151 { if(v < 5*scale) \
152 if(v < 2*scale) \
153 if(v < 1*scale) \
154 { digit = '0'; } \
155 else { digit = '1'; v -= 1*scale; } \
156 else if(v < 3*scale) \
157 { digit = '2'; v -= 2*scale; } \
158 else if(v < 4*scale) \
159 { digit = '3'; v -= 3*scale; } \
160 else { digit = '4'; v -= 4*scale; } \
161 else if(v < 7*scale) \
162 if(v < 6*scale) \
163 { digit = '5'; v -= 5*scale; } \
164 else { digit = '6'; v -= 6*scale; } \
165 else if(v < 8*scale) \
166 { digit = '7'; v -= 7*scale; } \
167 else if(v < 9*scale) \
168 { digit = '8'; v -= 8*scale; } \
169 else { digit = '9'; v -= 9*scale; } \
170 }
171#define sfucvt(v,s,n,list,type,utype) \
172 { while((utype)v >= 10000) \
173 { n = v; v = (type)(((utype)v)/10000); \
174 n = (type)((utype)n - ((utype)v)*10000); \
175 s -= 4; SFDIGIT(n,1000,s[0]); SFDIGIT(n,100,s[1]); \
176 s[2] = *(list = (char*)_Sfdec + (n <<= 1)); s[3] = *(list+1); \
177 } \
178 if(v < 100) \
179 { if(v < 10) \
180 { s -= 1; s[0] = (char)('0'+v); \
181 } else \
182 { s -= 2; s[0] = *(list = (char*)_Sfdec + (v <<= 1)); s[1] = *(list+1); \
183 } \
184 } else \
185 { if(v < 1000) \
186 { s -= 3; SFDIGIT(v,100,s[0]); \
187 s[1] = *(list = (char*)_Sfdec + (v <<= 1)); s[2] = *(list+1); \
188 } else \
189 { s -= 4; SFDIGIT(v,1000,s[0]); SFDIGIT(v,100,s[1]); \
190 s[2] = *(list = (char*)_Sfdec + (v <<= 1)); s[3] = *(list+1); \
191 } \
192 } \
193 }
194
195 extern Sftab_t _Sftable;
196
197 extern char *_sfcvt(void *, int, int *, int *, int);
198
199#ifdef __cplusplus
200}
201#endif
Sftab_t _Sftable
Definition sftable.c:30
#define ushort
Definition sfhdr.h:47
#define ulong
Definition sfhdr.h:44
char * _sfcvt(void *, int, int *, int *, int)
Definition sfcvt.c:31
#define uchar
Definition sfhdr.h:41
struct _sftab_ Sftab_t
#define SF_MAXEXP10
Definition sfhdr.h:122
uchar sf_dec[200]
Definition sfhdr.h:140
long double sf_pos10[SF_MAXEXP10]
positive powers of 10
Definition sfhdr.h:138
uchar sf_cv64[UCHAR_MAX+1]
Definition sfhdr.h:145
uchar sf_type[UCHAR_MAX+1]
Definition sfhdr.h:146
long double sf_neg10[SF_MAXEXP10]
negative powers of 10
Definition sfhdr.h:139
int sf_cvinit
Definition sfhdr.h:142
char * sf_digits
Definition sfhdr.h:141
uchar sf_cv36[UCHAR_MAX+1]
Definition sfhdr.h:144
Definition sfhdr.h:68
unsigned ui
Definition sfhdr.h:72
unsigned long long lu
Definition sfhdr.h:76
short h
Definition sfhdr.h:71
Sffmt_t * ft
Definition sfhdr.h:82
ulong ul
Definition sfhdr.h:73
char c
Definition sfhdr.h:80
void * vp
Definition sfhdr.h:81
long long ll
Definition sfhdr.h:75
double d
Definition sfhdr.h:78
long double ld
Definition sfhdr.h:77
ushort uh
Definition sfhdr.h:74
long l
Definition sfhdr.h:70
int i
Definition sfhdr.h:69
float f
Definition sfhdr.h:79
Definition grammar.c:93