4 * PCB, interactive printed circuit board design
5 * Copyright (C) 2011 Andrew Poelstra
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Contact addresses for paper mail and Email:
22 * Andrew Poelstra, 16966 60A Ave, V3S 8X5 Surrey, BC, Canada
27 /* This file defines a wrapper around sprintf, that
28 * defines new specifiers that take pcb Coord objects
31 * There is a fair bit of nasty (repetitious) code in
32 * here, but I feel the gain in clarity for output
33 * code elsewhere in the project will make it worth
36 * The new specifiers are:
37 * %mk output a measure in km
38 * %mf output a measure in meters
39 * %me output a measure in cm
40 * %mm output a measure in mm
41 * %mu output a measure in um
42 * %mn output a measure in nm
43 * %mM output a measure in scaled (mm/um) metric
44 * %ml output a measure in mil
45 * %mc output a measure in cmil
46 * %mt output a measure in 1/10 of mils (for Excellon drill files)
47 * %mL output a measure in scaled (mil/in) imperial
48 * %ms output a measure in most natural mm/mil units
49 * %mS output a measure in most natural scaled units
50 * %md output a pair of measures in most natural mm/mil units
51 * %mD output a pair of measures in most natural scaled units
52 * %m3 output 3 measures in most natural scaled units
54 * %m9 output 9 measures in most natural scaled units
55 * %m* output a measure with unit given as an additional
56 * const char* parameter
57 * %m+ accepts an e_allow parameter that masks all subsequent
58 * "natural" (S/D/3/.../9) specifiers to only use certain
60 * %mr output a measure in a unit readable by parse_l.l
61 * (this will always append a unit suffix)
62 * %ma output an angle in degrees (expects degrees)
64 * These accept the usual printf modifiers for %f, as well as
65 * $ output a unit suffix after the measure
66 * # prevents all scaling for %mS/D/1/.../9 (this should
67 * ONLY be used for debug code since its output exposes
69 * ` always use '.' as decimal separator (note that %mr uses
73 * No support for %zu size_t printf spec
76 #ifndef PCB_PCB_PRINTF_H
77 #define PCB_PCB_PRINTF_H
80 NO_PRINT
= 0, /* suffixes we can read but not print (i.e., "inch") */
93 ALLOW_METRIC
= ALLOW_NM
| ALLOW_UM
| ALLOW_MM
|
94 ALLOW_CM
| ALLOW_M
| ALLOW_KM
,
95 ALLOW_IMPERIAL
= ALLOW_CMIL
| ALLOW_DMIL
| ALLOW_MIL
| ALLOW_IN
,
96 /* This is all units allowed in parse_l.l */
98 ALLOW_READABLE
= ALLOW_NM
| ALLOW_UM
| ALLOW_MM
|
99 ALLOW_M
| ALLOW_KM
| ALLOW_CMIL
|
100 ALLOW_MIL
| ALLOW_IN
,
102 ALLOW_READABLE
= ALLOW_MIL
| ALLOW_MM
,
105 ALLOW_ALL
= ~ALLOW_DMIL
108 enum e_family
{ METRIC
, IMPERIAL
};
110 NO_SUFFIX
, /* no suffix */
111 SUFFIX
, /* suffix, prefixed with ' ' */
112 FILE_MODE_NO_SUFFIX
, /* no suffix, force '.' as decimal */
113 FILE_MODE
/* suffix, force '.' as decimal */
117 int index
; /* Index into Unit[] list */
119 const char *in_suffix
; /* internationalized suffix */
122 enum e_family family
;
125 /* used for gui spinboxes */
131 /* aliases -- right now we only need 1 ("inch"->"in"), add as needed */
132 const char *alias
[1];
137 /* key g and <shift>g value */
141 /* key s and <shift>s value */
145 /* key l and <shift>l value */
149 /* key k and <shift>k value */
155 void initialize_units();
157 const Unit
*get_unit_struct (const char *suffix
);
158 const Unit
*get_unit_list (void);
159 int get_n_units (void);
160 double coord_to_unit (const Unit
*, Coord
);
161 Coord
unit_to_coord (const Unit
*, double);
162 Increments
*get_increments_struct (enum e_family family
);
163 void copy_nonzero_increments (Increments
*dst
, const Increments
*src
);
164 enum e_allow
set_allow_readable(enum e_allow new_mask
);
166 int pcb_fprintf(FILE *f
, const char *fmt
, ...);
167 int pcb_snprintf(char *string
, size_t size
, const char *fmt
, ...);
168 int pcb_printf(const char *fmt
, ...);
169 char *pcb_g_strdup_printf(const char *fmt
, ...);
170 gchar
*pcb_vprintf(const char *fmt
, va_list args
);
173 void pcb_printf_register_tests ();
174 void pcb_printf_test_unit ();
175 void pcb_printf_test_printf ();