Skip to content

Commit 7153c16

Browse files
author
root
committed
Initial revision
CVS patchset: 1 CVS date: 1995/11/27 22:31:21
0 parents  commit 7153c16

19 files changed

+1544
-0
lines changed

Makefile.in

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SUBDIRS = lib
2+
OBJS = spec.o
3+
PROGS = build
4+
5+
WARNINGS = -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes
6+
DEBUG = -g
7+
OPTS = -O2
8+
CFLAGS = $(WARNINGS) $(DEBUG) $(OPTS) -Ilib
9+
LDFLAGS = $(DEBUG) -Llib
10+
LOADLIBES = -lrpm
11+
12+
all: make-subdirs $(OBJS) $(PROGS)
13+
14+
make-subdirs:
15+
for d in $(SUBDIRS); do \
16+
(cd $$d; $(MAKE)) ;\
17+
done
18+
19+
build: build.o spec.o
20+
21+
clean:
22+
for d in $(SUBDIRS); do \
23+
(cd $$d; $(MAKE) $@) ;\
24+
done
25+
rm -f *.o *~ $(PROGS)

build/build.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
#include "spec.h"
3+
4+
void main(int argc, char **argv)
5+
{
6+
FILE *f;
7+
8+
printf("hello\n");
9+
f = fopen(argv[1], "r");
10+
parse_spec(f);
11+
fclose(f);
12+
}

build/spec.c

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/* RPM - Copyright (C) 1995 Red Hat Software
2+
*
3+
* spec.c - routines for parsing a spec file
4+
*/
5+
6+
#include "header.h"
7+
#include "spec.h"
8+
#include "rpmerr.h"
9+
#include <stdlib.h>
10+
#include <string.h>
11+
12+
#define LINE_BUF_SIZE 1024
13+
14+
struct spec {
15+
Header header;
16+
char *prep;
17+
char *build;
18+
char *install;
19+
char *clean;
20+
};
21+
22+
void free_spec(Spec s)
23+
{
24+
freeHeader(s->header);
25+
free(s->prep);
26+
free(s->build);
27+
free(s->install);
28+
free(s->clean);
29+
free(s);
30+
}
31+
32+
static int read_line(FILE *f, char *line);
33+
static int match_arch(char *s);
34+
static int match_os(char *s);
35+
36+
static int match_arch(char *s)
37+
{
38+
if (! strncmp(s, "%ifarch i386", 12)) {
39+
return 1;
40+
} else {
41+
return 0;
42+
}
43+
}
44+
45+
static int match_os(char *s)
46+
{
47+
if (! strncmp(s, "%ifos linux", 11)) {
48+
return 1;
49+
} else {
50+
return 0;
51+
}
52+
}
53+
54+
static int reading = 0;
55+
static int iflevels = 0;
56+
static int skiplevels = 0;
57+
static int skip = 0;
58+
59+
static int read_line(FILE *f, char *line)
60+
{
61+
char *r = fgets(line, LINE_BUF_SIZE, f);
62+
63+
if (! r) {
64+
/* the end */
65+
if (iflevels) return RPMERR_UNMATCHEDIF;
66+
return 0;
67+
}
68+
69+
skip = 0;
70+
71+
if (! strncmp("%ifarch", line, 7)) {
72+
iflevels++;
73+
skip = 1;
74+
if (! match_arch(line)) {
75+
reading = 0;
76+
skiplevels++;
77+
}
78+
}
79+
if (! strncmp("%ifos", line, 5)) {
80+
iflevels++;
81+
skip = 1;
82+
if (! match_os(line)) {
83+
reading = 0;
84+
skiplevels++;
85+
}
86+
}
87+
88+
if (! strncmp("%endif", line, 6)) {
89+
iflevels--;
90+
skip = 1;
91+
if (skiplevels) {
92+
if (! --skiplevels) reading = 1;
93+
}
94+
}
95+
96+
return 1;
97+
}
98+
99+
Spec parse_spec(FILE *f)
100+
{
101+
char line[LINE_BUF_SIZE];
102+
Spec s = (struct spec *) malloc(sizeof(struct spec));
103+
int x;
104+
105+
reading = 1;
106+
107+
while ((x = read_line(f, line))) {
108+
if (!reading) continue;
109+
if (skip) continue;
110+
puts(line);
111+
}
112+
if (x < 0) {
113+
/* error */
114+
return NULL;
115+
}
116+
117+
return s;
118+
}

build/spec.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* RPM - Copyright (C) 1995 Red Hat Software
2+
*
3+
* spec.h - routines for parsing are looking up info in a spec file
4+
*/
5+
6+
#ifndef _spec_h
7+
#define _spec_h
8+
9+
typedef struct spec *Spec;
10+
11+
Spec parse_spec(FILE *f);
12+
void free_spec(Spec s);
13+
14+
#endif _spec_h

convertdb.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* This converts an old style (rpm 1.x) database to the new style */
2+
3+
#include <oldrpmdb.h>
4+
5+
int convertDB(char * dbprefix) {
6+
7+
}

lib/Makefile.in

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
LIBS = -lefence
2+
3+
LIBOBJECTS = header.o oldrpmdb.o misc.o messages.o
4+
LIBRPM = librpm.a
5+
6+
WARNINGS = -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes
7+
DEBUG = -g
8+
OPTS = -O2
9+
10+
all: test dump
11+
12+
# -----------------------------------------------------------------------
13+
14+
AR = ar r
15+
RANLIB = ranlib
16+
17+
CFLAGS = $(WARNINGS) $(DEBUG) $(OPTS)
18+
LDFLAGS = $(DEBUG) $(LIBS)
19+
20+
test: librpm.a
21+
$(CC) -o $@ test.c librpm.a $(LIBS)
22+
23+
dump: librpm.a
24+
$(CC) -o $@ dump.c librpm.a $(LIBS)
25+
26+
$(LIBRPM): $(LIBOBJECTS)
27+
$(AR) $@ $(LIBOBJECTS)
28+
$(RANLIB) $@
29+
30+
clean:
31+
rm -f *.a *.o *~ test dump test.out

0 commit comments

Comments
 (0)