find.c: Remove unused APIs SaveFindFlag() and RestoreFindFlag()
[geda-pcb/pcjc2.git] / src / pcb-printf.h
blob3d4e0d21696c6e3efd8a22619ce8d6a632f32391
1 /*
2 * COPYRIGHT
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
23 * asp11@sfu.ca
27 /* This file defines a wrapper around sprintf, that
28 * defines new specifiers that take pcb Coord objects
29 * as input.
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
34 * it.
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
46 * ...
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
52 * units
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
61 * pcb's base units).
62 * ` always use '.' as decimal separator (note that %mr uses
63 * this by default).
65 * KNOWN ISSUES:
66 * No support for %zu size_t printf spec
69 #ifndef PCB_PCB_PRINTF_H
70 #define PCB_PCB_PRINTF_H
72 enum e_allow {
73 NO_PRINT = 0, /* suffixes we can read but not print (i.e., "inch") */
74 ALLOW_NM = 1,
75 ALLOW_UM = 2,
76 ALLOW_MM = 4,
77 ALLOW_CM = 8,
78 ALLOW_M = 16,
79 ALLOW_KM = 32,
81 ALLOW_CMIL = 1024,
82 ALLOW_MIL = 2048,
83 ALLOW_IN = 4096,
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 */
89 #if 0
90 ALLOW_READABLE = ALLOW_NM | ALLOW_UM | ALLOW_MM |
91 ALLOW_M | ALLOW_KM | ALLOW_CMIL |
92 ALLOW_MIL | ALLOW_IN,
93 #else
94 ALLOW_READABLE = ALLOW_MIL | ALLOW_MM,
95 #endif
97 ALLOW_ALL = ~0
100 enum e_family { METRIC, IMPERIAL };
101 enum e_suffix {
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 */
108 struct unit {
109 int index; /* Index into Unit[] list */
110 const char *suffix;
111 const char *in_suffix; /* internationalized suffix */
112 char printf_code;
113 double scale_factor;
114 enum e_family family;
115 enum e_allow allow;
116 int default_prec;
117 /* used for gui spinboxes */
118 double step_tiny;
119 double step_small;
120 double step_medium;
121 double step_large;
122 double step_huge;
123 /* aliases -- right now we only need 1 ("inch"->"in"), add as needed */
124 const char *alias[1];
127 struct increments {
128 const char *suffix;
129 /* key g and <shift>g value */
130 Coord grid;
131 Coord grid_min;
132 Coord grid_max;
133 /* key s and <shift>s value */
134 Coord size;
135 Coord size_min;
136 Coord size_max;
137 /* key l and <shift>l value */
138 Coord line;
139 Coord line_min;
140 Coord line_max;
141 /* key k and <shift>k value */
142 Coord clear;
143 Coord clear_min;
144 Coord clear_max;
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);
163 #endif