Skip to content

Commit ca709f8

Browse files
committed
Merge branch 'master' into fastread
2 parents 8f59efa + 6dd8552 commit ca709f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2686
-970
lines changed

.circleci/config.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,44 @@ jobs:
2727
name: Build
2828
command: make 'ADDCFLAGS=-DGCDEBUG=1 -DREF_ASSERTIONS=1'
2929

30+
- run:
31+
name: Build test helper
32+
command: make testrun
33+
34+
- persist_to_workspace:
35+
root: .
36+
paths:
37+
- es
38+
- testrun
39+
40+
test:
41+
docker:
42+
- image: cimg/base:stable
43+
44+
steps:
45+
- checkout
46+
47+
- attach_workspace:
48+
at: .
49+
3050
- run:
3151
name: Test
32-
command: make trip
52+
command: |
53+
mkdir -p ./test/results
54+
./es -s < ./test/test.es --junit ./test/tests/* > ./test/results/results.xml
55+
56+
- store_artifacts:
57+
path: ./test/results/
58+
59+
- store_test_results:
60+
path: ./test/results/
61+
62+
63+
workflows:
64+
version: 2
65+
build_and_test:
66+
jobs:
67+
- build
68+
- test:
69+
requires:
70+
- build

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
trip.es diff -a
1+
test/tests/trip.es text diff

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ autom4te.cache
2121
/missing
2222
/stamp-h1
2323
/ltmain.sh
24+
/m4/libtool.m4
25+
/m4/ltoptions.m4
26+
/m4/ltsugar.m4
27+
/m4/ltversion.m4
28+
/m4/lt~obsolete.m4
29+
/config.h.in~
30+
/configure~
2431

2532
Makefile
2633
config.h
@@ -36,3 +43,4 @@ sigmsgs.c
3643
token.h
3744
es
3845
esdump
46+
testrun

INSTALL

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ execute configure with a path to the source. For example:
3333
Also obeying the GNU configure convention, configure will take
3434
arguments specifying a variety of directories. Currently the only
3535
relevant ones are the prefix directory (/usr/local by default); bindir,
36-
the directory in which `es' will reside ($prefix/bin by default); and
36+
the directory in which `es' will reside ($prefix/bin by default);
3737
mandir, the directory that will contain the manpage ($prefix/man by
38-
default). These are given to configure by:
38+
default); and datadir, the directory that will contain the es script
39+
library ($prefix/share by default). These are given to configure by:
3940

4041
% ./configure --prefix=directory
4142
% ./configure --bindir=directory --mandir=directory

Makefile.in

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,42 @@
2626
# to get definitions of all signals from <sys/signal.h>.
2727
# _POSIX_SOURCE, _XOPEN_SOURCE are the obvious ones.
2828

29-
datarootdir = @datarootdir@
3029
prefix = @prefix@
30+
datarootdir = @datarootdir@
31+
datadir = @datadir@
3132
exec_prefix = @exec_prefix@
3233
mandir = @mandir@
3334
bindir = @bindir@
3435
srcdir = @srcdir@
36+
testdir = @srcdir@/test
3537

3638

3739
SHELL = /bin/sh
3840
CC = @CC@
3941
INSTALL = @INSTALL@
42+
INSTALL_PROGRAM = ${INSTALL}
43+
INSTALL_DATA = ${INSTALL} -m 644
4044
MKDIR_P = @MKDIR_P@
4145

4246

4347
## Bison is generating incorrect parsers. So do not use, for now
4448
# YACC = @YACC@
4549

46-
CFLAGS = $(ADDCFLAGS) -I. -I$(srcdir) -W -Wall -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-missing-field-initializers -Wno-unused-parameter -Wno-clobbered @CFLAGS@
50+
CFLAGS = $(ADDCFLAGS) -I. -I$(srcdir) -W -Wall -Wdeclaration-after-statement @READLINE_CFLAGS@ @CFLAGS@
4751
LDFLAGS = $(ADDLDFLAGS) @LDFLAGS@
48-
LIBS = $(ADDLIBS) @LIBS@
52+
LIBS = $(ADDLIBS) @READLINE_LIBS@ @LIBS@
4953

5054
VPATH = $(srcdir)
5155

5256
HFILES = config.h es.h gc.h input.h prim.h print.h sigmsgs.h \
5357
stdenv.h syntax.h term.h var.h
5458
CFILES = access.c closure.c conv.c dict.c eval.c except.c fd.c gc.c glob.c \
55-
glom.c input.c heredoc.c list.c main.c match.c open.c opt.c \
59+
glom.c input.c heredoc.c history.c list.c main.c match.c open.c opt.c \
5660
prim-ctl.c prim-etc.c prim-io.c prim-sys.c prim.c print.c proc.c \
5761
sigmsgs.c signal.c split.c status.c str.c syntax.c term.c token.c \
5862
tree.c util.c var.c vec.c version.c y.tab.c dump.c
5963
OFILES = access.o closure.o conv.o dict.o eval.o except.o fd.o gc.o glob.o \
60-
glom.o input.o heredoc.o list.o main.o match.o open.o opt.o \
64+
glom.o input.o heredoc.o history.o list.o main.o match.o open.o opt.o \
6165
prim-ctl.o prim-etc.o prim-io.o prim-sys.o prim.o print.o proc.o \
6266
sigmsgs.o signal.o split.o status.o str.o syntax.o term.o token.o \
6367
tree.o util.o var.o vec.o version.o y.tab.o
@@ -73,7 +77,7 @@ esdump : ${OFILES} dump.o
7377
${CC} -o esdump ${LDFLAGS} ${OFILES} dump.o ${LIBS}
7478

7579
clean :
76-
rm -f es ${OFILES} ${GEN} dump.o initial.o
80+
rm -f es testrun ${OFILES} ${GEN} dump.o initial.o
7781

7882
distclean: clean
7983
rm -f config.cache config.log config.h Makefile cscope.out tags TAGS core cs.out config.status ltmain.sh
@@ -84,21 +88,26 @@ MANIFEST:
8488

8589
install : es
8690
$(MKDIR_P) $(DESTDIR)$(bindir)
87-
$(INSTALL) -s $(srcdir)/es $(DESTDIR)$(bindir)
91+
$(INSTALL_PROGRAM) -s es $(DESTDIR)$(bindir)
8892
$(MKDIR_P) $(DESTDIR)$(mandir)/man1
89-
$(INSTALL) $(srcdir)/doc/es.1 $(DESTDIR)$(mandir)/man1
93+
$(INSTALL_DATA) $(srcdir)/doc/es.1 $(DESTDIR)$(mandir)/man1
94+
$(MKDIR_P) $(DESTDIR)$(datadir)/es
95+
$(INSTALL_DATA) $(srcdir)/share/* $(DESTDIR)$(datadir)/es
9096

91-
test : trip
97+
testrun : $(testdir)/testrun.c
98+
${CC} -o testrun $(testdir)/testrun.c
9299

93-
trip : es $(srcdir)/trip.es
94-
./es < $(srcdir)/trip.es
100+
test : es testrun $(testdir)/test.es
101+
./es -s < $(testdir)/test.es $(testdir)/tests/*
95102

96103
src :
97104
@echo ${OTHER} ${CFILES} ${HFILES}
98105

99-
y.tab.c y.tab.h : parse.y
106+
y.tab.h : parse.y
100107
${YACC} -vd $(srcdir)/parse.y
101108

109+
y.tab.c : y.tab.h
110+
102111
token.h : y.tab.h
103112
-cmp -s y.tab.h token.h || cp y.tab.h token.h
104113

@@ -126,6 +135,7 @@ glob.o : glob.c es.h config.h stdenv.h gc.h
126135
glom.o : glom.c es.h config.h stdenv.h gc.h
127136
input.o : input.c es.h config.h stdenv.h input.h
128137
heredoc.o : heredoc.c es.h config.h stdenv.h gc.h input.h syntax.h
138+
history.o : history.c es.h config.h stdenv.h gc.h input.h
129139
list.o : list.c es.h config.h stdenv.h gc.h
130140
main.o : main.c es.h config.h stdenv.h
131141
match.o : match.c es.h config.h stdenv.h

access.c

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,34 @@
1414
#define GROUP 3
1515
#define OTHER 0
1616

17+
#define IFREG 1
18+
#define IFDIR 2
19+
#define IFCHR 3
20+
#define IFBLK 4
21+
#define IFLNK 5
22+
#define IFSOCK 6
23+
#define IFIFO 7
24+
1725
/* ingroupset -- determine whether gid lies in the user's set of groups */
1826
static Boolean ingroupset(gidset_t gid) {
19-
#ifdef NGROUPS
2027
int i;
2128
static int ngroups;
22-
static gidset_t gidset[NGROUPS];
29+
static gidset_t *gidset;
2330
static Boolean initialized = FALSE;
2431
if (!initialized) {
2532
initialized = TRUE;
26-
ngroups = getgroups(NGROUPS, gidset);
33+
ngroups = getgroups(0, gidset);
34+
gidset = ealloc(ngroups * sizeof(gidset_t));
35+
getgroups(ngroups, gidset);
2736
}
2837
for (i = 0; i < ngroups; i++)
2938
if (gid == gidset[i])
3039
return TRUE;
31-
#endif
3240
return FALSE;
3341
}
3442

