aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--awk.h2
-rw-r--r--debug.c30
-rw-r--r--eval.c39
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am5
-rw-r--r--test/Makefile.in10
-rw-r--r--test/Maketests5
-rw-r--r--test/sortfor.awk8
-rw-r--r--test/sortfor.in289
-rw-r--r--test/sortfor.ok289
11 files changed, 658 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index bd84c74a..9d756011 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Jan 27 22:52:54 2011 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awk.h (comp_func): Add declaration.
+ * debug.c (comp_func): Make not static, and move to ...
+ * eval.c (comp_func): ... here.
+ (r_interpret): Add array sorting if magic index is
+ set in PROCINFO.
+
Thu Jan 27 22:12:00 2011 Corinna Vinschen <vinschen@redhat.com>
* Makefile.am: Remove $(EXEEXT) from 'awk' symlink.
diff --git a/awk.h b/awk.h
index 13674448..8d6a7490 100644
--- a/awk.h
+++ b/awk.h
@@ -1186,6 +1186,8 @@ extern NODE *do_bindtextdomain(int nargs);
extern int strncasecmpmbs(const unsigned char *,
const unsigned char *, size_t);
#endif
+/* debug.c */
+extern int comp_func(const void *p1, const void *p2);
/* eval.c */
extern void PUSH_CODE(INSTRUCTION *cp);
extern INSTRUCTION *POP_CODE(void);
diff --git a/debug.c b/debug.c
index 3932d73b..9573e1fb 100644
--- a/debug.c
+++ b/debug.c
@@ -1056,36 +1056,6 @@ print_field(long field_num)
}
}
-/* comp_func --- array index comparison function for qsort */
-
-static int
-comp_func(const void *p1, const void *p2)
-{
- size_t len1, len2;
- const char *str1, *str2;
- const NODE *t1, *t2;
- int cmp1;
-
- t1 = *((const NODE *const *) p1);
- t2 = *((const NODE *const *) p2);
-
-/*
- t1 = force_string(t1);
- t2 = force_string(t2);
-*/
- len1 = t1->ahname_len;
- str1 = t1->ahname_str;
-
- len2 = t2->ahname_len;
- str2 = t2->ahname_str;
-
- /* Array indexes are strings, compare as such, always! */
- cmp1 = memcmp(str1, str2, len1 < len2 ? len1 : len2);
- /* if prefixes are equal, size matters */
- return (cmp1 != 0 ? cmp1 :
- len1 < len2 ? -1 : (len1 > len2));
-}
-
/* print_array --- print the contents of an array */
static int
diff --git a/eval.c b/eval.c
index e219875f..b9c84afd 100644
--- a/eval.c
+++ b/eval.c
@@ -1056,6 +1056,38 @@ update_FNR()
}
}
+/* comp_func --- array index comparison function for qsort */
+
+int
+comp_func(const void *p1, const void *p2)
+{
+ size_t len1, len2;
+ const char *str1, *str2;
+ const NODE *t1, *t2;
+ int cmp1;
+
+ t1 = *((const NODE *const *) p1);
+ t2 = *((const NODE *const *) p2);
+
+/*
+ t1 = force_string(t1);
+ t2 = force_string(t2);
+*/
+ len1 = t1->ahname_len;
+ str1 = t1->ahname_str;
+
+ len2 = t2->ahname_len;
+ str2 = t2->ahname_str;
+
+ /* Array indexes are strings, compare as such, always! */
+ cmp1 = memcmp(str1, str2, len1 < len2 ? len1 : len2);
+ /* if prefixes are equal, size matters */
+ return (cmp1 != 0 ? cmp1 :
+ len1 < len2 ? -1 : (len1 > len2));
+}
+
+
+
NODE *frame_ptr; /* current frame */
STACK_ITEM *stack_ptr = NULL;
@@ -2221,6 +2253,10 @@ post:
NODE *array;
size_t num_elems = 0;
size_t i, j;
+ static NODE *sorted_str = NULL;
+
+ if (sorted_str == NULL)
+ sorted_str = make_string("sorted_for_loop", 15);
/* get the array */
array = POP_ARRAY();
@@ -2244,6 +2280,9 @@ post:
}
}
+ if (PROCINFO_node != NULL
+ && in_array(PROCINFO_node, sorted_str))
+ qsort(list, num_elems, sizeof(NODE *), comp_func); /* shazzam! */
list[num_elems] = array; /* actual array for use in
* lint warning in Op_arrayfor_incr
*/
diff --git a/test/ChangeLog b/test/ChangeLog
index 88c0f137..fb96b5ce 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jan 27 22:56:19 2011 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (sortfor): New test.
+ * sortfor.awk, sortfor.in, sortfor.ok: New files.
+
Thu Jan 27 22:03:22 2011 John Haque <j.eh@mchsi.com>
* xref.awk, profile2.ok: Fixed to be character set independent.
diff --git a/test/Makefile.am b/test/Makefile.am
index 0ac57bd7..27876090 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -617,6 +617,9 @@ EXTRA_DIST = \
sort1.ok \
sortempty.awk \
sortempty.ok \
+ sortfor.awk \
+ sortfor.in \
+ sortfor.ok \
space.ok \
splitarg4.awk \
splitarg4.in \
@@ -760,7 +763,7 @@ GAWK_EXT_TESTS = \
lintold manyfiles match1 match2 match3 mbstr1 nondec nondec2 patsplit \
posix profile1 profile2 printfbad1 printfbad2 \
procinfs rebuf regx8bit reint reint2 rsstart1 rsstart2 rsstart3 \
- rstest6 shadow splitarg4 strftime strtonum switch2
+ rstest6 shadow sortfor splitarg4 strftime strtonum switch2
EXTRA_TESTS = regtest inftest
diff --git a/test/Makefile.in b/test/Makefile.in
index 58d0e6f4..d035ef22 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -802,6 +802,9 @@ EXTRA_DIST = \
sort1.ok \
sortempty.awk \
sortempty.ok \
+ sortfor.awk \
+ sortfor.in \
+ sortfor.ok \
space.ok \
splitarg4.awk \
splitarg4.in \
@@ -944,7 +947,7 @@ GAWK_EXT_TESTS = \
lintold manyfiles match1 match2 match3 mbstr1 nondec nondec2 patsplit \
posix profile1 profile2 printfbad1 printfbad2 \
procinfs rebuf regx8bit reint reint2 rsstart1 rsstart2 rsstart3 \
- rstest6 shadow splitarg4 strftime strtonum switch2
+ rstest6 shadow sortfor splitarg4 strftime strtonum switch2
EXTRA_TESTS = regtest inftest
INET_TESTS = inetechu inetecht inetdayu inetdayt
@@ -2696,6 +2699,11 @@ shadow:
@AWKPATH=$(srcdir) $(AWK) -f $@.awk --lint >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+sortfor:
+ @echo sortfor
+ @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
splitarg4:
@echo splitarg4
@AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index dc69aaf2..c0222139 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1030,6 +1030,11 @@ shadow:
@AWKPATH=$(srcdir) $(AWK) -f $@.awk --lint >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+sortfor:
+ @echo sortfor
+ @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+
splitarg4:
@echo splitarg4
@AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/sortfor.awk b/test/sortfor.awk
new file mode 100644
index 00000000..2b601c80
--- /dev/null
+++ b/test/sortfor.awk
@@ -0,0 +1,8 @@
+BEGIN {
+ PROCINFO["sorted_for_loop"] = 1
+}
+{ a[$0]++ }
+END {
+ for (i in a)
+ print i
+}
diff --git a/test/sortfor.in b/test/sortfor.in
new file mode 100644
index 00000000..f0e4d510
--- /dev/null
+++ b/test/sortfor.in
@@ -0,0 +1,289 @@
+fsspcoln
+ofmtfidl
+strtonum
+strftime
+uninitialized
+manyfiles
+delarpm2
+wideidx
+parseme
+paramres
+fldchgnf
+subslash
+intprec
+asorti
+mbprintf1
+mbprintf2
+synerr1
+mbprintf3
+synerr2
+arynasty
+swaplns
+asort
+patsplit
+delarprm
+gensub
+litoct
+opasnidx
+clsflnam
+fnarydel
+uparrfs
+argarray
+numindex
+devfd1
+devfd2
+delfunc
+localenl
+noeffect
+fstabplus
+hsprint
+fsfwfs
+tradanch
+fldchg
+printfbad1
+unterm
+printfbad2
+fmttest
+minusstr
+posix
+arrymem1
+concat1
+reint2
+gnuops2
+concat2
+fsrs
+gnuops3
+resplit
+concat3
+fnparydl
+concat4
+uninit2
+rs
+fnarray
+uninit3
+paramdup
+mmap8k
+fieldwdth
+devfd
+uninit4
+poundbang
+uninit5
+nondec2
+switch2
+numsubstr
+profile1
+regx8bit
+profile2
+getline
+membug1
+lint
+zeroflag
+fnasgnm
+widesub2
+widesub3
+reindops
+exitval1
+binmode1
+widesub4
+exitval2
+intest
+back89
+substr
+arynocls
+opasnslf
+ofmtbig
+mbfw1
+zeroe0
+arrayparm
+nasty
+aasort
+sclifin
+nofmtch
+leadnl
+getlnhd
+nofile
+fflush
+printf0
+reparse
+printf1
+prtoeval
+funsmnam
+tweakfld
+sclforin
+wjposer1
+clobber
+iobug1
+fnamedat
+leaddig
+double1
+double2
+strcat1
+prdupval
+messages
+space
+nlfldsep
+posix2008sub
+wideidx2
+nfldstr
+zero2
+rebt8b1
+onlynl
+rebt8b2
+fwtest
+anchgsub
+beginfile1
+fnmisc
+getlndir
+rand
+fwtest2
+nested
+childin
+mtchi18n
+gsubtest
+manglprm
+intformat
+longwrds
+splitarr
+arysubnm
+rsstart1
+procinfs
+argtest
+regeq
+rsstart2
+rsstart3
+sort1
+fmtspcl
+reint
+rsnulbig
+closebad
+strftlng
+parse1
+ofmt
+ignrcas2
+splitarg4
+range1
+noloop1
+longsub
+igncdym
+widesub
+noloop2
+aadelete1
+subi18n
+gsubtst2
+aadelete2
+gsubtst3
+gsubtst4
+convfmt
+gsubtst5
+nors
+arrayref
+gsubtst6
+parsefld
+indirectcall
+asgext
+shadow
+octsub
+nfneg
+backgsub
+math
+getlnbuf
+addcomma
+mbstr1
+subsepnm
+nulrsend
+rsnulbig2
+sprintfc
+redfilnm
+igncfs
+splitwht
+fcall_exit
+fordel
+subamp
+paramtyp
+nlinstr
+eofsplit
+fsbs
+dumpvars
+nlstrina
+datanonl
+fcall_exit2
+icasers
+badargs
+nfset
+gsubasgn
+lc_num1
+aasorti
+pipeio1
+pipeio2
+sortempty
+inputred
+backw
+rswhite
+awkpath
+forsimp
+match1
+match2
+splitvar
+match3
+aryprm1
+aryprm2
+aryprm3
+getline2
+aarray1
+aryprm4
+fnarray2
+getline3
+ignrcase
+aryprm5
+pcntplus
+aryprm6
+aryprm7
+ofmts
+aryprm8
+dynlj
+prec
+prmreuse
+gensub2
+splitdef
+prt1eval
+lintold
+scalar
+fnaryscl
+nondec
+compare2
+icasefs
+rstest1
+getnr2tb
+rstest2
+arryref2
+rstest3
+arryref3
+gnureops
+rstest4
+arryref4
+funstack
+splitargv
+rstest5
+arryref5
+rstest6
+clos1way
+pid
+rsnul1nl
+nasty2
+noparms
+defref
+rebuf
+strtod
+prmarscl
+arrayprm2
+arrayprm3
+getnr2tm
+forref
+funsemnl
+hex
+fpat1
+strnum1
+negexp
+compare
+funlen
+nonl
diff --git a/test/sortfor.ok b/test/sortfor.ok
new file mode 100644
index 00000000..3da24591
--- /dev/null
+++ b/test/sortfor.ok
@@ -0,0 +1,289 @@
+aadelete1
+aadelete2
+aarray1
+aasort
+aasorti
+addcomma
+anchgsub
+argarray
+argtest
+arrayparm
+arrayprm2
+arrayprm3
+arrayref
+arrymem1
+arryref2
+arryref3
+arryref4
+arryref5
+arynasty
+arynocls
+aryprm1
+aryprm2
+aryprm3
+aryprm4
+aryprm5
+aryprm6
+aryprm7
+aryprm8
+arysubnm
+asgext
+asort
+asorti
+awkpath
+back89
+backgsub
+backw
+badargs
+beginfile1
+binmode1
+childin
+clobber
+clos1way
+closebad
+clsflnam
+compare
+compare2
+concat1
+concat2
+concat3
+concat4
+convfmt
+datanonl
+defref
+delarpm2
+delarprm
+delfunc
+devfd
+devfd1
+devfd2
+double1
+double2
+dumpvars
+dynlj
+eofsplit
+exitval1
+exitval2
+fcall_exit
+fcall_exit2
+fflush
+fieldwdth
+fldchg
+fldchgnf
+fmtspcl
+fmttest
+fnamedat
+fnarray
+fnarray2
+fnarydel
+fnaryscl
+fnasgnm
+fnmisc
+fnparydl
+fordel
+forref
+forsimp
+fpat1
+fsbs
+fsfwfs
+fsrs
+fsspcoln
+fstabplus
+funlen
+funsemnl
+funsmnam
+funstack
+fwtest
+fwtest2
+gensub
+gensub2
+getline
+getline2
+getline3
+getlnbuf
+getlndir
+getlnhd
+getnr2tb
+getnr2tm
+gnuops2
+gnuops3
+gnureops
+gsubasgn
+gsubtest
+gsubtst2
+gsubtst3
+gsubtst4
+gsubtst5
+gsubtst6
+hex
+hsprint
+icasefs
+icasers
+igncdym
+igncfs
+ignrcas2
+ignrcase
+indirectcall
+inputred
+intest
+intformat
+intprec
+iobug1
+lc_num1
+leaddig
+leadnl
+lint
+lintold
+litoct
+localenl
+longsub
+longwrds
+manglprm
+manyfiles
+match1
+match2
+match3
+math
+mbfw1
+mbprintf1
+mbprintf2
+mbprintf3
+mbstr1
+membug1
+messages
+minusstr
+mmap8k
+mtchi18n
+nasty
+nasty2
+negexp
+nested
+nfldstr
+nfneg
+nfset
+nlfldsep
+nlinstr
+nlstrina
+noeffect
+nofile
+nofmtch
+noloop1
+noloop2
+nondec
+nondec2
+nonl
+noparms
+nors
+nulrsend
+numindex
+numsubstr
+octsub
+ofmt
+ofmtbig
+ofmtfidl
+ofmts
+onlynl
+opasnidx
+opasnslf
+paramdup
+paramres
+paramtyp
+parse1
+parsefld
+parseme
+patsplit
+pcntplus
+pid
+pipeio1
+pipeio2
+posix
+posix2008sub
+poundbang
+prdupval
+prec
+printf0
+printf1
+printfbad1
+printfbad2
+prmarscl
+prmreuse
+procinfs
+profile1
+profile2
+prt1eval
+prtoeval
+rand
+range1
+rebt8b1
+rebt8b2
+rebuf
+redfilnm
+regeq
+regx8bit
+reindops
+reint
+reint2
+reparse
+resplit
+rs
+rsnul1nl
+rsnulbig
+rsnulbig2
+rsstart1
+rsstart2
+rsstart3
+rstest1
+rstest2
+rstest3
+rstest4
+rstest5
+rstest6
+rswhite
+scalar
+sclforin
+sclifin
+shadow
+sort1
+sortempty
+space
+splitarg4
+splitargv
+splitarr
+splitdef
+splitvar
+splitwht
+sprintfc
+strcat1
+strftime
+strftlng
+strnum1
+strtod
+strtonum
+subamp
+subi18n
+subsepnm
+subslash
+substr
+swaplns
+switch2
+synerr1
+synerr2
+tradanch
+tweakfld
+uninit2
+uninit3
+uninit4
+uninit5
+uninitialized
+unterm
+uparrfs
+wideidx
+wideidx2
+widesub
+widesub2
+widesub3
+widesub4
+wjposer1
+zero2
+zeroe0
+zeroflag