From 871c95922018f555a4369980011161120c2e4790 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 11 Dec 1995 22:52:59 +0000 Subject: [PATCH] started parsing CVS patchset: 3 CVS date: 1995/12/11 22:52:59 --- build/build.c | 6 ++-- build/spec.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++------- build/spec.h | 6 ++-- 3 files changed, 100 insertions(+), 17 deletions(-) diff --git a/build/build.c b/build/build.c index 23cd917..eaa6e9a 100644 --- a/build/build.c +++ b/build/build.c @@ -1,12 +1,14 @@ #include #include "spec.h" +#include "messages.h" void main(int argc, char **argv) { FILE *f; - printf("hello\n"); + setVerbosity(MESS_DEBUG); + f = fopen(argv[1], "r"); - parse_spec(f); + parseSpec(f); fclose(f); } diff --git a/build/spec.c b/build/spec.c index f0d0353..6505c58 100644 --- a/build/spec.c +++ b/build/spec.c @@ -6,33 +6,53 @@ #include "header.h" #include "spec.h" #include "rpmerr.h" +#include "messages.h" #include #include +#include #define LINE_BUF_SIZE 1024 -struct spec { - Header header; +struct SpecRec { char *prep; char *build; char *install; char *clean; + struct PackageRec *packages; +}; + +struct PackageRec { + Header header; + char *filelist; + struct PackageRec *next; }; -void free_spec(Spec s) +static int read_line(FILE *f, char *line); +static int match_arch(char *s); +static int match_os(char *s); +static void free_packagerec(struct PackageRec *p); +static void init_spec(void); + +void free_packagerec(struct PackageRec *p) +{ + freeHeader(p->header); + free(p->filelist); + if (p->next) { + free_packagerec(p->next); + } + free(p); +} + +void freeSpec(Spec s) { - freeHeader(s->header); free(s->prep); free(s->build); free(s->install); free(s->clean); + free_packagerec(s->packages); free(s); } -static int read_line(FILE *f, char *line); -static int match_arch(char *s); -static int match_os(char *s); - static int match_arch(char *s) { if (! strncmp(s, "%ifarch i386", 12)) { @@ -96,20 +116,81 @@ static int read_line(FILE *f, char *line) return 1; } -Spec parse_spec(FILE *f) +static regex_t name_regex; +static regex_t description_regex; +static regex_t package_regex; +static regex_t version_regex; +static regex_t release_regex; +static regex_t copyright_regex; +static regex_t icon_regex; +static regex_t group_regex; + +struct regentry { + regex_t *p; + char *s; +} regexps[] = { + {&package_regex, "^package[[:space:]]*:[[:space:]]*"}, + {&name_regex, "^name[[:space:]]*:[[:space:]]*"}, + {&description_regex, "^description[[:space:]]*:[[:space:]]*"}, + {&version_regex, "^version[[:space:]]*:[[:space:]]*"}, + {&release_regex, "^release[[:space:]]*:[[:space:]]*"}, + {©right_regex, "^copyright[[:space:]]*:[[:space:]]*"}, + {&group_regex, "^group[[:space:]]*:[[:space:]]*"}, + {&icon_regex, "^icon[[:space:]]*:[[:space:]]*"}, + {0, 0} +}; + +static void init_spec() +{ + static done = 0; + struct regentry *r = regexps; + int opts = REG_ICASE | REG_EXTENDED; + + if (! done) { + while(r->p) { + regcomp(r->p, r->s, opts); + r++; + } + done = 1; + } +} + +#define PACKAGE_PART 0 +#define PREP_PART 1 +#define BUILD_PART 2 +#define INSTALL_PART 3 +#define CLEAN_PART 4 +#define PREIN_PART 5 +#define POSTIN_PART 6 +#define PREUN_PART 7 +#define POSTUN_PART 8 +#define FILES_PART 9 + +Spec parseSpec(FILE *f) { char line[LINE_BUF_SIZE]; - Spec s = (struct spec *) malloc(sizeof(struct spec)); + Spec s = (struct SpecRec *) malloc(sizeof(struct SpecRec)); + int part = PACKAGE_PART; + int x; + regmatch_t match; - reading = 1; + init_spec(); + reading = 1; while ((x = read_line(f, line))) { if (!reading) continue; if (skip) continue; - puts(line); + /* If we get here, this line is for us */ + printf(line); + if (! regexec(&description_regex, line, 1, &match, 0)) { + message(MESS_DEBUG, "description: %s", line + match.rm_eo); + } else if (! regexec(&name_regex, line, 1, &match, 0)) { + message(MESS_DEBUG, "name : %s", line + match.rm_eo); + } } if (x < 0) { + fprintf(stderr, "ERROR\n"); /* error */ return NULL; } diff --git a/build/spec.h b/build/spec.h index e61a6e6..d3c7b39 100644 --- a/build/spec.h +++ b/build/spec.h @@ -6,9 +6,9 @@ #ifndef _spec_h #define _spec_h -typedef struct spec *Spec; +typedef struct SpecRec *Spec; -Spec parse_spec(FILE *f); -void free_spec(Spec s); +Spec parseSpec(FILE *f); +void freeSpec(Spec s); #endif _spec_h -- 2.7.4