Debian Codegraph @

test/sort1.awk

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