35-
static int testperm(struct stat *stat, int perm) {
36-
int mask;
43+
static int testperm(struct stat *stat, unsigned int perm) {
44+
unsigned int mask;
3745
static gidset_t uid, gid;
3846
static Boolean initialized = FALSE;
3947
if (perm == 0)
@@ -51,21 +59,22 @@ static int testperm(struct stat *stat, int perm) {
5159
: ((gid == stat->st_gid || ingroupset(stat->st_gid))
5260
? GROUP
5361
: OTHER)));
54-
return (stat->st_mode & mask) ? 0 : EACCES;
62+
return (stat->st_mode & mask) == mask ? 0 : EACCES;
5563
}
5664

57-
static int testfile(char *path, int perm, unsigned int type) {
65+
static int testfile(char *path, unsigned int perm, unsigned int type) {
5866
struct stat st;
59-
#ifdef S_IFLNK
60-
if (type == S_IFLNK) {
61-
if (lstat(path, &st) == -1)
62-
return errno;
63-
} else
64-
#endif
65-
if (stat(path, &st) == -1)
66-
return errno;
67-
if (type != 0 && (st.st_mode & S_IFMT) != type)
68-
return EACCES; /* what is an appropriate return value? */
67+
if ((type == IFLNK ? lstat(path, &st) : stat(path, &st)) == -1)
68+
return errno;
69+
/* is EACCES the right return value? */
70+
switch(type) {
71+
case IFREG: if (!S_ISREG(st.st_mode)) return EACCES; break;
72+
case IFDIR: if (!S_ISDIR(st.st_mode)) return EACCES; break;
73+
case IFBLK: if (!S_ISBLK(st.st_mode)) return EACCES; break;
74+
case IFLNK: if (!S_ISLNK(st.st_mode)) return EACCES; break;
75+
case IFSOCK: if (!S_ISSOCK(st.st_mode)) return EACCES; break;
76+
case IFIFO: if (!S_ISFIFO(st.st_mode)) return EACCES; break;
77+
}
6978
return testperm(&st, perm);
7079
}
7180

@@ -97,8 +106,9 @@ static char *pathcat(char *prefix, char *suffix) {
97106
}
98107

99108
PRIM(access) {
100-
int c, perm = 0, type = 0, estatus = ENOENT;
101-
Boolean first = FALSE, exception = FALSE;
109+
int c, estatus = ENOENT;
110+
unsigned int perm = 0, type = 0;
111+
Boolean first = FALSE, throws = FALSE;
102112
char *suffix = NULL;
103113
List *lp;
104114
const char * const usage = "access [-n name] [-1e] [-rwx] [-fdcblsp] path ...";
@@ -109,23 +119,17 @@ PRIM(access) {
109119
switch (c) {
110120
case 'n': suffix = getstr(esoptarg()); break;
111121
case '1': first = TRUE; break;
112-
case 'e': exception = TRUE; break;
122+
case 'e': throws = TRUE; break;
113123
case 'r': perm |= READ; break;
114124
case 'w': perm |= WRITE; break;
115125
case 'x': perm |= EXEC; break;
116-
case 'f': type = S_IFREG; break;
117-
case 'd': type = S_IFDIR; break;
118-
case 'c': type = S_IFCHR; break;
119-
case 'b': type = S_IFBLK; break;
120-
#ifdef S_IFLNK
121-
case 'l': type = S_IFLNK; break;
122-
#endif
123-
#ifdef S_IFSOCK
124-
case 's': type = S_IFSOCK; break;
125-
#endif
126-
#ifdef S_IFIFO
127-
case 'p': type = S_IFIFO; break;
128-
#endif
126+
case 'f': type = IFREG; break;
127+
case 'd': type = IFDIR; break;
128+
case 'c': type = IFCHR; break;
129+
case 'b': type = IFBLK; break;
130+
case 'l': type = IFLNK; break;
131+
case 's': type = IFSOCK; break;
132+
case 'p': type = IFIFO; break;
129133
default:
130134
esoptend();
131135
fail("$&access", "access -%c is not supported on this system", c);
@@ -153,11 +157,11 @@ PRIM(access) {
153157
} else if (error != ENOENT)
154158
estatus = error;
155159
} else
156-
lp = mklist(mkstr(error == 0 ? "0" : esstrerror(error)),
160+
lp = mklist(mkstr(error == 0 ? "0" : gcdup(esstrerror(error))),
157161
lp);
158162
}
159163

160-
if (first && exception) {
164+
if (first && throws) {
161165
gcenable();
162166
if (suffix)
163167
fail("$&access", "%s: %s", suffix, esstrerror(estatus));
@@ -176,6 +180,6 @@ extern Dict *initprims_access(Dict *primdict) {
176180
}
177181

178182
extern char *checkexecutable(char *file) {
179-
int err = testfile(file, EXEC, S_IFREG);
183+
int err = testfile(file, EXEC, IFREG);
180184
return err == 0 ? NULL : esstrerror(err);
181185
}

0 commit comments

Comments
 (0)