[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: Using mm units in .pcb files



> - it is difficult for me (and no one did/do it),

Try this.  It allows "um", "mm", "mil", or "in" as suffixes after
floating point numbers (no space between), anywhere an integer is
otherwise allowed.  Example:

	Line[1.5mm 0 1.5mm 0.5 in 1mil 2mil "clearline"]

Index: parse_l.l
===================================================================
RCS file: /cvsroot/pcb/pcb/src/parse_l.l,v
retrieving revision 1.23
diff -p -U3 -r1.23 parse_l.l
--- parse_l.l	7 Jan 2008 03:44:18 -0000	1.23
+++ parse_l.l	10 Jun 2008 23:23:52 -0000
@@ -76,6 +76,8 @@ DataTypePtr		yyData;
 ElementTypePtr		yyElement;
 FontTypePtr		yyFont;
 
+static int parse_number (double);
+
 /* ---------------------------------------------------------------------------
  * an external prototypes
  */
@@ -90,7 +92,11 @@ static	int		Parse(char *, char *, char *
 
 HEX				0x[0-9a-fA-F]+
 DECIMAL			-?[1-9][0-9]*|0
-FLOATING                -?[0-9]*"."[0-9]*
+FLOATING                [+-]?[0-9]*("."[0-9]*)?
+FLOATINGMM              {FLOATING}[mM][mM]
+FLOATINGUM              {FLOATING}[uU][mM]
+FLOATINGIN              {FLOATING}[iI][nN]
+FLOATINGMIL             {FLOATING}[mM][iI][lL]
 CARDINAL		[1-9][0-9]*|0
 STRINGCHAR		([^"\n\r\\]|\\.)
 
@@ -133,10 +139,12 @@ Attribute	{ return(T_ATTRIBUTE); }
 						yylval.number = (unsigned) *(yytext+1);
 						return(CHAR_CONST);
 					}
-{DECIMAL}		{
-						sscanf((char *) yytext, "%i", &yylval.number);
-						return(NUMBER);
-					}
+{FLOATINGMM}		{	return parse_number(3937.0079); }
+{FLOATINGUM}		{	return parse_number(3.9370079); }
+{FLOATINGIN}		{	return parse_number(100000.0); }
+{FLOATINGMIL}		{	return parse_number(100.0); }
+{DECIMAL}		{	return parse_number(1.0); }
+
 {HEX}			{
 						sscanf((char *) yytext, "%x", &yylval.number);
 						return(NUMBER);
@@ -346,3 +354,11 @@ int ParseFont(FontTypePtr Ptr, char *Fil
 	return r;
 }
 
+static int
+parse_number (double scale)
+{
+  double val;
+  sscanf ((char *) yytext, "%lf", &val);
+  yylval.number = (int)(val * scale + 0.49);
+  return NUMBER;
+}


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user