cvs commit: ALFS/halfling/src halfling.c halfling.h Makefile.am help.c help.h lib.c lib.h main.c tags.c tags.h

highos at linuxfromscratch.org highos at linuxfromscratch.org
Wed Jul 17 15:27:47 PDT 2002


highos      02/07/17 15:27:47

  Modified:    halfling/src Makefile.am help.c help.h lib.c lib.h main.c
                        tags.c tags.h
  Added:       halfling/src halfling.c halfling.h
  Log:
  Should have commited this a while ago, been a little lazy, considering
  nobody has asked me much about halfling recently ;-)
  
  By default however, you will have to uncomment the code in execute()
  located in lib.c, for it to actually do something.  I have not yet
  implemented <stage>.  So, instead i've added in <setenv> support
  for now, untill i've gotten around to it.  And because of that, there
  is no chroot support, either.
  
  Given that, it does still work.  I have tested it with a set of LFS
  CVS profiles and a few extra things things from the blfs-book.  You
  can do a full LFS build using it as-is, by manually chroot'ing, etc.
  
  So.. you *can* use it as-is, however I wont recomment it, there is
  hardly any comments in the code, neither is there any documentation
  or much (or any ;p) error checking.
  
  Anyways, enjoy!  More commits coming soon...
  
  Revision  Changes    Path
  1.4       +1 -1      ALFS/halfling/src/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/Makefile.am,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Makefile.am	9 May 2002 20:52:34 -0000	1.3
  +++ Makefile.am	17 Jul 2002 22:27:46 -0000	1.4
  @@ -3,4 +3,4 @@
   bin_PROGRAMS = halfling
   halfling_CFLAGS = $(LIBXML2_CFLAGS)
   halfling_LDADD = $(LIBXML2_LIBS)
  -halfling_SOURCES = main.c help.c lib.c tags.c
  +halfling_SOURCES = main.c halfling.c help.c lib.c tags.c
  
  
  
  1.2       +9 -6      ALFS/halfling/src/help.c
  
  Index: help.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/help.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- help.c	9 May 2002 20:52:34 -0000	1.1
  +++ help.c	17 Jul 2002 22:27:46 -0000	1.2
  @@ -34,19 +34,22 @@
   
   
   #include <stdio.h>
  -
  -void print_usage(void) {
  -    printf("Usage: halfling [options] profile...\n");
  -}
  +#include "help.h"
   
   
   void print_help(void) {
       print_usage();
       printf("\
   Options:\n\
  -  -h,  --help       display this help and exit.\n\
  -  -v,  --version    print the version information and exit.\
  +  -h,  --help       Display this help and exit.\n\
  +  -v,  --version    Print the version information and exit.\n\
  +  -t,  --time       Print time with output.\
   \n");
  +}
  +
  +
  +void print_usage(void) {
  +    printf("Usage: halfling [options] profile(s)\n");
   }
   
   
  
  
  
  1.2       +1 -1      ALFS/halfling/src/help.h
  
  Index: help.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/help.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- help.h	9 May 2002 20:52:34 -0000	1.1
  +++ help.h	17 Jul 2002 22:27:46 -0000	1.2
  @@ -36,8 +36,8 @@
   #ifndef _HELP_H_
   #define _HELP_H_
   
  -void print_usage(void);
   void print_help(void);
  +void print_usage(void);
   void print_version(void);
   
   #endif /* _HELP_H_ */
  
  
  
  1.2       +173 -6    ALFS/halfling/src/lib.c
  
  Index: lib.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/lib.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- lib.c	9 May 2002 20:52:34 -0000	1.1
  +++ lib.c	17 Jul 2002 22:27:46 -0000	1.2
  @@ -34,15 +34,182 @@
   
   
   #include <stdio.h>
  +#include <stdlib.h>
   #include <stdarg.h>
  +#include <string.h>
  +#include <time.h>
  +#include <libxml/tree.h>
  +#include "halfling.h"
  +#include "lib.h"
   
  -void log (const char *format, ...) {
  -    va_list ap;
  +
  +void log(const char *format, ...) {
  +    va_list args;
       char msg[256];
  +    char *tmp = NULL;
  +
  +    va_start(args, format);
  +    vsnprintf(msg, sizeof msg, format, args);
  +    va_end(args);
  +
  +    if (showtime) {
  +	tmp = display_time("[%H:%M:%S]");
  +	printf("%s %s", tmp, msg);
  +	free(tmp);
  +    } else {
  +	printf("%s", msg);
  +    }
  +}
  +
  +
  +char *display_time(const char *format) {
  +    char str[256];
  +    struct tm *tm;
  +    time_t now;
  +
  +    now = time(NULL);
  +    tm = localtime(&now);
  +
  +    if (strftime(str, sizeof(str), format, tm) < 0) {
  +	return NULL;
  +    }
  +
  +    return strdup(str);
  +}
  +
  +
  +char *getTag(xmlDoc *doc, xmlNode *cur, const char *name) {
  +    char *tag = NULL;
  +
  +    cur = cur->xmlChildrenNode;
  +
  +    while (cur != NULL) {
  +	if (strcmp(cur->name, name) == 0) {
  +	    tag = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  +	    break;
  +	}
  +
  +	cur = cur->next;
  +    }
  +
  +    return(tag);
  +}
  +
  +
  +char *getMultiTag(xmlDoc *doc, xmlNode *cur, const char *name) {
  +    char *tag = NULL;
  +
  +    cur = cur->xmlChildrenNode;
  +
  +    tag = strconcat("", NULL);
  +
  +    while (cur != NULL) {
  +	if (strcmp(cur->name, name) == 0) {
  +	    tag = strconcat(tag, " ",  xmlNodeListGetString(doc, cur->xmlChildrenNode, 1), NULL);
  +	}
  +
  +	cur = cur->next;
  +    }
  +
  +    if (strcmp(tag, "") == 0) {
  +	free(tag);
  +	return("");
  +    } else {
  +	return(tag);
  +    }
  +}
  +
  +
  +/* 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;
  +    char *tmp = NULL;
  +    int len;
  +
  +    len = strlen(str) + 1;
  +    retval = malloc(len);
  +    strcpy(retval, str);
  +
  +    va_start(args, str);
  +    tmp = va_arg(args, char *);
  +
  +    while (tmp) {
  +        len += strlen(tmp);
  +        retval = realloc(retval, len);
  +        strcat(retval, tmp);
  +        tmp = va_arg(args, char *);
  +    }
  +
  +    va_end(args);
  +
  +    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;
  +    char *cmd = NULL;
  +
  +    bname = (char *)basename(source);
  +
  +    if (strcmp(source + strlen(source) - 8, ".tar.bz2") == 0) {
  +	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);
  +    } else if (strcmp(source + strlen(source) - 4, ".tar") == 0) {
  +	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);
  +    } 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);
  +    }
  +
  +    execute(destination, cmd);
  +
  +    free(cmd);
  +
  +    return(0);
  +}
  +
  +int execute(const char *base, const char *cmd) {
  +    FILE *output = NULL;
  +    char line[1024];
  +
  +    log("base: %s\n", base);
  +    log("cmd: %s\n", cmd);
  +
  +/*
  +    if (chdir(base)) {
  +	perror("chdir");
  +	return(1);
  +    }
  +
  +    output = popen(cmd, "r");
  +
  +    if (output == NULL) {
  +	perror("popen");
  +	return(1);
  +    }
  +
  +    while (fgets(line, sizeof line, output) != NULL) {
  +	log("%s", line);
  +    }
   
  -    va_start(ap, format);
  -    vsnprintf(msg, sizeof msg, format, ap);
  -    va_end(ap);
  +    pclose(output);
  +*/
   
  -    printf("%s", msg);
  +    return(0);
   }
  
  
  
  1.2       +6 -0      ALFS/halfling/src/lib.h
  
  Index: lib.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/lib.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- lib.h	9 May 2002 20:52:34 -0000	1.1
  +++ lib.h	17 Jul 2002 22:27:46 -0000	1.2
  @@ -37,5 +37,11 @@
   #define _LIB_H_
   
   void log(const char *format, ...);
  +char *display_time(const char *format);
  +char *getTag(xmlDoc *doc, xmlNode *cur, const char *name);
  +char *getMultiTag(xmlDoc *doc, xmlNode *cur, const char *name);
  +char *strconcat(const char *str, ...);
  +int unpack(const char *destination, const char *source);
  +int execute(const char *base, const char *cmd);
   
   #endif /* _LIB_H_ */
  
  
  
  1.4       +8 -45     ALFS/halfling/src/main.c
  
  Index: main.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/main.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- main.c	10 May 2002 17:15:42 -0000	1.3
  +++ main.c	17 Jul 2002 22:27:46 -0000	1.4
  @@ -37,65 +37,28 @@
   #include <getopt.h>
   #include <libxml/tree.h>
   #include <libxml/parser.h>
  +#include "halfling.h"
   #include "help.h"
  -#include "tags.h"
  -
  -
  -static struct option long_options[] = {
  -    {"help", no_argument, NULL, 'h'},
  -    {"version", no_argument, NULL, 'v'},
  -    {0, 0, NULL, 0}
  -};
  -
  -
  -int parse_profile(const char *filename) {
  -    xmlDoc *doc = NULL;
  -    xmlNode *cur = NULL;
  -
  -    doc = xmlParseFile(filename);
  -
  -    if (doc == NULL) {
  -	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);
  -    }
  -
  -    cur = cur->xmlChildrenNode;
  -
  -    while (cur != NULL) {
  -	if (!strcmp(cur->name, "package")) {
  -	    tag_package(doc, cur);
  -	}
  -
  -	cur = cur->next;
  -    }
  -
  -    xmlFreeDoc(doc);
  -
  -    return (0);
  -}
   
   
   int main(int argc, char **argv) {
       int c;
   
  -    while ((c = getopt_long(argc, argv, "hv", long_options, (int *)0)) != EOF) {
  +    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 't':
  +		showtime = 1;
  +		break;
   	}
       }
   
  @@ -108,5 +71,5 @@
   	printf("\nTry 'halfing --help' for more information.\n");
       }
   
  -    return (0);
  +    return(0);
   }
  
  
  
  1.2       +248 -2    ALFS/halfling/src/tags.c
  
  Index: tags.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/tags.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- tags.c	9 May 2002 20:52:34 -0000	1.1
  +++ tags.c	17 Jul 2002 22:27:46 -0000	1.2
  @@ -36,17 +36,263 @@
   #include <stdio.h>
   #include <libxml/tree.h>
   #include "lib.h"
  +#include "tags.h"
  +
  +
  +void tag_configure(xmlDoc *doc, xmlNode *cur) {
  +    char *base = NULL;
  +    char *command = NULL;
  +    char *options = NULL;
  +    char *cmd = NULL;
  +
  +    base = xmlGetProp(cur, "base");
  +    command = xmlGetProp(cur, "command");
  +    options = getMultiTag(doc, cur, "option");
  +
  +    if (command == NULL) {
  +	cmd = strconcat("./configure", options, NULL);
  +        log("Running `configure%s' in %s.\n", options, base);
  +    } else {
  +	cmd = strconcat(command, " ", options, NULL);
  +        log("Running `%s%s' in %s\n", command, options, base);
  +    }
  +
  +    execute(base, cmd);
  +
  +    free(base);
  +    free(command);
  +    if (options != "") {
  +	free(options);
  +    }
  +    free(cmd);
  +}
  +
  +
  +void tag_copy(xmlDoc *doc, xmlNode *cur) {
  +    char *base = NULL;
  +    char *source = NULL;
  +    char *destination = NULL;
  +    char *cmd = NULL;
  +
  +    base = xmlGetProp(cur, "base");
  +
  +    if (base == NULL) {
  +	base = strconcat("/", NULL);
  +    }
  +
  +    source = getTag(doc, cur, "source");
  +    destination = getTag(doc, cur, "destination");
  +
  +    cmd = strconcat("cp ", source, " ", destination, NULL);
  +
  +    log("Copying %s to %s.\n", source, destination);
  +
  +    execute(base, cmd);
  +
  +    free(base);
  +    free(source);
  +    free(destination);
  +    free(cmd);
  +}
  +
  +
  +void tag_execute(xmlDoc *doc, xmlNode *cur) {
  +    char *base = NULL;
  +    char *command = NULL;
  +    char *options = NULL;
  +    char *cmd = NULL;
  +
  +    base = xmlGetProp(cur, "base");
  +    command = xmlGetProp(cur, "command");
  +    options = getMultiTag(doc, cur, "option");
  +
  +    cmd = strconcat(command, options, NULL);
  +
  +    log("Executing `%s' in %s.\n", cmd, base);
  +
  +    execute(base, cmd);
  +
  +    free(base);
  +    free(command);
  +    free(options);
  +    free(cmd);
  +}
  +
  +
  +void tag_info(xmlDoc *doc, xmlNode *cur) {
  +    char *tmp = NULL;
  +
  +    log("Entering package info.\n");
  +
  +    cur = cur->xmlChildrenNode;
  +
  +    while (cur != NULL) {
  +        if (strcmp(cur->name, "name") == 0) {
  +            tmp = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  +            log("name: %s\n", tmp);
  +            free(tmp);
  +        } else if (strcmp(cur->name, "version") == 0) {
  +            tmp = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  +            log("version: %s\n", tmp);
  +            free(tmp);
  +        }
  +
  +        cur = cur->next;
  +    }
  +
  +    log("Leaving package info.\n");
  +}
  +
  +
  +void tag_link(xmlDoc *doc, xmlNode *cur) {
  +    char *base = NULL;
  +    char *source = NULL;
  +    char *destination = NULL;
  +    char *cmd = NULL;
  +
  +    base = xmlGetProp(cur, "base");
  +    source = getTag(doc, cur, "source");
  +    destination = getTag(doc, cur, "destination");
  +    cmd = strconcat("ln -sf ", source, " ", destination, NULL);
  +
  +    log("Creating symbolic link %s to %s in %s.\n", source, destination, base);
  +    execute(base, cmd);
  +
  +    free(base);
  +    free(source);
  +    free(destination);
  +    free(cmd);
  +}
  +
  +/* FIXME: -C isn't needed if we use base. */
  +void tag_make(xmlDoc *doc, xmlNode *cur) {
  +    char *base = NULL;
  +    char *options = NULL;
  +    char *cmd = NULL;
  +
  +    base = xmlGetProp(cur, "base");
  +    options = getMultiTag(doc, cur, "option");
  +    cmd = strconcat("make -C ", base, options, " 2>&1", NULL);
  +
  +    log("Running `make%s' in %s.\n", options, base);
  +    execute(base, cmd);
  +
  +    free(base);
  +    if (options != "") {
  +	free(options);
  +    }
  +    free(cmd);
  +}
  +
  +
  +void tag_mkdir(xmlDoc *doc, xmlNode *cur) {
  +    char *base = NULL;
  +    char *name = NULL;
  +    char *cmd = NULL;
  +
  +    base = xmlGetProp(cur, "base");
  +
  +    if (base == 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);
  +	}
  +
  +	cur = cur->next;
  +    }
  +
  +    free(base);
  +}
  +
   
   void tag_package(xmlDoc *doc, xmlNode *cur) {
   
       cur = cur->xmlChildrenNode;
   
       while (cur != NULL) {
  -	if (!strcmp(cur->name, "info")) {
  -	    /* missing */
  +	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;
       }
   
  +}
  +
  +
  +void tag_remove(xmlDoc *doc, xmlNode *cur) {
  +    char *file = NULL;
  +    char *cmd = NULL;
  +
  +    file = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
  +    cmd = strconcat("rm -rf ", file, NULL);
  +
  +    log("Removing %s.\n", file);
  +    execute("/", cmd);
  +
  +    free(file);
  +    free(cmd);
  +}
  +
  +
  +void tag_setenv(xmlDoc *doc, xmlNode *cur) {
  +    char *variable = NULL;
  +    char *value = NULL;
  +
  +    variable = getTag(doc, cur, "variable");
  +    value = getTag(doc, cur, "value");
  +
  +    if (value == NULL) {
  +	log("Unsetting %s environmental variable.\n", variable);
  +	unsetenv(variable);
  +    } else {
  +	log("Setting environmental variable %s to %s.\n", variable, value);
  +	setenv(variable, value, 1);
  +    }
  +
  +    free(variable);
  +    free(value);
  +}
  +
  +
  +void tag_unpack(xmlDoc *doc, xmlNode *cur) {
  +    char *source = NULL;
  +    char *destination = NULL;
  +
  +    source = getTag(doc, cur, "source");
  +    destination = getTag(doc, cur, "destination");
  +
  +    log("Unpacking %s into %s.\n", source, destination);
  +    unpack(destination, source);
  +
  +    free(source);
  +    free(destination);
   }
  
  
  
  1.2       +10 -0     ALFS/halfling/src/tags.h
  
  Index: tags.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/halfling/src/tags.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- tags.h	9 May 2002 20:52:34 -0000	1.1
  +++ tags.h	17 Jul 2002 22:27:46 -0000	1.2
  @@ -36,6 +36,16 @@
   #ifndef _TAGS_H_
   #define _TAGS_H_
   
  +void tag_configure(xmlDoc *doc, xmlNode *cur);
  +void tag_copy(xmlDoc *doc, xmlNode *cur);
  +void tag_execute(xmlDoc *doc, xmlNode *cur);
  +void tag_info(xmlDoc *doc, xmlNode *cur);
  +void tag_link(xmlDoc *doc, xmlNode *cur);
  +void tag_make(xmlDoc *doc, xmlNode *cur);
  +void tag_mkdir(xmlDoc *doc, xmlNode *cur);
   void tag_package(xmlDoc *doc, xmlNode *cur);
  +void tag_remove(xmlDoc *doc, xmlNode *cur);
  +void tag_setenv(xmlDoc *doc, xmlNode *cur);
  +void tag_unpack(xmlDoc *doc, xmlNode *cur);
   
   #endif /* _TAGS_H_ */
  
  
  
  1.1                  ALFS/halfling/src/halfling.c
  
  Index: halfling.c
  ===================================================================
  /* Copyright (c) 2001, 2002, Jesse Tie-Ten-Quee
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   *    o Redistributions of source code must retain the above copyright
   *      notice, this list of conditions and the following disclaimer.
   *
   *    o Redistributions in binary form must reproduce the above copyright
   *      notice, this list of conditions and the following disclaimer in
   *      the documentation and/or other materials provided with the
   *      distribution.
   *
   *    o Neither the name of "Automated Linux From Scratch" nor the names
   *      of its contributors may be used to endorse or promote products
   *      derived from this software without specific prior written
   *      permission.
   *
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
   * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   * POSSIBILITY OF SUCH DAMAGE.
   */
  
  
  #include <stdio.h>
  #include <libxml/tree.h>
  #include <libxml/parser.h>
  #include "halfling.h"
  #include "tags.h"
  
  
  int parse_profile(const char *filename) {
      xmlDoc *doc = NULL;
      xmlNode *cur = NULL;
  
      doc = xmlParseFile(filename);
  
      if (doc == NULL) {
  	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);
      }
  
      cur = cur->xmlChildrenNode;
  
      while (cur != NULL) {
  	if (strcmp(cur->name, "package") == 0) {
  	    tag_package(doc, cur);
  	}
  
  	cur = cur->next;
      }
  
      xmlFreeDoc(doc);
  
      return(0);
  }
  
  
  
  1.1                  ALFS/halfling/src/halfling.h
  
  Index: halfling.h
  ===================================================================
  /* Copyright (c) 2001, 2002, Jesse Tie-Ten-Quee
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   *    o Redistributions of source code must retain the above copyright
   *      notice, this list of conditions and the following disclaimer.
   *
   *    o Redistributions in binary form must reproduce the above copyright
   *      notice, this list of conditions and the following disclaimer in
   *      the documentation and/or other materials provided with the
   *      distribution.
   *
   *    o Neither the name of "Automated Linux From Scratch" nor the names
   *      of its contributors may be used to endorse or promote products
   *      derived from this software without specific prior written
   *      permission.
   *
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
   * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   * POSSIBILITY OF SUCH DAMAGE.
   */
  
  
  #ifndef _HALFLING_H_
  #define _HALFLING_H_
  
  #include <getopt.h>
  
  static struct option long_options[] = {
      {"help", no_argument, NULL, 'h'},
      {"version", no_argument, NULL, 'v'},
      {"time", no_argument, NULL, 't'},
      {0, 0, NULL, 0}
  };
  
  int showtime;
  
  int parse_profile(const char *filename);
  
  #endif /* _HALFLING_H_ */
  
  
  
-- 
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