1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // configs/parsenums.cfa |
---|
8 | // Testing parsing of integer arguments |
---|
9 | // |
---|
10 | // Author : Thierry Delisle |
---|
11 | // Created On : Wed Oct 12 15:28:01 2022 |
---|
12 | // Last Modified By : |
---|
13 | // Last Modified On : |
---|
14 | // Update Count : |
---|
15 | // |
---|
16 | |
---|
17 | #include <fstream.hfa> |
---|
18 | #include <parseargs.hfa> |
---|
19 | |
---|
20 | #include "../meta/fork+exec.hfa" |
---|
21 | |
---|
22 | #if __SIZEOF_LONG__ == 4 |
---|
23 | #define BIG_UNSIGNED_LONG "4294967295" |
---|
24 | #define TOO_BIG_UNSIGNED_LONG "4294967296" |
---|
25 | #elif __SIZEOF_LONG__ == 8 |
---|
26 | #define BIG_UNSIGNED_LONG "18446744073709551615" |
---|
27 | #define TOO_BIG_UNSIGNED_LONG "18446744073709551616" |
---|
28 | #else |
---|
29 | #error unexpected size of long |
---|
30 | #endif |
---|
31 | |
---|
32 | int true_main(const char * exec); |
---|
33 | |
---|
34 | int main(int argc, char * argv[]) { |
---|
35 | check_main(argv[0]); |
---|
36 | |
---|
37 | int i = -3; |
---|
38 | unsigned u = 3; |
---|
39 | unsigned long ul = 3; |
---|
40 | unsigned long long ull = 3; |
---|
41 | double d = 3.3; |
---|
42 | |
---|
43 | |
---|
44 | array( cfa_option, 5 ) options; |
---|
45 | options[0] = (cfa_option){ 'i', "int", "test int", i }; |
---|
46 | options[1] = (cfa_option){ 'u', "unsigned", "test unsigned", u }; |
---|
47 | options[2] = (cfa_option){ 'l', "unsignedlong", "test unsigned long", ul }; |
---|
48 | options[3] = (cfa_option){ 'L', "unsignedlonglong", "test unsigned long long", ull }; |
---|
49 | options[4] = (cfa_option){ 'd', "double", "test double", d }; |
---|
50 | |
---|
51 | char **left; |
---|
52 | parse_args( options, "[OPTIONS]...\ntesting bool parameters", left); |
---|
53 | |
---|
54 | sout | "int :" | i; |
---|
55 | sout | "unsigned :" | u; |
---|
56 | sout | "unsigned long :" | ul; |
---|
57 | sout | "unsigned long long :" | ull; |
---|
58 | sout | "double :" | d; |
---|
59 | } |
---|
60 | |
---|
61 | int true_main(const char * path, char * env[]) { |
---|
62 | printf("no arg:\n"); |
---|
63 | if(pid_t child = strict_fork(); child == 0) { |
---|
64 | int ret = execle(path, "parsenums", (const char*)0p, env); |
---|
65 | if(ret < 0) { |
---|
66 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
67 | exit(1); |
---|
68 | } |
---|
69 | } |
---|
70 | else { |
---|
71 | int status = do_wait(child); |
---|
72 | print_status(status); |
---|
73 | } |
---|
74 | |
---|
75 | printf("all 0 arg:\n"); |
---|
76 | if(pid_t child = strict_fork(); child == 0) { |
---|
77 | int ret = execle(path, "parsenums", "-i=0", "-u=0", "-l=0", "-L=0", "-d=0", (const char*)0p, env); |
---|
78 | if(ret < 0) { |
---|
79 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
80 | exit(1); |
---|
81 | } |
---|
82 | } |
---|
83 | else { |
---|
84 | int status = do_wait(child); |
---|
85 | print_status(status); |
---|
86 | } |
---|
87 | |
---|
88 | printf("negative vals arg:\n"); |
---|
89 | if(pid_t child = strict_fork(); child == 0) { |
---|
90 | int ret = execle(path, "parsenums", "-i=-1", "-d=-1", (const char*)0p, env); |
---|
91 | if(ret < 0) { |
---|
92 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
93 | exit(1); |
---|
94 | } |
---|
95 | } |
---|
96 | else { |
---|
97 | int status = do_wait(child); |
---|
98 | print_status(status); |
---|
99 | } |
---|
100 | |
---|
101 | printf("funky notation arg:\n"); |
---|
102 | if(pid_t child = strict_fork(); child == 0) { |
---|
103 | int ret = execle(path, "parsenums", "-i=0x10", "-u=0x20", "-l=0x300", "-L=0x4000", "-d=5e6", (const char*)0p, env); |
---|
104 | if(ret < 0) { |
---|
105 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
106 | exit(1); |
---|
107 | } |
---|
108 | } |
---|
109 | else { |
---|
110 | int status = do_wait(child); |
---|
111 | print_status(status); |
---|
112 | } |
---|
113 | |
---|
114 | printf("big values arg:\n"); |
---|
115 | if(pid_t child = strict_fork(); child == 0) { |
---|
116 | int ret = execle(path, "parsenums", "-i=2147483647", "-u=4294967295", "-l=" BIG_UNSIGNED_LONG, "-L=18446744073709551615", "-d=5e6", (const char*)0p, env); |
---|
117 | if(ret < 0) { |
---|
118 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
119 | exit(1); |
---|
120 | } |
---|
121 | } |
---|
122 | else { |
---|
123 | int status = do_wait(child); |
---|
124 | print_status(status); |
---|
125 | } |
---|
126 | |
---|
127 | printf("too big values arg:\n"); |
---|
128 | if(pid_t child = strict_fork(); child == 0) { |
---|
129 | int ret = execle(path, "parsenums", "-i=2147483648", (const char*)0p, env); |
---|
130 | if(ret < 0) { |
---|
131 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
132 | exit(1); |
---|
133 | } |
---|
134 | } |
---|
135 | else { |
---|
136 | int status = do_wait(child); |
---|
137 | print_status(status); |
---|
138 | } |
---|
139 | |
---|
140 | if(pid_t child = strict_fork(); child == 0) { |
---|
141 | int ret = execle(path, "parsenums", "-u=4294967296", (const char*)0p, env); |
---|
142 | if(ret < 0) { |
---|
143 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
144 | exit(1); |
---|
145 | } |
---|
146 | } |
---|
147 | else { |
---|
148 | int status = do_wait(child); |
---|
149 | print_status(status); |
---|
150 | } |
---|
151 | |
---|
152 | if(pid_t child = strict_fork(); child == 0) { |
---|
153 | int ret = execle(path, "parsenums", "-l=" TOO_BIG_UNSIGNED_LONG, (const char*)0p, env); |
---|
154 | if(ret < 0) { |
---|
155 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
156 | exit(1); |
---|
157 | } |
---|
158 | } |
---|
159 | else { |
---|
160 | int status = do_wait(child); |
---|
161 | print_status(status); |
---|
162 | } |
---|
163 | |
---|
164 | if(pid_t child = strict_fork(); child == 0) { |
---|
165 | int ret = execle(path, "parsenums", "-L=18446744073709551616", (const char*)0p, env); |
---|
166 | if(ret < 0) { |
---|
167 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
168 | exit(1); |
---|
169 | } |
---|
170 | } |
---|
171 | else { |
---|
172 | int status = do_wait(child); |
---|
173 | print_status(status); |
---|
174 | } |
---|
175 | |
---|
176 | printf("negative errors arg:\n"); |
---|
177 | if(pid_t child = strict_fork(); child == 0) { |
---|
178 | int ret = execle(path, "parsenums", "-u=-1", (const char*)0p, env); |
---|
179 | if(ret < 0) { |
---|
180 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
181 | exit(1); |
---|
182 | } |
---|
183 | } |
---|
184 | else { |
---|
185 | int status = do_wait(child); |
---|
186 | print_status(status); |
---|
187 | } |
---|
188 | |
---|
189 | if(pid_t child = strict_fork(); child == 0) { |
---|
190 | int ret = execle(path, "parsenums", "-l=-1", (const char*)0p, env); |
---|
191 | if(ret < 0) { |
---|
192 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
193 | exit(1); |
---|
194 | } |
---|
195 | } |
---|
196 | else { |
---|
197 | int status = do_wait(child); |
---|
198 | print_status(status); |
---|
199 | } |
---|
200 | |
---|
201 | if(pid_t child = strict_fork(); child == 0) { |
---|
202 | int ret = execle(path, "parsenums", "-L=-1", (const char*)0p, env); |
---|
203 | if(ret < 0) { |
---|
204 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
205 | exit(1); |
---|
206 | } |
---|
207 | } |
---|
208 | else { |
---|
209 | int status = do_wait(child); |
---|
210 | print_status(status); |
---|
211 | } |
---|
212 | |
---|
213 | printf("All Done!\n"); |
---|
214 | |
---|
215 | return 0; |
---|
216 | } |
---|