started parsing
CVS patchset: 3 CVS date: 1995/12/11 22:52:59
This commit is contained in:
parent
93db395636
commit
871c959220
|
@ -1,12 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
|
|
113
build/spec.c
113
build/spec.c
|
@ -6,32 +6,52 @@
|
|||
#include "header.h"
|
||||
#include "spec.h"
|
||||
#include "rpmerr.h"
|
||||
#include "messages.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <regex.h>
|
||||
|
||||
#define LINE_BUF_SIZE 1024
|
||||
|
||||
struct spec {
|
||||
Header header;
|
||||
struct SpecRec {
|
||||
char *prep;
|
||||
char *build;
|
||||
char *install;
|
||||
char *clean;
|
||||
struct PackageRec *packages;
|
||||
};
|
||||
|
||||
void free_spec(Spec s)
|
||||
{
|
||||
freeHeader(s->header);
|
||||
free(s->prep);
|
||||
free(s->build);
|
||||
free(s->install);
|
||||
free(s->clean);
|
||||
free(s);
|
||||
}
|
||||
struct PackageRec {
|
||||
Header header;
|
||||
char *filelist;
|
||||
struct PackageRec *next;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
free(s->prep);
|
||||
free(s->build);
|
||||
free(s->install);
|
||||
free(s->clean);
|
||||
free_packagerec(s->packages);
|
||||
free(s);
|
||||
}
|
||||
|
||||
static int match_arch(char *s)
|
||||
{
|
||||
|
@ -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));
|
||||
int x;
|
||||
Spec s = (struct SpecRec *) malloc(sizeof(struct SpecRec));
|
||||
int part = PACKAGE_PART;
|
||||
|
||||
reading = 1;
|
||||
int x;
|
||||
regmatch_t match;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue