Mail Archives: geda-user/2023/03/29/23:45:43
--sm4nu43k4a2Rpi4c
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hi Karl,
karl AT aspodata DOT se [via geda-user AT delorie DOT com] wrote:
> What sch2pcb wants is to find common.m4 and the footprint files.
> But how?
>
> 1, the dirname trick:
> $(dirname $(dirname $(which pcb)))/share/pcb
> followed by m4, pcblib-newlib alt. newlib depending of what
> we are looking for
This isn't a good choice at all since it makes assumptions about how
pcb was compiled - specifically that there is a fixed relationship
between the pcb binary path and the library path.
> 3, test /usr /usr/local etc. for share/pcb/m4/common.m4 etc.
This would be better than 1 but much worse than 2.
> 2, convince pcb devs. to add some cmdline option like
> $ pcb --libpath
> /usr/local/share/pcb
This is by far the best!
karl AT aspodata DOT se [via geda-user AT delorie DOT com] wrote:
> pcb already have:
> boxA:
> $ pcb --show-defaults 2>&1 | grep lib-command-dir
> lib-command-dir "/home/local/bin/../share/pcb"
>
> boxB:
> $ pcb --show-defaults 2>&1 | grep lib-command-dir
> lib-command-dir "/usr/bin/../share/pcb"
Perfect! Great find.
karl AT aspodata DOT se [via geda-user AT delorie DOT com] wrote:
> > But unfortunately, pcb depends on X beeing available:
> > $ pcb --show-defaults
> > Error: Can't open display:
>
> "pcb -x ps --show-defaults" solves that.
Okay - attached is a C snippet to grab the string.
//Peter
--sm4nu43k4a2Rpi4c
Content-Type: text/x-c; charset=us-ascii
Content-Disposition: attachment; filename="pcblib.c"
#define _POSIX_C_SOURCE 2 /* popen pclose */
#define _XOPEN_SOURCE 500 /* realpath */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <string.h>
int main(int argc, char *argv[]) {
int ret = EXIT_FAILURE;
FILE *p;
char buf[64 + PATH_MAX], *libdir, real_dir[PATH_MAX];
size_t n;
p = popen("pcb -x ps --show-defaults 2>&1", "r");
if (NULL == p) {
perror("popen");
exit(EXIT_FAILURE);
}
while (fgets(buf, sizeof buf, p)) {
if (strncmp(buf, "lib-command-dir ", 16))
continue;
libdir = buf + 16;
if ('"' == libdir[0])
libdir++;
n = strlen(libdir);
while (n > 0 && strchr("\r\n\t ", libdir[n - 1]))
libdir[--n] = 0;
if (n > 0 && '"' == libdir[n - 1])
libdir[--n] = 0;
printf("libdir '%s'\n", libdir);
if (NULL == realpath(libdir, real_dir)) {
perror("realpath");
continue;
}
printf("real dir '%s'\n", real_dir);
ret = EXIT_SUCCESS;
}
pclose(p);
return ret;
}
--sm4nu43k4a2Rpi4c--
- Raw text -