Re: gEDA-user: pcb: parameter escaping for commands

2008-12-03 Thread John Griessen
Sascha Silbe wrote:

>> To turn *on* the display, press the 'd' key over the element you're
>> interested in. [...]
>> Shift-D over an element does work, though.
> OK, the confusion was that PCB doesn't act on the _selected_ item(s), 
> but on the one under the pointer. That's inconsistent with any 
> application I've used so far. It also makes having those commands in the 
> menu not only useless, but severly misleading.

I agree.  I'd like to see default keybindings use selected set more often.

John Grioessen
-- 
Ecosensory   Austin TX


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


Re: gEDA-user: pcb: parameter escaping for commands

2008-12-03 Thread Dan McMahill
John Griessen wrote:
> Sascha Silbe wrote:
> 
>>> To turn *on* the display, press the 'd' key over the element you're
>>> interested in. [...]
>>> Shift-D over an element does work, though.
>> OK, the confusion was that PCB doesn't act on the _selected_ item(s), 
>> but on the one under the pointer. That's inconsistent with any 
>> application I've used so far. It also makes having those commands in the 
>> menu not only useless, but severly misleading.
> 
> I agree.  I'd like to see default keybindings use selected set more often.
> 
> John Grioessen

It wouldn't bother me to see that changed too.  It took me a long time 
to realize what was going on...  Despite it violating the principle of 
least surprise (why did everything change?), I think I'd be in favor of 
changing this.  I *think* it would just be a pcb-menu.res/gpcb-menu.res 
change.

-Dan





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


Re: gEDA-user: pcb: parameter escaping for commands

2008-12-03 Thread Sascha Silbe

On Sun, Nov 23, 2008 at 09:07:49PM -0500, DJ Delorie wrote:


I suppose the parser can return a pointer to the "leftovers", and we
can have a new function that continues parsing until the string is
used up.  I suspect the command line --action-string and
--action-script may need this type of functionality.
--action-script invokes the same function as ExecuteFile, but for 
--action-string it might actually be useful. As I don't expect that to 
be used extensively I've just updated hid_parse_actions to recurse if 
there's anything left to parse.


As there were no objections on code style or design, I've submitted the 
patch to the SourceForge Patch Tracker [3]. Together with the gsch2pcb 
patch (submitted as well [4]) PCB seems to handle pin names containing 
special characters fine now.



To turn *on* the display, press the 'd' key over the element you're
interested in. [...]
Shift-D over an element does work, though.
OK, the confusion was that PCB doesn't act on the _selected_ item(s), 
but on the one under the pointer. That's inconsistent with any 
application I've used so far. It also makes having those commands in the 
menu not only useless, but severly misleading.
Incidentally, there's a patch [1] in the PCB tracker at SourceForge that 
gives a hint if there's nothing under the cursor. Would have saved me 
quite some time. I do understand why it hasn't been applied, though 
(patches only Display(pinout), even though many more functions behave 
the same).



Window->Pinout is supposed to ask you to click on an element, file a
bug (with which HID you're using) if it doesn't.

Bug filed [2].


[1] 
https://sourceforge.net/tracker/index.php?func=detail&aid=1669634&group_id=73743&atid=538813
[2] 
https://sourceforge.net/tracker/index.php?func=detail&aid=2382939&group_id=73743&atid=538811
[3] 
https://sourceforge.net/tracker/index.php?func=detail&aid=2382954&group_id=73743&atid=538813
[4] 
https://sourceforge.net/tracker/index.php?func=detail&aid=2382988&group_id=161080&atid=818428


CU Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/


signature.asc
Description: Digital signature


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


Re: gEDA-user: pcb: parameter escaping for commands

2008-11-23 Thread DJ Delorie

> The old parser supported constructs like "Display(Name)
> Display(Value)", invoking both functions in sequence. The new one
> stops after the first ")".

I suppose the parser can return a pointer to the "leftovers", and we
can have a new function that continues parsing until the string is
used up.  I suspect the command line --action-string and
--action-script may need this type of functionality.

> Well, it doesn't display any number or name (for pins). By luck, I
> now found out that both work only if the pointer is above the
> currently selected element - which is impossible if I use the menu.

To turn *on* the display, press the 'd' key over the element you're
interested in.  The menu option changes *which* string is displayed,
not *if* it's displayed.

Window->Pinout is supposed to ask you to click on an element, file a
bug (with which HID you're using) if it doesn't.

Shift-D over an element does work, though.


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


Re: gEDA-user: pcb: parameter escaping for commands

2008-11-23 Thread Sascha Silbe

On Mon, Nov 24, 2008 at 12:51:33AM +, Peter Clifton wrote:

1. Action chaining isn't supported anymore. Wasn't documented, isn't 
used by anything AFAIK (resource parser does its own splitting).
Please don't break this. I already spend long enough finding the 
obscure

bug and fixing it which broke re-entrancy with the old code. This _is_
encountered in xgsch2pcb, where one action loads another action script
via an action.
I think we're talking about two different things here. The new parser 
doesn't handle several actions passed as a single string (e.g. 
"Display(Name) Display(Value)"). Having an action (lets say 
"SetAll(Clearance,0.1)") parse and execute another action (lets say 
"SetElement(U1,Clearance,0.1)") should work perfectly well.

Sorry if my imprecise description caused confusion.

CU Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/


signature.asc
Description: Digital signature


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


Re: gEDA-user: pcb: parameter escaping for commands

2008-11-23 Thread Peter Clifton
On Mon, 2008-11-24 at 00:51 +, Peter Clifton wrote:
> On Sun, 2008-11-23 at 22:12 +0100, Sascha Silbe wrote:
> > Two important changes:
> > 1. Action chaining isn't supported anymore. Wasn't documented, isn't 
> > used by anything AFAIK (resource parser does its own splitting).
> 
> Please don't break this. I already spend long enough finding the obscure
> bug and fixing it which broke re-entrancy with the old code. This _is_
> encountered in xgsch2pcb, where one action loads another action script
> via an action.

Given your previous explanation, I guess I misunderstood what you meant
by action chaining. What I was refering to was a bug with re-entrancy in
the parser which caused breakage.

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)



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


