cvs commit: ALFS/halfling/src halfling.c lib.c main.c tags.c

highos at linuxfromscratch.org highos at linuxfromscratch.org
Thu Oct 3 16:41:35 PDT 2002


highos      02/10/03 16:41:35

  Modified:    halfling/src halfling.c lib.c main.c tags.c
  Log:
   o Various formatting isues resolved. (tabs all over the place, etc)
   o Commenting out all free(options) which has a nasty effect of seqfaulting
     as getMultiTag() is broken and needs to be fixed.
   o Added xmlSubstituteEntitiesDefault so that Gerard would be happy.
  
  Revision  Changes    Path
  1.2       +11 -9     ALFS/halfling/src/halfling.c
  
  Index: halfling.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/halfling.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- halfling.c	17 Jul 2002 22:27:46 -0000	1.1
  +++ halfling.c	3 Oct 2002 23:41:35 -0000	1.2
  @@ -44,29 +44,31 @@
       xmlDoc *doc = NULL;
       xmlNode *cur = NULL;
   
  +    xmlSubstituteEntitiesDefault(1);
  +
       doc = xmlParseFile(filename);
   
       if (doc == NULL) {
  -	fprintf(stderr, "Document is not well-formed.\n");
  -	return(-1);
  +        fprintf(stderr, "Document is not well-formed.\n");
  +        return(-1);
       }
   
       cur = xmlDocGetRootElement(doc);
   
       if (cur == NULL) {
  -	fprintf(stderr, "Empty root element.\n");
  -	xmlFreeDoc(doc);
  -	return(-1);
  +        fprintf(stderr, "Empty root element.\n");
  +        xmlFreeDoc(doc);
  +        return(-1);
       }
   
       cur = cur->xmlChildrenNode;
   
       while (cur != NULL) {
  -	if (strcmp(cur->name, "package") == 0) {
  -	    tag_package(doc, cur);
  -	}
  +        if (strcmp(cur->name, "package") == 0) {
  +            tag_package(doc, cur);
  +        }
   
  -	cur = cur->next;
  +        cur = cur->next;
       }
   
       xmlFreeDoc(doc);
  
  
  
  1.3       +45 -35    ALFS/halfling/src/lib.c
  
  Index: lib.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/lib.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- lib.c	17 Jul 2002 22:27:46 -0000	1.2
  +++ lib.c	3 Oct 2002 23:41:35 -0000	1.3
  @@ -53,11 +53,11 @@
       va_end(args);
   
       if (showtime) {
  -	tmp = display_time("[%H:%M:%S]");
  -	printf("%s %s", tmp, msg);
  -	free(tmp);
  +        tmp = display_time("[%H:%M:%S]");
  +        printf("%s %s", tmp, msg);
  +        free(tmp);
       } else {
  -	printf("%s", msg);
  +        printf("%s", msg);
       }
   }
   
  @@ -71,7 +71,7 @@
       tm = localtime(&now);
   
       if (strftime(str, sizeof(str), format, tm) < 0) {
  -	return NULL;
  +        return NULL;
       }
   
       return strdup(str);
  @@ -84,18 +84,20 @@
       cur = cur->xmlChildrenNode;
   
       while (cur != NULL) {
  -	if (strcmp(cur->name, name) == 0) {
  -	    tag = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  -	    break;
  -	}
  +        if (strcmp(cur->name, name) == 0) {
  +            tag = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  +            break;
  +        }
   
  -	cur = cur->next;
  +        cur = cur->next;
       }
   
       return(tag);
   }
   
   
  +/* FIXME: the return types totally fuck everything else up */
  +
   char *getMultiTag(xmlDoc *doc, xmlNode *cur, const char *name) {
       char *tag = NULL;
   
  @@ -104,18 +106,19 @@
       tag = strconcat("", NULL);
   
       while (cur != NULL) {
  -	if (strcmp(cur->name, name) == 0) {
  -	    tag = strconcat(tag, " ",  xmlNodeListGetString(doc, cur->xmlChildrenNode, 1), NULL);
  -	}
  +        if (strcmp(cur->name, name) == 0) {
  +            tag = strconcat(tag, " ",  xmlNodeListGetString(doc, \
  +                                            cur->xmlChildrenNode, 1), NULL);
  +        }
   
  -	cur = cur->next;
  +        cur = cur->next;
       }
   
       if (strcmp(tag, "") == 0) {
  -	free(tag);
  -	return("");
  +        free(tag);
  +        return("");
       } else {
  -	return(tag);
  +        return(tag);
       }
   }
   
  @@ -123,6 +126,7 @@
   /* This function is a hack.  Har-har, but it does work for what I want todo.
      A friend suggested I try something similar as he likes to use it all the
      time while coding with glib. */
  +
   char *strconcat(const char *str, ...) {
       va_list args;
       char *retval = NULL;
  @@ -148,8 +152,10 @@
       return(retval);
   }
   
  +
   /* Should add an else, a-cactch all, considering this will bork,
      if it can't find any of the ones below */
  +
   int unpack(const char *destination, const char *source) {
       char *bname = NULL;
       char *tmp = NULL;
  @@ -158,23 +164,26 @@
       bname = (char *)basename(source);
   
       if (strcmp(source + strlen(source) - 8, ".tar.bz2") == 0) {
  -	cmd = strconcat("bzip2 -dc ", source, " | tar -x -C ", destination, NULL);
  +        cmd = strconcat("bzip2 -dc ", source, " | tar -x -C ", \
  +                                                        destination, NULL);
       } else if (strcmp(source + strlen(source) - 7, ".tar.gz") == 0) {
  -	cmd = strconcat("tar zxf ", source, " -C ", destination, NULL);
  +        cmd = strconcat("tar zxf ", source, " -C ", destination, NULL);
       } else if (strcmp(source + strlen(source) - 4, ".tar") == 0) {
  -	cmd = strconcat("tar xf ", source, " -C ", destination, NULL);
  +        cmd = strconcat("tar xf ", source, " -C ", destination, NULL);
       } else if (strcmp(source + strlen(source) - 4, ".bz2") == 0) {
  -	tmp = malloc(strlen(bname) - 3);
  -	tmp = memset(tmp, '\0', strlen(bname) - 3);
  -	tmp = strncpy(tmp, bname, strlen(bname) - 4);
  -	cmd = strconcat("bzip2 -dc ", source, " > ",  destination, "/", tmp, NULL);
  -	free(tmp);
  +        tmp = malloc(strlen(bname) - 3);
  +        tmp = memset(tmp, '\0', strlen(bname) - 3);
  +        tmp = strncpy(tmp, bname, strlen(bname) - 4);
  +        cmd = strconcat("bzip2 -dc ", source, " > ",  destination, "/", \
  +                                                                tmp, NULL);
  +        free(tmp);
       } else if (strcmp(source + strlen(source) - 3, ".gz") == 0) {
  -	tmp = malloc(strlen(bname) - 2);
  -	tmp = memset(tmp, '\0', strlen(bname) - 2);
  -	tmp = strncpy(tmp, bname, strlen(bname) - 3);
  -	cmd = strconcat("gzip -dc ", source, " > ", destination, "/", tmp, NULL);
  -	free(tmp);
  +        tmp = malloc(strlen(bname) - 2);
  +        tmp = memset(tmp, '\0', strlen(bname) - 2);
  +        tmp = strncpy(tmp, bname, strlen(bname) - 3);
  +        cmd = strconcat("gzip -dc ", source, " > ", destination, "/", \
  +                                                                tmp, NULL);
  +        free(tmp);
       }
   
       execute(destination, cmd);
  @@ -184,6 +193,7 @@
       return(0);
   }
   
  +
   int execute(const char *base, const char *cmd) {
       FILE *output = NULL;
       char line[1024];
  @@ -193,19 +203,19 @@
   
   /*
       if (chdir(base)) {
  -	perror("chdir");
  -	return(1);
  +        perror("chdir");
  +        return(1);
       }
   
       output = popen(cmd, "r");
   
       if (output == NULL) {
  -	perror("popen");
  -	return(1);
  +        perror("popen");
  +        return(1);
       }
   
       while (fgets(line, sizeof line, output) != NULL) {
  -	log("%s", line);
  +        log("%s", line);
       }
   
       pclose(output);
  
  
  
  1.5       +20 -19    ALFS/halfling/src/main.c
  
  Index: main.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/main.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- main.c	17 Jul 2002 22:27:46 -0000	1.4
  +++ main.c	3 Oct 2002 23:41:35 -0000	1.5
  @@ -44,31 +44,32 @@
   int main(int argc, char **argv) {
       int c;
   
  -    while ((c = getopt_long(argc, argv, "hvt", long_options, (int *)0)) != EOF) {
  -	switch (c) {
  -	    case 'h':
  -		print_help();
  -		exit(1);
  -		break;
  +    while ((c = getopt_long(argc, argv, "hvt", long_options, \
  +                                                        (int *)0)) != EOF) {
  +        switch (c) {
  +            case 'h':
  +                print_help();
  +                exit(1);
  +                break;
   
  -	    case 'v':
  -		print_version();
  -		exit(1);
  -		break;
  +            case 'v':
  +                print_version();
  +                exit(1);
  +                break;
   
  -	    case 't':
  -		showtime = 1;
  -		break;
  -	}
  +            case 't':
  +                showtime = 1;
  +                break;
  +        }
       }
   
       if (optind < argc) {
  -	while (optind < argc) {
  -	    parse_profile(argv[optind++]);
  -	}
  +        while (optind < argc) {
  +            parse_profile(argv[optind++]);
  +        }
       } else {
  -	print_usage();
  -	printf("\nTry 'halfing --help' for more information.\n");
  +        print_usage();
  +        printf("\nTry 'halfing --help' for more information.\n");
       }
   
       return(0);
  
  
  
  1.3       +57 -47    ALFS/halfling/src/tags.c
  
  Index: tags.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/tags.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- tags.c	17 Jul 2002 22:27:46 -0000	1.2
  +++ tags.c	3 Oct 2002 23:41:35 -0000	1.3
  @@ -50,10 +50,10 @@
       options = getMultiTag(doc, cur, "option");
   
       if (command == NULL) {
  -	cmd = strconcat("./configure", options, NULL);
  +    cmd = strconcat("./configure", options, NULL);
           log("Running `configure%s' in %s.\n", options, base);
       } else {
  -	cmd = strconcat(command, " ", options, NULL);
  +    cmd = strconcat(command, " ", options, NULL);
           log("Running `%s%s' in %s\n", command, options, base);
       }
   
  @@ -61,9 +61,9 @@
   
       free(base);
       free(command);
  -    if (options != "") {
  -	free(options);
  -    }
  +    /*if (options != "") {
  +    free(options);
  +    }*/
       free(cmd);
   }
   
  @@ -77,7 +77,7 @@
       base = xmlGetProp(cur, "base");
   
       if (base == NULL) {
  -	base = strconcat("/", NULL);
  +    base = strconcat("/", NULL);
       }
   
       source = getTag(doc, cur, "source");
  @@ -103,7 +103,17 @@
       char *cmd = NULL;
   
       base = xmlGetProp(cur, "base");
  +
  +    if (base == NULL) {
  +        base = strconcat("/", NULL);
  +    }
  +
       command = xmlGetProp(cur, "command");
  +
  +    if (command == NULL) {
  +        command = strconcat(" ", NULL);
  +    }
  +
       options = getMultiTag(doc, cur, "option");
   
       cmd = strconcat(command, options, NULL);
  @@ -114,7 +124,7 @@
   
       free(base);
       free(command);
  -    free(options);
  +    /*free(options);*/
       free(cmd);
   }
   
  @@ -164,6 +174,7 @@
       free(cmd);
   }
   
  +
   /* FIXME: -C isn't needed if we use base. */
   void tag_make(xmlDoc *doc, xmlNode *cur) {
       char *base = NULL;
  @@ -178,9 +189,9 @@
       execute(base, cmd);
   
       free(base);
  -    if (options != "") {
  -	free(options);
  -    }
  +    /*if (options != "") {
  +    free(options);
  +    }*/
       free(cmd);
   }
   
  @@ -193,22 +204,22 @@
       base = xmlGetProp(cur, "base");
   
       if (base == NULL) {
  -	base = strconcat("/", NULL);
  +    base = strconcat("/", NULL);
       }
   
       cur = cur->xmlChildrenNode;
   
       while (cur != NULL) {
  -	if (strcmp(cur->name, "name") == 0) {
  -	    name = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  -	    cmd = strconcat("mkdir ", name, NULL);
  -	    log("Creating directory %s in %s.\n", name, base);
  -	    execute(base, cmd);
  -	    free(name);
  -	    free(cmd);
  -	}
  +    if (strcmp(cur->name, "name") == 0) {
  +        name = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  +        cmd = strconcat("mkdir ", name, NULL);
  +        log("Creating directory %s in %s.\n", name, base);
  +        execute(base, cmd);
  +        free(name);
  +        free(cmd);
  +    }
   
  -	cur = cur->next;
  +    cur = cur->next;
       }
   
       free(base);
  @@ -220,31 +231,30 @@
       cur = cur->xmlChildrenNode;
   
       while (cur != NULL) {
  -	if (strcmp(cur->name, "info") == 0) {
  -	    tag_info(doc, cur);
  -	} else if (strcmp(cur->name, "unpack") == 0) {
  -	    tag_unpack(doc, cur);
  -	} else if (strcmp(cur->name, "configure") == 0) {
  -	    tag_configure(doc, cur);
  -	} else if (strcmp(cur->name, "copy") == 0 ) {
  -	    tag_copy(doc, cur);
  -	} else if (strcmp(cur->name, "execute") == 0) {
  -	    tag_execute(doc, cur);
  -	} else if (strcmp(cur->name, "make") == 0) {
  -	    tag_make(doc, cur);
  -	} else if (strcmp(cur->name, "mkdir") == 0) {
  -	    tag_mkdir(doc, cur);
  -	} else if (strcmp(cur->name, "link") == 0) {
  -	    tag_link(doc, cur);
  -	} else if (strcmp(cur->name, "remove") == 0) {
  -	    tag_remove(doc, cur);
  -	} else if (strcmp(cur->name, "setenv") == 0) {
  -	    tag_setenv(doc, cur);
  -	}
  +        if (strcmp(cur->name, "info") == 0) {
  +            tag_info(doc, cur);
  +        } else if (strcmp(cur->name, "unpack") == 0) {
  +            tag_unpack(doc, cur);
  +        } else if (strcmp(cur->name, "configure") == 0) {
  +            tag_configure(doc, cur);
  +        } else if (strcmp(cur->name, "copy") == 0 ) {
  +            tag_copy(doc, cur);
  +        } else if (strcmp(cur->name, "execute") == 0) {
  +            tag_execute(doc, cur);
  +        } else if (strcmp(cur->name, "make") == 0) {
  +            tag_make(doc, cur);
  +        } else if (strcmp(cur->name, "mkdir") == 0) {
  +            tag_mkdir(doc, cur);
  +        } else if (strcmp(cur->name, "link") == 0) {
  +            tag_link(doc, cur);
  +        } else if (strcmp(cur->name, "remove") == 0) {
  +            tag_remove(doc, cur);
  +        } else if (strcmp(cur->name, "setenv") == 0) {
  +            tag_setenv(doc, cur);
  +        }
   
  -	cur = cur->next;
  +        cur = cur->next;
       }
  -
   }
   
   
  @@ -271,11 +281,11 @@
       value = getTag(doc, cur, "value");
   
       if (value == NULL) {
  -	log("Unsetting %s environmental variable.\n", variable);
  -	unsetenv(variable);
  +        log("Unsetting %s environmental variable.\n", variable);
  +        unsetenv(variable);
       } else {
  -	log("Setting environmental variable %s to %s.\n", variable, value);
  -	setenv(variable, value, 1);
  +        log("Setting environmental variable %s to %s.\n", variable, value);
  +        setenv(variable, value, 1);
       }
   
       free(variable);
  
  
  
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe alfs-discuss' in the subject header of the message



More information about the alfs-discuss mailing list