Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwpl.git;a=commitdiff;h=7ffef2693547b095878cea777008d4fc921513f1
commit 7ffef2693547b095878cea777008d4fc921513f1 Author: James Buren <r...@frugalware.org> Date: Sun Sep 20 16:04:07 2009 -0500 src * create clean slate diff --git a/src/graphics.c b/src/graphics.c deleted file mode 100644 index b971f85..0000000 --- a/src/graphics.c +++ /dev/null @@ -1,66 +0,0 @@ -#include <gd.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <iso646.h> -#include <assert.h> -#include "utility.h" -#include "graphics.h" - -#define PNG_REG_EXP ".[pP][nN][gG]$" -#define JPG_REG_EXP ".[jJ][pP][eE]?[gG]$" - -Image image_create(int width,int height) { - gdImagePtr image; - - assert(width > 0 and height > 0); - - image = gdImageCreateTrueColor(width,height); - - if(!image) { - eprintf("Failed to allocate memory for image buffer.\n"); - abort(); - } - - return image; -} - -void image_destroy(Image image) { - assert(image); - - gdImageDestroy(image); -} - -Image image_load(const char *path) { - gdImagePtr image; - FILE *file; - - assert(path); - - file = fopen(path,"rb"); - - if(!file) { - eprintf("%s: %s\n",strerror(errno),path); - return NULL; - } - - if(regmatch(path,PNG_REG_EXP)) - image = gdImageCreateFromPng(file); - else if(regmatch(path,JPG_REG_EXP)) - image = gdImageCreateFromJpeg(file); - else { - eprintf("Unrecognized image format: %s\n",path); - fclose(file); - return NULL; - } - - if(!image) { - eprintf("Failed to load image: %s\n",path); - fclose(file); - return NULL; - } - - fclose(file); - - return image; -} diff --git a/src/graphics.h b/src/graphics.h deleted file mode 100644 index b75beb9..0000000 --- a/src/graphics.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _graphics_header_ -#define _graphics_header_ -typedef void * Image; - -extern Image image_create(int,int); -extern void image_destroy(Image); -extern Image image_load(const char *); -#endif diff --git a/src/utility.c b/src/utility.c deleted file mode 100644 index 638965e..0000000 --- a/src/utility.c +++ /dev/null @@ -1,132 +0,0 @@ -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <stdarg.h> -#include <regex.h> -#include <iso646.h> -#include <assert.h> -#include "utility.h" - -void *xmalloc(size_t size) { - void *ptr; - - assert(size); - - ptr = malloc(size); - - if(!ptr) { - eprintf("Memory allocation failure of %u bytes.\n",size); - abort(); - } - - return ptr; -} - -void *xrealloc(void *ptr,size_t size) { - assert(ptr and size); - - ptr = realloc(ptr,size); - - if(!ptr) { - eprintf("Memory reallocation failure of %u bytes.\n",size); - abort(); - } - - return ptr; -} - -char *xstrdup(const char *str1) { - char *str; - size_t size; - - assert(str1); - - size = (strlen(str1) + 1) * sizeof(*str); - - str = xmalloc(size); - - strcpy(str,str1); - - return str; -} - -char *xstrndup(const char *str1,size_t num) { - char *str; - size_t size; - - assert(str1 and num); - - size = strlen(str1); - - if(size > num) - size = num; - - size = (size + 1) * sizeof(*str); - - str = xmalloc(size); - - memcpy(str,str1,size); - - --size; - - if(str[size]) - str[size] = '\0'; - - return str; -} - -char *xstrcmb(const char *str1,const char *str2) { - char *str; - size_t size; - - assert(str1 and str2); - - size = (strlen(str1) + strlen(str2) + 1) * sizeof(*str); - - str = xmalloc(size); - - strcpy(stpcpy(str,str1),str2); - - return str; -} - -bool regmatch(const char *str,const char *pat) { - regex_t regex; - int flags; - bool ret; - - assert(str and pat); - - flags = REG_EXTENDED | REG_NOSUB; - - ret = true; - - if(regcomp(®ex,pat,flags)) { - ret = false; - goto Bail; - } - - if(regexec(®ex,str,0,NULL,0)) - ret = false; - - regfree(®ex); - - Bail: - - return ret; -} - -int eprintf(const char *fmt,...) { - va_list args; - int ret; - - assert(fmt); - - va_start(args,fmt); - - ret = vfprintf(stderr,fmt,args); - - va_end(args); - - return ret; -} diff --git a/src/utility.h b/src/utility.h deleted file mode 100644 index bbef739..0000000 --- a/src/utility.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _utility_header_ -#define _utility_header_ -#include <stddef.h> -#include <stdbool.h> - -extern void *xmalloc(size_t); -extern void *xrealloc(void *,size_t); -extern char *xstrdup(const char *); -extern char *xstrndup(const char *,size_t); -extern char *xstrcmb(const char *,const char *); -extern bool regmatch(const char *,const char *); -extern int eprintf(const char *,...); -#endif _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git