Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 6720) +++ trunk/scconfig/Rev.h (revision 6721) @@ -1 +1 @@ -static const int myrev = 6681; +static const int myrev = 6720; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 6720) +++ trunk/scconfig/Rev.tab (revision 6721) @@ -1,4 +1,4 @@ -6681 configure new libcschem source file for project support +6720 configure new libcschem source file for project support 6294 configure remove excess export API 6180 configure move plug_io_act from lib to sch-rnd as it depends on sch-rnd assumptions on project file naming and file formats and other implementation-specific details 6070 configure rnd_printf support for %rc for printing 'k' coords properly Index: trunk/src/libcschem/Makefile.in =================================================================== --- trunk/src/libcschem/Makefile.in (revision 6720) +++ trunk/src/libcschem/Makefile.in (revision 6721) @@ -49,6 +49,7 @@ util_grp.o util_lib_fs.o util_loclib.o + util_path.o util_parse.o util_project.o util_wirenet.o Index: trunk/src/libcschem/util_path.c =================================================================== --- trunk/src/libcschem/util_path.c (nonexistent) +++ trunk/src/libcschem/util_path.c (revision 6721) @@ -0,0 +1,72 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - libcschem (core library) + * Copyright (C) 2023 Tibor 'Igor2' Palinkas + * + * (Supported by NLnet NGI0 Entrust in 2023) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version.* + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contact: + * Project page: http://repo.hu/projects/sch-rnd + * contact lead developer: http://www.repo.hu/projects/sch-rnd/contact.html + * mailing list: http://www.repo.hu/projects/sch-rnd/contact.html + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include "util_path.h" + +char *csch_relative_path_files(const char *pth, const char *relto) +{ + char *freeme1 = NULL, *freeme2 = NULL; + const char *s, *s1, *s2; + int offs, commsep = -1; + gds_t res = {0}; + + + /* make sure both inputs are full paths */ + if (!rnd_is_path_abs(pth)) + pth = freeme1 = rnd_lrealpath(pth); + if (!rnd_is_path_abs(relto)) + relto = freeme2 = rnd_lrealpath(relto); + + /* calculate common part */ + for(offs = 0, s1 = pth, s2 = relto; *s1 == *s2; s1++, s2++, offs++) + if ((*s1 == '/') && (*s2 == '/')) + commsep = offs; + + assert(commsep >= 0); /* both paths are absolute, worst case first char match */ + + /* add all the ../ */ + for(s = relto+commsep+1; *s != '\0'; s++) { + if ((s[0] == '/') && (s[1] != '/')) + gds_append_str(&res, "../"); + } + + /* append partial path to dest file */ + gds_append_str(&res, pth+commsep+1); + + free(freeme1); + free(freeme2); + return res.array; +} Index: trunk/src/libcschem/util_path.h =================================================================== --- trunk/src/libcschem/util_path.h (nonexistent) +++ trunk/src/libcschem/util_path.h (revision 6721) @@ -0,0 +1,7 @@ +/* Allocate a new string and store a path of pth relative to relto, assuming + both path and relto are files. For example if + path=/home/foo/bar/baz.pcb and relto=/home/foo/heh.txt, the result is + bar/baz.pcb; if they are swapped the result is ../heh.txt */ +char *csch_relative_path_files(const char *pth, const char *relto); + +