# HG changeset patch # User ali # Date 1327681082 0 # Node ID faab25d520dd1f771f1291e14da78f6c318de459 # Parent f600b0d1fc5dc428bfd7d0e747f034a40e30b949 Rely on glib being available everywhere diff -r f600b0d1fc5d -r faab25d520dd README --- a/README Fri Jan 27 10:30:16 2012 +0000 +++ b/README Fri Jan 27 16:18:02 2012 +0000 @@ -25,10 +25,6 @@ % sudo apt-get install gcc pkgconfig glib2-devel -If you get really stuck, you can use the --without-glib option to configure, -but this may well not be supported in a future version so this is probably -best avoided. - Microsoft Windows ----------------- diff -r f600b0d1fc5d -r faab25d520dd bl/Makefile.am --- a/bl/Makefile.am Fri Jan 27 10:30:16 2012 +0000 +++ b/bl/Makefile.am Fri Jan 27 16:18:02 2012 +0000 @@ -4,7 +4,3 @@ noinst_LTLIBRARIES=libbl.la libbl_la_SOURCES=bl.h textfileutils.c textfileutils.h spawn.c spawn.h -if !HAVE_GLIB -libbl_la_SOURCES+=macros.h types.h fileutils.c fileutils.h mem.c mem.h \ - strfuncs.c strfuncs.h blstring.c blstring.h utils.c utils.h -endif diff -r f600b0d1fc5d -r faab25d520dd bl/bl.h --- a/bl/bl.h Fri Jan 27 10:30:16 2012 +0000 +++ b/bl/bl.h Fri Jan 27 16:18:02 2012 +0000 @@ -1,36 +1,2 @@ -#if HAVE_GLIB - -#include -#define BL_DIR_SEPARATOR G_DIR_SEPARATOR -#define BL_DIR_SEPARATOR_S G_DIR_SEPARATOR_S -#define BL_IS_DIR_SEPARATOR(c) G_IS_DIR_SEPARATOR(c) -#define boolean gboolean -#define String GString -#define mem_new0 g_new0 -#define mem_free g_free -#define str_dup g_strdup -#define str_ndup g_strndup -#define path_get_basename g_path_get_basename -#define file_get_contents(filename,contents,length) \ - g_file_get_contents(filename,contents,length,NULL) -#define string_new g_string_new -#define string_append g_string_append -#define string_append_len g_string_append_len -#define string_append_c g_string_append_c -#define string_free g_string_free -#define string_set_size g_string_set_size - -#else /* !HAVE_GLIB */ - -#include -#include -#include -#include -#include -#include -#include - -#endif /* HAVE_GLIB */ - #include #include diff -r f600b0d1fc5d -r faab25d520dd bl/blstring.c --- a/bl/blstring.c Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* - * Strings which manage their own memory - */ - -String *string_new(const char *init) -{ - String *string=mem_new(String,1); - if (!init) - init=""; - string->len=strlen(init); - string->alloc=string->len+1; - string->str=str_dup(init); - return string; -} - -/* - * Free a string and either return the contents (if free_segment is FALSE) - * or free the contents as well and return NULL (if free_segment is TRUE). - */ -char *string_free(String *string,boolean free_segment) -{ - char *retval; - if (free_segment) - { - mem_free(string->str); - retval=NULL; - } - else - retval=string->str; - mem_free(string); - return retval; -} - -/* - * Append a byte to string. - */ -void string_append_c(String *string,char c) -{ - if (string->len+1==string->alloc) - { - string->alloc*=2; - string->str=mem_renew(char,string->str,string->alloc); - } - string->str[string->len++]=c; - string->str[string->len]='\0'; -} - -/* - * Append len bytes from s to string. len may be passed as <0 if s is - * a nul-terminated string of unknown length. - */ -void string_append_len(String *string,const char *s,ssize_t len) -{ - if (len<0) - len=strlen(s); - if (string->len+len>=string->alloc) - { - while (string->len+len>=string->alloc) - string->alloc*=2; - string->str=mem_renew(char,string->str,string->alloc); - } - memcpy(string->str+string->len,s,len); - string->len+=len; - string->str[string->len]='\0'; -} - -/* - * Sets the length of a String. If the length is less than the current length, - * the string will be truncated. If the length is greater than the current - * length, the contents of the newly added area are undefined. (However, as - * always, string->str[string->len] will be a nul byte.) - */ -void string_set_size(String *string,size_t len) -{ - if (len>=string->alloc) - { - while (len>=string->alloc) - string->alloc*=2; - string->str=mem_renew(char,string->str,string->alloc); - } - string->len=len; - string->str[string->len]='\0'; -} diff -r f600b0d1fc5d -r faab25d520dd bl/blstring.h --- a/bl/blstring.h Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#ifndef BL_STRING_H -#define BL_STRING_H - -#include -#include - -typedef struct { - char *str; - size_t alloc,len; -} String; - -String *string_new(const char *init); -char *string_free(String *string,boolean free_segment); -void string_append_c(String *string,char c); -void string_append_len(String *string,const char *s,ssize_t len); -#define string_append(string,s) string_append_len(string,s,-1) - -#endif /* BL_STRING_H */ diff -r f600b0d1fc5d -r faab25d520dd bl/fileutils.c --- a/bl/fileutils.c Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* - * Read a file into memory (which should be freed with mem_free when no - * longer required). Returns FALSE on error and outputs a suitable error - * message to stderr. - */ -boolean file_get_contents(const char *filename,char **contents,size_t *length) -{ - FILE *fp; - size_t n; - char *buffer; - String *string; - fp=fopen(filename,"rb"); - if (!fp) - { - perror(filename); - return FALSE; - } - buffer=mem_new(char,1024); - string=string_new(NULL); - do - { - n=fread(buffer,1,1024,fp); - if (n<0) - { - perror(filename); - string_free(string,TRUE); - mem_free(buffer); - free(fp); - return FALSE; - } - string_append_len(string,buffer,n); - } while(n); - mem_free(buffer); - if (length) - *length=string->len; - *contents=string_free(string,FALSE); - fclose(fp); - return TRUE; -} diff -r f600b0d1fc5d -r faab25d520dd bl/fileutils.h --- a/bl/fileutils.h Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#ifndef BL_FILEUTILS_H -#define BL_FILEUTILS_H - -#include - -boolean file_get_contents(const char *filename,char **contents,size_t *length); - -#endif /* BL_FILEUTILS_H */ diff -r f600b0d1fc5d -r faab25d520dd bl/macros.h --- a/bl/macros.h Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif diff -r f600b0d1fc5d -r faab25d520dd bl/mem.c --- a/bl/mem.c Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -#include -#include -#include -#include - -/* - * A memory allocator that aborts on failure (so that the caller never - * needs to handle out of memory, which we assume is very unlikely to - * happen under normal circumstances on any modern machine). - */ -void *mem_alloc(size_t nmemb,size_t size) -{ - void *ptr=malloc(nmemb*size); - if (!ptr) - { - fprintf(stderr, - "Not enough memory to allocate %lu elements of %lu bytes.\n", - (unsigned long)nmemb,(unsigned long)size); - abort(); - } - return ptr; -} - -/* - * As mem_new, but new memory is cleared to zero. - */ -void *mem_alloc0(size_t nmemb,size_t size) -{ - void *ptr=calloc(nmemb,size); - if (!ptr) - { - fprintf(stderr, - "Not enough memory to allocate %lu elements of %lu bytes.\n", - (unsigned long)nmemb,(unsigned long)size); - abort(); - } - return ptr; -} - -/* - * Grow or shrink a memory block, aborting on failure. - */ -void *mem_realloc(void *ptr,size_t nmemb,size_t size) -{ - ptr=realloc(ptr,nmemb*size); - if (!ptr) - { - fprintf(stderr, - "Not enough memory to allocate %lu elements of %lu bytes.\n", - (unsigned long)nmemb,(unsigned long)size); - abort(); - } - return ptr; -} diff -r f600b0d1fc5d -r faab25d520dd bl/mem.h --- a/bl/mem.h Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -#ifndef BL_MEM_H -#define BL_MEM_H - -void *mem_alloc(size_t nmemb,size_t size); -void *mem_alloc0(size_t nmemb,size_t size); -void *mem_realloc(void *ptr,size_t nmemb,size_t size); - -#define mem_new(type,n) ((type *)mem_alloc(n,sizeof(type))) -#define mem_new0(type,n) ((type *)mem_alloc0(n,sizeof(type))) -#define mem_renew(type,ptr,n) ((type *)mem_realloc(ptr,n,sizeof(type))) -#define mem_free(ptr) free(ptr) - -#endif /* BL_MEM_H */ diff -r f600b0d1fc5d -r faab25d520dd bl/spawn.c --- a/bl/spawn.c Fri Jan 27 10:30:16 2012 +0000 +++ b/bl/spawn.c Fri Jan 27 16:18:02 2012 +0000 @@ -7,10 +7,10 @@ #define SPAWN_BUFSIZE 128 -boolean spawn_sync(char **argv,char **standard_output,int *exit_status) +gboolean spawn_sync(char **argv,char **standard_output,int *exit_status) { /* Don't use g_spawn_sync on WIN32 for now to avoid needing the helper */ -#if HAVE_GLIB && !defined(WIN32) +#ifndef WIN32 char *standard_error; GError *error=NULL; gboolean retval; @@ -33,41 +33,41 @@ FILE *fp; int i,r; size_t n,len; - String *command_line,*string; - command_line=string_new(NULL); + GString *command_line,*string; + command_line=g_string_new(NULL); for(i=0;argv[i];i++) { if (i) - string_append_c(command_line,' '); - string_append(command_line,argv[i]); + g_string_append_c(command_line,' '); + g_string_append(command_line,argv[i]); } fp=popen(command_line->str,"r"); - string_free(command_line,TRUE); + g_string_free(command_line,TRUE); if (!fp) { perror(command_line->str); return FALSE; } - string=string_new(NULL); + string=g_string_new(NULL); do { len=string->len; - string_set_size(string,len+SPAWN_BUFSIZE); + g_string_set_size(string,len+SPAWN_BUFSIZE); n=fread(string->str+len,1,SPAWN_BUFSIZE,fp); if (n<0) { perror("fread"); (void)pclose(fp); - string_free(string,TRUE); + g_string_free(string,TRUE); return FALSE; } - string_set_size(string,len+n); + g_string_set_size(string,len+n); } while(n); r=pclose(fp); if (r<0) { perror("pclose"); - string_free(string,TRUE); + g_string_free(string,TRUE); return FALSE; } else @@ -75,9 +75,9 @@ if (exit_status) *exit_status=r; if (standard_output) - *standard_output=string_free(string,FALSE); + *standard_output=g_string_free(string,FALSE); else - string_free(string,TRUE); + g_string_free(string,TRUE); return TRUE; } #endif diff -r f600b0d1fc5d -r faab25d520dd bl/spawn.h --- a/bl/spawn.h Fri Jan 27 10:30:16 2012 +0000 +++ b/bl/spawn.h Fri Jan 27 16:18:02 2012 +0000 @@ -1,8 +1,8 @@ #ifndef BL_SPAWN_H #define BL_SPAWN_H -#include +#include -boolean spawn_sync(char **argv,char **standard_output,int *exit_status); +gboolean spawn_sync(char **argv,char **standard_output,int *exit_status); #endif /* BL_SPAWN_H */ diff -r f600b0d1fc5d -r faab25d520dd bl/strfuncs.c --- a/bl/strfuncs.c Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#include -#include -#include -#include - -/* - * Like strndup, but only returns NULL if str is NULL. - * Note that this routine copies n bytes rather than n characters. - */ -char *str_ndup(const char *str,size_t n) -{ - char *dup; - if (!str) - return NULL; - dup=mem_alloc0(n+1,1); - strncpy(dup,str,n); - return dup; -} - -/* - * Like strdup, but only returns NULL if str is NULL. - */ -char *str_dup(const char *str) -{ - return str_ndup(str,strlen(str)); -} diff -r f600b0d1fc5d -r faab25d520dd bl/strfuncs.h --- a/bl/strfuncs.h Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef BL_STRFUNCS_H -#define BL_STRFUNCS_H - -char *str_dup(const char *str); -char *str_ndup(const char *str,size_t n); - -#endif /* BL_STRFUNCS_H */ diff -r f600b0d1fc5d -r faab25d520dd bl/textfileutils.c --- a/bl/textfileutils.c Fri Jan 27 10:30:16 2012 +0000 +++ b/bl/textfileutils.c Fri Jan 27 16:18:02 2012 +0000 @@ -9,25 +9,30 @@ * DOS-style line endings are handled transparently even on platforms which * don't normally use this format. */ -boolean file_get_contents_text(const char *filename,char **contents, +gboolean file_get_contents_text(const char *filename,char **contents, size_t *length) { int i; char *raw; size_t raw_length; - String *string; - if (!file_get_contents(filename,&raw,&raw_length)) + GString *string; + GError *error=NULL; + if (!g_file_get_contents(filename,&raw,&raw_length,&error)) + { + fprintf(stderr,"%s: %s\n",filename,error->message); + g_error_free(error); return FALSE; - string=string_new(NULL); + } + string=g_string_new(NULL); for(i=0;ilen; if (contents) - *contents=string_free(string,FALSE); + *contents=g_string_free(string,FALSE); else - string_free(string,TRUE); + g_string_free(string,TRUE); return TRUE; } diff -r f600b0d1fc5d -r faab25d520dd bl/textfileutils.h --- a/bl/textfileutils.h Fri Jan 27 10:30:16 2012 +0000 +++ b/bl/textfileutils.h Fri Jan 27 16:18:02 2012 +0000 @@ -1,9 +1,9 @@ #ifndef BL_TEXTFILEUTILS_H #define BL_TEXTFILEUTILS_H -#include +#include -boolean file_get_contents_text(const char *filename,char **contents, +gboolean file_get_contents_text(const char *filename,char **contents, size_t *length); #endif /* BL_TEXTFILEUTILS_H */ diff -r f600b0d1fc5d -r faab25d520dd bl/types.h --- a/bl/types.h Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#ifndef BL_TYPES_H -#define BL_TYPES_H - -typedef int boolean; - -#endif /* BL_TYPES_H */ diff -r f600b0d1fc5d -r faab25d520dd bl/utils.c --- a/bl/utils.c Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#define is_valid_drive(d) ((d)>='a' && (d)<='z' || (d)>='A' && (d)<='Z') - -/* - * Gets the last component of the filename. If filename ends with a directory - * separator it gets the component before the last slash. If filename consists - * only of directory separators (and on Windows, possibly a drive letter), a - * single separator is returned. If filename is empty, it gets ".". - */ -char *path_get_basename(const char *filename) -{ - ssize_t base,last_nonslash; - size_t len; - char *retval; - if (*filename=='\0') - return str_dup("."); - last_nonslash=strlen(filename)-1; - while (last_nonslash>=0 && BL_IS_DIR_SEPARATOR(filename[last_nonslash])) - last_nonslash--; - if (last_nonslash<0) - /* string only containing slashes */ - return str_dup(BL_DIR_SEPARATOR_S); -#ifdef WIN32 - if (last_nonslash==1 && is_valid_drive(filename[0]) && filename[1]==':') - /* string only containing slashes and a drive */ - return str_dup(BL_DIR_SEPARATOR_S); -#endif - base=last_nonslash; - while (base>=0 && !BL_IS_DIR_SEPARATOR(filename[base])) - base--; -#ifdef WIN32 - if (base==-1 && is_valid_drive(filename[0]) && filename[1] == ':') - base=1; -#endif - len=last_nonslash-base; - retval=mem_alloc(len+1,1); - memcpy(retval,filename+base+1,len); - retval[len]='\0'; - return retval; -} diff -r f600b0d1fc5d -r faab25d520dd bl/utils.h --- a/bl/utils.h Fri Jan 27 10:30:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#ifndef BL_UTIL_H -#define BL_UTIL_H - -#ifdef WIN32 -#define BL_DIR_SEPARATOR '\\' -#define BL_DIR_SEPARATOR_S "\\" -#define BL_IS_DIR_SEPARATOR(c) ((c)==BL_DIR_SEPARATOR || (c)=='/') -#else -#define BL_DIR_SEPARATOR '/' -#define BL_DIR_SEPARATOR_S "/" -#define BL_IS_DIR_SEPARATOR(c) ((c)==BL_DIR_SEPARATOR) -#endif - -char *path_get_basename(const char *filename); - -#endif /* BL_UTIL_H */ diff -r f600b0d1fc5d -r faab25d520dd configure.ac --- a/configure.ac Fri Jan 27 10:30:16 2012 +0000 +++ b/configure.ac Fri Jan 27 16:18:02 2012 +0000 @@ -58,17 +58,7 @@ ################################################## # Checks for libraries. ################################################## -AC_MSG_CHECKING([whether to use glib]) -AC_ARG_WITH([glib],[AS_HELP_STRING([--without-glib], - [use internal re-invented wheel rather than glib2])]) -AS_IF([test "$with_glib" != no],[ - AC_MSG_RESULT([yes]) - PKG_CHECK_MODULES([GLIB],[glib-2.0]) - AC_DEFINE([HAVE_GLIB],[1],[Define if you have glib version 2.x]) -],[ - AC_MSG_RESULT([no]) -]) -AM_CONDITIONAL([HAVE_GLIB],[test "$with_glib" != no]) +PKG_CHECK_MODULES([GLIB],[glib-2.0]) # NOTE: If we are using a static version of glib then we # should define GLIB_STATIC_COMPILATION. This isn't needed diff -r f600b0d1fc5d -r faab25d520dd test/harness/loupe-test.c --- a/test/harness/loupe-test.c Fri Jan 27 10:30:16 2012 +0000 +++ b/test/harness/loupe-test.c Fri Jan 27 16:18:02 2012 +0000 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "testcase.h" #include "testcaseio.h" @@ -9,10 +10,10 @@ * Returns FALSE if the test should be considered to have failed. * (returns TRUE on pass or expected-fail). */ -boolean run_test(const char *filename) +gboolean run_test(const char *filename) { Testcase *testcase; - boolean retval; + gboolean retval; testcase=testcase_parse_file(filename); if (!testcase) return FALSE; @@ -24,7 +25,7 @@ int main(int argc,char **argv) { int i; - boolean pass=TRUE; + gboolean pass=TRUE; for(i=1;i0) { strcpy(template,s); - mem_free(s); + g_free(s); return fd; } else - mem_free(s); + g_free(s); } } #endif /* !HAVE_MKSTEMP */ @@ -100,16 +100,16 @@ * TRUE on pass or expected-fail. * Suitable message(s) will be printed in all cases. */ -boolean testcase_run(Testcase *testcase) +gboolean testcase_run(Testcase *testcase) { - boolean r; + gboolean r; int fd,exit_status,col; size_t n,pos,offset,header_len; FILE *fp; char input[]="TEST-XXXXXX"; char *endp,*bol; char *command[3]; - String *expected,*report; + GString *expected,*report; char *output; fd=mkstemp(input); if (testcase->input) @@ -126,7 +126,7 @@ close(fd); command[0]=getenv("BOOKLOUPE"); if (!command[0]) - command[0]="." BL_DIR_SEPARATOR_S "bookloupe"; + command[0]="." G_DIR_SEPARATOR_S "bookloupe"; command[1]=input; command[2]=NULL; if (testcase->expected) @@ -141,11 +141,11 @@ return FALSE; if (testcase->expected) { - expected=string_new("\n\nFile: "); - string_append(expected,input); - string_append(expected,"\n\n\n"); + expected=g_string_new("\n\nFile: "); + g_string_append(expected,input); + g_string_append(expected,"\n\n\n"); header_len=expected->len; - string_append(expected,testcase->expected); + g_string_append(expected,testcase->expected); } else { @@ -163,8 +163,8 @@ endp=strchr(output+offset,'\n'); if (!endp) endp=output+strlen(output); - report=string_new(NULL); - string_append_len(report,output,endp-output); + report=g_string_new(NULL); + g_string_append_len(report,output,endp-output); bol=strrchr(report->str,'\n'); if (bol) bol++; @@ -176,14 +176,14 @@ fprintf(stderr,"%s\n%*s^\n",report->str+header_len,col,""); else fprintf(stderr,"%s\n%*s^\n",report->str,col,""); - string_free(report,TRUE); + g_string_free(report,TRUE); } - string_free(expected,TRUE); - mem_free(output); + g_string_free(expected,TRUE); + g_free(output); return FALSE; } - string_free(expected,TRUE); - mem_free(output); + g_string_free(expected,TRUE); + g_free(output); if (exit_status) fprintf(stderr,"bookloupe exited with code %d\n",r); if (!exit_status) @@ -196,8 +196,8 @@ */ void testcase_free(Testcase *testcase) { - mem_free(testcase->basename); - mem_free(testcase->input); - mem_free(testcase->expected); - mem_free(testcase); + g_free(testcase->basename); + g_free(testcase->input); + g_free(testcase->expected); + g_free(testcase); } diff -r f600b0d1fc5d -r faab25d520dd test/harness/testcase.h --- a/test/harness/testcase.h Fri Jan 27 10:30:16 2012 +0000 +++ b/test/harness/testcase.h Fri Jan 27 16:18:02 2012 +0000 @@ -1,6 +1,8 @@ #ifndef TESTCASE_H #define TESTCASE_H +#include + typedef struct { char *basename; char *input; @@ -10,7 +12,7 @@ } flags; } Testcase; -boolean testcase_run(Testcase *testcase); +gboolean testcase_run(Testcase *testcase); void testcase_free(Testcase *testcase); #endif /* TESTCASE_H */ diff -r f600b0d1fc5d -r faab25d520dd test/harness/testcaseio.c --- a/test/harness/testcaseio.c Fri Jan 27 10:30:16 2012 +0000 +++ b/test/harness/testcaseio.c Fri Jan 27 16:18:02 2012 +0000 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "testcaseparser.h" #include "testcaseio.h" @@ -16,7 +17,7 @@ TestcaseParser *parser; char *s; const char *tag,*text; - boolean found_tag=FALSE; + gboolean found_tag=FALSE; parser=testcase_parser_new_from_file(filename); if (!parser) return NULL; @@ -26,17 +27,17 @@ testcase_parser_free(parser); return NULL; } - testcase=mem_new0(Testcase,1); - testcase->basename=path_get_basename(filename); + testcase=g_new0(Testcase,1); + testcase->basename=g_path_get_basename(filename); s=strrchr(testcase->basename,'.'); if (s) *s='\0'; while(testcase_parser_get_next_tag(parser,&tag,&text)) { if (!testcase->input && !strcmp(tag,"INPUT")) - testcase->input=str_dup(text); + testcase->input=g_strdup(text); else if (!testcase->expected && !strcmp(tag,"EXPECTED")) - testcase->expected=str_dup(text); + testcase->expected=g_strdup(text); else { fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag); diff -r f600b0d1fc5d -r faab25d520dd test/harness/testcaseparser.c --- a/test/harness/testcaseparser.c Fri Jan 27 10:30:16 2012 +0000 +++ b/test/harness/testcaseparser.c Fri Jan 27 16:18:02 2012 +0000 @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include "testcaseparser.h" @@ -13,9 +13,9 @@ char *s=parser->contents; if (!parser->flag) { - parser->flag=string_new(NULL); + parser->flag=g_string_new(NULL); while(*s>' ' && *s<='~') - string_append_c(parser->flag,*s++); + g_string_append_c(parser->flag,*s++); } return parser->flag->str; } @@ -23,7 +23,7 @@ /* * Test if the parser has reached the end of the input file */ -boolean testcase_parser_at_eof(TestcaseParser *parser) +gboolean testcase_parser_at_eof(TestcaseParser *parser) { return !parser->contents[parser->pos]; } @@ -34,15 +34,15 @@ * Callers can call testcase_parser_at_eof() when testcase_parser_get_next_tag() * to distinguish EOF and text which isn't a valid tag. */ -boolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag, +gboolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag, const char **text) { size_t n; char *eol,*endp; - String *string; - mem_free(parser->tag); + GString *string; + g_free(parser->tag); parser->tag=NULL; - mem_free(parser->tag_text); + g_free(parser->tag_text); parser->tag_text=NULL; (void)testcase_parser_get_flag(parser); if (strncmp(parser->contents+parser->pos,parser->flag->str, @@ -54,15 +54,15 @@ endp=eol-parser->flag->len; if (strncmp(endp,parser->flag->str,parser->flag->len)) return FALSE; - while(endp>parser->contents && isspace(endp[-1])) + while(endp>parser->contents && g_ascii_isspace(endp[-1])) endp--; parser->pos+=parser->flag->len; - while(isspace(parser->contents[parser->pos])) + while(g_ascii_isspace(parser->contents[parser->pos])) parser->pos++; - parser->tag=str_ndup(parser->contents+parser->pos, + parser->tag=g_strndup(parser->contents+parser->pos, endp-(parser->contents+parser->pos)); parser->pos=eol-parser->contents+1; - string=string_new(NULL); + string=g_string_new(NULL); while (!testcase_parser_at_eof(parser) && strncmp(parser->contents+parser->pos,parser->flag->str,parser->flag->len)) { @@ -71,12 +71,12 @@ n=eol-(parser->contents+parser->pos)+1; else n=strlen(parser->contents+parser->pos); - string_append_len(string,parser->contents+parser->pos,n); + g_string_append_len(string,parser->contents+parser->pos,n); parser->pos+=n; } - parser->tag_text=string_free(string,FALSE); + parser->tag_text=g_string_free(string,FALSE); if (!parser->tag_text) - parser->tag_text=str_dup(""); + parser->tag_text=g_strdup(""); if (tag) *tag=parser->tag; if (text) @@ -90,13 +90,13 @@ TestcaseParser *testcase_parser_new_from_file(const char *filename) { TestcaseParser *parser; - parser=mem_new0(TestcaseParser,1); + parser=g_new0(TestcaseParser,1); if (!file_get_contents_text(filename,&parser->contents,NULL)) { - mem_free(parser); + g_free(parser); return NULL; } - parser->filename=str_dup(filename); + parser->filename=g_strdup(filename); return parser; } @@ -105,11 +105,11 @@ */ void testcase_parser_free(TestcaseParser *parser) { - mem_free(parser->filename); - mem_free(parser->contents); + g_free(parser->filename); + g_free(parser->contents); if (parser->flag) - string_free(parser->flag,TRUE); - mem_free(parser->tag); - mem_free(parser->tag_text); - mem_free(parser); + g_string_free(parser->flag,TRUE); + g_free(parser->tag); + g_free(parser->tag_text); + g_free(parser); } diff -r f600b0d1fc5d -r faab25d520dd test/harness/testcaseparser.h --- a/test/harness/testcaseparser.h Fri Jan 27 10:30:16 2012 +0000 +++ b/test/harness/testcaseparser.h Fri Jan 27 16:18:02 2012 +0000 @@ -1,21 +1,22 @@ #ifndef TESTCASE_PARSER_H #define TESTCASE_PARSER_H +#include #include typedef struct { char *filename; char *contents; - String *flag; + GString *flag; size_t pos; char *tag; char *tag_text; } TestcaseParser; const char *testcase_parser_get_flag(TestcaseParser *parser); -boolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag, +gboolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag, const char **text); -boolean testcase_parser_at_eof(TestcaseParser *parser); +gboolean testcase_parser_at_eof(TestcaseParser *parser); TestcaseParser *testcase_parser_new_from_file(const char *filename); void testcase_parser_free(TestcaseParser *parser);