[Initng-svn] r1917 - initng/tools

svn at initng.thinktux.net svn at initng.thinktux.net
Wed Nov 2 00:16:52 CET 2005


Author: jimmy
Date: Wed Nov  2 00:16:51 2005
New Revision: 1917

Modified:
   initng/tools/Makefile.install_service
   initng/tools/install_service.c
Log:
install_service.c is the moast ugly code i have ever written.


Modified: initng/tools/Makefile.install_service
==============================================================================
--- initng/tools/Makefile.install_service	(original)
+++ initng/tools/Makefile.install_service	Wed Nov  2 00:16:51 2005
@@ -1,6 +1,7 @@
 
 %.i: %.ii $(top_srcdir)/tools/install_service.pl
-	$(top_srcdir)/tools/install_service.pl -i $<
+	#$(top_srcdir)/tools/install_service.pl -i $<
+	$(top_srcdir)/tools/install_service -i $<
 	chmod 644 $@
 
 CLEANFILES = *.i

Modified: initng/tools/install_service.c
==============================================================================
--- initng/tools/install_service.c	(original)
+++ initng/tools/install_service.c	Wed Nov  2 00:16:51 2005
@@ -30,7 +30,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-/*#define DEBUG */
+#define DEBUG
 
 #ifdef DEBUG
 #define D_(fmt,...) printf(fmt, ## __VA_ARGS__)
@@ -138,6 +138,18 @@
     return NULL;
 }
 
+static int keyword_in_row(const char *key, const char *row)
+{
+    char *tmp;
+    char *st=strndup(row, strcspn(row, "\n\0;"));
+    tmp = strstr(st, key);
+    printf("checking for %s in %s\n", key, st);
+    free(st);
+    if(tmp) return(TRUE);
+    return(FALSE);
+}
+
+
 int main(int argc, char **argv)
 {
     int i = 1;
@@ -147,6 +159,7 @@
     off_t fsize = 0;
     int f_in;
     int f_out;
+    int g_e = 0;
     int print_row = 1;
     int exec_row = 0;
     char exec_buffer[1024];
@@ -237,7 +250,6 @@
     while (pt[0])
     {
         int row_len = 0;
-        char *tmp = NULL;
 
         /* calculate row lenght */
         while (pt[row_len] != '\n' && pt[row_len])
@@ -266,15 +278,19 @@
                 }
             }
 
+
+	    /* this is a if block, if found distro in row set print_row = 1 */
             if (strncmp("#ifd", pt, 4) == 0)
             {
                 D_(" #ifd block : ");
 
-                print_row = 0;
-                tmp = strstr(pt + 4, distro);
-                /* if distro was found, and on this row */
-                if (tmp && (tmp - pt) < row_len)
-                    print_row = 1;
+		if(keyword_in_row(distro, pt + 5))
+		    print_row = 1;
+		else
+		    print_row = 0;
+		    
+		g_e = 0;
+		
 #ifdef DEBUG
                 if (print_row == 1)
                     printf("Printing..\n");
@@ -283,15 +299,34 @@
 #endif
                 goto next;
             }
+	    
+	    
             else if (strncmp("#elsed", pt, 6) == 0)
             {
                 D_(" #elsed block :");
-                /* check variables */
-                tmp = strstr(pt + 6, distro);
-                /* if distro was found, and on this row */
-                if (tmp && (tmp - pt) < row_len)
-                {
-                    print_row = 1;
+		if(pt[5]=='\n' || pt[6]=='\n')
+		{
+		    if(g_e==1)
+		    {
+			print_row=0;
+			goto next;
+		    }
+	
+		    if (print_row==1)
+			print_row=0;
+		    else if (print_row==0)
+			print_row=1;
+		    goto next;
+		}
+
+		g_e = 1;
+		if(keyword_in_row(distro, pt + 6))
+		{
+		    print_row = 1;
+		} else {
+		    print_row = 0;
+		}
+
 #ifdef DEBUG
                     if (print_row == 1)
                         printf("Printing..\n");
@@ -299,22 +334,8 @@
                         printf("Quiet..\n");
 #endif
                     goto next;
-                }
-
-                /* else youst swap */
-                if (print_row == 1)
-                    print_row = 0;
-                else
-                    print_row = 1;
-
-#ifdef DEBUG
-                if (print_row == 1)
-                    printf("Printing..\n");
-                else
-                    printf("Quiet..\n");
-#endif
-                goto next;
             }
+
             else if (strncmp("#endd", pt, 5) == 0)
             {
                 D_("#endd block, all prints.\n");


More information about the Initng-svn mailing list