Skip to content

Commit a0f669d

Browse files
authored
Merge pull request #1230 from xexyl/uuids
Add -U UUID option - resolve #1229 Please NOTE: This commit, while recommended, is not mandatory for IOCCC28. Existing submissions under the previously released mkiocccentry toolkit remain valid.
2 parents a35c353 + 3b313e4 commit a0f669d

File tree

5 files changed

+141
-48
lines changed

5 files changed

+141
-48
lines changed

CHANGES.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# Major changes to the IOCCC entry toolkit
22

33

4+
## Release 2.4.5 2025-03-10
5+
6+
Add `-U UUID` option - resolve #1229.
7+
8+
Also fixed an error with `-u uuidfile` where it would not set the `test` boolean
9+
to true if the UUID was `"true"`.
10+
11+
The `-u uuidfile` and `-U UUID` options may not be used with `-i answers`, `-d`
12+
or `-s seed`.
13+
14+
Updated man page for the above changes.
15+
16+
**IMPORTANT NOTE**: you do NOT need to use this update in order to participate
17+
in the IOCCC28!
18+
19+
420
## Release 2.4.4 2025-03-09
521

622
Resolve some (mostly top priority) issues.

mkiocccentry.c

+97-43
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ static const char * const usage_msg3 =
142142
"\t-A answers\twrite answers file even if it already exists\n"
143143
"\t-i answers\tread answers from file previously written by -a|-A answers\n"
144144
"\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"
146146
"\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"
147151
"\t-s seed\t\tGenerate and use pseudo-random answers, seeding with\n"
148152
"\t\t\t seed & 0x%08u (def: do not)\n"
149153
"\t-d\t\tAlias for -s %u\n"
@@ -222,8 +226,8 @@ main(int argc, char *argv[])
222226
char *make = MAKE_PATH_0; /* path to make(1) executable */
223227
char *answers = NULL; /* path to the answers file (recording input given on stdin) */
224228
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 */
227231
char *submission_dir = NULL; /* submission directory from which to form a compressed tarball */
228232
char *tarball_path = NULL; /* path of the compressed tarball to form */
229233
struct info info; /* data to form .info.json */
@@ -234,7 +238,8 @@ main(int argc, char *argv[])
234238
bool ls_flag_used = false; /* true ==> -l /path/to/ls was given */
235239
bool make_flag_used = false; /* true ==> -m /path/to/make was given */
236240
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 */
238243
bool overwrite_answers_flag_used = false; /* true ==> don't prompt to overwrite answers if it already exists */
239244
bool txzchk_flag_used = false; /* true ==> -T /path/to/txzchk was given */
240245
bool fnamchk_flag_used = false; /* true ==> -F /path/to/fnamchk was given */
@@ -253,6 +258,7 @@ main(int argc, char *argv[])
253258
*/
254259
memset(&auth, 0, sizeof(auth));
255260

261+
256262
/*
257263
* even though these stat structs are in file scope, make sure they are
258264
* zeroed out
@@ -265,7 +271,7 @@ main(int argc, char *argv[])
265271
*/
266272
input_stream = stdin; /* default to reading from standard in */
267273
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) {
269275
switch (i) {
270276
case 'h': /* -h - print help to stderr and exit 2 */
271277
usage(2, program, ""); /*ooo*/
@@ -419,9 +425,13 @@ main(int argc, char *argv[])
419425
append_path(&info.ignore_paths, optarg, true, false, false);
420426
break;
421427
case 'u':
422-
uuid = optarg;
428+
uuidfile = optarg;
423429
read_uuid_flag_used = true;
424430
break;
431+
case 'U':
432+
uuidstr = optarg;
433+
uuid_flag_used = true;
434+
break;
425435
case ':': /* option requires an argument */
426436
case '?': /* illegal option */
427437
default: /* anything else but should not actually happen */
@@ -477,7 +487,23 @@ main(int argc, char *argv[])
477487
not_reached();
478488
}
479489
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*/
481507
not_reached();
482508
}
483509
if (ignore_warnings && abort_on_warning) {
@@ -725,26 +751,10 @@ main(int argc, char *argv[])
725751
input_stream = answersp;
726752
}
727753

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-
744754
/*
745755
* obtain the IOCCC contest ID
746756
*/
747-
info.ioccc_id = get_contest_id(&info.test_mode, uuidp);
757+
info.ioccc_id = get_contest_id(&info.test_mode, uuidfile, uuidstr);
748758
dbg(DBG_LOW, "Submission: IOCCC contest ID: %s", info.ioccc_id);
749759

