base infra
This commit is contained in:
commit
3246535ae6
10 changed files with 1121 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.cache
|
||||||
|
build
|
||||||
|
day*_input.h
|
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch",
|
||||||
|
"program": "${workspaceFolder}/build/adventofcode/adventofcode",
|
||||||
|
"args": ["2024", "1", "1"],
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"preLaunchTask": "CMake: build",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
19
2024/CMakeLists.txt
Normal file
19
2024/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
add_library(2024 SHARED)
|
||||||
|
|
||||||
|
foreach(i RANGE 1 1)
|
||||||
|
set(out_path "${CMAKE_CURRENT_SOURCE_DIR}/src/include/day${i}_input.h")
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/include/day${i}_input.h"
|
||||||
|
COMMAND xxd -i input/day${i}.txt > src/include/day${i}_input.h
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
)
|
||||||
|
list(APPEND adv_input ${out_path})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_custom_target(prebuild_target DEPENDS ${adv_input})
|
||||||
|
|
||||||
|
add_dependencies(2024 prebuild_target)
|
||||||
|
target_sources(2024
|
||||||
|
PRIVATE
|
||||||
|
src/day1.c
|
||||||
|
)
|
1000
2024/input/day1.txt
Normal file
1000
2024/input/day1.txt
Normal file
File diff suppressed because it is too large
Load diff
3
2024/src/day1.c
Normal file
3
2024/src/day1.c
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
void *day_1_part_1() {
|
||||||
|
return "yes";
|
||||||
|
}
|
0
2024/src/include/day1.h
Normal file
0
2024/src/include/day1.h
Normal file
3
2024/src/include/days.h
Normal file
3
2024/src/include/days.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#include "day1.h"
|
||||||
|
|
||||||
|
char *day_1_part_1(void);
|
9
CMakeLists.txt
Normal file
9
CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
project(advent_of_code
|
||||||
|
DESCRIPTION "bad code for a good thing"
|
||||||
|
HOMEPAGE_URL https://adventofcode.com
|
||||||
|
LANGUAGES C #of course
|
||||||
|
)
|
||||||
|
|
||||||
|
add_subdirectory(adventofcode)
|
||||||
|
add_subdirectory(2024)
|
7
adventofcode/CMakeLists.txt
Normal file
7
adventofcode/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
add_executable(adventofcode)
|
||||||
|
|
||||||
|
target_sources(adventofcode
|
||||||
|
PRIVATE
|
||||||
|
src/main.c
|
||||||
|
)
|
||||||
|
target_link_libraries(adventofcode PRIVATE 2024)
|
63
adventofcode/src/main.c
Normal file
63
adventofcode/src/main.c
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
main.c
|
||||||
|
AdventOfCode
|
||||||
|
|
||||||
|
Author: thebread (contact@thebread.dev)
|
||||||
|
Date: 01.12.2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
int err = 0;
|
||||||
|
if(argc == 4) {
|
||||||
|
int year = strtoimax(argv[1], NULL, 10);
|
||||||
|
int day = strtoimax(argv[2], NULL, 10);
|
||||||
|
int part = strtoimax(argv[3], NULL, 10);
|
||||||
|
|
||||||
|
// TODO: clean this mess up
|
||||||
|
if (year != 2024 || (day < 1 || day > 25) || (part < 1 || part > 2)) {
|
||||||
|
err = 2;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Calling year %d day %d part %d\n", year, day, part);
|
||||||
|
|
||||||
|
char *template = "lib%d.so";
|
||||||
|
size_t len = snprintf(NULL, 0, template, year) +1;
|
||||||
|
char *libname = malloc(len);
|
||||||
|
snprintf(libname, len, template, year);
|
||||||
|
|
||||||
|
void *handle = dlopen(libname, RTLD_LAZY);
|
||||||
|
if(!handle) {
|
||||||
|
fprintf(stderr, "Year %s not implemented! (%s)\n", argv[1], libname);
|
||||||
|
err = 3;
|
||||||
|
} else {
|
||||||
|
char *template = "day_%d_part_%d";
|
||||||
|
size_t len = snprintf(NULL, 0, template, day, part) +1;
|
||||||
|
char *fname = malloc(len);
|
||||||
|
snprintf(fname, len, template, day, part);
|
||||||
|
|
||||||
|
char *(*part_func)(void) = dlsym(handle, fname);
|
||||||
|
|
||||||
|
if(part_func) {
|
||||||
|
fprintf(stderr, "day %s part %s: %s\n", argv[2], argv[3], part_func());
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Failed to call %s", fname);
|
||||||
|
err = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(fname);
|
||||||
|
dlclose(handle);
|
||||||
|
}
|
||||||
|
free(libname);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Usage: adventofcode <year> <day> <part>\n");
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue