Overview
| Comment: | simplified command line validation |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
f66f7bf395d05e01977407137327154f |
| User & Date: | nnz on 2024-12-04 16:13:50.333 |
| Other Links: | manifest | tags |
Context
|
2024-12-04
| ||
| 18:21 | 201503 1st star check-in: 84c4349d5e user: nnz tags: trunk | |
| 16:13 | simplified command line validation check-in: f66f7bf395 user: nnz tags: trunk | |
| 15:15 | added to the ignore glob check-in: 9bfa42bf5d user: nnz tags: trunk | |
Changes
Modified aoc.c
from [fb51c0a099]
to [66f06825e4].
1 2 3 | #include <stdio.h> #include <stdlib.h> #include <string.h> | | < < < | < | < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocdailies.h" // prototypes for all aocYYYYdd functions!
#include "aocutils.h"
#define MAX_YEAR 2024
int main(int argc, char **argv) {
unsigned y = 0, d = 0;
char dataname[99];
if (argc >= 3) {
char *err;
y = strtoul(argv[1], &err, 10);
if (*err || (y < 2015) || (y > MAX_YEAR)) y = 0;
d = strtoul(argv[2], &err, 10);
if (*err || (d < 1) || (d > 25)) d = 0;
if (argc >= 4) {
sprintf(dataname, "%.98s", argv[3]);
} else {
sprintf(dataname, ".%04u%02u.txt", y, d);
}
}
if ((y == 0) || (d == 0)) {
fprintf(stderr, "syntax: %s yyyy dd [input-file]\n", argv[0]);
fprintf(stderr, " where 2015 <= yyyy <= %d\n", MAX_YEAR);
fprintf(stderr, " and 1 <= dd <= 25\n");
fprintf(stderr, "if no [input-file] is supplied loads the file .yyyydd.txt\n");
exit(EXIT_FAILURE);
}
// read data from dataname into input
char *input = NULL;
size_t ilen = slurp(&input, dataname);
// call the right function
aocfunc *p = aocselect(y, d);
if (p) p(input, ilen);
else fprintf(stderr, "Error: aoc%04u%02u() is missing.\n", y, d);
free(input);
}
|
Modified aoc2024.c
from [b9786e59e9]
to [4bb9424853].
1 2 3 4 5 6 | #include <ctype.h> #include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aocdailies.h"
#include "aocutils.h"
static size_t rcmap(unsigned size, unsigned row, unsigned col) {
return row * (size + 1) + col;
}
|
| ︙ | ︙ |