750760
/*
@@ -1074,14 +1084,6 @@ main(int argc, char *argv[])
10741084
remarks_md = NULL;
10751085
}
10761086

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-
10851087
/*
10861088
* All Done!!! All Done!!! -- Jessica Noll, Age 2
10871089
*/
@@ -4323,7 +4325,9 @@ prompt(char const *str, size_t *lenp)
43234325
* *testp will be set to true, otherwise it will be set to false.
43244326
*
43254327
* 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)
43274331
*
43284332
* returns:
43294333
* allocated contest ID string
@@ -4332,13 +4336,14 @@ prompt(char const *str, size_t *lenp)
43324336
* This function does not return on error or if the contest ID is malformed.
43334337
*/
43344338
static char *
4335-
get_contest_id(bool *testp, FILE *uuidp)
4339+
get_contest_id(bool *testp, char const *uuidfile, char *uuidstr)
43364340
{
43374341
char *malloc_ret = NULL; /* allocated return string */
43384342
char *linep = NULL; /* when reading from file */
43394343
size_t len; /* input string length */
43404344
bool valid = false; /* true ==> IOCCC_contest_id is valid */
43414345
bool seen_answers_header = false;
4346+
FILE *uuidfp = NULL; /* if -u uuidfile */
43424347

43434348
/*
43444349
* firewall
@@ -4349,17 +4354,66 @@ get_contest_id(bool *testp, FILE *uuidp)
43494354
}
43504355

43514356
/*
4352-
* explain contest ID unless uuidp != NULL
4357+
* if -U UUID not used check if -u uuidfile was used
43534358
*/
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");
43594397
}
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+
}
43634417
}
43644418
/*
43654419
* if we get here then the user has to input their uuid manually

mkiocccentry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void mkiocccentry_sanity_chks(struct info *infop, char const *workdir, ch
181181
char const *ls, char const *txzchk, char const *fnamchk, char const *chkentry,
182182
char const *make);
183183
static char *prompt(char const *str, size_t *lenp);
184-
static char *get_contest_id(bool *testp, FILE *uuidp);
184+
static char *get_contest_id(bool *testp, char const *uuidf, char *uuidstr);
185185
static int get_submit_slot(struct info *infop);
186186
static char *mk_submission_dir(char const *workdir, char const *ioccc_id, int submit_slot,
187187
char **tarball_path, time_t tstamp, bool test_mode);

soup/man/man1/mkiocccentry.1

+26-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.\" "Share and Enjoy!"
1010
.\" -- Sirius Cybernetics Corporation Complaints Division, JSON spec department. :-)
1111
.\"
12-
.TH mkiocccentry 1 "08 March 2025" "mkiocccentry" "IOCCC tools"
12+
.TH mkiocccentry 1 "10 March 2025" "mkiocccentry" "IOCCC tools"
1313
.SH NAME
1414
.B mkiocccentry
1515
\- make an IOCCC compressed tarball for an IOCCC entry
@@ -297,11 +297,34 @@ This option implies
297297
and disables some messages as well.
298298
However you will still be prompted to verify files and directories are okay.
299299
.TP
300-
.BI \-u\ uuid
300+
.BI \-u\ uuidfile
301301
Read UUID from a text file.
302-
If this file cannot be read or does not have a valid UUID
302+
If this file cannot be read or does not have a valid UUID by itself,
303303
.BR mkiocccentry (1)
304304
will prompt you as usual.
305+
This option cannot be used with
306+
.BI \-U\ UUID
307+
or
308+
.BI \-s\ seed
309+
or
310+
.BI \-i\ answers
311+
or
312+
.BR \-d .
313+
.TP
314+
.BI \-U\ UUID
315+
Set UUID to
316+
.IR UUID .
317+
If this an invalid UUID
318+
.BR mkiocccentry (1)
319+
will prompt you as usual.
320+
This option cannot be used with
321+
.BI \-u\ uuidfile
322+
or
323+
.BI \-s\ seed
324+
or
325+
.BI \-i\ answers
326+
or
327+
.BR \-d .
305328
.TP
306329
.BI \-s\ seed
307330
Generate pseudo-random answers to the questions

soup/version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
*
8484
* NOTE: This should match the latest Release string in CHANGES.md
8585
*/
86-
#define MKIOCCCENTRY_REPO_VERSION "2.4.4 2025-03-09" /* special release format: major.minor[.patch] YYYY-MM-DD */
86+
#define MKIOCCCENTRY_REPO_VERSION "2.4.5 2025-03-10" /* special release format: major.minor[.patch] YYYY-MM-DD */
8787

8888

8989
/*

0 commit comments

Comments
 (0)