Re: gEDA-user: pcb: parameter escaping for commands

2008-11-23 Thread Peter Clifton
On Sun, 2008-11-23 at 22:12 +0100, Sascha Silbe wrote:
> Two important changes:
> 1. Action chaining isn't supported anymore. Wasn't documented, isn't 
> used by anything AFAIK (resource parser does its own splitting).

Please don't break this. I already spend long enough finding the obscure
bug and fixing it which broke re-entrancy with the old code. This _is_
encountered in xgsch2pcb, where one action loads another action script
via an action.

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)



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


Re: gEDA-user: pcb: parameter escaping for commands

2008-11-23 Thread Sascha Silbe

On Sun, Nov 23, 2008 at 04:14:46PM -0500, DJ Delorie wrote:

1. Action chaining isn't supported anymore. Wasn't documented, 
isn't=20

used by anything AFAIK (resource parser does its own splitting).

Er, what was this?
The old parser supported constructs like "Display(Name) Display(Value)", 
invoking both functions in sequence. The new one stops after the first 
")". In the resource file, those are two different entries anyway, so it 
doesn't matter there.


PS: How do I display the pin names (besides "Generate object report" 
on=20
a pin)? Neither "View -> Pins/Vias show Name/Number" nor "Window 
->=20

Pinout" show any effect (regardless of selection).

That's the way.  Most pins have the same string for name and number
until you run the script from gsch2pcb to change them.
Well, it doesn't display any number or name (for pins). By luck, I now 
found out that both work only if the pointer is above the currently 
selected element - which is impossible if I use the menu.


CU Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/


signature.asc
Description: Digital signature


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


Re: gEDA-user: pcb: parameter escaping for commands

2008-11-23 Thread DJ Delorie

> 1. Action chaining isn't supported anymore. Wasn't documented, isn't=20
> used by anything AFAIK (resource parser does its own splitting).

Er, what was this?

> PS: How do I display the pin names (besides "Generate object report" on=20
> a pin)? Neither "View -> Pins/Vias show Name/Number" nor "Window ->=20
> Pinout" show any effect (regardless of selection).

That's the way.  Most pins have the same string for name and number
until you run the script from gsch2pcb to change them.


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


Re: gEDA-user: pcb: parameter escaping for commands

2008-11-23 Thread Sascha Silbe

On Sat, Nov 22, 2008 at 01:49:57PM -0500, DJ Delorie wrote:


Is the supported syntax described anywhere?

Nope.  You get to write it!  :-)
As long as it can do everything in pcb-menu.res it will be fine.

That's what I wanted to hear (the latter part at least). 
Patch attached. I tried to follow the current coding style, including 
usage of libc string functions (DJB-style string buffer functions would 
have made it easier). If the style is fine with you, I can create a bug 
report and attach it.

It seems to work fine for me, but I could not find any test suite.

Two important changes:
1. Action chaining isn't supported anymore. Wasn't documented, isn't 
used by anything AFAIK (resource parser does its own splitting).
2. The sequence "\_" will now be parsed as "_", so if PCB did use that 
to create negation lines, it will be broken until gsch2pcb and possibly 
other tools are adapted. Special-casing that sequence is possible, but 
IMO ugly.


The patch is only for actions - haven't looked at footprint etc. formats 
yet.


PS: How do I display the pin names (besides "Generate object report" on 
a pin)? Neither "View -> Pins/Vias show Name/Number" nor "Window -> 
Pinout" show any effect (regardless of selection).


CU Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/
Index: src/hid/common/actions.c
===
RCS file: /cvsroot/pcb/pcb/src/hid/common/actions.c,v
retrieving revision 1.12
diff -u -d -r1.12 actions.c
--- src/hid/common/actions.c	5 Jan 2008 05:37:08 -	1.12
+++ src/hid/common/actions.c	23 Nov 2008 20:56:14 -
@@ -219,123 +219,152 @@
   return a->trigger_cb (argc, argv, x, y);
 }
 
