Advent of Code

Diff
Login

Diff

Differences From Artifact [fb51c0a099]:

To Artifact [66f06825e4]:


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
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "aocutils.h"
#include "aocdailies.h" // prototypes for all aocYYYYdd functions!

#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 && *err) y = 0;
        if (y < 2015) y = 0;
        if (y > MAX_YEAR) y = 0;
        d = strtoul(argv[2], &err, 10);
        if (err && *err) d = 0;
        if (d < 1) d = 0;
        if (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, "Impossible!\n");
    free(input);
}



|

<









<
<
|

<
|
<




















|


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);
}