aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--builtin.c8
-rw-r--r--io.c15
-rw-r--r--nonposix.h18
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile2
-rw-r--r--str_array.c9
-rw-r--r--test/ChangeLog7
-rw-r--r--test/Makefile.am9
-rw-r--r--test/Makefile.in19
-rw-r--r--test/Maketests10
-rwxr-xr-xtest/arrayind1.awk99
-rw-r--r--test/arrayind1.in2
-rw-r--r--test/arrayind1.ok9
-rw-r--r--test/sigpipe1.awk13
-rw-r--r--test/sigpipe1.ok3
16 files changed, 239 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index ff73db97..732d3ece 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2016-05-12 Arnold Robbins <arnold@skeeve.com>
+
+ * str_array.c (str_lookup): Remove MAYBE_NUM from subscript flags.
+ Bug reported by Andres Legarra <Andres.Legarra@toulouse.inra.fr>.
+
+ Unrelated: Fix issues with SIGPIPE. Reported by
+ Ian Jackson <ijackson@chiark.greenend.org.uk>.
+
+ * builtin.c (do_system): Reset/restore SIGPIPE to/from default around
+ call to system.
+ * io.c (redirect, gawk_popen [PIPES_SIMULATED]): Same.
+
+2016-05-12 Eli Zaretskii <eliz@gnu.org>
+
+ * nonposix.h: Add prototypes for Posix functions emulated in pc/*
+ files.
+
2016-05-09 Andrew J. Schorr <aschorr@telemetry-investments.com>
* interpret.h (r_interpret): Op_ext_builtin. No need to test whether
diff --git a/builtin.c b/builtin.c
index 77314d48..25304f31 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2110,6 +2110,10 @@ do_system(int nargs)
cmd[tmp->stlen] = '\0';
os_restore_mode(fileno(stdin));
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_DFL);
+#endif
+
status = system(cmd);
/*
* 3/2016. What to do with ret? It's never simple.
@@ -2141,8 +2145,12 @@ do_system(int nargs)
} else
ret = 0; /* shouldn't get here */
}
+
if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_IGN);
+#endif
cmd[tmp->stlen] = save;
}
diff --git a/io.c b/io.c
index b81ebf3f..7e97b953 100644
--- a/io.c
+++ b/io.c
@@ -900,6 +900,9 @@ redirect_string(const char *str, size_t explen, bool not_string,
(void) flush_io();
os_restore_mode(fileno(stdin));
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_DFL);
+#endif
/*
* Don't check failure_fatal; see input pipe below.
* Note that the failure happens upon failure to fork,
@@ -909,6 +912,9 @@ redirect_string(const char *str, size_t explen, bool not_string,
if ((rp->output.fp = popen(str, binmode("w"))) == NULL)
fatal(_("can't open pipe `%s' for output (%s)"),
str, strerror(errno));
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_IGN);
+#endif
/* set close-on-exec */
os_close_on_exec(fileno(rp->output.fp), str, "pipe", "to");
@@ -2532,9 +2538,18 @@ gawk_popen(const char *cmd, struct redirect *rp)
FILE *current;
os_restore_mode(fileno(stdin));
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_DFL);
+#endif
+
current = popen(cmd, binmode("r"));
+
if ((BINMODE & BINMODE_INPUT) != 0)
os_setbinmode(fileno(stdin), O_BINARY);
+#ifdef SIGPIPE
+ signal(SIGPIPE, SIG_IGN);
+#endif
+
if (current == NULL)
return NULL;
os_close_on_exec(fileno(current), cmd, "pipe", "from");
diff --git a/nonposix.h b/nonposix.h
index 976e0b7d..744914b1 100644
--- a/nonposix.h
+++ b/nonposix.h
@@ -43,4 +43,22 @@
int w32_status_to_termsig (unsigned);
+/* Prototypes of for Posix functions for which we define replacements
+ in pc/ files. */
+
+/* getid.c */
+unsigned int getuid (void);
+unsigned int geteuid (void);
+unsigned int getgid (void);
+unsigned int getegid (void);
+
+/* gawkmisc.pc */
+int unsetenv (const char *);
+int setenv (const char *, const char *, int);
+#endif /* __MINGW32__ */
+
+int getpgrp(void);
+
+#if defined(__DJGPP__) || defined(__MINGW32__)
+int getppid(void);
#endif
diff --git a/pc/ChangeLog b/pc/ChangeLog
index bcc3a934..e991a514 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2016-05-12 Eli Zaretskii <eliz@gnu.org>
+
+ * Makefile ($(ALLOBJS) $(LIBOBJS)): Depend on nonposix.h.
+
2016-04-23 Eli Zaretskii <eliz@gnu.org>
* Makefile.tst (pty1): Ignore errors (happens with MinGW).
diff --git a/pc/Makefile b/pc/Makefile
index 23b90464..57c0dc45 100644
--- a/pc/Makefile
+++ b/pc/Makefile
@@ -242,7 +242,7 @@ $(RSPFILE) : $(GAWKOBJS)
# included by awk.h.
# 2. custom.h is not mentioned because pc ports don't use it.
$(ALLOBJS) $(LIBOBJS): \
- awk.h regex.h config.h gettext.h mbsupport.h protos.h dfa.h getopt.h
+ awk.h regex.h config.h gettext.h mbsupport.h protos.h dfa.h getopt.h nonposix.h
builtin$O: floatmagic.h random.h popen.h
diff --git a/str_array.c b/str_array.c
index 2ffa5df9..c122ab94 100644
--- a/str_array.c
+++ b/str_array.c
@@ -187,6 +187,15 @@ str_lookup(NODE *symbol, NODE *subs)
subs = dupnode(subs);
}
+ /*
+ * Repeat after me: "Array indices are always strings."
+ * "Array indices are always strings."
+ * "Array indices are always strings."
+ * "Array indices are always strings."
+ * ....
+ */
+ subs->flags &= ~MAYBE_NUM;
+
getbucket(b);
b->ahnext = symbol->buckets[hash1];
symbol->buckets[hash1] = b;
diff --git a/test/ChangeLog b/test/ChangeLog
index d9ec5498..096f9050 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,10 @@
+2016-05-12 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (arrayind1): New test.
+ * arrayind1.awk, arrayind1.in, arrayind1.ok: New files.
+ * Makefile.am (sigpipe1): New test.
+ * sigpipe1.awk, sigpipe1.ok: New files.
+
2016-04-27 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (rscompat): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index ea483401..63990647 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -52,6 +52,9 @@ EXTRA_DIST = \
argarray.ok \
argtest.awk \
argtest.ok \
+ arrayind1.awk \
+ arrayind1.in \
+ arrayind1.ok \
arrayparm.awk \
arrayparm.ok \
arrayprm2.awk \
@@ -923,6 +926,8 @@ EXTRA_DIST = \
shadow.ok \
shadowbuiltin.awk \
shadowbuiltin.ok \
+ sigpipe1.awk \
+ sigpipe1.ok \
sort1.awk \
sort1.ok \
sortempty.awk \
@@ -1089,7 +1094,7 @@ CLEANFILES = core core.* fmtspcl.ok
# try to keep these sorted. each letter starts a new line
BASIC_TESTS = \
- addcomma anchgsub argarray arrayparm arrayprm2 arrayprm3 \
+ addcomma anchgsub argarray arrayind1 arrayparm arrayprm2 arrayprm3 \
arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 arynasty \
arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
aryprm8 aryprm9 arysubnm asgext awkpath \
@@ -1121,7 +1126,7 @@ BASIC_TESTS = \
regexprange regrange reindops \
reparse resplit rri1 rs rscompat rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite \
- scalar sclforin sclifin sortempty sortglos splitargv splitarr splitdef \
+ scalar sclforin sclifin sigpipe1 sortempty sortglos splitargv splitarr splitdef \
splitvar splitwht strcat1 strnum1 strtod subamp subi18n \
subsepnm subslash substr swaplns synerr1 synerr2 tradanch tweakfld \
uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs \
diff --git a/test/Makefile.in b/test/Makefile.in
index 7cbf8003..cc44371c 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -309,6 +309,9 @@ EXTRA_DIST = \
argarray.ok \
argtest.awk \
argtest.ok \
+ arrayind1.awk \
+ arrayind1.in \
+ arrayind1.ok \
arrayparm.awk \
arrayparm.ok \
arrayprm2.awk \
@@ -1180,6 +1183,8 @@ EXTRA_DIST = \
shadow.ok \
shadowbuiltin.awk \
shadowbuiltin.ok \
+ sigpipe1.awk \
+ sigpipe1.ok \
sort1.awk \
sort1.ok \
sortempty.awk \
@@ -1345,7 +1350,7 @@ CLEANFILES = core core.* fmtspcl.ok
# try to keep these sorted. each letter starts a new line
BASIC_TESTS = \
- addcomma anchgsub argarray arrayparm arrayprm2 arrayprm3 \
+ addcomma anchgsub argarray arrayind1 arrayparm arrayprm2 arrayprm3 \
arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 arynasty \
arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
aryprm8 aryprm9 arysubnm asgext awkpath \
@@ -1377,7 +1382,7 @@ BASIC_TESTS = \
regexprange regrange reindops \
reparse resplit rri1 rs rscompat rsnul1nl rsnulbig rsnulbig2 rstest1 rstest2 \
rstest3 rstest4 rstest5 rswhite \
- scalar sclforin sclifin sortempty sortglos splitargv splitarr splitdef \
+ scalar sclforin sclifin sigpipe1 sortempty sortglos splitargv splitarr splitdef \
splitvar splitwht strcat1 strnum1 strtod subamp subi18n \
subsepnm subslash substr swaplns synerr1 synerr2 tradanch tweakfld \
uninit2 uninit3 uninit4 uninit5 uninitialized unterm uparrfs \
@@ -2689,6 +2694,11 @@ anchgsub:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+arrayind1:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
arrayparm:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@@ -3501,6 +3511,11 @@ sclifin:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+sigpipe1:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
sortempty:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index d10c2e45..a831496c 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -10,6 +10,11 @@ anchgsub:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+arrayind1:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
arrayparm:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@@ -822,6 +827,11 @@ sclifin:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+sigpipe1:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
sortempty:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/arrayind1.awk b/test/arrayind1.awk
new file mode 100755
index 00000000..29fe80bc
--- /dev/null
+++ b/test/arrayind1.awk
@@ -0,0 +1,99 @@
+#!/usr/local/bin/awk -f
+# this script renums pedigrees with metafounders
+# so that they are added *before*regular animals
+# mf are ascertained because they are not in the 1st column
+# also ordered by generation assuming that all metafounders
+# start at generation 1
+#
+#
+ function maxval (a,b) {
+ max=b
+ if (a>b){max=a}
+ return max
+ }
+BEGIN{
+ pos[0]=0 # actual position in the original data file
+ changed=1
+ posout[0]=0 # position in the new file
+ last=0
+ cum[0]=0 #number of times it acts as parent
+ gen[0]=0
+}
+# read and store pedigree file
+{
+ pos[$1]=NR
+ dam[$1]=$2
+ sire[$1]=$3
+ included[$1]=0
+ gen[$1]=9999
+}
+END{
+ #printf("%10s%10s\n",NR,"animals") > "/dev/stderr"
+ # find out who is a genetic group
+ for (x in sire){
+ if(! (sire[x] in pos)){
+ is_group[sire[x]]=1
+ #printf("%10s%10s\n","sire",sire[x]) > "/dev/stderr"
+ cum[sire[x],"sire"]++
+ }
+ }
+ for (x in dam){
+ if(! (dam[x] in pos)){
+ is_group[dam[x]]=1
+ #printf("%10s%10s\n","dam",dam[x]) > "/dev/stderr"
+ cum[dam[x],"dam"]++
+ }
+ }
+ # compute numbers, but don't write them out
+ #printf("%16s\n","info on mf") > "/dev/stderr"
+ for (x in is_group){
+ nmf++
+ posout[x]=posout[last]+1
+ printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],0,0,x,0,0,0)
+ included[x]=1
+ gen[x]=0
+ last=x
+ cumgen[0]++
+ #printf("%10s%16s%10s%16s%10s%10s%10s\n","group",last," included as",posout[x]," as sire, as dam",cum[x,"sire"],cum[x,"dam"]) > "/dev/stderr"
+ }
+ # regular individuals
+ printf("%16s\n","recoding animals") > "/dev/stderr"
+ iter=1
+ #--> comment next line and this element of the associative array becomes null
+ #printf("%s%16s\n","at the beginning it should be empty: ",posout["00000779770060"]) > "/dev/stderr"
+ #-->
+ while (changed){
+ changed=0
+ for (x in pos){
+ if(x!=0 && !included[x]){
+ # change to number of generation
+ # if(included[dam[x]] && included[sire[x]]){
+ if((gen[dam[x]]<iter) && (gen[sire[x]]<iter)){
+ # the new code is actually the order animals are printed
+ posout[x]=posout[last]+1
+ gen[x]=maxval(gen[dam[x]],gen[sire[x]])+1
+ printf("%16s%16s%16s%16s%16s%16s%16s\n", posout[x],posout[dam[x]],posout[sire[x]],x,dam[x],sire[x],gen[x])
+ included[x]=1
+ changed=1
+ last=x
+ nanim++
+ cumgen[gen[x]]++
+ }
+ # }
+ }
+ }
+ iter++
+ #-->
+ printf("%s%16s\n","in the loop: ",posout["00000779770060"]) > "/dev/stderr"
+ #-->
+ #printf("%10s%10s%10s%10s%16s%16s\n","round",iter,"included",posout[last],"last ",last) > "/dev/stderr"
+ }
+ #printf("%10s%10s%10s%10s%10s%10s\n","metafounders:",nmf," animals",nanim," total",posout[last]) > "/dev/stderr"
+ #printf("%16s%16s\n","pseudogenerations:",gen[last]) > "/dev/stderr"
+ for (x in cumgen){
+ #printf("%10s%16s%10s%16s\n","pseudogeneration:",x," including: ",cumgen[x]) > "/dev/stderr"
+ }
+ #--> this is the guilty line
+ printf("%s%16s\n","at the end: ",posout["00000779770060"]) > "/dev/stderr"
+ #-->
+}
diff --git a/test/arrayind1.in b/test/arrayind1.in
new file mode 100644
index 00000000..915d8657
--- /dev/null
+++ b/test/arrayind1.in
@@ -0,0 +1,2 @@
+64000757790003 00000779770060 00000757740011 1979 2 1975 0
+00000779770060 1975su1du1 1975su1du1 1975 1 1975 1975su1du1
diff --git a/test/arrayind1.ok b/test/arrayind1.ok
new file mode 100644
index 00000000..c68346ea
--- /dev/null
+++ b/test/arrayind1.ok
@@ -0,0 +1,9 @@
+recoding animals
+in the loop: 3
+in the loop: 3
+in the loop: 3
+at the end: 3
+ 1 0 0 00000757740011 0 0 0
+ 2 0 0 1975su1du1 0 0 0
+ 3 2 2 00000779770060 1975su1du1 1975su1du1 1
+ 4 3 1 64000757790003 00000779770060 00000757740011 2
diff --git a/test/sigpipe1.awk b/test/sigpipe1.awk
new file mode 100644
index 00000000..9b23f390
--- /dev/null
+++ b/test/sigpipe1.awk
@@ -0,0 +1,13 @@
+BEGIN {
+ print "system"
+ command = "yes | true"
+ system(command)
+
+ print "pipe to command"
+ print "hi" | command
+ close(command)
+
+ print "pipe from command"
+ command | getline x
+ close(command)
+}
diff --git a/test/sigpipe1.ok b/test/sigpipe1.ok
new file mode 100644
index 00000000..6596f076
--- /dev/null
+++ b/test/sigpipe1.ok
@@ -0,0 +1,3 @@
+system
+pipe to command
+pipe from command