[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: a pcb level panelizer tool
On Sun, 2008-09-14 at 19:07 +0200, Stephan Boettcher wrote:
> Saving a copy of the block into a file, doing the renumber with sed,
> and importing the resulting copies was what I did.
I wrote a PCB plugin to do this. It is a little ugly - uses a fixed-name
temp file, makes assumptions - that various operations work, but it
"works for me".
The action is "sedrename", which pops up a dialog box to enter the sed
expression. It remembers the last expression entered, and the rename
just operates on elements - not the netlist.
Best wishes,
--
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!)
/* Sed rename plug-in for PCB
Copyright (C) 2008 Peter Clifton <pcjc2@xxxxxxxxx>
Licensed under the terms of the GNU General Public License, version
2 or later.
Compile like this:
gcc -Wall -I$HOME/pcbsrc/pcb.clean/src -I$HOME/pcbsrc/pcb.clean -O2 -shared sedrename.c -o sedrename.so
The resulting sedrename.so goes in $HOME/.pcb/plugins/sedrename.so.
*/
#include <stdio.h>
#include "global.h"
#include "data.h"
#include "hid.h"
#include "misc.h"
#include "create.h"
#include "error.h"
#include "change.h"
#include "rtree.h"
#include "undo.h"
static int
sedrename (int argc, char **argv, int x, int y)
{
FILE *fp;
int result = STATUS_OK;
char *sed_prog = "sed ";
char *sed_postfix = " > sedrename.tmp";
char *sed_arguments;
char *sed_cmd;
static char *last_argument = NULL;
if (last_argument == NULL)
last_argument = strdup ("s///");
#if 0
if (argc != 1) {
Message("Usage: sedrename sed_expression");
return 1;
}
sed_arguments = argv[0];
#else
if (argc != 0) {
Message("Usage: sedrename");
return 1;
}
sed_arguments = gui->prompt_for ("sedrename", last_argument);
if (sed_arguments == NULL) {
Message("Got null for sed arguments");
return 1;
}
free (last_argument);
last_argument = sed_arguments;
#endif
sed_cmd = (char *) malloc (strlen (sed_prog) + strlen (sed_arguments) + strlen (sed_postfix) + 1);
memcpy (sed_cmd, sed_prog, strlen (sed_prog) + 1);
strcpy (sed_cmd + strlen (sed_prog), sed_arguments);
strcpy (sed_cmd + strlen (sed_prog) + strlen (sed_arguments), sed_postfix);
printf ("Calling sed: '%s'\n", sed_cmd);
if ((fp = popen (sed_cmd, "w")) == NULL) {
PopenErrorMessage (sed_cmd);
free (sed_cmd);
return STATUS_ERROR;
}
free (sed_cmd);
SET_FLAG (NAMEONPCBFLAG, PCB);
ELEMENT_LOOP (PCB->Data);
{
if (!TEST_FLAG (SELECTEDFLAG, element))
continue;
/* BADNESS.. IF SED DOESN'T MATCH OUTPUT LINE FOR LINE, WE STALL */
fprintf (fp, "%s\n", element->Name[1].TextString);
}
END_LOOP;
if (pclose (fp))
return STATUS_ERROR;
if ((fp = fopen ("sedrename.tmp", "rb")) == NULL) {
Message("Cannot open sedrename.tmp for reading");
return STATUS_ERROR;
}
ELEMENT_LOOP (PCB->Data);
{
char *new_ref;
if (!TEST_FLAG (SELECTEDFLAG, element))
continue;
if (fscanf (fp, "%as", &new_ref) != EOF) {
printf ("Send '%s', got '%s'\n", element->Name[1].TextString, new_ref);
AddObjectToChangeNameUndoList (ELEMENT_TYPE, NULL, NULL,
element,
NAMEONPCB_NAME (element));
ChangeObjectName (ELEMENT_TYPE, element, NULL, NULL, new_ref);
}
}
END_LOOP;
gui->invalidate_all ();
IncrementUndoSerialNumber ();
return (fclose (fp) ? STATUS_ERROR : result);
}
static HID_Action sedrename_action_list[] = {
{"sedrename", NULL, sedrename,
NULL, NULL}
};
REGISTER_ACTIONS (sedrename_action_list)
void
pcb_plugin_init()
{
register_sedrename_action_list();
}
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user