@@ -125,7 +125,8 @@ static const char * const usage_msg0 =
125
125
"\t\t\t NOTE: the judges will NOT use this option\n"
126
126
"\t-E\t\texit non-zero after the first warning (def: do not)\n"
127
127
"\t\t\t NOTE: one cannot use both -W and -E.\n"
128
- "\t-y\t\tanswer yes to most questions (use with EXTREME caution!)" ;
128
+ "\t-y\t\tanswer yes to most questions (use with EXTREME caution!)\n"
129
+ "\t-Y\t\tforce answer yes even when using -i answers" ;
129
130
static const char * const usage_msg1 =
130
131
"\t-t tar\t\tpath to tar(1) that supports the -J (xz) option (def: %s)\n"
131
132
"\t-l ls\t\tpath to ls(1) (def: %s)\n"
@@ -184,6 +185,10 @@ static uintmax_t feathery = 3; /* for entertain option of txzchk (-e) */
184
185
static bool silence_prompt = false; /* true ==> do not display prompts */
185
186
static bool read_answers_flag_used = false; /* true ==> -i read answers from answers file */
186
187
static bool seed_used = false; /* true ==> -d or -s seed given */
188
+ static bool copying_topdir = false; /* true ==> copying topdir and checking submission dir */
189
+ static bool saved_answer_yes = false; /* set to answer_yes before modifying it for scanning/copying topdir */
190
+ static bool saved_silence_prompt = false; /* set to silence_prompt before modifying it for scanning/copying topdir */
191
+ static bool force_yes = false; /* force -y even when scanning/copying/verifying in -i answers mode */
187
192
188
193
/*
189
194
* forward declarations
@@ -245,7 +250,7 @@ main(int argc, char *argv[])
245
250
*/
246
251
input_stream = stdin ; /* default to reading from standard in */
247
252
program = argv [0 ];
248
- while ((i = getopt (argc , argv , ":hv:J:qVt:l:a:i:A:WT:ef:F:C:yds :m:I:" )) != -1 ) {
253
+ while ((i = getopt (argc , argv , ":hv:J:qVt:l:a:i:A:WT:ef:F:C:yYds :m:I:" )) != -1 ) {
249
254
switch (i ) {
250
255
case 'h' : /* -h - print help to stderr and exit 2 */
251
256
usage (2 , program , "" ); /*ooo*/
@@ -301,20 +306,21 @@ main(int argc, char *argv[])
301
306
answers_flag_used = true;
302
307
break ;
303
308
case 'i' : /* -i input_recorded_answers */
309
+ read_answers_flag_used = true;
310
+ /*
311
+ * set need_confirm to false to prevent problem where a user might
312
+ * have a different file set
313
+ */
314
+ need_confirm = false;
315
+ /*
316
+ * set answer_yes to prevent problem where a user might have a
317
+ * different file set
318
+ */
319
+ answer_yes = true;
320
+ need_hints = false;
321
+ silence_prompt = true;
304
322
answers = optarg ;
305
- read_answers_flag_used = true;
306
- /*
307
- * set need_confirm to false to prevent problem where a user might
308
- * have a different file set
309
- */
310
- need_confirm = false;
311
- /*
312
- * set answer_yes to prevent problem where a user might have a
313
- * different file set
314
- */
315
323
answer_yes = true;
316
- need_hints = false;
317
- silence_prompt = true;
318
324
break ;
319
325
case 'W' : /* -W ignores all warnings (this does NOT the judges will! :) ) */
320
326
ignore_warnings = true;
@@ -347,6 +353,11 @@ main(int argc, char *argv[])
347
353
answer_yes = true;
348
354
need_confirm = false;
349
355
break ;
356
+ case 'Y' : /* force yes even when we would normally temporarily undo it */
357
+ force_yes = true;
358
+ answer_yes = true;
359
+ need_confirm = false;
360
+ break ;
350
361
case 'd' : /* alias for -s DEFAULT_SEED */
351
362
answer_seed = DEFAULT_SEED ;
352
363
seed_used = true;
@@ -358,6 +369,7 @@ main(int argc, char *argv[])
358
369
silence_prompt = true;
359
370
/* set -E boolean */
360
371
abort_on_warning = true;
372
+ force_yes = true;
361
373
break ;
362
374
case 's' : /* set seed as seed & SEED_MASK */
363
375
/*
@@ -381,6 +393,7 @@ main(int argc, char *argv[])
381
393
silence_prompt = true;
382
394
/* set -E boolean */
383
395
abort_on_warning = true;
396
+ force_yes = true;
384
397
}
385
398
break ;
386
399
case 'm' : /* set path to make(1) */
@@ -643,6 +656,7 @@ main(int argc, char *argv[])
643
656
}
644
657
input_stream = answersp ;
645
658
}
659
+
646
660
/*
647
661
* obtain the IOCCC contest ID
648
662
*/
@@ -1190,6 +1204,7 @@ scan_topdir(char *args, struct info *infop, char const *make, char const *submis
1190
1204
not_reached ();
1191
1205
}
1192
1206
1207
+
1193
1208
/*
1194
1209
* list of required files (prog.c, Makefile and remarks.md) (this will be
1195
1210
* shown to the user too)
@@ -1803,13 +1818,29 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
1803
1818
* files list is empty (though in theory if that did happen we should never
1804
1819
* get here).
1805
1820
*/
1806
-
1807
1821
/*
1808
- * free arrays IFF (if and only if) they are empty
1822
+ * If -Y is not used and -i answers is used we need to temporarily disable
1823
+ * the -y so that the user can verify different file sets (if something
1824
+ * changes for example). Normally we don't need to do this as it would
1825
+ * happen anyway but with -i answers it is disabled as it forces -y. If one
1826
+ * is SURE they are okay they can use -Y instead and they won't be bothered
1827
+ * even in this and the next function (check_submission_dir()).
1828
+ *
1829
+ * NOTE: we will undo these at the end of check_submission_dir().
1830
+ *
1831
+ * NOTE: we will always save the current status of the silence_prompt and
1832
+ * answer_yes booleans.
1809
1833
*/
1810
- free_paths_array (& infop -> required_files , true);
1811
- if (infop -> required_files == NULL ) {
1812
- err (4 , __func__ , "NULL required files list array" );/*ooo*/
1834
+ copying_topdir = true;
1835
+ saved_silence_prompt = silence_prompt ;
1836
+ saved_answer_yes = answer_yes ;
1837
+ if (!force_yes ) {
1838
+ answer_yes = false;
1839
+ silence_prompt = false;
1840
+ }
1841
+
1842
+ if (paths_in_array (infop -> required_files ) <= 0 ) {
1843
+ err (4 , __func__ , "required files list array is empty" );/*ooo*/
1813
1844
not_reached ();
1814
1845
}
1815
1846
/*
@@ -1933,7 +1964,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
1933
1964
}
1934
1965
print ("%s\n" , p );
1935
1966
}
1936
- if (!answer_yes && ! read_answers_flag_used ) {
1967
+ if (!answer_yes ) {
1937
1968
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
1938
1969
if (!yorn ) {
1939
1970
print ("we suggest you delete %s and try again\nwith the correct options used\n" ,
@@ -1981,7 +2012,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
1981
2012
}
1982
2013
print ("%s\n" , p );
1983
2014
}
1984
- if (!answer_yes && ! read_answers_flag_used ) {
2015
+ if (!answer_yes ) {
1985
2016
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
1986
2017
if (!yorn ) {
1987
2018
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -2022,7 +2053,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
2022
2053
}
2023
2054
print ("%s\n" , p );
2024
2055
}
2025
- if (!answer_yes && ! read_answers_flag_used ) {
2056
+ if (!answer_yes ) {
2026
2057
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
2027
2058
if (!yorn ) {
2028
2059
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -2072,7 +2103,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
2072
2103
}
2073
2104
print ("%s\n" , p );
2074
2105
}
2075
- if (!answer_yes && ! read_answers_flag_used ) {
2106
+ if (!answer_yes ) {
2076
2107
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
2077
2108
if (!yorn ) {
2078
2109
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -2112,7 +2143,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
2112
2143
}
2113
2144
print ("%s\n" , p );
2114
2145
}
2115
- if (!answer_yes && ! read_answers_flag_used ) {
2146
+ if (!answer_yes ) {
2116
2147
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
2117
2148
if (!yorn ) {
2118
2149
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -2149,7 +2180,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
2149
2180
}
2150
2181
print ("%s\n" , p );
2151
2182
}
2152
- if (!answer_yes && ! read_answers_flag_used ) {
2183
+ if (!answer_yes ) {
2153
2184
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
2154
2185
if (!yorn ) {
2155
2186
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -2183,7 +2214,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
2183
2214
}
2184
2215
print ("%s\n" , p );
2185
2216
}
2186
- if (!answer_yes && ! read_answers_flag_used ) {
2217
+ if (!answer_yes ) {
2187
2218
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
2188
2219
if (!yorn ) {
2189
2220
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -2243,7 +2274,7 @@ copy_topdir(struct info *infop, char const *make, char const *submission_dir, ch
2243
2274
print ("%s\n" , p );
2244
2275
}
2245
2276
}
2246
- if (!answer_yes && ! read_answers_flag_used ) {
2277
+ if (!answer_yes ) {
2247
2278
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
2248
2279
if (!yorn ) {
2249
2280
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -3362,7 +3393,7 @@ check_submission_dir(struct info *infop, char *submit_path, char *topdir_path,
3362
3393
print ("%s\n" , p );
3363
3394
}
3364
3395
3365
- if (!answer_yes && ! read_answers_flag_used ) {
3396
+ if (!answer_yes ) {
3366
3397
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
3367
3398
if (!yorn ) {
3368
3399
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -3421,7 +3452,7 @@ check_submission_dir(struct info *infop, char *submit_path, char *topdir_path,
3421
3452
}
3422
3453
}
3423
3454
}
3424
- if (!answer_yes && ! read_answers_flag_used ) {
3455
+ if (!answer_yes ) {
3425
3456
yorn = yes_or_no ("\nIs this OK? [Yn]" , true);
3426
3457
if (!yorn ) {
3427
3458
print ("we suggest you fix your %s directory,\ndelete %s and try again\n" ,
@@ -3484,6 +3515,12 @@ check_submission_dir(struct info *infop, char *submit_path, char *topdir_path,
3484
3515
errp (114 , __func__ , "failed to close(cwd)" );
3485
3516
not_reached ();
3486
3517
}
3518
+ /*
3519
+ * undo special checks for -i answers
3520
+ */
3521
+ copying_topdir = false;
3522
+ silence_prompt = saved_silence_prompt ;
3523
+ answer_yes = saved_answer_yes ;
3487
3524
}
3488
3525
3489
3526
/*
@@ -3986,6 +4023,7 @@ prompt(char const *str, size_t *lenp)
3986
4023
int ret ; /* libc function return value */
3987
4024
size_t len ; /* length of input */
3988
4025
char * buf ; /* allocated input string */
4026
+ FILE * stream = NULL ; /* input_stream or stdin depending on options used */
3989
4027
3990
4028
/*
3991
4029
* firewall
@@ -3997,6 +4035,13 @@ prompt(char const *str, size_t *lenp)
3997
4035
not_reached ();
3998
4036
}
3999
4037
4038
+ if (copying_topdir ) {
4039
+ stream = stdin ;
4040
+ } else {
4041
+ stream = input_stream ;
4042
+ }
4043
+
4044
+
4000
4045
/*
4001
4046
* prompt + :<space> if silence_prompt is false
4002
4047
*/
@@ -4051,7 +4096,7 @@ prompt(char const *str, size_t *lenp)
4051
4096
/*
4052
4097
* read user input - return input length
4053
4098
*/
4054
- buf = readline_dup (& linep , true, & len , input_stream );
4099
+ buf = readline_dup (& linep , true, & len , stream );
4055
4100
if (buf == NULL ) {
4056
4101
err (148 , __func__ , "EOF while reading prompt input" );
4057
4102
not_reached ();
@@ -5970,7 +6015,7 @@ get_abstract(struct info *infop)
5970
6015
* true ==> input is yes in some form,
5971
6016
* false ==> input is not yes or there was a read error.
5972
6017
*
5973
- * NOTE: The -y (answer_yes) as no impact on this function as
6018
+ * NOTE: The -y (answer_yes) has no impact on this function as
5974
6019
* the yes or no input will be read regardless.
5975
6020
*/
5976
6021
static bool
@@ -5980,12 +6025,18 @@ noprompt_yes_or_no(void)
5980
6025
size_t len ; /* length of input */
5981
6026
char * response ; /* yes or no response */
5982
6027
char * p ;
6028
+ FILE * stream = NULL ; /* we need this so we can prompt users with -i answers */
5983
6029
6030
+ if (read_answers_flag_used && !answer_yes ) {
6031
+ stream = stdin ;
6032
+ } else {
6033
+ stream = input_stream ;
6034
+ }
5984
6035
/*
5985
6036
* read user input - return input length
5986
6037
*/
5987
6038
errno = 0 ; /* pre-clear errno for warnp() */
5988
- response = readline_dup (& linep , true, & len , input_stream );
6039
+ response = readline_dup (& linep , true, & len , stream );
5989
6040
if (response == NULL ) {
5990
6041
5991
6042
/*
@@ -7402,16 +7453,14 @@ verify_submission_dir(char const *submission_dir, char const *ls)
7402
7453
ls_stream = NULL ;
7403
7454
7404
7455
/*
7405
- * if either -d or -s seed are used, temporarily turn on prompting
7456
+ * we make sure that unless -Y is used the user always has a chance to look
7457
+ * at the final directory output
7406
7458
*/
7407
- if (seed_used ) {
7408
- silence_prompt = false;
7409
-
7410
- /*
7411
- * however, if -i input_recorded_answers is used, force prompting
7412
- */
7413
- } else if (read_answers_flag_used ) {
7414
- silence_prompt = false;
7459
+ saved_silence_prompt = silence_prompt ;
7460
+ saved_answer_yes = answer_yes ;
7461
+ if (!force_yes ) {
7462
+ answer_yes = false;
7463
+ silence_prompt = false;
7415
7464
}
7416
7465
7417
7466
/*
@@ -7430,23 +7479,13 @@ verify_submission_dir(char const *submission_dir, char const *ls)
7430
7479
"not the topdir where your submission files are) and then rerun this tool" ,
7431
7480
"again." ,
7432
7481
NULL );
7433
- err (14 , __func__ , "user rejected listing of submission directory: %s" , submission_dir );
7482
+ err (5 , __func__ , "user rejected listing of submission directory: %s" , submission_dir );/*ooo*/
7434
7483
not_reached ();
7435
7484
}
7436
7485
}
7437
7486
7438
- /*
7439
- * if either -d or -s seed are used, silence prompting again
7440
- */
7441
- if (seed_used ) {
7442
- silence_prompt = true;
7443
-
7444
- /*
7445
- * and of input_recorded_answers was used, silence prompting and turn back on -y
7446
- */
7447
- } else if (read_answers_flag_used ) {
7448
- silence_prompt = true;
7449
- }
7487
+ silence_prompt = saved_silence_prompt ;
7488
+ answer_yes = saved_answer_yes ;
7450
7489
7451
7490
/*
7452
7491
* free storage
0 commit comments