source: tests/configs/parsebools.cfa@ bc899d6

ADT ast-experimental
Last change on this file since bc899d6 was d1abc63c, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Change parse args to use new arrays instead of C arrays.
Also added const ?? to arrays.

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