diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/feh.h | 1 | ||||
-rw-r--r-- | src/gib_hash.c | 7 | ||||
-rw-r--r-- | src/gib_imlib.c | 41 | ||||
-rw-r--r-- | src/gib_list.c | 60 | ||||
-rw-r--r-- | src/gib_style.c | 7 | ||||
-rw-r--r-- | src/gib_utils.c | 121 | ||||
-rw-r--r-- | src/gib_utils.h | 53 | ||||
-rw-r--r-- | src/utils.h | 7 |
8 files changed, 41 insertions, 256 deletions
@@ -61,7 +61,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "gib_imlib.h" #include "gib_list.h" #include "gib_style.h" -#include "gib_utils.h" #include "structs.h" #include "menu.h" diff --git a/src/gib_hash.c b/src/gib_hash.c index 054161d..a378b9c 100644 --- a/src/gib_hash.c +++ b/src/gib_hash.c @@ -24,11 +24,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "gib_hash.h" -#include "gib_utils.h" +#include "utils.h" +#include "debug.h" gib_hash_node *gib_hash_node_new(char *key, void *data) { - gib_hash_node *node = malloc(sizeof(gib_hash_node)); + gib_hash_node *node = emalloc(sizeof(gib_hash_node)); node->key = strdup(key); GIB_LIST(node)->data = data; GIB_LIST(node)->next = NULL; @@ -53,7 +54,7 @@ void gib_hash_node_free_and_data(gib_hash_node *node) gib_hash *gib_hash_new() { - gib_hash *hash = malloc(sizeof(gib_hash)); + gib_hash *hash = emalloc(sizeof(gib_hash)); hash->base = gib_hash_node_new("__gib_hash_new",NULL); return hash; } diff --git a/src/gib_imlib.c b/src/gib_imlib.c index 5c9d9ef..b53b1cc 100644 --- a/src/gib_imlib.c +++ b/src/gib_imlib.c @@ -24,7 +24,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "gib_imlib.h" -#include "gib_utils.h" +#include "utils.h" +#include "debug.h" int gib_imlib_load_image(Imlib_Image * im, char *filename) @@ -41,47 +42,47 @@ gib_imlib_load_image(Imlib_Image * im, char *filename) switch (err) { case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: - gib_weprintf("%s - File does not exist", filename); + weprintf("%s - File does not exist", filename); break; case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: - gib_weprintf("%s - Directory specified for image filename", filename); + weprintf("%s - Directory specified for image filename", filename); break; case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: - gib_weprintf("%s - No read access to directory", filename); + weprintf("%s - No read access to directory", filename); break; case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: - gib_weprintf("%s - No Imlib2 loader for that file format", filename); + weprintf("%s - No Imlib2 loader for that file format", filename); break; case IMLIB_LOAD_ERROR_PATH_TOO_LONG: - gib_weprintf("%s - Path specified is too long", filename); + weprintf("%s - Path specified is too long", filename); break; case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: - gib_weprintf("%s - Path component does not exist", filename); + weprintf("%s - Path component does not exist", filename); break; case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: - gib_weprintf("%s - Path component is not a directory", filename); + weprintf("%s - Path component is not a directory", filename); break; case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: - gib_weprintf("%s - Path points outside address space", filename); + weprintf("%s - Path points outside address space", filename); break; case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: - gib_weprintf("%s - Too many levels of symbolic links", filename); + weprintf("%s - Too many levels of symbolic links", filename); break; case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: - gib_eprintf("While loading %s - Out of memory", filename); + eprintf("While loading %s - Out of memory", filename); break; case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS: - gib_eprintf("While loading %s - Out of file descriptors", filename); + eprintf("While loading %s - Out of file descriptors", filename); break; case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: - gib_weprintf("%s - Cannot write to directory", filename); + weprintf("%s - Cannot write to directory", filename); break; case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: - gib_weprintf("%s - Cannot write - out of disk space", filename); + weprintf("%s - Cannot write - out of disk space", filename); break; case IMLIB_LOAD_ERROR_UNKNOWN: default: - gib_weprintf + weprintf ("While loading %s - Unknown error. Attempting to continue", filename); break; @@ -628,7 +629,7 @@ void gib_imlib_parse_color(char *col, int *r, int *g, int *b, int *a) } else { - gib_weprintf("unable to parse color %s\n", col); + weprintf("unable to parse color %s\n", col); return; } } @@ -638,7 +639,7 @@ void gib_imlib_parse_color(char *col, int *r, int *g, int *b, int *a) ll = gib_string_split(col, ","); if (!ll) { - gib_weprintf("unable to parse color %s\n", col); + weprintf("unable to parse color %s\n", col); return; } len = gib_list_length(ll); @@ -658,7 +659,7 @@ void gib_imlib_parse_color(char *col, int *r, int *g, int *b, int *a) } else { - gib_weprintf("unable to parse color %s\n", col); + weprintf("unable to parse color %s\n", col); return; } } @@ -695,10 +696,10 @@ gib_imlib_load_font(char *name) if ((fn = imlib_load_font(name))) return fn; - gib_weprintf("couldn't load font %s, attempting to fall back to fixed.", name); + weprintf("couldn't load font %s, attempting to fall back to fixed.", name); if ((fn = imlib_load_font("fixed"))) return fn; - gib_weprintf("failed to even load fixed! Attempting to find any font."); + weprintf("failed to even load fixed! Attempting to find any font."); return imlib_load_font("*"); } diff --git a/src/gib_list.c b/src/gib_list.c index a05fb4c..281f528 100644 --- a/src/gib_list.c +++ b/src/gib_list.c @@ -25,14 +25,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <time.h> #include "gib_list.h" -#include "gib_utils.h" +#include "utils.h" +#include "debug.h" gib_list * gib_list_new(void) { gib_list *l; - l = (gib_list *) malloc(sizeof(gib_list)); + l = (gib_list *) emalloc(sizeof(gib_list)); l->data = NULL; l->next = NULL; l->prev = NULL; @@ -354,7 +355,7 @@ gib_list_randomize(gib_list * list) len = gib_list_length(list); if (len <= 1) return (list); - farray = (gib_list **) malloc(sizeof(gib_list *) * len); + farray = (gib_list **) emalloc(sizeof(gib_list *) * len); for (f = list, i = 0; f; f = f->next, i++) { farray[i] = f; @@ -556,7 +557,7 @@ gib_string_split(const char *string, const char *delimiter) char *new_string; len = s - string; - new_string = malloc(sizeof(char) * (len + 1)); + new_string = emalloc(sizeof(char) * (len + 1)); strncpy(new_string, string, len); new_string[len] = 0; @@ -577,54 +578,3 @@ gib_string_split(const char *string, const char *delimiter) return string_list; } - -#if 0 -char * -gib_strjoin(const char *separator, ...) -{ - char *string, *s; - va_list args; - int len; - int separator_len; - - if (separator == NULL) - separator = ""; - - separator_len = strlen(separator); - va_start(args, separator); - s = va_arg(args, char *); - - if (s) - { - len = strlen(s); - s = va_arg(args, char *); - - while (s) - { - len += separator_len + strlen(s); - s = va_arg(args, char *); - } - va_end(args); - string = malloc(sizeof(char) * (len + 1)); - - *string = 0; - va_start(args, separator); - s = va_arg(args, char *); - - strcat(string, s); - s = va_arg(args, char *); - - while (s) - { - strcat(string, separator); - strcat(string, s); - s = va_arg(args, char *); - } - } - else - string = strdup(""); - va_end(args); - - return string; -} -#endif diff --git a/src/gib_style.c b/src/gib_style.c index 6671e6e..9280217 100644 --- a/src/gib_style.c +++ b/src/gib_style.c @@ -24,14 +24,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "gib_style.h" -#include "gib_utils.h" +#include "utils.h" +#include "debug.h" gib_style * gib_style_new(char *name) { gib_style *s = NULL; - s = malloc(sizeof(gib_style)); + s = emalloc(sizeof(gib_style)); memset(s, 0, sizeof(gib_style)); if (name) @@ -69,7 +70,7 @@ gib_style_bit_new(int x_offset, int y_offset, int r, int g, int b, int a) { gib_style_bit *sb; - sb = malloc(sizeof(gib_style_bit)); + sb = emalloc(sizeof(gib_style_bit)); memset(sb, 0, sizeof(gib_style_bit)); sb->x_offset = x_offset; diff --git a/src/gib_utils.c b/src/gib_utils.c deleted file mode 100644 index e851b0d..0000000 --- a/src/gib_utils.c +++ /dev/null @@ -1,121 +0,0 @@ -/* gib_utils.c - -Copyright (C) 1999,2000 Tom Gilbert. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies of the Software and its documentation and acknowledgment shall be -given in the documentation and software packages that this Software was -used. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -*/ - -#include "gib_utils.h" - -/* eprintf: print error message and exit */ -void -gib_eprintf(char *fmt, ...) -{ - va_list args; - - fflush(stdout); - fprintf(stderr, "giblib error: "); - - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); - - if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':') - fprintf(stderr, "%s", strerror(errno)); - fprintf(stderr, "\n"); - exit(2); -} - -/* weprintf: print warning message and continue */ -void -gib_weprintf(char *fmt, ...) -{ - va_list args; - - fflush(stdout); - fprintf(stderr, "giblib warning: "); - - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); - - if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':') - fprintf(stderr, "%s", strerror(errno)); - fprintf(stderr, "\n"); -} - -/* estrdup: duplicate a string, report if error */ -char * -_strdup(char *s) -{ - char *t; - if(!s) - return NULL; - t = (char *) malloc(strlen(s) + 1); - if (t == NULL) - gib_eprintf("estrdup(\"%.20s\") failed:", s); - strcpy(t, s); - return t; -} - -/* emalloc: malloc and report if error */ -void * -_malloc(size_t n) -{ - void *p; - - p = malloc(n); - if (p == NULL) - gib_eprintf("malloc of %u bytes failed:", n); - return p; -} - -/* erealloc: realloc and report if error */ -void * -_realloc(void *ptr, size_t n) -{ - void *p; - - p = realloc(ptr, n); - if (p == NULL) - gib_eprintf("realloc of %p by %u bytes failed:", ptr, n); - return p; -} - -/* efree: just do the free for now */ -void -_free(void *p) -{ - free(p); -} - -char * -gib_stroflen(char c, int l) -{ - static char buf[1024]; - int i = 0; - - buf[0] = '\0'; - while (l--) - buf[i++] = c; - buf[i] = '\0'; - return buf; -} diff --git a/src/gib_utils.h b/src/gib_utils.h deleted file mode 100644 index 82ef878..0000000 --- a/src/gib_utils.h +++ /dev/null @@ -1,53 +0,0 @@ -/* gib_utils.h - -Copyright (C) 1999,2000 Tom Gilbert. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies of the Software and its documentation and acknowledgment shall be -given in the documentation and software packages that this Software was -used. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -*/ - -#ifndef GIB_UTILS_H -#define GIB_UTILS_H - -#include <stdio.h> -#include <stdarg.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> - -#ifdef __cplusplus -extern "C" -{ -#endif - -void gib_eprintf(char *fmt, ...); -void gib_weprintf(char *fmt, ...); -char *_strdup(char *s); -void *_malloc(size_t n); -void _free(void *p); -void *_realloc(void *ptr, size_t n); -char *gib_stroflen(char c, int l); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/utils.h b/src/utils.h index cd00a33..c0d243b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -26,6 +26,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef UTILS_H #define UTILS_H +#include <stdio.h> +#include <stdarg.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + #ifndef __GNUC__ # define __attribute__(x) #endif |