# HG changeset patch # User Tuomo Valkonen # Date 1198173854 -3600 # Node ID 0f2da6be13b139d7ea1384eb135761774439ce23 # Parent ccc57312b8d03150780961545d536806610b6258 Added prefix stuff diff -r ccc57312b8d0 -r 0f2da6be13b1 Makefile --- a/Makefile Wed Jun 20 22:24:09 2007 +0200 +++ b/Makefile Thu Dec 20 19:04:14 2007 +0100 @@ -12,7 +12,7 @@ SOURCES=misc.c output.c util.c optparser.c parser.c tokenizer.c \ map.c obj.c objlist.c errorlog.c ptrlist.c rb.c \ - stringstore.c iterable.c setparam.c + stringstore.c iterable.c setparam.c prefix.c ifdef LIBTU_NO_ERRMSG DEFINES += -DLIBTU_NO_ERRMSG diff -r ccc57312b8d0 -r 0f2da6be13b1 prefix.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prefix.c Thu Dec 20 19:04:14 2007 +0100 @@ -0,0 +1,61 @@ +/* + * libtu/prefix.c + * + * Copyright (c) Tuomo Valkonen 1999-2007. + * + * You may distribute and modify this library under the terms of either + * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. + */ + +#include +#include "misc.h" +#include "locale.h" +#include "output.h" + +static char *the_prefix=NULL; + +void prefix_set(const char *binloc, const char *dflt) +{ + int i=strlen(binloc); + int j=strlen(dflt); + + if(binloc[0]!='/') + die(TR("This relocatable binary should be started with an absolute path.")); + + while(i>0 && j>0){ + if(binloc[i-1]!=dflt[j-1]) + break; + i--; + j--; + } + + the_prefix=scopyn(binloc, i); + +} + + +char *prefix_add(const char *s) +{ + if(the_prefix==NULL) + return scopy(s); + else + return scat3(the_prefix, "/", s); +} + + +bool prefix_wrap_simple(bool (*fn)(const char *s), const char *s) +{ + bool ret=FALSE; + + if(the_prefix==NULL){ + ret=fn(s); + }else{ + char *s2=prefix_add(s); + if(s2!=NULL){ + ret=fn(s2); + free(s2); + } + } + + return ret; +} diff -r ccc57312b8d0 -r 0f2da6be13b1 prefix.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prefix.h Thu Dec 20 19:04:14 2007 +0100 @@ -0,0 +1,17 @@ +/* + * libtu/prefix.h + * + * Copyright (c) Tuomo Valkonen 1999-2007. + * + * You may distribute and modify this library under the terms of either + * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. + */ + +#ifndef _LIBTU_PREFIX_H +#define _LIBTU_PREFIX_H + +extern void prefix_set(const char *binloc, const char *dflt); +extern char *prefix_add(const char *s); +extern bool prefix_wrap_simple(bool (*fn)(const char *s), const char *s); + +#endif /* _LIBTU_PREFIX_H */