|
From: <gi...@gp...> - 2011-05-03 20:23:13
|
The branch, master has been updated
via 9acdd88e22717510ff5dde277ecbd6f1de60b69d (commit)
from 31b7309764f2e4bd40141038c30f1f38309efb4a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
=========
Summary
=========
src/hid/common/flags.c | 2 +-
src/hid/gtk/gtkhid-main.c | 40 +++++++-----------
src/hid/lesstif/main.c | 39 +++++++----------
src/main.c | 2 +-
src/misc.c | 102 +++++++++++++++++++++++++++++++++++----------
src/misc.h | 11 ++++-
src/parse_y.y | 4 +-
7 files changed, 125 insertions(+), 75 deletions(-)
=================
Commit Messages
=================
commit 9acdd88e22717510ff5dde277ecbd6f1de60b69d
Author: Andrew Poelstra <as...@sf...>
Commit: Peter Clifton <pc...@ca...>
Universal use of GetValue
This is a patch to make all numeric code use GetValue, to unify parsing
code and make sure everything uses the same units. Contained is almost
a complete rewrite of GetValue to simplify code that uses funny units.
Reviewed-by: Peter Clifton <pc...@ca...>
When committing the patch from Launchpad, I rebased it to apply with
strcasecmp and strncasecmp changed to strcmp and strncmp, as changed
by commit 31b7309764f2e4bd40141038c30f1f38309efb4a
Affects-bug: lp-772027
:100644 100644 23c7c57... 15e77ad... M src/hid/common/flags.c
:100644 100644 66a279b... fd092c6... M src/hid/gtk/gtkhid-main.c
:100644 100644 3a57ca5... b2c1098... M src/hid/lesstif/main.c
:100644 100644 b147a5c... 0e6852f... M src/main.c
:100644 100644 4f308ed... e505047... M src/misc.c
:100644 100644 cd7eb3d... fb303d6... M src/misc.h
:100644 100644 ad8cb44... 5290b53... M src/parse_y.y
=========
Changes
=========
commit 9acdd88e22717510ff5dde277ecbd6f1de60b69d
Author: Andrew Poelstra <as...@sf...>
Commit: Peter Clifton <pc...@ca...>
Universal use of GetValue
This is a patch to make all numeric code use GetValue, to unify parsing
code and make sure everything uses the same units. Contained is almost
a complete rewrite of GetValue to simplify code that uses funny units.
Reviewed-by: Peter Clifton <pc...@ca...>
When committing the patch from Launchpad, I rebased it to apply with
strcasecmp and strncasecmp changed to strcmp and strncmp, as changed
by commit 31b7309764f2e4bd40141038c30f1f38309efb4a
Affects-bug: lp-772027
diff --git a/src/hid/common/flags.c b/src/hid/common/flags.c
index 23c7c57..15e77ad 100644
--- a/src/hid/common/flags.c
+++ b/src/hid/common/flags.c
@@ -114,7 +114,7 @@ hid_get_flag (const char *name)
}
memcpy (buf, name, cp - name);
buf[cp - name] = 0;
- wv = strtol (cp + 1, 0, 0);
+ wv = GetValue (cp + 1, NULL, NULL);
f = hid_find_flag (buf);
if (!f)
return 0;
diff --git a/src/hid/gtk/gtkhid-main.c b/src/hid/gtk/gtkhid-main.c
index 66a279b..fd092c6 100644
--- a/src/hid/gtk/gtkhid-main.c
+++ b/src/hid/gtk/gtkhid-main.c
@@ -1626,9 +1626,20 @@ The values are percentages of the board size. Thus, a move of
static int
CursorAction(int argc, char **argv, int x, int y)
{
+ UnitList extra_units_x = {
+ { "grid", PCB->Grid, 0 },
+ { "view", gport->view_width, UNIT_PERCENT },
+ { "board", PCB->MaxWidth, UNIT_PERCENT },
+ { "", 0, 0 }
+ };
+ UnitList extra_units_y = {
+ { "grid", PCB->Grid, 0 },
+ { "view", gport->view_height, UNIT_PERCENT },
+ { "board", PCB->MaxHeight, UNIT_PERCENT },
+ { "", 0, 0 }
+ };
int pan_warp = HID_SC_DO_NOTHING;
double dx, dy;
- double xu = 0.0, yu = 0.0;
if (argc != 4)
AFAIL (cursor);
@@ -1640,35 +1651,14 @@ CursorAction(int argc, char **argv, int x, int y)
else
AFAIL (cursor);
- dx = strtod (argv[1], 0);
+ dx = GetValueEx (argv[1], argv[3], NULL, extra_units_x, "");
if (ghid_flip_x)
dx = -dx;
- dy = strtod (argv[2], 0);
+ dy = GetValueEx (argv[2], argv[3], NULL, extra_units_y, "");
if (!ghid_flip_y)
dy = -dy;
- /*
- * xu and yu are the scale factors that we multiply dx and dy by to
- * come up with PCB internal units.
- */
- if (strncmp (argv[3], "mm", 2) == 0)
- xu = yu = MM_TO_COORD(1);
- else if (strncmp (argv[3], "mil", 3) == 0)
- xu = yu = MIL_TO_COORD(1);
- else if (strncmp (argv[3], "grid", 4) == 0)
- xu = yu = PCB->Grid;
- else if (strncmp (argv[3], "view", 4) == 0)
- {
- xu = gport->view_width / 100.0;
- yu = gport->view_height / 100.0;
- }
- else if (strncmp (argv[3], "board", 4) == 0)
- {
- xu = PCB->MaxWidth / 100.0;
- yu = PCB->MaxHeight / 100.0;
- }
-
- EventMoveCrosshair (Crosshair.X+(int)(dx*xu), Crosshair.Y+(int)(dy*yu));
+ EventMoveCrosshair (Crosshair.X + dx, Crosshair.Y + dy);
gui->set_crosshair (Crosshair.X, Crosshair.Y, pan_warp);
return 0;
diff --git a/src/hid/lesstif/main.c b/src/hid/lesstif/main.c
index 3a57ca5..b2c1098 100644
--- a/src/hid/lesstif/main.c
+++ b/src/hid/lesstif/main.c
@@ -869,8 +869,20 @@ The values are percentages of the board size. Thus, a move of
static int
CursorAction(int argc, char **argv, int x, int y)
{
+ UnitList extra_units_x = {
+ { "grid", PCB->Grid, 0 },
+ { "view", Pz(view_width), UNIT_PERCENT },
+ { "board", PCB->MaxWidth, UNIT_PERCENT },
+ { "", 0, 0 }
+ };
+ UnitList extra_units_y = {
+ { "grid", PCB->Grid, 0 },
+ { "view", Pz(view_height), UNIT_PERCENT },
+ { "board", PCB->MaxHeight, UNIT_PERCENT },
+ { "", 0, 0 }
+ };
int pan_warp = HID_SC_DO_NOTHING;
- double dx, dy, xu, yu;
+ double dx, dy;
if (argc != 4)
AFAIL(cursor);
@@ -882,33 +894,14 @@ CursorAction(int argc, char **argv, int x, int y)
else
AFAIL(cursor);
- dx = strtod (argv[1], 0);
+ dx = GetValueEx (argv[1], argv[3], NULL, extra_units_x, "mil");
if (flip_x)
dx = -dx;
- dy = strtod (argv[2], 0);
+ dy = GetValueEx (argv[2], argv[3], NULL, extra_units_y, "mil");
if (!flip_y)
dy = -dy;
- if (strncmp (argv[3], "mm", 2) == 0)
- xu = yu = MM_TO_COORD(1);
- else if (strncmp (argv[3], "mil", 3) == 0)
- xu = yu = MIL_TO_COORD(1);
- else if (strncmp (argv[3], "grid", 4) == 0)
- xu = yu = PCB->Grid;
- else if (strncmp (argv[3], "view", 4) == 0)
- {
- xu = Pz(view_width) / 100.0;
- yu = Pz(view_height) / 100.0;
- }
- else if (strncmp (argv[3], "board", 4) == 0)
- {
- xu = PCB->MaxWidth / 100.0;
- yu = PCB->MaxHeight / 100.0;
- }
- else
- xu = yu = MIL_TO_COORD(1);
-
- EventMoveCrosshair (Crosshair.X+(int)(dx*xu), Crosshair.Y+(int)(dy*yu));
+ EventMoveCrosshair (Crosshair.X + dx, Crosshair.Y + dy);
gui->set_crosshair (Crosshair.X, Crosshair.Y, pan_warp);
return 0;
diff --git a/src/main.c b/src/main.c
index b147a5c..0e6852f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -622,7 +622,7 @@ REGISTER_ATTRIBUTES (main_attribute_list)
Settings.MaxWidth = MIN (MAX_COORD, MAX (Settings.MaxWidth, MIN_SIZE));
Settings.MaxHeight = MIN (MAX_COORD, MAX (Settings.MaxHeight, MIN_SIZE));
- ParseRouteString (Settings.Routes, &Settings.RouteStyle[0], 1);
+ ParseRouteString (Settings.Routes, &Settings.RouteStyle[0], "cmil");
/*
* Make sure we have settings for some various programs we may wish
diff --git a/src/misc.c b/src/misc.c
index 4f308ed..e505047 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -110,8 +110,29 @@ static struct
double
GetValue (const char *val, const char *units, bool * absolute)
{
+ return GetValueEx(val, units, absolute, NULL, "cmil");
+}
+
+double
+GetValueEx (const char *val, const char *units, bool * absolute, UnitList extra_units, const char *default_unit)
+{
+ static UnitList default_units = {
+ { "mm", MM_TO_COORD(1), 0 },
+ { "um", MM_TO_COORD(0.001), 0 },
+ { "nm", MM_TO_COORD(0.000001), 0 },
+ { "mil", MIL_TO_COORD(1), 0 },
+ { "cmil", MIL_TO_COORD(0.01), 0 },
+ { "in", MIL_TO_COORD(1000), 0 },
+ { "", 1, 0 }
+ };
double value;
int n = -1;
+ bool scaled = 0;
+ bool dummy;
+
+ /* Allow NULL to be passed for absolute */
+ if(absolute == NULL)
+ absolute = &dummy;
/* if the first character is a sign we have to add the
* value to the current one
@@ -138,15 +159,52 @@ GetValue (const char *val, const char *units, bool * absolute)
if (units && *units)
{
- if (strncmp (units, "mm", 2) == 0)
- value = MM_TO_COORD(value);
- else if (strncmp (units, "cm", 2) == 0)
- value = 10 * MM_TO_COORD(value);
- else if (strncmp (units, "mil", 3) == 0)
- value = MIL_TO_COORD(value);
- else if (strncmp (units, "in", 3) == 0)
- value = INCH_TO_COORD(value);
+ int i;
+ for (i = 0; *default_units[i].suffix; ++i)
+ {
+ if (strncmp (units, default_units[i].suffix, strlen(default_units[i].suffix)) == 0)
+ {
+ value *= default_units[i].scale;
+ if (default_units[i].flags & UNIT_PERCENT)
+ value /= 100.0;
+ scaled = 1;
+ }
+ }
+ if (extra_units)
+ {
+ for (i = 0; *extra_units[i].suffix; ++i)
+ {
+ if (strncmp (units, extra_units[i].suffix, strlen(extra_units[i].suffix)) == 0)
+ {
+ value *= extra_units[i].scale;
+ if (extra_units[i].flags & UNIT_PERCENT)
+ value /= 100.0;
+ scaled = 1;
+ }
+ }
+ }
+ }
+ /* Apply default unit */
+ if (!scaled && default_unit && *default_unit)
+ {
+ int i;
+ for (i = 0; *default_units[i].suffix; ++i)
+ if (strcmp (default_units[i].suffix, default_unit) == 0)
+ {
+ value *= default_units[i].scale;
+ if (default_units[i].flags & UNIT_PERCENT)
+ value /= 100.0;
+ }
+ if (extra_units)
+ for (i = 0; *extra_units[i].suffix; ++i)
+ if (strcmp (extra_units[i].suffix, default_unit) == 0)
+ {
+ value *= extra_units[i].scale;
+ if (extra_units[i].flags & UNIT_PERCENT)
+ value /= 100.0;
+ }
}
+
return value;
}
@@ -785,12 +843,16 @@ SetFontInfo (FontTypePtr Ptr)
Ptr->DefaultSymbol.Y2 = Ptr->DefaultSymbol.Y1 + Ptr->MaxHeight;
}
-static void
-GetNum (char **s, BDimension * num)
+static BDimension
+GetNum (char **s, const char *default_unit)
{
- *num = atoi (*s);
- while (isdigit ((int) **s))
- (*s)++;
+ BDimension ret_val;
+ /* Read value */
+ ret_val = GetValueEx(*s, NULL, NULL, NULL, default_unit);
+ /* Advance pointer */
+ while(isalnum(**s) || **s == '.')
+ (*s)++;
+ return ret_val;
}
@@ -800,7 +862,7 @@ GetNum (char **s, BDimension * num)
* e.g. Signal,20,40,20,10:Power,40,60,28,10:...
*/
int
-ParseRouteString (char *s, RouteStyleTypePtr routeStyle, int scale)
+ParseRouteString (char *s, RouteStyleTypePtr routeStyle, const char *default_unit)
{
int i, style;
char Name[256];
@@ -816,8 +878,7 @@ ParseRouteString (char *s, RouteStyleTypePtr routeStyle, int scale)
routeStyle->Name = strdup (Name);
if (!isdigit ((int) *++s))
goto error;
- GetNum (&s, &routeStyle->Thick);
- routeStyle->Thick *= scale;
+ routeStyle->Thick = GetNum (&s, default_unit);
while (*s && isspace ((int) *s))
s++;
if (*s++ != ',')
@@ -826,8 +887,7 @@ ParseRouteString (char *s, RouteStyleTypePtr routeStyle, int scale)
s++;
if (!isdigit ((int) *s))
goto error;
- GetNum (&s, &routeStyle->Diameter);
- routeStyle->Diameter *= scale;
+ routeStyle->Diameter = GetNum (&s, default_unit);
while (*s && isspace ((int) *s))
s++;
if (*s++ != ',')
@@ -836,8 +896,7 @@ ParseRouteString (char *s, RouteStyleTypePtr routeStyle, int scale)
s++;
if (!isdigit ((int) *s))
goto error;
- GetNum (&s, &routeStyle->Hole);
- routeStyle->Hole *= scale;
+ routeStyle->Hole = GetNum (&s, default_unit);
/* for backwards-compatibility, we use a 10-mil default
* for styles which omit the keepaway specification. */
if (*s != ',')
@@ -849,8 +908,7 @@ ParseRouteString (char *s, RouteStyleTypePtr routeStyle, int scale)
s++;
if (!isdigit ((int) *s))
goto error;
- GetNum (&s, &routeStyle->Keepaway);
- routeStyle->Keepaway *= scale;
+ routeStyle->Keepaway = GetNum (&s, default_unit);
while (*s && isspace ((int) *s))
s++;
}
diff --git a/src/misc.h b/src/misc.h
index cd7eb3d..fb303d6 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -35,6 +35,14 @@
#include "global.h"
#include "mymem.h"
+enum unitflags { UNIT_PERCENT = 1 };
+
+typedef struct {
+ const char *suffix;
+ double scale;
+ enum unitflags flags;
+} UnitList[];
+
void r_delete_element (DataTypePtr, ElementTypePtr);
void SetLineBoundingBox (LineTypePtr);
void SetArcBoundingBox (ArcTypePtr);
@@ -52,7 +60,7 @@ BoxTypePtr GetDataBoundingBox (DataTypePtr);
void CenterDisplay (LocationType, LocationType, bool);
void SetFontInfo (FontTypePtr);
int ParseGroupString (char *, LayerGroupTypePtr, int /* LayerN */);
-int ParseRouteString (char *, RouteStyleTypePtr, int);
+int ParseRouteString (char *, RouteStyleTypePtr, const char *);
void QuitApplication (void);
char *EvaluateFilename (char *, char *, char *, char *);
char *ExpandFilename (char *, char *);
@@ -79,6 +87,7 @@ void ChangeArcAngles (LayerTypePtr, ArcTypePtr, long int, long int);
char *UniqueElementName (DataTypePtr, char *);
void AttachForCopy (LocationType, LocationType);
double GetValue (const char *, const char *, bool *);
+double GetValueEx (const char *, const char *, bool *, UnitList, const char *);
int FileExists (const char *);
char *Concat (const char *, ...); /* end with NULL */
diff --git a/src/parse_y.y b/src/parse_y.y
index ad8cb44..5290b53 100644
--- a/src/parse_y.y
+++ b/src/parse_y.y
@@ -647,7 +647,7 @@ is split across lines only to make it readable.
pcbstyles
: T_STYLES '(' STRING ')'
{
- if (ParseRouteString($3, &yyPCB->RouteStyle[0], 100))
+ if (ParseRouteString($3, &yyPCB->RouteStyle[0], "mil"))
{
Message("illegal route-style string\n");
YYABORT;
@@ -655,7 +655,7 @@ pcbstyles
}
| T_STYLES '[' STRING ']'
{
- if (ParseRouteString($3, &yyPCB->RouteStyle[0], 1))
+ if (ParseRouteString($3, &yyPCB->RouteStyle[0], "cmil"))
{
Message("illegal route-style string\n");
YYABORT;
|