@@ -142,8 +142,12 @@ static const char * const usage_msg3 =
142
142
"\t-A answers\twrite answers file even if it already exists\n"
143
143
"\t-i answers\tread answers from file previously written by -a|-A answers\n"
144
144
"\t\t\t NOTE: One cannot use both -a/-A answers and -i answers.\n"
145
- "\t-u uuid\t \tread UUID from a file (def: prompt for UUID)\n"
145
+ "\t-u uuidfile \tread UUID from a file (def: prompt for UUID)\n"
146
146
"\t\t\t NOTE: if an invalid UUID is in the file, it will try the usual way\n"
147
+ "\t\t\t NOTE: this option may not be used with -U UUID, -d, -s seed or -i answers\n"
148
+ "\t-U UUID\t\tset UUID to UUID\n"
149
+ "\t\t\t NOTE: if an invalid UUID is in the file, it will try the usual way\n"
150
+ "\t\t\t NOTE: this option may not be used with -u uuidfile, -d, -s seed or -i answers\n"
147
151
"\t-s seed\t\tGenerate and use pseudo-random answers, seeding with\n"
148
152
"\t\t\t seed & 0x%08u (def: do not)\n"
149
153
"\t-d\t\tAlias for -s %u\n"
@@ -222,8 +226,8 @@ main(int argc, char *argv[])
222
226
char * make = MAKE_PATH_0 ; /* path to make(1) executable */
223
227
char * answers = NULL ; /* path to the answers file (recording input given on stdin) */
224
228
FILE * answersp = NULL ; /* file pointer to the answers file */
225
- char * uuid = NULL ; /* path to the UUID file */
226
- FILE * uuidp = NULL ; /* file pointer to the UUID file */
229
+ char * uuidfile = NULL ; /* path to the UUID file */
230
+ char * uuidstr = NULL ; /* -U UUID option or UUID environmental var */
227
231
char * submission_dir = NULL ; /* submission directory from which to form a compressed tarball */
228
232
char * tarball_path = NULL ; /* path of the compressed tarball to form */
229
233
struct info info ; /* data to form .info.json */
@@ -234,7 +238,8 @@ main(int argc, char *argv[])
234
238
bool ls_flag_used = false; /* true ==> -l /path/to/ls was given */
235
239
bool make_flag_used = false; /* true ==> -m /path/to/make was given */
236
240
bool answers_flag_used = false; /* true ==> -a write answers to answers file */
237
- bool read_uuid_flag_used = false; /* true ==> -u uuid used */
241
+ bool read_uuid_flag_used = false; /* true ==> -u uuidfile used */
242
+ bool uuid_flag_used = false; /* true ==> -U uuid used */
238
243
bool overwrite_answers_flag_used = false; /* true ==> don't prompt to overwrite answers if it already exists */
239
244
bool txzchk_flag_used = false; /* true ==> -T /path/to/txzchk was given */
240
245
bool fnamchk_flag_used = false; /* true ==> -F /path/to/fnamchk was given */
@@ -253,6 +258,7 @@ main(int argc, char *argv[])
253
258
*/
254
259
memset (& auth , 0 , sizeof (auth ));
255
260
261
+
256
262
/*
257
263
* even though these stat structs are in file scope, make sure they are
258
264
* zeroed out
@@ -265,7 +271,7 @@ main(int argc, char *argv[])
265
271
*/
266
272
input_stream = stdin ; /* default to reading from standard in */
267
273
program = argv [0 ];
268
- while ((i = getopt (argc , argv , ":hv:J:qVt:l:a:i:A:WT:ef:F:C:yYds:m:I:u:" )) != -1 ) {
274
+ while ((i = getopt (argc , argv , ":hv:J:qVt:l:a:i:A:WT:ef:F:C:yYds:m:I:u:U: " )) != -1 ) {
269
275
switch (i ) {
270
276
case 'h' : /* -h - print help to stderr and exit 2 */
271
277
usage (2 , program , "" ); /*ooo*/
@@ -419,9 +425,13 @@ main(int argc, char *argv[])
419
425
append_path (& info .ignore_paths , optarg , true, false, false);
420
426
break ;
421
427
case 'u' :
422
- uuid = optarg ;
428
+ uuidfile = optarg ;
423
429
read_uuid_flag_used = true;
424
430
break ;
431
+ case 'U' :
432
+ uuidstr = optarg ;
433
+ uuid_flag_used = true;
434
+ break ;
425
435
case ':' : /* option requires an argument */
426
436
case '?' : /* illegal option */
427
437
default : /* anything else but should not actually happen */
@@ -477,7 +487,23 @@ main(int argc, char *argv[])
477
487
not_reached ();
478
488
}
479
489
if (seed_used && read_uuid_flag_used ) {
480
- err (3 , __func__ , "-u uuid cannot be used with either -d or -s seed" );/*ooo*/
490
+ err (3 , __func__ , "-u uuidfile cannot be used with either -d or -s seed" );/*ooo*/
491
+ not_reached ();
492
+ }
493
+ if (seed_used && uuidstr != NULL ) {
494
+ err (3 , __func__ , "-U UUID cannot be used with -d or -s seed" );/*ooo*/
495
+ not_reached ();
496
+ }
497
+ if (read_uuid_flag_used && uuid_flag_used ) {
498
+ err (3 , __func__ , "-u uuidfile and -U UUID cannot be used together" );/*ooo*/
499
+ not_reached ();
500
+ }
501
+ if ((read_uuid_flag_used || uuid_flag_used ) && seed_used ) {
502
+ err (3 , __func__ , "-U UUID or -u uuidfile cannot be used with -d or -s seed" );/*ooo*/
503
+ not_reached ();
504
+ }
505
+ if ((read_uuid_flag_used || uuid_flag_used ) && read_answers_flag_used ) {
506
+ err (3 , __func__ , "-U UUID or -u uuidfile cannot be used with -i answers" );/*ooo*/
481
507
not_reached ();
482
508
}
483
509
if (ignore_warnings && abort_on_warning ) {
@@ -725,26 +751,10 @@ main(int argc, char *argv[])
725
751
input_stream = answersp ;
726
752
}
727
753
728
- /*
729
- * check if we should read input from UUID file
730
- */
731
- if (read_uuid_flag_used && uuid != NULL && strlen (uuid ) > 0 ) {
732
- if (!is_read (uuid )) {
733
- warn (__func__ , "cannot read UUID file, will prompt for UUID" );
734
- } else {
735
- errno = 0 ; /* pre-clear errno for errp() */
736
- uuidp = fopen (uuid , "r" );
737
- if (uuidp == NULL ) {
738
- warnp (__func__ , "cannot open UUID file, will prompt for UUID" );
739
- }
740
- }
741
- }
742
-
743
-
744
754
/*
745
755
* obtain the IOCCC contest ID
746
756
*/
747
- info .ioccc_id = get_contest_id (& info .test_mode , uuidp );
757
+ info .ioccc_id = get_contest_id (& info .test_mode , uuidfile , uuidstr );
748
758
dbg (DBG_LOW , "Submission: IOCCC contest ID: %s" , info .ioccc_id );
749
759
750
760
/*
@@ -1074,14 +1084,6 @@ main(int argc, char *argv[])
1074
1084
remarks_md = NULL ;
1075
1085
}
1076
1086
1077
- /*
1078
- * if uuid file is open, close it
1079
- */
1080
- if (uuidp != NULL && is_open_file_stream (uuidp )) {
1081
- fclose (uuidp );
1082
- uuidp = NULL ;
1083
- }
1084
-
1085
1087
/*
1086
1088
* All Done!!! All Done!!! -- Jessica Noll, Age 2
1087
1089
*/
@@ -4323,7 +4325,9 @@ prompt(char const *str, size_t *lenp)
4323
4325
* *testp will be set to true, otherwise it will be set to false.
4324
4326
*
4325
4327
* given:
4326
- * testp - pointer to boolean (in struct info) for test mode
4328
+ * testp - pointer to boolean (in struct info) for test mode
4329
+ * uuidfile - -u uuidfile option - path to file which if not NULL and is open can have a UUID
4330
+ * uuidstr - -U UUID option (only used if -u uuidfile not used or is invalid)
4327
4331
*
4328
4332
* returns:
4329
4333
* allocated contest ID string
@@ -4332,13 +4336,14 @@ prompt(char const *str, size_t *lenp)
4332
4336
* This function does not return on error or if the contest ID is malformed.
4333
4337
*/
4334
4338
static char *
4335
- get_contest_id (bool * testp , FILE * uuidp )
4339
+ get_contest_id (bool * testp , char const * uuidfile , char * uuidstr )
4336
4340
{
4337
4341
char * malloc_ret = NULL ; /* allocated return string */
4338
4342
char * linep = NULL ; /* when reading from file */
4339
4343
size_t len ; /* input string length */
4340
4344
bool valid = false; /* true ==> IOCCC_contest_id is valid */
4341
4345
bool seen_answers_header = false;
4346
+ FILE * uuidfp = NULL ; /* if -u uuidfile */
4342
4347
4343
4348
/*
4344
4349
* firewall
@@ -4349,17 +4354,66 @@ get_contest_id(bool *testp, FILE *uuidp)
4349
4354
}
4350
4355
4351
4356
/*
4352
- * explain contest ID unless uuidp != NULL
4357
+ * if -U UUID not used check if -u uuidfile was used
4353
4358
*/
4354
- if (uuidp != NULL && is_open_file_stream (uuidp )) {
4355
- malloc_ret = readline_dup (& linep , true, NULL , uuidp );
4356
- if (malloc_ret != NULL ) {
4357
- if (valid_contest_id (malloc_ret )) {
4358
- return malloc_ret ;
4359
+ if (uuidstr == NULL ) {
4360
+ if (uuidfile != NULL ) {
4361
+ if (is_read (uuidfile )) {
4362
+ errno = 0 ; /* pre-clear errno for warnp() */
4363
+ uuidfp = fopen (uuidfile , "r" );
4364
+ if (uuidfp == NULL ) {
4365
+ warnp (__func__ , "failed to open uuidfile, will prompt instead" );
4366
+ } else {
4367
+ uuidstr = readline_dup (& linep , true, NULL , uuidfp );
4368
+ errno = 0 ; /* pre-clear errno for warnp() */
4369
+ if (fclose (uuidfp ) != 0 ) {
4370
+ warnp (__func__ , "failed to fclose(uuidfp)" );
4371
+ }
4372
+ if (uuidstr != NULL ) {
4373
+ if (valid_contest_id (uuidstr )) {
4374
+ if (strcmp (uuidstr , "test" ) == 0 ) {
4375
+
4376
+ /*
4377
+ * report test mode
4378
+ */
4379
+ para ("" ,
4380
+ "IOCCC contest ID is test, entering test mode." ,
4381
+ NULL );
4382
+ * testp = true;
4383
+ } else {
4384
+ * testp = false;
4385
+ }
4386
+ return uuidstr ;
4387
+ }
4388
+ free (uuidstr );
4389
+ uuidstr = NULL ;
4390
+ /*
4391
+ * we will have to prompt the user instead
4392
+ */
4393
+ }
4394
+ }
4395
+ } else {
4396
+ warn (__func__ , "-u uuidfile not readable, will prompt instead" );
4359
4397
}
4360
- free (malloc_ret );
4361
- malloc_ret = NULL ;
4362
- }
4398
+ }
4399
+ } else if (valid_contest_id (uuidstr )) {
4400
+ /*
4401
+ * case: IOCCC contest ID is test, quick return
4402
+ */
4403
+ if (strcmp (uuidstr , "test" ) == 0 ) {
4404
+
4405
+ /*
4406
+ * report test mode
4407
+ */
4408
+ para ("" ,
4409
+ "IOCCC contest ID is test, entering test mode." ,
4410
+ NULL );
4411
+ * testp = true;
4412
+ return uuidstr ;
4413
+ } else {
4414
+ * testp = false;
4415
+ return uuidstr ;
4416
+ }
4363
4417
}
4364
4418
/*
4365
4419
* if we get here then the user has to input their uuid manually
0 commit comments