Mon, 20 Apr 2020 10:14:32 -0500
Convert README to markdown
| 113 | 1 | /* |
| 2 | * libtu/prefix.c | |
| 3 | * | |
| 4 | * Copyright (c) Tuomo Valkonen 1999-2007. | |
| 5 | * | |
| 6 | * You may distribute and modify this library under the terms of either | |
| 7 | * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. | |
| 8 | */ | |
| 9 | ||
| 10 | #include <string.h> | |
| 11 | #include "misc.h" | |
|
117
c7ad4b23a277
locale.h name seems to conflict with system locale.h name on some systems
tuomov
parents:
113
diff
changeset
|
12 | #include "localex.h" |
| 113 | 13 | #include "output.h" |
| 14 | ||
| 15 | static char *the_prefix=NULL; | |
| 16 | ||
| 17 | void prefix_set(const char *binloc, const char *dflt) | |
| 18 | { | |
| 19 | int i=strlen(binloc); | |
| 20 | int j=strlen(dflt); | |
| 21 | ||
| 22 | if(binloc[0]!='/') | |
| 23 | die(TR("This relocatable binary should be started with an absolute path.")); | |
| 24 | ||
| 25 | while(i>0 && j>0){ | |
| 26 | if(binloc[i-1]!=dflt[j-1]) | |
| 27 | break; | |
| 28 | i--; | |
| 29 | j--; | |
| 30 | } | |
| 31 | ||
| 32 | the_prefix=scopyn(binloc, i); | |
| 33 | ||
| 34 | } | |
| 35 | ||
| 36 | ||
| 37 | char *prefix_add(const char *s) | |
| 38 | { | |
| 39 | if(the_prefix==NULL) | |
| 40 | return scopy(s); | |
| 41 | else | |
| 42 | return scat3(the_prefix, "/", s); | |
| 43 | } | |
| 44 | ||
| 45 | ||
| 46 | bool prefix_wrap_simple(bool (*fn)(const char *s), const char *s) | |
| 47 | { | |
| 48 | bool ret=FALSE; | |
| 49 | ||
| 50 | if(the_prefix==NULL){ | |
| 51 | ret=fn(s); | |
| 52 | }else{ | |
| 53 | char *s2=prefix_add(s); | |
| 54 | if(s2!=NULL){ | |
| 55 | ret=fn(s2); | |
| 56 | free(s2); | |
| 57 | } | |
| 58 | } | |
| 59 | ||
| 60 | return ret; | |
| 61 | } |