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 * %mm output a measure in mm
38 * %mM output a measure in scaled (mm/um) metric
39 * %ml output a measure in mil
40 * %mL output a measure in scaled (mil/in) imperial
41 * %ms output a measure in most natural mm/mil units
42 * %mS output a measure in most natural scaled units
43 * %md output a pair of measures in most natural mm/mil units
44 * %mD output a pair of measures in most natural scaled units
45 * %m3 output 3 measures in most natural scaled units
47 * %m9 output 9 measures in most natural scaled units
48 * %m* output a measure with unit given as an additional
49 * const char* parameter
50 * %m+ accepts an e_allow parameter that masks all subsequent
51 * "natural" (S/D/3/.../9) specifiers to only use certain
53 * %mr output a measure in a unit readable by parse_l.l
54 * (this will always append a unit suffix)
55 * %ma output an angle in degrees (expects degrees)
57 * These accept the usual printf modifiers for %f, as well as
58 * $ output a unit suffix after the measure
59 * # prevents all scaling for %mS/D/1/.../9 (this should
60 * ONLY be used for debug code since its output exposes
62 * ` always use '.' as decimal separator (note that %mr uses
66 * No support for %zu size_t printf spec
69 #ifndef PCB_PCB_PRINTF_H
70 #define PCB_PCB_PRINTF_H
73 NO_PRINT
= 0, /* suffixes we can read but not print (i.e., "inch") */
85 ALLOW_METRIC
= ALLOW_NM
| ALLOW_UM
| ALLOW_MM
|
86 ALLOW_CM
| ALLOW_M
| ALLOW_KM
,
87 ALLOW_IMPERIAL
= ALLOW_CMIL
| ALLOW_MIL
| ALLOW_IN
,
88 /* This is all units allowed in parse_l.l */
90 ALLOW_READABLE
= ALLOW_NM
| ALLOW_UM
| ALLOW_MM
|
91 ALLOW_M
| ALLOW_KM
| ALLOW_CMIL
|
94 ALLOW_READABLE
= ALLOW_MIL
| ALLOW_MM
,
100 enum e_family
{ METRIC
, IMPERIAL
};
102 NO_SUFFIX
, /* no suffix */
103 SUFFIX
, /* suffix, prefixed with ' ' */
104 FILE_MODE_NO_SUFFIX
, /* no suffix, force '.' as decimal */
105 FILE_MODE
/* suffix, force '.' as decimal */
109 int index
; /* Index into Unit[] list */
111 const char *in_suffix
; /* internationalized suffix */
114 enum e_family family
;
117 /* used for gui spinboxes */
123 /* aliases -- right now we only need 1 ("inch"->"in"), add as needed */
124 const char *alias
[1];
129 /* key g and <shift>g value */
133 /* key s and <shift>s value */
137 /* key l and <shift>l value */
141 /* key k and <shift>k value */
147 void initialize_units();
149 const Unit
*get_unit_struct (const char *suffix
);
150 const Unit
*get_unit_list (void);
151 int get_n_units (void);
152 double coord_to_unit (const Unit
*, Coord
);
153 Coord
unit_to_coord (const Unit
*, double);
154 Increments
*get_increments_struct (enum e_family family
);
155 void copy_nonzero_increments (Increments
*dst
, const Increments
*src
);
157 int pcb_fprintf(FILE *f
, const char *fmt
, ...);
158 int pcb_sprintf(char *string
, const char *fmt
, ...);
159 int pcb_printf(const char *fmt
, ...);
160 char *pcb_g_strdup_printf(const char *fmt
, ...);
161 gchar
*pcb_vprintf(const char *fmt
, va_list args
);