Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 4486) +++ trunk/src/Makefile.in (revision 4487) @@ -45,6 +45,7 @@ file_act.o find.o find_act.o + flag.o free_atexit.o funchash.o gui_act.o Index: trunk/src/data.h =================================================================== --- trunk/src/data.h (revision 4486) +++ trunk/src/data.h (revision 4487) @@ -60,8 +60,6 @@ extern pcb_bool Bumped; -extern FlagType no_flags; - /****** callback based loops *****/ /* The functions returning int are called once when processing of a new layer Index: trunk/src/flag.c =================================================================== --- trunk/src/flag.c (nonexistent) +++ trunk/src/flag.c (revision 4487) @@ -0,0 +1,75 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 1994,1995,1996,2004,2006 Thomas Nau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Contact addresses for paper mail and Email: + * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany + * Thomas.Nau@rz.uni-ulm.de + * + */ + +#include +#include "flag.h" + +/* This just fills in a FlagType with current flags. */ +FlagType MakeFlags(unsigned int flags) +{ + FlagType rv; + memset(&rv, 0, sizeof(rv)); + rv.f = flags; + return rv; +} + +/* This converts old flag bits (from saved PCB files) to new format. */ +FlagType OldFlags(unsigned int flags) +{ + FlagType rv; + int i, f; + memset(&rv, 0, sizeof(rv)); + /* If we move flag bits around, this is where we map old bits to them. */ + rv.f = flags & 0xffff; + f = 0x10000; + for (i = 0; i < 8; i++) { + /* use the closest thing to the old thermal style */ + if (flags & f) + rv.t[i / 2] |= (1 << (4 * (i % 2))); + f <<= 1; + } + return rv; +} + +FlagType AddFlags(FlagType flag, unsigned int flags) +{ + flag.f |= flags; + return flag; +} + +FlagType MaskFlags(FlagType flag, unsigned int flags) +{ + flag.f &= ~flags; + return flag; +} + +int mem_any_set(unsigned char *ptr, int bytes) +{ + while (bytes--) + if (*ptr++) + return 1; + return 0; +} Index: trunk/src/flag.h =================================================================== --- trunk/src/flag.h (nonexistent) +++ trunk/src/flag.h (revision 4487) @@ -0,0 +1,106 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 1994,1995,1996,2006 Thomas Nau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Contact addresses for paper mail and Email: + * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany + * Thomas.Nau@rz.uni-ulm.de + * + */ + +#ifndef PCB_FLAG_H +#define PCB_FLAG_H + +#include "globalconst.h" + +/* Nobody should know about the internals of this except the macros in + macros.h that access it. This structure must be simple-assignable + for now. */ +typedef struct unknown_flag_s unknown_flag_t; +struct unknown_flag_s { + char *str; + unknown_flag_t *next; +}; + +typedef struct { + unsigned long f; /* generic flags */ + unsigned char t[(MAX_LAYER + 1) / 2]; /* thermals */ + unsigned char q; /* square geometry flag */ + unsigned char int_conn_grp; + unknown_flag_t *unknowns; +} FlagType, *FlagTypePtr; + + + +extern FlagType no_flags; + + +/* For passing modified flags to other functions. */ +FlagType MakeFlags(unsigned int); +FlagType OldFlags(unsigned int); +FlagType AddFlags(FlagType, unsigned int); +FlagType MaskFlags(FlagType, unsigned int); +#define NoFlags() MakeFlags(0) + +/* --------------------------------------------------------------------------- + * some routines for flag setting, clearing, changing and testing + */ +#define SET_FLAG(F,P) ((P)->Flags.f |= (F)) +#define CLEAR_FLAG(F,P) ((P)->Flags.f &= (~(F))) +#define TEST_FLAG(F,P) ((P)->Flags.f & (F) ? 1 : 0) +#define TOGGLE_FLAG(F,P) ((P)->Flags.f ^= (F)) +#define ASSIGN_FLAG(F,V,P) ((P)->Flags.f = ((P)->Flags.f & (~(F))) | ((V) ? (F) : 0)) +#define TEST_FLAGS(F,P) (((P)->Flags.f & (F)) == (F) ? 1 : 0) + +typedef enum { + PCB_CHGFLG_CLEAR, + PCB_CHGFLG_SET, + PCB_CHGFLG_TOGGLE +} pcb_change_flag_t; + +#define CHANGE_FLAG(how, F, P) \ +do { \ + switch(how) { \ + case PCB_CHGFLG_CLEAR: CLEAR_FLAG(F, P); break; \ + case PCB_CHGFLG_SET: SET_FLAG(F, P); break; \ + case PCB_CHGFLG_TOGGLE: TOGGLE_FLAG(F, P); break; \ + } \ +} while(0) + +#define FLAGS_EQUAL(F1,F2) (memcmp (&F1, &F2, sizeof(FlagType)) == 0) + +#define THERMFLAG(L) (0xf << (4 *((L) % 2))) + +#define TEST_THERM(L,P) ((P)->Flags.t[(L)/2] & THERMFLAG(L) ? 1 : 0) +#define GET_THERM(L,P) (((P)->Flags.t[(L)/2] >> (4 * ((L) % 2))) & 0xf) +#define CLEAR_THERM(L,P) (P)->Flags.t[(L)/2] &= ~THERMFLAG(L) +#define ASSIGN_THERM(L,V,P) (P)->Flags.t[(L)/2] = ((P)->Flags.t[(L)/2] & ~THERMFLAG(L)) | ((V) << (4 * ((L) % 2))) + + +#define GET_SQUARE(P) ((P)->Flags.q) +#define CLEAR_SQUARE(P) (P)->Flags.q = 0 +#define ASSIGN_SQUARE(V,P) (P)->Flags.q = V + + +#define GET_INTCONN(P) ((P)->Flags.int_conn_grp) + +extern int mem_any_set(unsigned char *, int); +#define TEST_ANY_THERMS(P) mem_any_set((P)->Flags.t, sizeof((P)->Flags.t)) + +#endif Index: trunk/src/global_objs.h =================================================================== --- trunk/src/global_objs.h (revision 4486) +++ trunk/src/global_objs.h (revision 4487) @@ -29,6 +29,7 @@ #include #include "config.h" #include "attrib.h" +#include "flag.h" #include "globalconst.h" #include "global_typedefs.h" #include "polyarea.h" @@ -63,24 +64,6 @@ Coord X2, Y2; /* and lower right corner */ }; -/* Nobody should know about the internals of this except the macros in - macros.h that access it. This structure must be simple-assignable - for now. */ -typedef struct unknown_flag_s unknown_flag_t; -struct unknown_flag_s { - char *str; - unknown_flag_t *next; -}; - -typedef struct { - unsigned long f; /* generic flags */ - unsigned char t[(MAX_LAYER + 1) / 2]; /* thermals */ - unsigned char q; /* square geometry flag */ - unsigned char int_conn_grp; - unknown_flag_t *unknowns; -} FlagType, *FlagTypePtr; - - /* All on-pcb objects (elements, lines, pads, vias, rats, etc) are based on this. */ typedef struct { Index: trunk/src/macro.h =================================================================== --- trunk/src/macro.h (revision 4486) +++ trunk/src/macro.h (revision 4487) @@ -80,51 +80,6 @@ #define PASTEBUFFER (&Buffers[conf_core.editor.buffer_number]) /* --------------------------------------------------------------------------- - * some routines for flag setting, clearing, changing and testing - */ -#define SET_FLAG(F,P) ((P)->Flags.f |= (F)) -#define CLEAR_FLAG(F,P) ((P)->Flags.f &= (~(F))) -#define TEST_FLAG(F,P) ((P)->Flags.f & (F) ? 1 : 0) -#define TOGGLE_FLAG(F,P) ((P)->Flags.f ^= (F)) -#define ASSIGN_FLAG(F,V,P) ((P)->Flags.f = ((P)->Flags.f & (~(F))) | ((V) ? (F) : 0)) -#define TEST_FLAGS(F,P) (((P)->Flags.f & (F)) == (F) ? 1 : 0) - -typedef enum { - PCB_CHGFLG_CLEAR, - PCB_CHGFLG_SET, - PCB_CHGFLG_TOGGLE -} pcb_change_flag_t; - -#define CHANGE_FLAG(how, F, P) \ -do { \ - switch(how) { \ - case PCB_CHGFLG_CLEAR: CLEAR_FLAG(F, P); break; \ - case PCB_CHGFLG_SET: SET_FLAG(F, P); break; \ - case PCB_CHGFLG_TOGGLE: TOGGLE_FLAG(F, P); break; \ - } \ -} while(0) - -#define FLAGS_EQUAL(F1,F2) (memcmp (&F1, &F2, sizeof(FlagType)) == 0) - -#define THERMFLAG(L) (0xf << (4 *((L) % 2))) - -#define TEST_THERM(L,P) ((P)->Flags.t[(L)/2] & THERMFLAG(L) ? 1 : 0) -#define GET_THERM(L,P) (((P)->Flags.t[(L)/2] >> (4 * ((L) % 2))) & 0xf) -#define CLEAR_THERM(L,P) (P)->Flags.t[(L)/2] &= ~THERMFLAG(L) -#define ASSIGN_THERM(L,V,P) (P)->Flags.t[(L)/2] = ((P)->Flags.t[(L)/2] & ~THERMFLAG(L)) | ((V) << (4 * ((L) % 2))) - - -#define GET_SQUARE(P) ((P)->Flags.q) -#define CLEAR_SQUARE(P) (P)->Flags.q = 0 -#define ASSIGN_SQUARE(V,P) (P)->Flags.q = V - - -#define GET_INTCONN(P) ((P)->Flags.int_conn_grp) - -extern int mem_any_set(unsigned char *, int); -#define TEST_ANY_THERMS(P) mem_any_set((P)->Flags.t, sizeof((P)->Flags.t)) - -/* --------------------------------------------------------------------------- * access macros for elements name structure */ #define DESCRIPTION_INDEX 0 Index: trunk/src/misc.c =================================================================== --- trunk/src/misc.c (revision 4486) +++ trunk/src/misc.c (revision 4487) @@ -1019,45 +1019,6 @@ Crosshair.AttachedObject.Ptr1, Crosshair.AttachedObject.Ptr2, Crosshair.AttachedObject.Ptr3); } -/* This just fills in a FlagType with current flags. */ -FlagType MakeFlags(unsigned int flags) -{ - FlagType rv; - memset(&rv, 0, sizeof(rv)); - rv.f = flags; - return rv; -} - -/* This converts old flag bits (from saved PCB files) to new format. */ -FlagType OldFlags(unsigned int flags) -{ - FlagType rv; - int i, f; - memset(&rv, 0, sizeof(rv)); - /* If we move flag bits around, this is where we map old bits to them. */ - rv.f = flags & 0xffff; - f = 0x10000; - for (i = 0; i < 8; i++) { - /* use the closest thing to the old thermal style */ - if (flags & f) - rv.t[i / 2] |= (1 << (4 * (i % 2))); - f <<= 1; - } - return rv; -} - -FlagType AddFlags(FlagType flag, unsigned int flags) -{ - flag.f |= flags; - return flag; -} - -FlagType MaskFlags(FlagType flag, unsigned int flags) -{ - flag.f &= ~flags; - return flag; -} - void r_delete_element(DataType * data, ElementType * element) { r_delete_entry(data->element_tree, (BoxType *) element); Index: trunk/src/misc.h =================================================================== --- trunk/src/misc.h (revision 4486) +++ trunk/src/misc.h (revision 4487) @@ -70,13 +70,6 @@ char *UniqueElementName(DataTypePtr, char *); void AttachForCopy(Coord, Coord); -/* For passing modified flags to other functions. */ -FlagType MakeFlags(unsigned int); -FlagType OldFlags(unsigned int); -FlagType AddFlags(FlagType, unsigned int); -FlagType MaskFlags(FlagType, unsigned int); -#define NoFlags() MakeFlags(0) - /* Returns a string with info about this copy of pcb. */ char *GetInfoString(void); Index: trunk/src/misc_util.c =================================================================== --- trunk/src/misc_util.c (revision 4486) +++ trunk/src/misc_util.c (revision 4487) @@ -171,11 +171,3 @@ va_end(a); return rv; } - -int mem_any_set(unsigned char *ptr, int bytes) -{ - while (bytes--) - if (*ptr++) - return 1; - return 0; -} Index: trunk/src_plugins/fontmode/fontmode.c =================================================================== --- trunk/src_plugins/fontmode/fontmode.c (revision 4486) +++ trunk/src_plugins/fontmode/fontmode.c (revision 4487) @@ -37,6 +37,7 @@ #include "create.h" #include "data.h" #include "draw.h" +#include "flag.h" #include "layer.h" #include "misc.h" #include "move.h"