Remove superfluous check that unsigned int is nonnegative.
[geda-pcb/whiteaudio.git] / src / flags.c
blobd809ad51d6153ba10d3e701c7cd03ac760975bc8
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 2005 DJ Delorie
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.
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include <math.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #ifdef HAVE_STRING_H
32 #include <string.h>
33 #endif
35 #include "global.h"
36 #include "data.h"
37 #include "pcb-printf.h"
39 #ifdef HAVE_LIBDMALLOC
40 #include <dmalloc.h>
41 #endif
43 static int
44 FlagCurrentStyle (int dummy)
46 STYLE_LOOP (PCB);
48 if (style->Thick == Settings.LineThickness &&
49 style->Diameter == Settings.ViaThickness &&
50 style->Hole == Settings.ViaDrillingHole &&
51 style->Keepaway == Settings.Keepaway)
52 return n + 1;
54 END_LOOP;
55 return 0;
58 static int
59 FlagGrid (int dummy)
61 return PCB->Grid > 1;
64 static int
65 FlagGridSize (int dummy)
67 return PCB->Grid;
70 static int
71 FlagUnitsMm (int dummy)
73 static const Unit *u = NULL;
74 if (u == NULL)
75 u = get_unit_struct ("mm");
76 return (Settings.grid_unit == u);
79 static int
80 FlagUnitsMil (int dummy)
82 static const Unit *u = NULL;
83 if (u == NULL)
84 u = get_unit_struct ("mil");
85 return (Settings.grid_unit == u);
88 static int
89 FlagBuffer (int dummy)
91 return (int) (Settings.BufferNumber + 1);
94 static int
95 FlagElementName (int dummy)
97 if (TEST_FLAG (NAMEONPCBFLAG, PCB))
98 return 2;
99 if (TEST_FLAG (DESCRIPTIONFLAG, PCB))
100 return 1;
101 return 3;
104 static int
105 FlagTESTFLAG (int bit)
107 return TEST_FLAG (bit, PCB) ? 1 : 0;
110 static int
111 FlagSETTINGS (int ofs)
113 return *(bool *) ((char *) (&Settings) + ofs);
116 static int
117 FlagMode (int x)
119 if (x == -1)
120 return Settings.Mode;
121 return Settings.Mode == x;
124 static int
125 FlagHaveRegex (int x)
127 #if defined(HAVE_REGCOMP) || defined(HAVE_RE_COMP)
128 return 1;
129 #else
130 return 0;
131 #endif
134 enum {
135 FL_SILK = -6,
136 FL_PINS,
137 FL_RATS,
138 FL_VIAS,
139 FL_BACK,
140 FL_MASK
143 static int
144 FlagLayerShown (int n)
146 switch (n)
148 case FL_SILK:
149 return PCB->ElementOn;
150 case FL_PINS:
151 return PCB->PinOn;
152 case FL_RATS:
153 return PCB->RatOn;
154 case FL_VIAS:
155 return PCB->ViaOn;
156 case FL_BACK:
157 return PCB->InvisibleObjectsOn;
158 case FL_MASK:
159 return TEST_FLAG (SHOWMASKFLAG, PCB);
160 default:
161 if (n >= 0 && n < max_copper_layer)
162 return PCB->Data->Layer[n].On;
164 return 0;
167 static int
168 FlagLayerActive (int n)
170 int current_layer;
171 if (PCB->RatDraw)
172 current_layer = FL_RATS;
173 else if (PCB->SilkActive)
174 current_layer = FL_SILK;
175 else
176 return 0;
178 return current_layer == n;
181 /* The cast to (int) is ONLY valid because we know we are
182 * taking offsets on structures where the offset will fit
183 * in an integer variable. It silences compile warnings on
184 * 64bit machines.
186 #define OffsetOf(a,b) (int)(size_t)(&(((a *)0)->b))
188 HID_Flag flags_flag_list[] = {
189 {"style", FlagCurrentStyle, 0},
190 {"grid", FlagGrid, 0},
191 {"gridsize", FlagGridSize, 0},
192 {"elementname", FlagElementName, 0},
193 {"have_regex", FlagHaveRegex, 0},
195 {"silk_shown", FlagLayerShown, FL_SILK},
196 {"pins_shown", FlagLayerShown, FL_PINS},
197 {"rats_shown", FlagLayerShown, FL_RATS},
198 {"vias_shown", FlagLayerShown, FL_VIAS},
199 {"back_shown", FlagLayerShown, FL_BACK},
200 {"mask_shown", FlagLayerShown, FL_MASK},
201 {"silk_active", FlagLayerActive, FL_SILK},
202 {"rats_active", FlagLayerActive, FL_RATS},
204 {"mode", FlagMode, -1},
205 {"nomode", FlagMode, NO_MODE},
206 {"arcmode", FlagMode, ARC_MODE},
207 {"arrowmode", FlagMode, ARROW_MODE},
208 {"copymode", FlagMode, COPY_MODE},
209 {"insertpointmode", FlagMode, INSERTPOINT_MODE},
210 {"linemode", FlagMode, LINE_MODE},
211 {"lockmode", FlagMode, LOCK_MODE},
212 {"movemode", FlagMode, MOVE_MODE},
213 {"pastebuffermode", FlagMode, PASTEBUFFER_MODE},
214 {"polygonmode", FlagMode, POLYGON_MODE},
215 {"polygonholemode", FlagMode, POLYGONHOLE_MODE},
216 {"rectanglemode", FlagMode, RECTANGLE_MODE},
217 {"removemode", FlagMode, REMOVE_MODE},
218 {"rotatemode", FlagMode, ROTATE_MODE},
219 {"rubberbandmovemode", FlagMode, RUBBERBANDMOVE_MODE},
220 {"textmode", FlagMode, TEXT_MODE},
221 {"thermalmode", FlagMode, THERMAL_MODE},
222 {"viamode", FlagMode, VIA_MODE},
224 {"shownumber", FlagTESTFLAG, SHOWNUMBERFLAG},
225 {"localref", FlagTESTFLAG, LOCALREFFLAG},
226 {"checkplanes", FlagTESTFLAG, CHECKPLANESFLAG},
227 {"showdrc", FlagTESTFLAG, SHOWDRCFLAG},
228 {"rubberband", FlagTESTFLAG, RUBBERBANDFLAG},
229 {"description", FlagTESTFLAG, DESCRIPTIONFLAG},
230 {"nameonpcb", FlagTESTFLAG, NAMEONPCBFLAG},
231 {"autodrc", FlagTESTFLAG, AUTODRCFLAG},
232 {"alldirection", FlagTESTFLAG, ALLDIRECTIONFLAG},
233 {"swapstartdir", FlagTESTFLAG, SWAPSTARTDIRFLAG},
234 {"uniquename", FlagTESTFLAG, UNIQUENAMEFLAG},
235 {"clearnew", FlagTESTFLAG, CLEARNEWFLAG},
236 {"snappin", FlagTESTFLAG, SNAPPINFLAG},
237 {"showmask", FlagTESTFLAG, SHOWMASKFLAG},
238 {"thindraw", FlagTESTFLAG, THINDRAWFLAG},
239 {"orthomove", FlagTESTFLAG, ORTHOMOVEFLAG},
240 {"liveroute", FlagTESTFLAG, LIVEROUTEFLAG},
241 {"thindrawpoly", FlagTESTFLAG, THINDRAWPOLYFLAG},
242 {"locknames", FlagTESTFLAG, LOCKNAMESFLAG},
243 {"onlynames", FlagTESTFLAG, ONLYNAMESFLAG},
244 {"newfullpoly", FlagTESTFLAG, NEWFULLPOLYFLAG},
245 {"hidenames", FlagTESTFLAG, HIDENAMESFLAG},
247 {"fullpoly", FlagSETTINGS, OffsetOf (SettingType, FullPoly)},
248 {"grid_units_mm", FlagUnitsMm, -1},
249 {"grid_units_mil", FlagUnitsMil, -1},
250 {"clearline", FlagSETTINGS, OffsetOf (SettingType, ClearLine)},
251 {"uniquenames", FlagSETTINGS, OffsetOf (SettingType, UniqueNames)},
252 {"showsolderside", FlagSETTINGS, OffsetOf (SettingType, ShowSolderSide)},
253 {"savelastcommand", FlagSETTINGS, OffsetOf (SettingType, SaveLastCommand)},
254 {"saveintmp", FlagSETTINGS, OffsetOf (SettingType, SaveInTMP)},
255 {"drawgrid", FlagSETTINGS, OffsetOf (SettingType, DrawGrid)},
256 {"ratwarn", FlagSETTINGS, OffsetOf (SettingType, RatWarn)},
257 {"stipplepolygons", FlagSETTINGS, OffsetOf (SettingType, StipplePolygons)},
258 {"alldirectionlines", FlagSETTINGS,
259 OffsetOf (SettingType, AllDirectionLines)},
260 {"rubberbandmode", FlagSETTINGS, OffsetOf (SettingType, RubberBandMode)},
261 {"swapstartdirection", FlagSETTINGS,
262 OffsetOf (SettingType, SwapStartDirection)},
263 {"showdrcmode", FlagSETTINGS, OffsetOf (SettingType, ShowDRC)},
264 {"resetafterelement", FlagSETTINGS,
265 OffsetOf (SettingType, ResetAfterElement)},
266 {"ringbellwhenfinished", FlagSETTINGS,
267 OffsetOf (SettingType, RingBellWhenFinished)},
269 {"buffer", FlagBuffer, 0},
273 REGISTER_FLAGS (flags_flag_list)