source: tests/configs/parsebools.cfa@ bd30231

ADT ast-experimental stuck-waitfor-destruct
Last change on this file since bd30231 was 481f882, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Added some missing headers and cleaned up some of the fork+exec stuff.

  • Property mode set to 100644
File size: 3.8 KB
Line 
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/parsebools.cfa
8// Testing parsing of boolean 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 <parseargs.hfa>
18#include <fstream.hfa>
19
20#include "../meta/fork+exec.hfa"
21
22int main(int argc, char * argv[]) {
23 check_main(argv[0]);
24
25 bool YN = false;
26 bool Yn = false;
27 bool yn = false;
28 bool tf = false;
29 bool st = false;
30 bool sf = true;
31
32 cfa_option options[] = {
33 {'e', "yesno", "test yes/no", YN, parse_yesno},
34 {'y', "YN", "test yes/no", Yn, parse_yesno},
35 {'n', "yn", "test yes/no", yn, parse_yesno},
36 {'t', "truefalse", "test true/false", tf, parse_truefalse},
37 {'s', "settrue", "test set true", st, parse_settrue},
38 {'u', "setfalse", "test set false", sf, parse_setfalse},
39 };
40 int options_cnt = sizeof(options) / sizeof(cfa_option);
41
42 char **left;
43 parse_args( options, options_cnt, "[OPTIONS]...\ntesting bool parameters", left);
44
45 sout | "yes/no :" | YN;
46 sout | "Y/N :" | Yn;
47 sout | "y/n :" | yn;
48 sout | "true/false :" | tf;
49 sout | "set true :" | st;
50 sout | "set false :" | sf;
51}
52
53int true_main(const char * path, char * env[]) {
54 printf("no arg:\n");
55 if(pid_t child = strict_fork(); child == 0) {
56 int ret = execle(path, "parsebools", (const char*)0p, env);
57 if(ret < 0) {
58 fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
59 exit(1);
60 }
61 }
62 else {
63 int status = do_wait(child);
64 print_status(status);
65 }
66
67 printf("all true/set arg:\n");
68 if(pid_t child = strict_fork(); child == 0) {
69 int ret = execle(path, "parsebools", "-e=yes", "-y=Y", "-n=y", "-t=true", "-s", "-u", (const char*)0p, env);
70 if(ret < 0) {
71 fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
72 exit(1);
73 }
74 }
75 else {
76 int status = do_wait(child);
77 print_status(status);
78 }
79
80 printf("all false/unset arg:\n");
81 if(pid_t child = strict_fork(); child == 0) {
82 int ret = execle(path, "parsebools", "-e=no", "-y=N", "-n=n", "-t=false", (const char*)0p, env);
83 if(ret < 0) {
84 fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
85 exit(1);
86 }
87 }
88 else {
89 int status = do_wait(child);
90 print_status(status);
91 }
92
93 printf("gibberish arg 1:\n");
94 if(pid_t child = strict_fork(); child == 0) {
95 int ret = execle(path, "parsebools", "-y=true", (const char*)0p, env);
96 if(ret < 0) {
97 fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
98 exit(1);
99 }
100 }
101 else {
102 int status = do_wait(child);
103 print_status(status);
104 }
105
106 printf("gibberish arg 2:\n");
107 if(pid_t child = strict_fork(); child == 0) {
108 int ret = execle(path, "parsebools", "-t=yes", (const char*)0p, env);
109 if(ret < 0) {
110 fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
111 exit(1);
112 }
113 }
114 else {
115 int status = do_wait(child);
116 print_status(status);
117 }
118
119 printf("gibberish arg 3:\n");
120 if(pid_t child = strict_fork(); child == 0) {
121 int ret = execle(path, "parsebools", "-s=yes", (const char*)0p, env);
122 if(ret < 0) {
123 fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
124 exit(1);
125 }
126 }
127 else {
128 int status = do_wait(child);
129 print_status(status);
130 }
131
132 printf("gibberish arg 4:\n");
133 if(pid_t child = strict_fork(); child == 0) {
134 int ret = execle(path, "parsebools", "-u=yes", (const char*)0p, env);
135 if(ret < 0) {
136 fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
137 exit(1);
138 }
139 }
140 else {
141 int status = do_wait(child);
142 print_status(status);
143 }
144
145 printf("All Done!\n");
146
147 return 0;
148}
Note: See TracBrowser for help on using the repository browser.