[481f882] | 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 | //
|
---|
[fd90096] | 16 |
|
---|
| 17 | #include <fstream.hfa>
|
---|
| 18 |
|
---|
[481f882] | 19 | #include "../meta/fork+exec.hfa"
|
---|
[fd90096] | 20 |
|
---|
[9e042d8] | 21 | // last as a work around to a parse bug
|
---|
| 22 | #include <parseargs.hfa>
|
---|
| 23 |
|
---|
[fd90096] | 24 | int main(int argc, char * argv[]) {
|
---|
[481f882] | 25 | check_main(argv[0]);
|
---|
[fd90096] | 26 |
|
---|
| 27 | bool YN = false;
|
---|
| 28 | bool Yn = false;
|
---|
| 29 | bool yn = false;
|
---|
| 30 | bool tf = false;
|
---|
| 31 | bool st = false;
|
---|
| 32 | bool sf = true;
|
---|
| 33 |
|
---|
[d1abc63c] | 34 | array( cfa_option, 6 ) options;
|
---|
| 35 | options[0] = (cfa_option){'e', "yesno", "test yes/no", YN, parse_yesno};
|
---|
| 36 | options[1] = (cfa_option){'y', "YN", "test yes/no", Yn, parse_yesno};
|
---|
| 37 | options[2] = (cfa_option){'n', "yn", "test yes/no", yn, parse_yesno};
|
---|
| 38 | options[3] = (cfa_option){'t', "truefalse", "test true/false", tf, parse_truefalse};
|
---|
| 39 | options[4] = (cfa_option){'s', "settrue", "test set true", st, parse_settrue};
|
---|
| 40 | options[5] = (cfa_option){'u', "setfalse", "test set false", sf, parse_setfalse};
|
---|
[fd90096] | 41 |
|
---|
| 42 | char **left;
|
---|
[d1abc63c] | 43 | parse_args( options, "[OPTIONS]...\ntesting bool parameters", left);
|
---|
[fd90096] | 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 |
|
---|
[481f882] | 53 | int true_main(const char * path, char * env[]) {
|
---|
[fd90096] | 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;
|
---|
[9e042d8] | 148 | }
|
---|