Added prefix stuff

Thu, 20 Dec 2007 19:04:14 +0100

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 20 Dec 2007 19:04:14 +0100
changeset 113
0f2da6be13b1
parent 112
ccc57312b8d0
child 114
29e881a58856

Added prefix stuff

Makefile file | annotate | diff | comparison | revisions
prefix.c file | annotate | diff | comparison | revisions
prefix.h file | annotate | diff | comparison | revisions
--- 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
--- /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 <string.h>
+#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;
+}
--- /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 */

mercurial