+static char *
+strip (const char *s)
+{
+  const char *sp = s;
+  unsigned int len;
+  char *res;
+
+  /* skip leading spaces and tabs */
+  while (*sp && isspace ((int) *sp))
+sp++;
+
+  len = strlen(sp);
+
+  /* skip trailing spaces and tabs */
+  while (len && isspace((int) sp[len-1]))
+len--;
+
+  if (!len)
+  return "";
+
+  res = (char *) malloc(len+1); // ENOMEM not checked
+  if (!res)
+return NULL;
+
+  strncpy(res, sp, len);
+  res[len] = '\0';
+
+  return res;
+}
+
+static char *
+my_strndup(const char *s, size_t n)
+{
+  char *res = (char *) malloc(n+1);
+  strncpy(res, s, n);
+  res[n] = '\0';
+  return res;
+}
+
+/* returns copy of next parameter, updating sp to point behind separator */
+static char *
+get_next_param(char **sp)
+{
+  char *sep, *res;
+
+  sep = strpbrk(*sp, "\\,)");
+
+  if (!sep)
+sep = *sp + strlen(*sp);
+
+  if (*sep == '\\' && *(sep+1))
+{
+  /* recursively process remaining part, concatenate
+ escaping is considered to be rare, so we don't need to optimize it */
+  size_t curlen = sep-*sp;
+  char escaped = sep[1];
+  char *rem;
+  sep += 2;
+  rem = get_next_param(&sep);
+  res = (char *) malloc(curlen+1+strlen(rem)+1);
+  strncpy(res, *sp, curlen);
+  res[curlen] = escaped;
+  strcpy(res+curlen+1, rem);
+  free(rem);
+  *sp = sep;
+  return res;
+}
+
+  /* ignore trailing whitespace */
+  while ((sep > *sp) && isspace((int) *(sep-1)))
+sep--;
+
+  /* return copy of parameter */
+  res = my_strndup(*sp, sep-*sp);
+  *sp = (*sep) ? sep+1 : sep;
+  return res;
+}
+
 int
 hid_parse_actions (const char *rstr,
-		   int (*function) (const char *, int, char **))
+   int (*function) (const char *, int, char **))
 {
+  char *str, *sp, *aname;
+  int num = 0, max = 0;
   char **list = NULL;
-  int max = 0;
-  int num;
-  char *str = NULL;
-  char *sp, *aname, *sp2;
-  int maybe_empty = 0;
-  int retcode = 0;
+  char *paren_pos;
+  int retcode;
 
   if (function == NULL)
 function = hid_actionv;
 
-  /*fprintf(stderr, "invoke: `%s'\n", rstr); */
-
-  sp = str = strdup (rstr);
+  aname = sp = str = strip (rstr);
+  if (!sp || !*sp)
+return 0;
 
-another:
-  num = 0;
-  /* eat leading spaces and tabs */
-  while (*sp && isspace ((int) *sp))
-sp++;
-  
-  if (!*sp)
+  /* action names don't need to be escaped so strchr suffices */
+  paren_pos = strchr(sp, '(');
+  if (paren_pos)
 {
-  retcode = 0;
-  goto cleanup;
-}
+  /* NUL-terminate action name */
+  *paren_pos = '\0';
+  sp = paren_pos+1;
+
+  /* scan for parameters */
+  while (*sp && *sp != ')')
+{
+  char *param;
+
+  /* ignore leading whitespace */
+  while (*sp && isspace ((int) *sp))
+sp++;
+
+  if (!*sp || (*sp == ')'))
+break;
+
+  /* get_next_param updates sp */
+  param = get_next_param(&sp);
   
-  aname = sp;
+  /* ensure list is big enough */
+  if (num <= max)
+{
+  max += 10;
+  if (list)
+list = (char **) realloc (list, max * sizeof (char *));
+  else
+list = (char **) malloc (max * sizeof (char *));
+  

Re: gEDA-user: pcb: parameter escaping for commands (was: Re: pcb/gsch2pcb: problem with special characters in pin names)

2008-11-22 Thread DJ Delorie

> Is the supported syntax described anywhere?

Nope.  You get to write it!  :-)

As long as it can do everything in pcb-menu.res it will be fine.



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


gEDA-user: pcb: parameter escaping for commands (was: Re: pcb/gsch2pcb: problem with special characters in pin names)

2008-11-22 Thread Sascha Silbe

On Fri, Nov 14, 2008 at 12:55:30PM -0500, DJ Delorie wrote:


pcb currently has no escape mechanism for that.  It would be added to
src/hid/common/actions.c in hid_parse_actions() if you want to work on
it.
Looks like it's going to need a full rewrite of that function to 
implement escaping.
Is the supported syntax described anywhere? hid_parse_actions is able to 
parse multiple invocations with parameters, but an invocation without 
parameters must be the last one; empty parentheses supply a single, 
empty parameter (instead of no parameters like an invocation without 
parentheses does) etc. I'd rather do the reimplementation based on a 
syntax definition than trying to mimic the old function as much as 
possible.


CU Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/


signature.asc
Description: Digital signature


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