[Initng-svn] r1954 - initng/tools

svn at initng.thinktux.net svn at initng.thinktux.net
Sun Nov 6 17:56:21 CET 2005


Author: SaTaN0r1
Date: Sun Nov  6 17:56:20 2005
New Revision: 1954

Modified:
   initng/tools/install_service.c
Log:
Added support @binary@ to install_service.cnow you ccan write for example @udhcpc@ and it will translate to /sbin/udhcpc or /usr/sbin/udhcpc or whatever

Modified: initng/tools/install_service.c
==============================================================================
--- initng/tools/install_service.c	(original)
+++ initng/tools/install_service.c	Sun Nov  6 17:56:20 2005
@@ -42,6 +42,7 @@
 #define MATCH(PATTERN, LINE) (strncmp(PATTERN, skip_spaces(LINE), sizeof(PATTERN) - 1) == 0)
 #define LEN(STR) (sizeof(STR) - 1)	
 
+const char* path;
 
 /* this program will parse all .i files in installation
    setting distribution dependent values on install time */
@@ -79,6 +80,96 @@
     return ("unknown");
 }
 
+/* This should find string like @mknod@ and return a pointer to it if found,
+ * otherwise return NULL */
+
+static const char* find_at_phrases (const char* in) {
+    const char* first;
+    const char* second;
+    const char* tmp;
+
+    if (! (first = strchr(in, '@')))
+        return NULL; /* no '@' */
+    while (1) {
+        if (! (second = strchr(first + 1, '@')))
+            return NULL; /* only one '@' */
+
+        for (tmp = first + 1; tmp < second; tmp++)
+            if (*tmp == ' ' || *tmp == '\t') {
+                /* whitespace in between: no match */
+                first = second;
+		continue;
+	    }
+        return first;
+    }
+}
+
+static void parse_phrase(FILE* stream, const char* phrase) {
+#define FILENAME_LEN 1000
+    char filename[FILENAME_LEN];
+    const char* tmp;
+    int i;
+    
+    if (! *phrase) {
+        fputc('@', stream);
+	return;
+    }
+    
+    if (!path)
+        return;
+    tmp = path;
+    while (1) {
+        i = 0;
+        while (*tmp != ':' && *tmp != '\0' && i < FILENAME_LEN - 1)
+            filename[i++] = *(tmp++);
+	if (*tmp)
+            tmp++; /* skip ':' */
+	if (filename[i] != '/')
+	    filename[i++] = '/';
+	filename[i] = '\0';
+	strncat(filename, phrase, FILENAME_LEN - 1 - i);
+	/* TODO: check if executable*/
+	if (is_file(filename)) {
+	    fputs(filename, stream);
+	    return;
+	}
+	if (! *tmp){
+	    fprintf(stderr, "WARNING: No executable found for \"%s\"\n", phrase);
+	    return;
+	}
+    }
+}
+
+static void print_it(FILE* stream, const char* buf){
+    const char* tmp;
+    const char* phrase;
+    int i = 0;
+#define PHRASE_LEN 1000
+    char phrase_name[PHRASE_LEN];
+    while (1) {
+        phrase_name[0] = '\0';
+        if (!(phrase = find_at_phrases(buf))) {
+            fputs(buf, stream);
+	    return;
+        }
+
+        /* write all chars up to the beginning '@' thingie to stream */
+	for (tmp = buf; tmp < phrase; tmp++)
+            fputc(*tmp, stream);
+	
+	/* copy Phrase to phrase_name */
+	i = 0;
+	for (tmp = phrase + 1; *tmp != '@' && i < PHRASE_LEN; tmp++){
+	    phrase_name[i++] = *tmp;
+        }
+	phrase_name[i] = '\0';
+	/* pasrse Phrase */
+	parse_phrase(stream, phrase_name);
+	/* re-adjust output buffer */
+	buf = tmp + 1;
+    }
+}
+
 static char *do_exec(char *data, int length)
 {
     int pipe_fork[2], inpipe_fork[2];
@@ -204,7 +295,7 @@
 
     int distro_len = -1;
     
-
+    path = getenv("PATH");
     /* check cmdline for set distribution */
     while (argv[i])
     {
@@ -277,7 +368,7 @@
 	if (feof(in))
             break;
 	if (! in_block && line[0] != '#') {
-	    fprintf(out, "%s", line);
+	    print_it(out, line);
 	    continue; /* read next line */
 	}
 	
@@ -311,7 +402,7 @@
 		    /* exit here ??? */
 		}
 		/* this is a comment so print it */
-		fprintf(out, "%s", line);
+		print_it(out, line);
 		continue; /* read next line */
 	    }
 	}
@@ -332,7 +423,7 @@
 		    continue;
                 } else {
                     /* in if block that should be printed => print it */
-                    fprintf(out, "%s", line);
+                    print_it(out, line);
 		    continue;
 		}
 	    


More information about the Initng-svn mailing list