aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--snag/.gitignore5
-rwxr-xr-xsnag/configure (renamed from snag/gen.sh)6
-rw-r--r--snag/makefile22
-rwxr-xr-xsnag/scripts/get_pkg_attrs.sh (renamed from snag/get_pkg_attrs.sh)0
-rwxr-xr-xsnag/scripts/run_pkg_install.sh (renamed from snag/run_pkg_install.sh)0
-rw-r--r--snag/src/libargs/args.c (renamed from snag/libargs/args.c)0
-rw-r--r--snag/src/libargs/args.h (renamed from snag/libargs/args.h)0
-rw-r--r--snag/src/libargs/license.txt (renamed from snag/libargs/license.txt)0
-rw-r--r--snag/src/libargs/readme.txt (renamed from snag/libargs/readme.txt)0
-rw-r--r--snag/src/main.c (renamed from snag/main.c)0
-rw-r--r--snag/src/pkg_db.c (renamed from snag/pkg_db.c)16
-rw-r--r--snag/src/pkg_db.h (renamed from snag/pkg_db.h)0
-rw-r--r--snag/src/util.c (renamed from snag/util.c)29
-rw-r--r--snag/src/util.h (renamed from snag/util.h)18
-rw-r--r--todo.txt2
15 files changed, 44 insertions, 54 deletions
diff --git a/snag/.gitignore b/snag/.gitignore
index 9a9d059..ca60f7e 100644
--- a/snag/.gitignore
+++ b/snag/.gitignore
@@ -1,6 +1,7 @@
+/objs/
+/build/
*.o
snag
compile_flags.txt
TAGS
-build.ninja
-objs/ \ No newline at end of file
+build.ninja \ No newline at end of file
diff --git a/snag/gen.sh b/snag/configure
index 3e420f1..9b73f97 100755
--- a/snag/gen.sh
+++ b/snag/configure
@@ -2,7 +2,7 @@
bin="snag"
libs=""
-builddir="objs"
+builddir="build"
PREFIX="/usr"
while [ "$1" ]; do
@@ -17,9 +17,7 @@ CFLAGS=${CFLAGS:-""}
CFLAGS_RELEASE="$CFLAGS -O2"
CFLAGS_DEBUG="$CFLAGS -Wall -g -DDEBUG=1"
-write() {
- echo "$@" >> build.ninja
-}
+write() { echo "$@" >> build.ninja; }
echo "$CFLAGS_DEBUG $(pkg-config --cflags $libs 2>/dev/null)" | tr ' ' '\n' > compile_flags.txt
rm -f build.ninja
diff --git a/snag/makefile b/snag/makefile
deleted file mode 100644
index 8770725..0000000
--- a/snag/makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-CC = gcc
-CFLAGS = -Wall -g
-
-TARGET = snag
-
-SRCS = main.c pkg_db.c util.c libargs/args.c
-OBJS = $(SRCS:.c=.o)
-
-.SILENT: $(OBJS) $(TARGET)
-
-all: $(TARGET)
-
-clean:
- rm -f $(OBJS) $(TARGET)
-
-$(TARGET): $(OBJS)
- printf " LD %s\n" $@
- $(CC) $(CFLAGS) -o $@ $^
-
-%.o: %.c
- printf " CC %s\n" $<
- $(CC) $(CFLAGS) -c $< -o $@
diff --git a/snag/get_pkg_attrs.sh b/snag/scripts/get_pkg_attrs.sh
index 25f9177..25f9177 100755
--- a/snag/get_pkg_attrs.sh
+++ b/snag/scripts/get_pkg_attrs.sh
diff --git a/snag/run_pkg_install.sh b/snag/scripts/run_pkg_install.sh
index d48d831..d48d831 100755
--- a/snag/run_pkg_install.sh
+++ b/snag/scripts/run_pkg_install.sh
diff --git a/snag/libargs/args.c b/snag/src/libargs/args.c
index b004525..b004525 100644
--- a/snag/libargs/args.c
+++ b/snag/src/libargs/args.c
diff --git a/snag/libargs/args.h b/snag/src/libargs/args.h
index ea91142..ea91142 100644
--- a/snag/libargs/args.h
+++ b/snag/src/libargs/args.h
diff --git a/snag/libargs/license.txt b/snag/src/libargs/license.txt
index d5710a2..d5710a2 100644
--- a/snag/libargs/license.txt
+++ b/snag/src/libargs/license.txt
diff --git a/snag/libargs/readme.txt b/snag/src/libargs/readme.txt
index d725590..d725590 100644
--- a/snag/libargs/readme.txt
+++ b/snag/src/libargs/readme.txt
diff --git a/snag/main.c b/snag/src/main.c
index 0429fda..0429fda 100644
--- a/snag/main.c
+++ b/snag/src/main.c
diff --git a/snag/pkg_db.c b/snag/src/pkg_db.c
index 2bfa686..c35e47b 100644
--- a/snag/pkg_db.c
+++ b/snag/src/pkg_db.c
@@ -8,8 +8,8 @@
#include <errno.h>
#include <sys/wait.h>
-#define PKG_INFO_CMD "./get_pkg_attrs.sh"
-#define PKG_INST_CMD "./run_pkg_install.sh"
+#define PKG_INFO_CMD "./scripts/get_pkg_attrs.sh"
+#define PKG_INST_CMD "./scripts/run_pkg_install.sh"
// note: fixed location of package database for now
const char pkg_db[] = "../packages";
@@ -30,7 +30,7 @@ bool load_package_info(char* pkgid, package_info_t* info) {
memcpy(pkg_dir + pkg_db_len + 1, pkgid, pkgid_len);
pkg_dir[pkg_dir_len] = '\0';
if (access(pkg_dir, F_OK) != 0) {
- log("Package '%s' not found\n", pkgid);
+ print("Package '%s' not found\n", pkgid);
free(pkg_dir);
return false;
}
@@ -48,7 +48,7 @@ bool load_package_info(char* pkgid, package_info_t* info) {
info->script_path[script_path_len] = '\0';
free(pkg_dir);
if (access(info->script_path, F_OK) != 0) {
- log("Package '%s' broken, doesn't have description script\n", pkgid);
+ print("Package '%s' broken, doesn't have description script\n", pkgid);
free(info->script_path);
return false;
}
@@ -71,7 +71,7 @@ bool load_package_info(char* pkgid, package_info_t* info) {
char* envp[] = { NULL };
execve(PKG_INFO_CMD, argv, envp);
// what are you still doing here?
- die("execve failed");
+ die("CHILD - execve to %s failed: %s", PKG_INFO_CMD, strerror(errno));
} else {
// parent proc, close write end of pipe
close(pipefds[1]);
@@ -80,7 +80,7 @@ bool load_package_info(char* pkgid, package_info_t* info) {
// wait for child to finish
int wstatus;
if (waitpid(pid, &wstatus, 0) < 0) die("waitpid failed: %s", strerror(errno));
- if (WEXITSTATUS(wstatus) != 0) die("failed to execute get pkg attr script");
+ if (WEXITSTATUS(wstatus) != 0) die("the child failed to execute get_pkg_attr script");
// read all bytes from pipe into attr buffer
ssize_t bytes_read = read(pipefds[0], info->attrs.buffer, sizeof(info->attrs.buffer));
@@ -134,7 +134,7 @@ void run_package_install(const package_info_t* info) {
char* envp[] = { NULL };
execve(PKG_INST_CMD, argv, envp);
// what are you still doing here?
- die("execve failed");
+ die("CHILD - execve to %s failed: %s", PKG_INST_CMD, strerror(errno));
} else {
// parent proc, close write end of pipe
close(pipefds[1]);
@@ -153,5 +153,5 @@ void run_package_install(const package_info_t* info) {
// reap the child to finish
int wstatus;
if (waitpid(pid, &wstatus, 0) < 0) die("waitpid failed: %s", strerror(errno));
- if (WEXITSTATUS(wstatus) != 0) die("failed to execute install script");
+ if (WEXITSTATUS(wstatus) != 0) die("the child failed to execute install script");
}
diff --git a/snag/pkg_db.h b/snag/src/pkg_db.h
index 0d34a61..0d34a61 100644
--- a/snag/pkg_db.h
+++ b/snag/src/pkg_db.h
diff --git a/snag/util.c b/snag/src/util.c
index 9a962b0..8cc9b18 100644
--- a/snag/util.c
+++ b/snag/src/util.c
@@ -1,14 +1,15 @@
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "util.h"
-#if DEBUG
-void _log(int line, const char* file, const char* format, ...) {
- fprintf(stderr, "%s:%d: info: ", file, line);
+#if !DEBUG
+void log(const char* format, ...) {
#else
-void _log(const char* format, ...) {
+void _log(int line, const char* file, const char* format, ...) {
+ fprintf(stderr, "%s:%d: info: ", file, line);
#endif
va_list args;
va_start(args, format);
@@ -16,25 +17,33 @@ void _log(const char* format, ...) {
va_end(args);
}
-#if DEBUG
-void _die(int line, const char* file, const char* format, ...) {
- fprintf(stderr, "%s:%d: error: ", file, line);
+#if !DEBUG
+void die(const char* format, ...) {
#else
-void _die(const char* format, ...) {
+void _die(int line, const char* file, const char* format, ...) {
+ fprintf(stderr, "%s:%d: error: ", file, line);
#endif
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
+ fprintf(stderr, "\n");
exit(1);
}
-
+#if !DEBUG
void* emalloc(size_t size, char* alloc_reason) {
void* d = malloc(size);
- if (d == NULL) die("Failed to allocate %s", alloc_reason);
+ if (d == NULL) _die("failed to allocate '%s': %s", alloc_reason, strerror(errno));
return d;
}
+#else
+void* _emalloc(int line, const char* file, size_t size, char* alloc_reason) {
+ void* d = malloc(size);
+ if (d == NULL) _die(line, file, "failed to allocate '%s': %s", alloc_reason, strerror(errno));
+ return d;
+}
+#endif
char* vastrcat_(int dummy, ...) {
diff --git a/snag/util.h b/snag/src/util.h
index fbf9018..3813903 100644
--- a/snag/util.h
+++ b/snag/src/util.h
@@ -5,20 +5,24 @@
#include <stddef.h>
// utility for errors
-#if DEBUG
+#if !DEBUG
+ void log(const char* format, ...) __attribute__((format(printf, 1, 2)));
+ void die(const char* format, ...) __attribute__((format(printf, 1, 2)));
+ void* emalloc(size_t size, char* alloc_reason);
+#else
#define log(fmt, ...) _log(__LINE__, __FILE__, fmt, ##__VA_ARGS__)
void _log(int line, const char* file, const char* format, ...) __attribute__((format(printf, 3, 4)));
#define die(fmt, ...) _die(__LINE__, __FILE__, fmt, ##__VA_ARGS__)
void _die(int line, const char* file, const char* format, ...) __attribute__((format(printf, 3, 4)));
-#else
- #define log(fmt, ...) _log(fmt, ##__VA_ARGS__)
- void _log(const char* format, ...) __attribute__((format(printf, 1, 2)));
- #define die(fmt, ...) _die(fmt, ##__VA_ARGS__)
- void _die(const char* format, ...) __attribute__((format(printf, 1, 2)));
+ #define emalloc(size, alloc_reason) _emalloc(__LINE__, __FILE__, size, alloc_reason)
+ void* _emalloc(int line, const char* file, size_t size, char* alloc_reason);
#endif
-void* emalloc(size_t size, char* alloc_reason);
+
+// functions for outputting and displaying text
+#define printout(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
+#define print(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
// string functions
char* vastrcat_(int dummy, ...);
diff --git a/todo.txt b/todo.txt
index 54aac73..1d35394 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,7 +1,7 @@
SNAG
- [x] make install subcommand actually run the install script
- [x] multiple subcommand handling and proper argument parsing
-- [ ] add output and error functions for regular program output, make emalloc also have file info, also gen sh to configure
+- [x] add output and error functions for regular program output, make emalloc also have file info, also gen sh to configure
- [ ] download packages to download db and verify hash
- [ ] actually create install environment for packages in install script
- [ ] snag api