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 : Peter A. Buhr
|
---|
13 | // Last Modified On : Sun Feb 11 09:26:13 2024
|
---|
14 | // Update Count : 2
|
---|
15 | //
|
---|
16 |
|
---|
17 | #include <fstream.hfa>
|
---|
18 | #include "../meta/fork+exec.hfa"
|
---|
19 |
|
---|
20 | // last as a work around to a parse bug
|
---|
21 | #include <parseargs.hfa>
|
---|
22 |
|
---|
23 | int main( int argc, char * argv[] ) {
|
---|
24 | check_main(argv[0]);
|
---|
25 |
|
---|
26 | bool YN = false;
|
---|
27 | bool Yn = false;
|
---|
28 | bool yn = false;
|
---|
29 | bool tf = false;
|
---|
30 | bool st = false;
|
---|
31 | bool sf = true;
|
---|
32 |
|
---|
33 | array( cfa_option, 6 ) options;
|
---|
34 | options[0] = (cfa_option){'e', "yesno", "test yes/no", YN, parse_yesno};
|
---|
35 | options[1] = (cfa_option){'y', "YN", "test yes/no", Yn, parse_yesno};
|
---|
36 | options[2] = (cfa_option){'n', "yn", "test yes/no", yn, parse_yesno};
|
---|
37 | options[3] = (cfa_option){'t', "truefalse", "test true/false", tf, parse_truefalse};
|
---|
38 | options[4] = (cfa_option){'s', "settrue", "test set true", st, parse_settrue};
|
---|
39 | options[5] = (cfa_option){'u', "setfalse", "test set false", sf, parse_setfalse};
|
---|
40 |
|
---|
41 | char **left;
|
---|
42 | parse_args( options, "[OPTIONS]...\ntesting bool parameters", left );
|
---|
43 |
|
---|
44 | sout | "yes/no :" | YN;
|
---|
45 | sout | "Y/N :" | Yn;
|
---|
46 | sout | "y/n :" | yn;
|
---|
47 | sout | "true/false :" | tf;
|
---|
48 | sout | "set true :" | st;
|
---|
49 | sout | "set false :" | sf;
|
---|
50 | }
|
---|
51 |
|
---|
52 | int true_main( const char * path, char * env[] ) {
|
---|
53 | printf( "no arg:\n" );
|
---|
54 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
55 | int ret = execle( path, "parsebools", (const char*)0p, env );
|
---|
56 | if ( ret < 0 ) {
|
---|
57 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
|
---|
58 | exit( 1 );
|
---|
59 | }
|
---|
60 | } else {
|
---|
61 | int status = do_wait( child );
|
---|
62 | print_status( status );
|
---|
63 | } // if
|
---|
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 | } // if
|
---|
72 | } else {
|
---|
73 | int status = do_wait( child );
|
---|
74 | print_status( status );
|
---|
75 | } // if
|
---|
76 |
|
---|
77 | printf( "all false/unset arg:\n" );
|
---|
78 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
79 | int ret = execle( path, "parsebools", "-e=no", "-y=N", "-n=n", "-t=false", (const char*)0p, env );
|
---|
80 | if ( ret < 0 ) {
|
---|
81 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
|
---|
82 | exit( 1 );
|
---|
83 | } // if
|
---|
84 | } else {
|
---|
85 | int status = do_wait( child );
|
---|
86 | print_status( status );
|
---|
87 | } // if
|
---|
88 |
|
---|
89 | printf( "gibberish arg 1:\n" );
|
---|
90 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
91 | int ret = execle( path, "parsebools", "-y=true", (const char*)0p, env );
|
---|
92 | if ( ret < 0 ) {
|
---|
93 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
|
---|
94 | exit( 1 );
|
---|
95 | } // if
|
---|
96 | } else {
|
---|
97 | int status = do_wait( child );
|
---|
98 | print_status( status );
|
---|
99 | } // if
|
---|
100 |
|
---|
101 | printf( "gibberish arg 2:\n" );
|
---|
102 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
103 | int ret = execle( path, "parsebools", "-t=yes", (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 | } // if
|
---|
108 | } else {
|
---|
109 | int status = do_wait( child );
|
---|
110 | print_status( status );
|
---|
111 | } // if
|
---|
112 |
|
---|
113 | printf( "gibberish arg 3:\n" );
|
---|
114 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
115 | int ret = execle( path, "parsebools", "-s=yes", (const char*)0p, env );
|
---|
116 | if ( ret < 0 ) {
|
---|
117 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
|
---|
118 | exit( 1 );
|
---|
119 | } // if
|
---|
120 | } else {
|
---|
121 | int status = do_wait( child );
|
---|
122 | print_status( status );
|
---|
123 | } // if
|
---|
124 |
|
---|
125 | printf( "gibberish arg 4:\n" );
|
---|
126 | if ( pid_t child = strict_fork(); child == 0 ) {
|
---|
127 | int ret = execle( path, "parsebools", "-u=yes", ( const char*)0p, env );
|
---|
128 | if ( ret < 0 ) {
|
---|
129 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) );
|
---|
130 | exit( 1 );
|
---|
131 | } // if
|
---|
132 | } else {
|
---|
133 | int status = do_wait( child );
|
---|
134 | print_status( status );
|
---|
135 | } // if
|
---|
136 |
|
---|
137 | printf( "All Done!\n" );
|
---|
138 |
|
---|
139 | return 0;
|
---|
140 | }
|
---|