all: ./devforge
-./devforge: ./main.o ./log.o ./config.o
+./devforge: ./main.o ./log.o ./config.o ./util.o
$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@ $^ $(LIBS) $(EXTRA_LIBS)
./main.o: ./main.c ./devforge.h
/* -------------------------------------------------------------------------- */
/* --- END LICENSE --- */
-void devforge_load_config(const char* path) {}
+#include "df_config.h"
+
+#include "df_log.h"
+#include "df_util.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int devforge_load_config(const char* path) {
+ char* str = devforge_strcat3("Loading the config `", path, "`");
+ devforge_log(DF_LOG, str);
+ free(str);
+
+ FILE* f = fopen(path, "r");
+ if(f != NULL) {
+ fclose(f);
+ } else {
+ devforge_log(DF_ERROR, strerror(errno));
+ return 1;
+ }
+
+ return 0;
+}
+
+int devforge_create_config(const char* path) {
+ char* str = devforge_strcat3("Creating the config `", path, "`");
+ devforge_log(DF_LOG, str);
+ free(str);
+
+ FILE* f = fopen(path, "w");
+ if(f != NULL) {
+ fclose(f);
+ devforge_log(DF_LOG, "Created the config");
+ } else {
+ devforge_log(DF_ERROR, strerror(errno));
+ return 1;
+ }
+
+ return 0;
+}
#ifndef __DEVFORGE_DF_CONFIG_H__
#define __DEVFORGE_DF_CONFIG_H__
-void devforge_load_config(const char* path);
+int devforge_load_config(const char* path);
+int devforge_create_config(const char* path);
#endif
--- /dev/null
+/* $Id$ */
+/* --- START LICENSE --- */
+/* -------------------------------------------------------------------------- */
+/* DevForge - Build Automation */
+/* -------------------------------------------------------------------------- */
+/* Copyright (c) 2024 Nishi. */
+/* Redistribution and use in source and binary forms, with or without modific */
+/* ation, are permitted provided that the following conditions are met: */
+/* 1. Redistributions of source code must retain the above copyright noti */
+/* ce, this list of conditions and the following disclaimer. */
+/* 2. Redistributions in binary form must reproduce the above copyright n */
+/* otice, this list of conditions and the following disclaimer in the documen */
+/* tation and/or other materials provided with the distribution. */
+/* 3. Neither the name of the copyright holder nor the names of its contr */
+/* ibutors may be used to endorse or promote products derived from this softw */
+/* are without specific prior written permission. */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS */
+/* " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TH */
+/* E IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPO */
+/* SE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS */
+/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CON */
+/* SEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITU */
+/* TE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPT */
+/* ION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S */
+/* TRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN AN */
+/* Y WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY */
+/* OF SUCH DAMAGE. */
+/* -------------------------------------------------------------------------- */
+/* --- END LICENSE --- */
+
+#ifndef __DEVFORGE_DF_UTIL_H__
+#define __DEVFORGE_DF_UTIL_H__
+
+char* devforge_strcat(const char* str1, const char* str2);
+char* devforge_strcat3(const char* str1, const char* str2, const char* str3);
+
+#endif
#include "df_config.h"
#include "df_log.h"
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
int i;
+ bool loaded_config = false;
devforge_log(DF_INFO, "DevForge " DEVFORGE_VERSION " Copyright (C) 2024 Nishi");
for(i = 1; i < argc; i++) {
if(argv[i][0] == '-') {
fprintf(stderr, "%s: %s: needs argument\n", argv[0], argv[i - 1]);
return 1;
} else {
- devforge_load_config(argv[i]);
+ int ret = devforge_load_config(argv[i]);
+ if(ret != 0) return ret;
+ loaded_config = true;
+ }
+ } else if(strcmp(argv[i], "--create") == 0) {
+ i++;
+ if(argv[i] == NULL) {
+ fprintf(stderr, "%s: %s: needs argument\n", argv[0], argv[i - 1]);
+ return 1;
+ } else {
+ return devforge_create_config(argv[i]);
}
} else {
fprintf(stderr, "%s: %s: unknown option\n", argv[0], argv[i]);
}
}
}
+ if(!loaded_config) {
+ int ret = devforge_load_config(PREFIX "/etc/devforge.conf");
+ if(ret != 0) return ret;
+ }
}
--- /dev/null
+/* $Id$ */
+/* --- START LICENESE --- */
+/* --- END LICENSE --- */
+
+#include "df_util.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+char* devforge_strcat(const char* str1, const char* str2) {
+ char* str = malloc(strlen(str1) + strlen(str2) + 1);
+ memcpy(str, str1, strlen(str1));
+ memcpy(str + strlen(str1), str2, strlen(str2));
+ str[strlen(str1) + strlen(str2)] = 0;
+ return str;
+}
+
+char* devforge_strcat3(const char* str1, const char* str2, const char* str3) {
+ char* tmp = devforge_strcat(str1, str2);
+ char* r = devforge_strcat(tmp, str3);
+ free(tmp);
+ return r;
+}
# $Id$
+PREFIX := /usr/local
+
CC := gcc
-CFLAGS := -g -std=c99
+CFLAGS := -g -std=c99 -DPREFIX=\\\"$(PREFIX)\\\"
LDFLAGS :=
LIBS :=