1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
BEGIN{
for (IGNORECASE=0; IGNORECASE <= 1; IGNORECASE++) {
SORT_STR = -1
makea(a)
asort1(a, "")
printf("---end asort(a), IGNORECASE = %d---\n", IGNORECASE)
makea(a)
asort2(a, "")
printf("---end asort(a, b), IGNORECASE = %d---\n", IGNORECASE)
makea(a)
SORT_STR = ""
asort1(a)
printf("---end asort(a, a), IGNORECASE = %d---\n", IGNORECASE)
makea(a)
SORT_STR = "@ind_num_asc"
asort2(a, "")
printf("---end asort(a, b, \"%s\"), IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
makea(a)
SORT_STR = "@ind_str_desc"
asort1(a, "")
printf("---end asort(a, a, \"%s\"), IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
makea(a)
SORT_STR = "@val_str_asc"
proc_sort(a, "")
printf("---end PROCINFO[\"sorted_in\"] = \"%s\", IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
makea(a)
SORT_STR = "@val_num_asc"
proc_sort(a, "")
printf("---end PROCINFO[\"sorted_in\"] = \"%s\", IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
makea(a)
SORT_STR = "@val_str_desc"
proc_sort(a, "")
printf("---end PROCINFO[\"sorted_in\"] = \"%s\", IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
makea(a)
SORT_STR = "@val_num_desc"
proc_sort(a, "")
printf("---end PROCINFO[\"sorted_in\"] = \"%s\", IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
makea(a)
SORT_STR = "@val_type_asc"
proc_sort(a, "")
printf("---end PROCINFO[\"sorted_in\"] = \"%s\", IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
makea(a)
SORT_STR = "@val_type_desc"
proc_sort(a, "")
printf("---end PROCINFO[\"sorted_in\"] = \"%s\", IGNORECASE = %d---\n",
SORT_STR, IGNORECASE)
}
}
function makea(aa)
{
delete aa
aa[1] = "barz";
aa[2] = "blattt";
aa[3] = "Zebra";
aa[4] = 1234;
aa[5] = 234;
aa[6][1] = 4321;
# aa[6][2] = 432;
aa[6][3] = "tttalb";
aa[6][2] = "arbeZ";
aa[6][4] = "zrab";
}
# source array != destination array
function asort2(c, s, d, k, m)
{
if (SORT_STR < 0)
m = asort(c, d);
else
m = asort(c, d, SORT_STR);
for(k=1; k <= m; k++) {
if (isarray(d[k]))
asort2(d[k], s"["k"]")
else
printf("%10s:%10s%10s\n", s"["k"]", c[k], d[k])
}
}
# source array == destination array
function asort1(c, s, k, m)
{
if (SORT_STR < 0)
m = asort(c)
else if (SORT_STR != "")
m = asort(c, c, SORT_STR)
else
m = asort(c, c);
for(k=1; k <= m; k++) {
if (isarray(c[k]))
asort1(c[k], s"["k"]")
else
printf("%10s:%10s\n", s"["k"]", c[k])
}
}
function proc_sort(c, s, k)
{
PROCINFO["sorted_in"] = SORT_STR
for(k in c) {
if (isarray(c[k]))
proc_sort(c[k], s"["k"]")
else
printf("%10s:%10s\n", s"["k"]", c[k])
}
}
|