Index: trunk/src/hid_cam.c =================================================================== --- trunk/src/hid_cam.c (revision 28614) +++ trunk/src/hid_cam.c (revision 28615) @@ -41,6 +41,7 @@ #include "layer_addr.h" #include "layer_vis.h" #include "plug_io.h" +#include "misc_util.h" htsp_t *pcb_cam_vars = NULL; /* substitute %% variables from this hash */ @@ -200,19 +201,6 @@ filename_attrib->default_val.str = pcb_derive_default_filename_(pcbfile, suffix); } -/* remove leading and trailing whitespace */ -static char *strip(char *s) -{ - char *end; - while(isspace(*s)) s++; - end = s + strlen(s) - 1; - while((end >= s) && (isspace(*end))) { - *end = '\0'; - end--; - } - return s; -} - static void layervis_save_and_reset(pcb_cam_t *cam) { pcb_layer_id_t n; @@ -229,68 +217,6 @@ cam->pcb->Data->Layer[n].meta.real.vis = cam->orig_vis[n]; } -static char *lp_err = ""; - -/* Parse a layer directive: split at comma, curr will end up holding the - layer name. If there were transformations in (), they are split and - listed in tr up to at most *spc entries. Returns NULL on error or - pointer to the next layer directive. */ -static char *parse_layer(char *curr, char **spk, char **spv, int *spc) -{ - char *s, *lasta, *eq; - int level = 0, trmax = *spc; - *spc = 0; - - for(s = curr; *s != '\0'; s++) { - switch(*s) { - case '(': - if (level == 0) { - *s = '\0'; - lasta = s+1; - } - level++; - break; - case ')': - if (level > 0) - level--; - if (level == 0) - goto append; - break; - case ',': - if (level == 0) - goto out; - append:; - *s = '\0'; - if (*spc >= trmax) - return lp_err; - lasta = strip(lasta); - spk[*spc] = lasta; - eq = strchr(lasta, '='); - if (eq != NULL) { - *eq = '\0'; - eq++; - } - spv[*spc] = eq; - (*spc)++; - *s = '\0'; - lasta = s+1; - } - } - - if (level > 0) - return lp_err; - - out:; - - if (*s != '\0') { - *s = '\0'; - s++; - return s; - } - - return NULL; /* no more layers */ -} - static void cam_xform_init(pcb_xform_t *dst_xform) { memset(dst_xform, 0, sizeof(pcb_xform_t)); @@ -360,7 +286,7 @@ goto err; } read_out_params(dst, &next); - dst->fn = strip(dst->inst); + dst->fn = pcb_str_strip(dst->inst); if (strchr(dst->fn, '%') != NULL) { dst->fn_template = dst->fn; @@ -379,13 +305,13 @@ char *spk[64], *spv[64]; int spc = sizeof(spk) / sizeof(spk[0]); - next = parse_layer(curr, spk, spv, &spc); - if (next == lp_err) { + next = pcb_parse_layergrp_address(curr, spk, spv, &spc); + if (next == pcb_parse_layergrp_err) { pcb_message(PCB_MSG_ERROR, "CAM rule: invalid layer transformation\n"); goto err; } - curr = strip(curr); + curr = pcb_str_strip(curr); numg = pcb_layergrp_list_by_addr(pcb, curr, gids, spk, spv, spc, &vid, &xf, &xf_, "CAM rule: "); if (numg < 0) goto err; @@ -461,7 +387,7 @@ pcb_xform_t *dummy; tmp = pcb_strdup(start); - end = parse_layer(start, spk, spv, &spc); + end = pcb_parse_layergrp_address(start, spk, spv, &spc); if ((end != NULL) && (*end != '\0')) pcb_message(PCB_MSG_ERROR, "global exporter --cam takes only one set of global supplements\n"); pcb_parse_layer_supplements(spk, spv, spc, &purpose, &dummy, dst_xform); Index: trunk/src/layer_addr.c =================================================================== --- trunk/src/layer_addr.c (revision 28614) +++ trunk/src/layer_addr.c (revision 28615) @@ -29,9 +29,67 @@ #include "board.h" #include "data.h" #include "error.h" +#include "misc_util.h" #include "layer_addr.h" +char *pcb_parse_layergrp_err = ""; +char *pcb_parse_layergrp_address(char *curr, char **spk, char **spv, int *spc) +{ + char *s, *lasta, *eq; + int level = 0, trmax = *spc; + *spc = 0; + + for(s = curr; *s != '\0'; s++) { + switch(*s) { + case '(': + if (level == 0) { + *s = '\0'; + lasta = s+1; + } + level++; + break; + case ')': + if (level > 0) + level--; + if (level == 0) + goto append; + break; + case ',': + if (level == 0) + goto out; + append:; + *s = '\0'; + if (*spc >= trmax) + return pcb_parse_layergrp_err; + lasta = pcb_str_strip(lasta); + spk[*spc] = lasta; + eq = strchr(lasta, '='); + if (eq != NULL) { + *eq = '\0'; + eq++; + } + spv[*spc] = eq; + (*spc)++; + *s = '\0'; + lasta = s+1; + } + } + + if (level > 0) + return pcb_parse_layergrp_err; + + out:; + + if (*s != '\0') { + *s = '\0'; + s++; + return s; + } + + return NULL; /* no more layers */ +} + static int parse_layer_type(char *type, pcb_layer_type_t *lyt, int *offs, int *has_offs) { char *soffs, *end, *nxt, *cur; Index: trunk/src/layer_addr.h =================================================================== --- trunk/src/layer_addr.h (revision 28614) +++ trunk/src/layer_addr.h (revision 28615) @@ -13,6 +13,13 @@ /*** for internal use ***/ +/* Parse a layer group address: split at comma, addr will end up holding the + layer name. If there were transformations in (), they are split and + listed in tr up to at most *spc entries. Returns NULL on error or + pointer to the next layer directive. */ +char *pcb_parse_layergrp_address(char *curr, char **spk, char **spv, int *spc); +extern char *pcb_parse_layergrp_err; + void pcb_parse_layer_supplements(char **spk, char **spv, int spc, char **purpose, pcb_xform_t **xf, pcb_xform_t *xf_); /* parse addr into: Index: trunk/src/misc_util.c =================================================================== --- trunk/src/misc_util.c (revision 28614) +++ trunk/src/misc_util.c (revision 28615) @@ -265,3 +265,15 @@ } return inp; } + +char *pcb_str_strip(char *s) +{ + char *end; + while(isspace(*s)) s++; + end = s + strlen(s) - 1; + while((end >= s) && (isspace(*end))) { + *end = '\0'; + end--; + } + return s; +} Index: trunk/src/misc_util.h =================================================================== --- trunk/src/misc_util.h (revision 28614) +++ trunk/src/misc_util.h (revision 28615) @@ -66,4 +66,7 @@ original sep chaarcters with nonsep. */ char *pcb_text_wrap(char *inp, int len, int sep, int nonsep); +/* remove leading and trailing whitespace */ +char *pcb_str_strip(char *s); + #endif