From 63b339b383294a032da86bc52bfb452fb494e62f Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 21 Jul 2022 15:13:00 +0200 Subject: only load current build fully --- src/config.c | 1 + src/config.h | 1 - src/parser.c | 41 ++++++++++++++++++++++++++--------------- src/parser.h | 5 +++++ 4 files changed, 32 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index 02ad9e3..4eb5621 100644 --- a/src/config.c +++ b/src/config.c @@ -57,6 +57,7 @@ void init_config() if (!strcmp(context.index, config.projects[i].builds[j].name)) { current_build = &config.projects[i].builds[j]; + load_full_build(current_project, current_build); break; } } diff --git a/src/config.h b/src/config.h index 49daf77..8cc27a0 100644 --- a/src/config.h +++ b/src/config.h @@ -43,7 +43,6 @@ extern struct build_t* current_build; void init_config(); void deinit_config(); -void parse_config(); char* cache_dir(); char* project_dir(char* project); diff --git a/src/parser.c b/src/parser.c index d8ad576..f13cbe5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -208,21 +208,6 @@ void parse_config() } build[build_size] = '\0'; - strcat(build, "/log"); - fd = fopen(build, "rb"); - if (fd) - { - fseek(fd, 0, SEEK_END); - size_t size = (size_t)ftell(fd); - rewind(fd); - - config.projects[i].builds[config.projects[i].build_count-1].log = malloc(size + 1); - fread(config.projects[i].builds[config.projects[i].build_count-1].log, sizeof(char), size, fd); - fclose(fd); - config.projects[i].builds[config.projects[i].build_count-1].log[size] = '\0'; - } - build[build_size] = '\0'; - free(build); } closedir(dir); @@ -252,6 +237,32 @@ void parse_config() free(buf); } +void load_full_build(struct project_t* project, struct build_t* build) +{ + if (!build) + return; + + char* path = build_dir(project->name, build->name); + size_t build_size = strlen(path); + path = realloc(path, (build_size + 11 + 1) * sizeof(char)); + FILE* fd; + + strcat(path, "/log"); + fd = fopen(path, "rb"); + if (fd) + { + fseek(fd, 0, SEEK_END); + size_t size = (size_t)ftell(fd); + rewind(fd); + + build->log = malloc(size + 1); + fread(build->log, sizeof(char), size, fd); + fclose(fd); + build->log[size] = '\0'; + } + path[build_size] = '\0'; +} + void parse_path(const char* path) { size_t path_len = strlen(path) + 1; diff --git a/src/parser.h b/src/parser.h index e5d5465..09e1710 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,6 +1,11 @@ #ifndef PARSER_H #define PARSER_H +#include "config.h" + +void parse_config(); +void load_full_build(struct project_t*, struct build_t*); + void argv_to_path(int, char**); void parse_path(const char*); void parse_query(const char*); -- cgit v1.2.3