diff --git a/gj_common/Makefile b/gj_common/Makefile index c87b896e..b26bd85e 100644 --- a/gj_common/Makefile +++ b/gj_common/Makefile @@ -1,4 +1,4 @@ CC=clang -test: gitjournal.c test.c keygen.c - $(CC) -o test -g test.c gitjournal.c keygen.c -lgit2 -lssl -lcrypto +test: gitjournal.c test.c keygen.c common.c + $(CC) -o test -g test.c common.c gitjournal.c keygen.c -lgit2 -lssl -lcrypto diff --git a/gj_common/common.c b/gj_common/common.c new file mode 100644 index 00000000..a9e9dc9d --- /dev/null +++ b/gj_common/common.c @@ -0,0 +1,65 @@ +#include "gitjournal.h" + +#include +#include +#include +#include +#include + +void gj_log_internal(const char *format, ...) +{ + char buffer[1024]; + va_list args; + va_start(args, format); + vsprintf(buffer, format, args); + gj_log(buffer); + va_end(args); +} + +gj_error *gj_error_info(int err) +{ + if (err == 0) + return NULL; + + gj_error *error = (gj_error *)malloc(sizeof(gj_error)); + error->message_allocated = false; + if (err >= GJ_ERR_FIRST && err <= GJ_ERR_LAST) + { + switch (err) + { + case GJ_ERR_EMPTY_COMMIT: + error->code = err; + error->message = "Empty Commit"; + break; + + case GJ_ERR_PULL_INVALID_STATE: + error->code = err; + error->message = "GitPull Invalid State"; + break; + } + return error; + } + + const git_error *e = git_error_last(); + if (e) + { + error->code = e->klass; + error->message = (char *)malloc(strlen(e->message)); + strcpy(error->message, e->message); + error->message_allocated = true; + } + else + { + error->code = 1000; + error->message = "Unknown Message"; + } + + return error; +} + +void gj_error_free(const gj_error *err) +{ + if (err->message_allocated) + free(err->message); + free((void *)err); +} diff --git a/gj_common/gitjournal.c b/gj_common/gitjournal.c index c8353990..fc87aa92 100644 --- a/gj_common/gitjournal.c +++ b/gj_common/gitjournal.c @@ -1,78 +1,14 @@ #include "gitjournal.h" -#include -#include #include #include -#include +#include +#include #include -#define GJ_ERR_FIRST -954 -#define GJ_ERR_EMPTY_COMMIT -954 -#define GJ_ERR_PULL_INVALID_STATE -955 -#define GJ_ERR_LAST -955 - #define UNUSED(x) (void)(x) -void gj_log_internal(const char *format, ...) -{ - char buffer[1024]; - va_list args; - va_start(args, format); - vsprintf(buffer, format, args); - gj_log(buffer); - va_end(args); -} - -gj_error *gj_error_info(int err) -{ - if (err == 0) - return NULL; - - gj_error *error = (gj_error *)malloc(sizeof(gj_error)); - error->message_allocated = false; - if (err >= GJ_ERR_FIRST && err <= GJ_ERR_LAST) - { - switch (err) - { - case GJ_ERR_EMPTY_COMMIT: - error->code = err; - error->message = "Empty Commit"; - break; - - case GJ_ERR_PULL_INVALID_STATE: - error->code = err; - error->message = "GitPull Invalid State"; - break; - } - return error; - } - - const git_error *e = git_error_last(); - if (e) - { - error->code = e->klass; - error->message = (char *)malloc(strlen(e->message)); - strcpy(error->message, e->message); - error->message_allocated = true; - } - else - { - error->code = 1000; - error->message = "Unknown Message"; - } - - return error; -} - -void gj_error_free(const gj_error *err) -{ - if (err->message_allocated) - free(err->message); - free((void *)err); -} - int match_cb(const char *path, const char *spec, void *payload) { UNUSED(spec); diff --git a/gj_common/gitjournal.h b/gj_common/gitjournal.h index 940d2cc5..8b8e9216 100644 --- a/gj_common/gitjournal.h +++ b/gj_common/gitjournal.h @@ -33,7 +33,14 @@ void gj_error_free(const gj_error *err); // This must be implemented by you void gj_log(const char *message); +void gj_log_internal(const char *format, ...); + int gj_generate_ssh_keys(const char *private_key_path, const char *public_key_path, const char *comment); +#define GJ_ERR_FIRST -954 +#define GJ_ERR_EMPTY_COMMIT -954 +#define GJ_ERR_PULL_INVALID_STATE -955 +#define GJ_ERR_LAST -955 + #endif