Rely on glib being available everywhere
authorali <ali@juiblex.co.uk>
Fri Jan 27 16:18:02 2012 +0000 (2012-01-27)
changeset 6faab25d520dd
parent 5 f600b0d1fc5d
child 7 721e468c10f3
Rely on glib being available everywhere
README
bl/Makefile.am
bl/bl.h
bl/blstring.c
bl/blstring.h
bl/fileutils.c
bl/fileutils.h
bl/macros.h
bl/mem.c
bl/mem.h
bl/spawn.c
bl/spawn.h
bl/strfuncs.c
bl/strfuncs.h
bl/textfileutils.c
bl/textfileutils.h
bl/types.h
bl/utils.c
bl/utils.h
configure.ac
test/harness/loupe-test.c
test/harness/testcase.c
test/harness/testcase.h
test/harness/testcaseio.c
test/harness/testcaseparser.c
test/harness/testcaseparser.h
     1.1 --- a/README	Fri Jan 27 10:30:16 2012 +0000
     1.2 +++ b/README	Fri Jan 27 16:18:02 2012 +0000
     1.3 @@ -25,10 +25,6 @@
     1.4  
     1.5  % sudo apt-get install gcc pkgconfig glib2-devel
     1.6  
     1.7 -If you get really stuck, you can use the --without-glib option to configure,
     1.8 -but this may well not be supported in a future version so this is probably
     1.9 -best avoided.
    1.10 -
    1.11  Microsoft Windows
    1.12  -----------------
    1.13  
     2.1 --- a/bl/Makefile.am	Fri Jan 27 10:30:16 2012 +0000
     2.2 +++ b/bl/Makefile.am	Fri Jan 27 16:18:02 2012 +0000
     2.3 @@ -4,7 +4,3 @@
     2.4  
     2.5  noinst_LTLIBRARIES=libbl.la
     2.6  libbl_la_SOURCES=bl.h textfileutils.c textfileutils.h spawn.c spawn.h
     2.7 -if !HAVE_GLIB
     2.8 -libbl_la_SOURCES+=macros.h types.h fileutils.c fileutils.h mem.c mem.h \
     2.9 -  strfuncs.c strfuncs.h blstring.c blstring.h utils.c utils.h
    2.10 -endif
     3.1 --- a/bl/bl.h	Fri Jan 27 10:30:16 2012 +0000
     3.2 +++ b/bl/bl.h	Fri Jan 27 16:18:02 2012 +0000
     3.3 @@ -1,36 +1,2 @@
     3.4 -#if HAVE_GLIB
     3.5 -
     3.6 -#include <glib.h>
     3.7 -#define BL_DIR_SEPARATOR G_DIR_SEPARATOR
     3.8 -#define BL_DIR_SEPARATOR_S G_DIR_SEPARATOR_S
     3.9 -#define BL_IS_DIR_SEPARATOR(c) G_IS_DIR_SEPARATOR(c)
    3.10 -#define boolean gboolean
    3.11 -#define String GString
    3.12 -#define mem_new0 g_new0
    3.13 -#define mem_free g_free
    3.14 -#define str_dup g_strdup
    3.15 -#define str_ndup g_strndup
    3.16 -#define path_get_basename g_path_get_basename
    3.17 -#define file_get_contents(filename,contents,length) \
    3.18 -  g_file_get_contents(filename,contents,length,NULL)
    3.19 -#define string_new g_string_new
    3.20 -#define string_append g_string_append
    3.21 -#define string_append_len g_string_append_len
    3.22 -#define string_append_c g_string_append_c
    3.23 -#define string_free g_string_free
    3.24 -#define string_set_size g_string_set_size
    3.25 -
    3.26 -#else	/* !HAVE_GLIB */
    3.27 -
    3.28 -#include <bl/macros.h>
    3.29 -#include <bl/types.h>
    3.30 -#include <bl/mem.h>
    3.31 -#include <bl/fileutils.h>
    3.32 -#include <bl/strfuncs.h>
    3.33 -#include <bl/blstring.h>
    3.34 -#include <bl/utils.h>
    3.35 -
    3.36 -#endif	/* HAVE_GLIB */
    3.37 -
    3.38  #include <bl/textfileutils.h>
    3.39  #include <bl/spawn.h>
     4.1 --- a/bl/blstring.c	Fri Jan 27 10:30:16 2012 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,90 +0,0 @@
     4.4 -#include <stdlib.h>
     4.5 -#include <string.h>
     4.6 -#include <bl/blstring.h>
     4.7 -#include <bl/types.h>
     4.8 -#include <bl/mem.h>
     4.9 -#include <bl/strfuncs.h>
    4.10 -
    4.11 -/*
    4.12 - * Strings which manage their own memory
    4.13 - */
    4.14 -
    4.15 -String *string_new(const char *init)
    4.16 -{
    4.17 -    String *string=mem_new(String,1);
    4.18 -    if (!init)
    4.19 -	init="";
    4.20 -    string->len=strlen(init);
    4.21 -    string->alloc=string->len+1;
    4.22 -    string->str=str_dup(init);
    4.23 -    return string;
    4.24 -}
    4.25 -
    4.26 -/*
    4.27 - * Free a string and either return the contents (if free_segment is FALSE)
    4.28 - * or free the contents as well and return NULL (if free_segment is TRUE).
    4.29 - */
    4.30 -char *string_free(String *string,boolean free_segment)
    4.31 -{
    4.32 -    char *retval;
    4.33 -    if (free_segment)
    4.34 -    {
    4.35 -	mem_free(string->str);
    4.36 -	retval=NULL;
    4.37 -    }
    4.38 -    else
    4.39 -	retval=string->str;
    4.40 -    mem_free(string);
    4.41 -    return retval;
    4.42 -}
    4.43 -
    4.44 -/*
    4.45 - * Append a byte to string.
    4.46 - */
    4.47 -void string_append_c(String *string,char c)
    4.48 -{
    4.49 -    if (string->len+1==string->alloc)
    4.50 -    {
    4.51 -	string->alloc*=2;
    4.52 -	string->str=mem_renew(char,string->str,string->alloc);
    4.53 -    }
    4.54 -    string->str[string->len++]=c;
    4.55 -    string->str[string->len]='\0';
    4.56 -}
    4.57 -
    4.58 -/*
    4.59 - * Append len bytes from s to string. len may be passed as <0 if s is
    4.60 - * a nul-terminated string of unknown length.
    4.61 - */
    4.62 -void string_append_len(String *string,const char *s,ssize_t len)
    4.63 -{
    4.64 -    if (len<0)
    4.65 -	len=strlen(s);
    4.66 -    if (string->len+len>=string->alloc)
    4.67 -    {
    4.68 -	while (string->len+len>=string->alloc)
    4.69 -	    string->alloc*=2;
    4.70 -	string->str=mem_renew(char,string->str,string->alloc);
    4.71 -    }
    4.72 -    memcpy(string->str+string->len,s,len);
    4.73 -    string->len+=len;
    4.74 -    string->str[string->len]='\0';
    4.75 -}
    4.76 -
    4.77 -/*
    4.78 - * Sets the length of a String. If the length is less than the current length,
    4.79 - * the string will be truncated. If the length is greater than the current
    4.80 - * length, the contents of the newly added area are undefined. (However, as
    4.81 - * always, string->str[string->len] will be a nul byte.)
    4.82 - */
    4.83 -void string_set_size(String *string,size_t len)
    4.84 -{
    4.85 -    if (len>=string->alloc)
    4.86 -    {
    4.87 -	while (len>=string->alloc)
    4.88 -	    string->alloc*=2;
    4.89 -	string->str=mem_renew(char,string->str,string->alloc);
    4.90 -    }
    4.91 -    string->len=len;
    4.92 -    string->str[string->len]='\0';
    4.93 -}
     5.1 --- a/bl/blstring.h	Fri Jan 27 10:30:16 2012 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,18 +0,0 @@
     5.4 -#ifndef BL_STRING_H
     5.5 -#define BL_STRING_H
     5.6 -
     5.7 -#include <unistd.h>
     5.8 -#include <bl/types.h>
     5.9 -
    5.10 -typedef struct {
    5.11 -    char *str;
    5.12 -    size_t alloc,len;
    5.13 -} String;
    5.14 -
    5.15 -String *string_new(const char *init);
    5.16 -char *string_free(String *string,boolean free_segment);
    5.17 -void string_append_c(String *string,char c);
    5.18 -void string_append_len(String *string,const char *s,ssize_t len);
    5.19 -#define string_append(string,s)		string_append_len(string,s,-1)
    5.20 -
    5.21 -#endif /* BL_STRING_H */
     6.1 --- a/bl/fileutils.c	Fri Jan 27 10:30:16 2012 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,46 +0,0 @@
     6.4 -#include <stdlib.h>
     6.5 -#include <stdio.h>
     6.6 -#include <bl/macros.h>
     6.7 -#include <bl/mem.h>
     6.8 -#include <bl/fileutils.h>
     6.9 -#include <bl/blstring.h>
    6.10 -
    6.11 -/*
    6.12 - * Read a file into memory (which should be freed with mem_free when no
    6.13 - * longer required). Returns FALSE on error and outputs a suitable error
    6.14 - * message to stderr.
    6.15 - */
    6.16 -boolean file_get_contents(const char *filename,char **contents,size_t *length)
    6.17 -{
    6.18 -    FILE *fp;
    6.19 -    size_t n;
    6.20 -    char *buffer;
    6.21 -    String *string;
    6.22 -    fp=fopen(filename,"rb");
    6.23 -    if (!fp)
    6.24 -    {
    6.25 -	perror(filename);
    6.26 -	return FALSE;
    6.27 -    }
    6.28 -    buffer=mem_new(char,1024);
    6.29 -    string=string_new(NULL);
    6.30 -    do
    6.31 -    {
    6.32 -	n=fread(buffer,1,1024,fp);
    6.33 -	if (n<0)
    6.34 -	{
    6.35 -	    perror(filename);
    6.36 -	    string_free(string,TRUE);
    6.37 -	    mem_free(buffer);
    6.38 -	    free(fp);
    6.39 -	    return FALSE;
    6.40 -	}
    6.41 -	string_append_len(string,buffer,n);
    6.42 -    } while(n);
    6.43 -    mem_free(buffer);
    6.44 -    if (length)
    6.45 -	*length=string->len;
    6.46 -    *contents=string_free(string,FALSE);
    6.47 -    fclose(fp);
    6.48 -    return TRUE;
    6.49 -}
     7.1 --- a/bl/fileutils.h	Fri Jan 27 10:30:16 2012 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,8 +0,0 @@
     7.4 -#ifndef BL_FILEUTILS_H
     7.5 -#define BL_FILEUTILS_H
     7.6 -
     7.7 -#include <bl/types.h>
     7.8 -
     7.9 -boolean file_get_contents(const char *filename,char **contents,size_t *length);
    7.10 -
    7.11 -#endif /* BL_FILEUTILS_H */
     8.1 --- a/bl/macros.h	Fri Jan 27 10:30:16 2012 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,7 +0,0 @@
     8.4 -#ifndef FALSE
     8.5 -#define FALSE	0
     8.6 -#endif
     8.7 -
     8.8 -#ifndef TRUE
     8.9 -#define TRUE	(!FALSE)
    8.10 -#endif
     9.1 --- a/bl/mem.c	Fri Jan 27 10:30:16 2012 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,54 +0,0 @@
     9.4 -#include <stdlib.h>
     9.5 -#include <stdio.h>
     9.6 -#include <string.h>
     9.7 -#include <bl/mem.h>
     9.8 -
     9.9 -/*
    9.10 - * A memory allocator that aborts on failure (so that the caller never
    9.11 - * needs to handle out of memory, which we assume is very unlikely to
    9.12 - * happen under normal circumstances on any modern machine).
    9.13 - */
    9.14 -void *mem_alloc(size_t nmemb,size_t size)
    9.15 -{
    9.16 -    void *ptr=malloc(nmemb*size);
    9.17 -    if (!ptr)
    9.18 -    {
    9.19 -	fprintf(stderr,
    9.20 -	  "Not enough memory to allocate %lu elements of %lu bytes.\n",
    9.21 -	  (unsigned long)nmemb,(unsigned long)size);
    9.22 -	abort();
    9.23 -    }
    9.24 -    return ptr;
    9.25 -}
    9.26 -
    9.27 -/*
    9.28 - * As mem_new, but new memory is cleared to zero.
    9.29 - */
    9.30 -void *mem_alloc0(size_t nmemb,size_t size)
    9.31 -{
    9.32 -    void *ptr=calloc(nmemb,size);
    9.33 -    if (!ptr)
    9.34 -    {
    9.35 -	fprintf(stderr,
    9.36 -	  "Not enough memory to allocate %lu elements of %lu bytes.\n",
    9.37 -	  (unsigned long)nmemb,(unsigned long)size);
    9.38 -	abort();
    9.39 -    }
    9.40 -    return ptr;
    9.41 -}
    9.42 -
    9.43 -/*
    9.44 - * Grow or shrink a memory block, aborting on failure.
    9.45 - */
    9.46 -void *mem_realloc(void *ptr,size_t nmemb,size_t size)
    9.47 -{
    9.48 -    ptr=realloc(ptr,nmemb*size);
    9.49 -    if (!ptr)
    9.50 -    {
    9.51 -	fprintf(stderr,
    9.52 -	  "Not enough memory to allocate %lu elements of %lu bytes.\n",
    9.53 -	  (unsigned long)nmemb,(unsigned long)size);
    9.54 -	abort();
    9.55 -    }
    9.56 -    return ptr;
    9.57 -}
    10.1 --- a/bl/mem.h	Fri Jan 27 10:30:16 2012 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,13 +0,0 @@
    10.4 -#ifndef BL_MEM_H
    10.5 -#define BL_MEM_H
    10.6 -
    10.7 -void *mem_alloc(size_t nmemb,size_t size);
    10.8 -void *mem_alloc0(size_t nmemb,size_t size);
    10.9 -void *mem_realloc(void *ptr,size_t nmemb,size_t size);
   10.10 -
   10.11 -#define mem_new(type,n)		((type *)mem_alloc(n,sizeof(type)))
   10.12 -#define mem_new0(type,n)	((type *)mem_alloc0(n,sizeof(type)))
   10.13 -#define mem_renew(type,ptr,n)	((type *)mem_realloc(ptr,n,sizeof(type)))
   10.14 -#define mem_free(ptr)		free(ptr)
   10.15 -
   10.16 -#endif /* BL_MEM_H */
    11.1 --- a/bl/spawn.c	Fri Jan 27 10:30:16 2012 +0000
    11.2 +++ b/bl/spawn.c	Fri Jan 27 16:18:02 2012 +0000
    11.3 @@ -7,10 +7,10 @@
    11.4  
    11.5  #define SPAWN_BUFSIZE	128
    11.6  
    11.7 -boolean spawn_sync(char **argv,char **standard_output,int *exit_status)
    11.8 +gboolean spawn_sync(char **argv,char **standard_output,int *exit_status)
    11.9  {
   11.10  /* Don't use g_spawn_sync on WIN32 for now to avoid needing the helper */
   11.11 -#if HAVE_GLIB && !defined(WIN32)
   11.12 +#ifndef WIN32
   11.13      char *standard_error;
   11.14      GError *error=NULL;
   11.15      gboolean retval;
   11.16 @@ -33,41 +33,41 @@
   11.17      FILE *fp;
   11.18      int i,r;
   11.19      size_t n,len;
   11.20 -    String *command_line,*string;
   11.21 -    command_line=string_new(NULL);
   11.22 +    GString *command_line,*string;
   11.23 +    command_line=g_string_new(NULL);
   11.24      for(i=0;argv[i];i++)
   11.25      {
   11.26  	if (i)
   11.27 -	    string_append_c(command_line,' ');
   11.28 -	string_append(command_line,argv[i]);
   11.29 +	    g_string_append_c(command_line,' ');
   11.30 +	g_string_append(command_line,argv[i]);
   11.31      }
   11.32      fp=popen(command_line->str,"r");
   11.33 -    string_free(command_line,TRUE);
   11.34 +    g_string_free(command_line,TRUE);
   11.35      if (!fp)
   11.36      {
   11.37  	perror(command_line->str);
   11.38  	return FALSE;
   11.39      }
   11.40 -    string=string_new(NULL);
   11.41 +    string=g_string_new(NULL);
   11.42      do
   11.43      {
   11.44  	len=string->len;
   11.45 -	string_set_size(string,len+SPAWN_BUFSIZE);
   11.46 +	g_string_set_size(string,len+SPAWN_BUFSIZE);
   11.47  	n=fread(string->str+len,1,SPAWN_BUFSIZE,fp);
   11.48  	if (n<0)
   11.49  	{
   11.50  	    perror("fread");
   11.51  	    (void)pclose(fp);
   11.52 -	    string_free(string,TRUE);
   11.53 +	    g_string_free(string,TRUE);
   11.54  	    return FALSE;
   11.55  	}
   11.56 -	string_set_size(string,len+n);
   11.57 +	g_string_set_size(string,len+n);
   11.58      } while(n);
   11.59      r=pclose(fp);
   11.60      if (r<0)
   11.61      {
   11.62  	perror("pclose");
   11.63 -	string_free(string,TRUE);
   11.64 +	g_string_free(string,TRUE);
   11.65  	return FALSE;
   11.66      }
   11.67      else
   11.68 @@ -75,9 +75,9 @@
   11.69  	if (exit_status)
   11.70  	    *exit_status=r;
   11.71  	if (standard_output)
   11.72 -	    *standard_output=string_free(string,FALSE);
   11.73 +	    *standard_output=g_string_free(string,FALSE);
   11.74  	else
   11.75 -	    string_free(string,TRUE);
   11.76 +	    g_string_free(string,TRUE);
   11.77  	return TRUE;
   11.78      }
   11.79  #endif
    12.1 --- a/bl/spawn.h	Fri Jan 27 10:30:16 2012 +0000
    12.2 +++ b/bl/spawn.h	Fri Jan 27 16:18:02 2012 +0000
    12.3 @@ -1,8 +1,8 @@
    12.4  #ifndef BL_SPAWN_H
    12.5  #define BL_SPAWN_H
    12.6  
    12.7 -#include <bl/bl.h>
    12.8 +#include <glib.h>
    12.9  
   12.10 -boolean spawn_sync(char **argv,char **standard_output,int *exit_status);
   12.11 +gboolean spawn_sync(char **argv,char **standard_output,int *exit_status);
   12.12  
   12.13  #endif /* BL_SPAWN_H */
    13.1 --- a/bl/strfuncs.c	Fri Jan 27 10:30:16 2012 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,26 +0,0 @@
    13.4 -#include <stdlib.h>
    13.5 -#include <string.h>
    13.6 -#include <bl/mem.h>
    13.7 -#include <bl/strfuncs.h>
    13.8 -
    13.9 -/*
   13.10 - * Like strndup, but only returns NULL if str is NULL.
   13.11 - * Note that this routine copies n bytes rather than n characters.
   13.12 - */
   13.13 -char *str_ndup(const char *str,size_t n)
   13.14 -{
   13.15 -    char *dup;
   13.16 -    if (!str)
   13.17 -	return NULL;
   13.18 -    dup=mem_alloc0(n+1,1);
   13.19 -    strncpy(dup,str,n);
   13.20 -    return dup;
   13.21 -}
   13.22 -
   13.23 -/*
   13.24 - * Like strdup, but only returns NULL if str is NULL.
   13.25 - */
   13.26 -char *str_dup(const char *str)
   13.27 -{
   13.28 -    return str_ndup(str,strlen(str));
   13.29 -}
    14.1 --- a/bl/strfuncs.h	Fri Jan 27 10:30:16 2012 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,7 +0,0 @@
    14.4 -#ifndef BL_STRFUNCS_H
    14.5 -#define BL_STRFUNCS_H
    14.6 -
    14.7 -char *str_dup(const char *str);
    14.8 -char *str_ndup(const char *str,size_t n);
    14.9 -
   14.10 -#endif /* BL_STRFUNCS_H */
    15.1 --- a/bl/textfileutils.c	Fri Jan 27 10:30:16 2012 +0000
    15.2 +++ b/bl/textfileutils.c	Fri Jan 27 16:18:02 2012 +0000
    15.3 @@ -9,25 +9,30 @@
    15.4   * DOS-style line endings are handled transparently even on platforms which
    15.5   * don't normally use this format.
    15.6   */
    15.7 -boolean file_get_contents_text(const char *filename,char **contents,
    15.8 +gboolean file_get_contents_text(const char *filename,char **contents,
    15.9    size_t *length)
   15.10  {
   15.11      int i;
   15.12      char *raw;
   15.13      size_t raw_length;
   15.14 -    String *string;
   15.15 -    if (!file_get_contents(filename,&raw,&raw_length))
   15.16 +    GString *string;
   15.17 +    GError *error=NULL;
   15.18 +    if (!g_file_get_contents(filename,&raw,&raw_length,&error))
   15.19 +    {
   15.20 +	fprintf(stderr,"%s: %s\n",filename,error->message);
   15.21 +	g_error_free(error);
   15.22  	return FALSE;
   15.23 -    string=string_new(NULL);
   15.24 +    }
   15.25 +    string=g_string_new(NULL);
   15.26      for(i=0;i<raw_length;i++)
   15.27  	if (raw[i]!='\r')
   15.28 -	    string_append_c(string,raw[i]);
   15.29 -    mem_free(raw);
   15.30 +	    g_string_append_c(string,raw[i]);
   15.31 +    g_free(raw);
   15.32      if (length)
   15.33  	*length=string->len;
   15.34      if (contents)
   15.35 -	*contents=string_free(string,FALSE);
   15.36 +	*contents=g_string_free(string,FALSE);
   15.37      else
   15.38 -	string_free(string,TRUE);
   15.39 +	g_string_free(string,TRUE);
   15.40      return TRUE;
   15.41  }
    16.1 --- a/bl/textfileutils.h	Fri Jan 27 10:30:16 2012 +0000
    16.2 +++ b/bl/textfileutils.h	Fri Jan 27 16:18:02 2012 +0000
    16.3 @@ -1,9 +1,9 @@
    16.4  #ifndef BL_TEXTFILEUTILS_H
    16.5  #define BL_TEXTFILEUTILS_H
    16.6  
    16.7 -#include <bl/bl.h>
    16.8 +#include <glib.h>
    16.9  
   16.10 -boolean file_get_contents_text(const char *filename,char **contents,
   16.11 +gboolean file_get_contents_text(const char *filename,char **contents,
   16.12    size_t *length);
   16.13  
   16.14  #endif /* BL_TEXTFILEUTILS_H */
    17.1 --- a/bl/types.h	Fri Jan 27 10:30:16 2012 +0000
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,6 +0,0 @@
    17.4 -#ifndef BL_TYPES_H
    17.5 -#define BL_TYPES_H
    17.6 -
    17.7 -typedef int boolean;
    17.8 -
    17.9 -#endif	/* BL_TYPES_H */
    18.1 --- a/bl/utils.c	Fri Jan 27 10:30:16 2012 +0000
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,46 +0,0 @@
    18.4 -#include <stdlib.h>
    18.5 -#include <string.h>
    18.6 -#include <unistd.h>
    18.7 -#include <bl/mem.h>
    18.8 -#include <bl/strfuncs.h>
    18.9 -#include <bl/utils.h>
   18.10 -
   18.11 -#define is_valid_drive(d)	((d)>='a' && (d)<='z' || (d)>='A' && (d)<='Z')
   18.12 -
   18.13 -/*
   18.14 - * Gets the last component of the filename. If filename ends with a directory
   18.15 - * separator it gets the component before the last slash. If filename consists
   18.16 - * only of directory separators (and on Windows, possibly a drive letter), a
   18.17 - * single separator is returned. If filename is empty, it gets ".".
   18.18 - */
   18.19 -char *path_get_basename(const char *filename)
   18.20 -{
   18.21 -    ssize_t base,last_nonslash;
   18.22 -    size_t len;
   18.23 -    char *retval;
   18.24 -    if (*filename=='\0')
   18.25 -        return str_dup(".");
   18.26 -    last_nonslash=strlen(filename)-1;
   18.27 -    while (last_nonslash>=0 && BL_IS_DIR_SEPARATOR(filename[last_nonslash]))
   18.28 -	last_nonslash--;
   18.29 -    if (last_nonslash<0)
   18.30 -	/* string only containing slashes */
   18.31 -    return str_dup(BL_DIR_SEPARATOR_S);
   18.32 -#ifdef WIN32
   18.33 -    if (last_nonslash==1 && is_valid_drive(filename[0]) && filename[1]==':')
   18.34 -	/* string only containing slashes and a drive */
   18.35 -	return str_dup(BL_DIR_SEPARATOR_S);
   18.36 -#endif
   18.37 -    base=last_nonslash;
   18.38 -    while (base>=0 && !BL_IS_DIR_SEPARATOR(filename[base]))
   18.39 -	base--;
   18.40 -#ifdef WIN32
   18.41 -    if (base==-1 && is_valid_drive(filename[0]) && filename[1] == ':')
   18.42 -	  base=1;
   18.43 -#endif
   18.44 -    len=last_nonslash-base;
   18.45 -    retval=mem_alloc(len+1,1);
   18.46 -    memcpy(retval,filename+base+1,len);
   18.47 -    retval[len]='\0';
   18.48 -    return retval;
   18.49 -}
    19.1 --- a/bl/utils.h	Fri Jan 27 10:30:16 2012 +0000
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,16 +0,0 @@
    19.4 -#ifndef BL_UTIL_H
    19.5 -#define BL_UTIL_H
    19.6 -
    19.7 -#ifdef WIN32
    19.8 -#define BL_DIR_SEPARATOR '\\'
    19.9 -#define BL_DIR_SEPARATOR_S "\\"
   19.10 -#define BL_IS_DIR_SEPARATOR(c) ((c)==BL_DIR_SEPARATOR || (c)=='/')
   19.11 -#else
   19.12 -#define BL_DIR_SEPARATOR '/'
   19.13 -#define BL_DIR_SEPARATOR_S "/"
   19.14 -#define BL_IS_DIR_SEPARATOR(c) ((c)==BL_DIR_SEPARATOR)
   19.15 -#endif
   19.16 -
   19.17 -char *path_get_basename(const char *filename);
   19.18 -
   19.19 -#endif /* BL_UTIL_H */
    20.1 --- a/configure.ac	Fri Jan 27 10:30:16 2012 +0000
    20.2 +++ b/configure.ac	Fri Jan 27 16:18:02 2012 +0000
    20.3 @@ -58,17 +58,7 @@
    20.4  ##################################################
    20.5  # Checks for libraries.
    20.6  ##################################################
    20.7 -AC_MSG_CHECKING([whether to use glib])
    20.8 -AC_ARG_WITH([glib],[AS_HELP_STRING([--without-glib],
    20.9 -  [use internal re-invented wheel rather than glib2])])
   20.10 -AS_IF([test "$with_glib" != no],[
   20.11 -  AC_MSG_RESULT([yes])
   20.12 -  PKG_CHECK_MODULES([GLIB],[glib-2.0])
   20.13 -  AC_DEFINE([HAVE_GLIB],[1],[Define if you have glib version 2.x])
   20.14 -],[
   20.15 -  AC_MSG_RESULT([no])
   20.16 -])
   20.17 -AM_CONDITIONAL([HAVE_GLIB],[test "$with_glib" != no])
   20.18 +PKG_CHECK_MODULES([GLIB],[glib-2.0])
   20.19  
   20.20  # NOTE: If we are using a static version of glib then we
   20.21  # should define GLIB_STATIC_COMPILATION. This isn't needed
    21.1 --- a/test/harness/loupe-test.c	Fri Jan 27 10:30:16 2012 +0000
    21.2 +++ b/test/harness/loupe-test.c	Fri Jan 27 16:18:02 2012 +0000
    21.3 @@ -1,6 +1,7 @@
    21.4  #include <stdlib.h>
    21.5  #include <stdio.h>
    21.6  #include <string.h>
    21.7 +#include <glib.h>
    21.8  #include <bl/bl.h>
    21.9  #include "testcase.h"
   21.10  #include "testcaseio.h"
   21.11 @@ -9,10 +10,10 @@
   21.12   * Returns FALSE if the test should be considered to have failed.
   21.13   * (returns TRUE on pass or expected-fail).
   21.14   */
   21.15 -boolean run_test(const char *filename)
   21.16 +gboolean run_test(const char *filename)
   21.17  {
   21.18      Testcase *testcase;
   21.19 -    boolean retval;
   21.20 +    gboolean retval;
   21.21      testcase=testcase_parse_file(filename);
   21.22      if (!testcase)
   21.23  	return FALSE;
   21.24 @@ -24,7 +25,7 @@
   21.25  int main(int argc,char **argv)
   21.26  {
   21.27      int i;
   21.28 -    boolean pass=TRUE;
   21.29 +    gboolean pass=TRUE;
   21.30      for(i=1;i<argc;i++)
   21.31  	pass&=run_test(argv[i]);
   21.32      return pass?0:1;
    22.1 --- a/test/harness/testcase.c	Fri Jan 27 10:30:16 2012 +0000
    22.2 +++ b/test/harness/testcase.c	Fri Jan 27 16:18:02 2012 +0000
    22.3 @@ -21,23 +21,23 @@
    22.4      char *s;
    22.5      for(;;)
    22.6      {
    22.7 -	s=str_dup(template);
    22.8 +	s=g_strdup(template);
    22.9  	mktemp(s);
   22.10  	if (!*s)
   22.11  	{
   22.12  	    errno=EEXIST;
   22.13 -	    mem_free(s);
   22.14 +	    g_free(s);
   22.15  	    return -1;
   22.16  	}
   22.17  	fd=open(s,O_RDWR|O_CREAT|O_EXCL,0600);
   22.18  	if (fd>0)
   22.19  	{
   22.20  	    strcpy(template,s);
   22.21 -	    mem_free(s);
   22.22 +	    g_free(s);
   22.23  	    return fd;
   22.24  	}
   22.25  	else
   22.26 -	    mem_free(s);
   22.27 +	    g_free(s);
   22.28      }
   22.29  }
   22.30  #endif	/* !HAVE_MKSTEMP */
   22.31 @@ -100,16 +100,16 @@
   22.32   * TRUE on pass or expected-fail.
   22.33   * Suitable message(s) will be printed in all cases.
   22.34   */
   22.35 -boolean testcase_run(Testcase *testcase)
   22.36 +gboolean testcase_run(Testcase *testcase)
   22.37  {
   22.38 -    boolean r;
   22.39 +    gboolean r;
   22.40      int fd,exit_status,col;
   22.41      size_t n,pos,offset,header_len;
   22.42      FILE *fp;
   22.43      char input[]="TEST-XXXXXX";
   22.44      char *endp,*bol;
   22.45      char *command[3];
   22.46 -    String *expected,*report;
   22.47 +    GString *expected,*report;
   22.48      char *output;
   22.49      fd=mkstemp(input);
   22.50      if (testcase->input)
   22.51 @@ -126,7 +126,7 @@
   22.52      close(fd);
   22.53      command[0]=getenv("BOOKLOUPE");
   22.54      if (!command[0])
   22.55 -	command[0]="." BL_DIR_SEPARATOR_S "bookloupe";
   22.56 +	command[0]="." G_DIR_SEPARATOR_S "bookloupe";
   22.57      command[1]=input;
   22.58      command[2]=NULL;
   22.59      if (testcase->expected)
   22.60 @@ -141,11 +141,11 @@
   22.61  	return FALSE;
   22.62      if (testcase->expected)
   22.63      {
   22.64 -	expected=string_new("\n\nFile: ");
   22.65 -	string_append(expected,input);
   22.66 -	string_append(expected,"\n\n\n");
   22.67 +	expected=g_string_new("\n\nFile: ");
   22.68 +	g_string_append(expected,input);
   22.69 +	g_string_append(expected,"\n\n\n");
   22.70  	header_len=expected->len;
   22.71 -	string_append(expected,testcase->expected);
   22.72 +	g_string_append(expected,testcase->expected);
   22.73      }
   22.74      else
   22.75      {
   22.76 @@ -163,8 +163,8 @@
   22.77  	    endp=strchr(output+offset,'\n');
   22.78  	    if (!endp)
   22.79  		endp=output+strlen(output);
   22.80 -	    report=string_new(NULL);
   22.81 -	    string_append_len(report,output,endp-output);
   22.82 +	    report=g_string_new(NULL);
   22.83 +	    g_string_append_len(report,output,endp-output);
   22.84  	    bol=strrchr(report->str,'\n');
   22.85  	    if (bol)
   22.86  		bol++;
   22.87 @@ -176,14 +176,14 @@
   22.88  		fprintf(stderr,"%s\n%*s^\n",report->str+header_len,col,"");
   22.89  	    else
   22.90  		fprintf(stderr,"%s\n%*s^\n",report->str,col,"");
   22.91 -	    string_free(report,TRUE);
   22.92 +	    g_string_free(report,TRUE);
   22.93  	}
   22.94 -	string_free(expected,TRUE);
   22.95 -	mem_free(output);
   22.96 +	g_string_free(expected,TRUE);
   22.97 +	g_free(output);
   22.98  	return FALSE;
   22.99      }
  22.100 -    string_free(expected,TRUE);
  22.101 -    mem_free(output);
  22.102 +    g_string_free(expected,TRUE);
  22.103 +    g_free(output);
  22.104      if (exit_status)
  22.105  	fprintf(stderr,"bookloupe exited with code %d\n",r);
  22.106      if (!exit_status)
  22.107 @@ -196,8 +196,8 @@
  22.108   */
  22.109  void testcase_free(Testcase *testcase)
  22.110  {
  22.111 -    mem_free(testcase->basename);
  22.112 -    mem_free(testcase->input);
  22.113 -    mem_free(testcase->expected);
  22.114 -    mem_free(testcase);
  22.115 +    g_free(testcase->basename);
  22.116 +    g_free(testcase->input);
  22.117 +    g_free(testcase->expected);
  22.118 +    g_free(testcase);
  22.119  }
    23.1 --- a/test/harness/testcase.h	Fri Jan 27 10:30:16 2012 +0000
    23.2 +++ b/test/harness/testcase.h	Fri Jan 27 16:18:02 2012 +0000
    23.3 @@ -1,6 +1,8 @@
    23.4  #ifndef TESTCASE_H
    23.5  #define TESTCASE_H
    23.6  
    23.7 +#include <glib.h>
    23.8 +
    23.9  typedef struct {
   23.10      char *basename;
   23.11      char *input;
   23.12 @@ -10,7 +12,7 @@
   23.13      } flags;
   23.14  } Testcase;
   23.15  
   23.16 -boolean testcase_run(Testcase *testcase);
   23.17 +gboolean testcase_run(Testcase *testcase);
   23.18  void testcase_free(Testcase *testcase);
   23.19  
   23.20  #endif	/* TESTCASE_H */
    24.1 --- a/test/harness/testcaseio.c	Fri Jan 27 10:30:16 2012 +0000
    24.2 +++ b/test/harness/testcaseio.c	Fri Jan 27 16:18:02 2012 +0000
    24.3 @@ -1,6 +1,7 @@
    24.4  #include <stdlib.h>
    24.5  #include <stdio.h>
    24.6  #include <string.h>
    24.7 +#include <glib.h>
    24.8  #include <bl/bl.h>
    24.9  #include "testcaseparser.h"
   24.10  #include "testcaseio.h"
   24.11 @@ -16,7 +17,7 @@
   24.12      TestcaseParser *parser;
   24.13      char *s;
   24.14      const char *tag,*text;
   24.15 -    boolean found_tag=FALSE;
   24.16 +    gboolean found_tag=FALSE;
   24.17      parser=testcase_parser_new_from_file(filename);
   24.18      if (!parser)
   24.19  	return NULL;
   24.20 @@ -26,17 +27,17 @@
   24.21  	testcase_parser_free(parser);
   24.22  	return NULL;
   24.23      }
   24.24 -    testcase=mem_new0(Testcase,1);
   24.25 -    testcase->basename=path_get_basename(filename);
   24.26 +    testcase=g_new0(Testcase,1);
   24.27 +    testcase->basename=g_path_get_basename(filename);
   24.28      s=strrchr(testcase->basename,'.');
   24.29      if (s)
   24.30  	*s='\0';
   24.31      while(testcase_parser_get_next_tag(parser,&tag,&text))
   24.32      {
   24.33  	if (!testcase->input && !strcmp(tag,"INPUT"))
   24.34 -	    testcase->input=str_dup(text);
   24.35 +	    testcase->input=g_strdup(text);
   24.36  	else if (!testcase->expected && !strcmp(tag,"EXPECTED"))
   24.37 -	    testcase->expected=str_dup(text);
   24.38 +	    testcase->expected=g_strdup(text);
   24.39  	else
   24.40  	{
   24.41  	    fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag);
    25.1 --- a/test/harness/testcaseparser.c	Fri Jan 27 10:30:16 2012 +0000
    25.2 +++ b/test/harness/testcaseparser.c	Fri Jan 27 16:18:02 2012 +0000
    25.3 @@ -1,7 +1,7 @@
    25.4  #include <stdlib.h>
    25.5  #include <stdio.h>
    25.6  #include <string.h>
    25.7 -#include <ctype.h>
    25.8 +#include <glib.h>
    25.9  #include <bl/bl.h>
   25.10  #include "testcaseparser.h"
   25.11  
   25.12 @@ -13,9 +13,9 @@
   25.13      char *s=parser->contents;
   25.14      if (!parser->flag)
   25.15      {
   25.16 -	parser->flag=string_new(NULL);
   25.17 +	parser->flag=g_string_new(NULL);
   25.18  	while(*s>' ' && *s<='~')
   25.19 -	    string_append_c(parser->flag,*s++);
   25.20 +	    g_string_append_c(parser->flag,*s++);
   25.21      }
   25.22      return parser->flag->str;
   25.23  }
   25.24 @@ -23,7 +23,7 @@
   25.25  /*
   25.26   * Test if the parser has reached the end of the input file
   25.27   */
   25.28 -boolean testcase_parser_at_eof(TestcaseParser *parser)
   25.29 +gboolean testcase_parser_at_eof(TestcaseParser *parser)
   25.30  {
   25.31      return !parser->contents[parser->pos];
   25.32  }
   25.33 @@ -34,15 +34,15 @@
   25.34   * Callers can call testcase_parser_at_eof() when testcase_parser_get_next_tag()
   25.35   * to distinguish EOF and text which isn't a valid tag.
   25.36   */
   25.37 -boolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag,
   25.38 +gboolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag,
   25.39    const char **text)
   25.40  {
   25.41      size_t n;
   25.42      char *eol,*endp;
   25.43 -    String *string;
   25.44 -    mem_free(parser->tag);
   25.45 +    GString *string;
   25.46 +    g_free(parser->tag);
   25.47      parser->tag=NULL;
   25.48 -    mem_free(parser->tag_text);
   25.49 +    g_free(parser->tag_text);
   25.50      parser->tag_text=NULL;
   25.51      (void)testcase_parser_get_flag(parser);
   25.52      if (strncmp(parser->contents+parser->pos,parser->flag->str,
   25.53 @@ -54,15 +54,15 @@
   25.54      endp=eol-parser->flag->len;
   25.55      if (strncmp(endp,parser->flag->str,parser->flag->len))
   25.56  	return FALSE;
   25.57 -    while(endp>parser->contents && isspace(endp[-1]))
   25.58 +    while(endp>parser->contents && g_ascii_isspace(endp[-1]))
   25.59  	endp--;
   25.60      parser->pos+=parser->flag->len;
   25.61 -    while(isspace(parser->contents[parser->pos]))
   25.62 +    while(g_ascii_isspace(parser->contents[parser->pos]))
   25.63  	parser->pos++;
   25.64 -    parser->tag=str_ndup(parser->contents+parser->pos,
   25.65 +    parser->tag=g_strndup(parser->contents+parser->pos,
   25.66        endp-(parser->contents+parser->pos));
   25.67      parser->pos=eol-parser->contents+1;
   25.68 -    string=string_new(NULL);
   25.69 +    string=g_string_new(NULL);
   25.70      while (!testcase_parser_at_eof(parser) &&
   25.71        strncmp(parser->contents+parser->pos,parser->flag->str,parser->flag->len))
   25.72      {
   25.73 @@ -71,12 +71,12 @@
   25.74  	    n=eol-(parser->contents+parser->pos)+1;
   25.75  	else
   25.76  	    n=strlen(parser->contents+parser->pos);
   25.77 -	string_append_len(string,parser->contents+parser->pos,n);
   25.78 +	g_string_append_len(string,parser->contents+parser->pos,n);
   25.79  	parser->pos+=n;
   25.80      }
   25.81 -    parser->tag_text=string_free(string,FALSE);
   25.82 +    parser->tag_text=g_string_free(string,FALSE);
   25.83      if (!parser->tag_text)
   25.84 -	parser->tag_text=str_dup("");
   25.85 +	parser->tag_text=g_strdup("");
   25.86      if (tag)
   25.87  	*tag=parser->tag;
   25.88      if (text)
   25.89 @@ -90,13 +90,13 @@
   25.90  TestcaseParser *testcase_parser_new_from_file(const char *filename)
   25.91  {
   25.92      TestcaseParser *parser;
   25.93 -    parser=mem_new0(TestcaseParser,1);
   25.94 +    parser=g_new0(TestcaseParser,1);
   25.95      if (!file_get_contents_text(filename,&parser->contents,NULL))
   25.96      {
   25.97 -	mem_free(parser);
   25.98 +	g_free(parser);
   25.99  	return NULL;
  25.100      }
  25.101 -    parser->filename=str_dup(filename);
  25.102 +    parser->filename=g_strdup(filename);
  25.103      return parser;
  25.104  }
  25.105  
  25.106 @@ -105,11 +105,11 @@
  25.107   */
  25.108  void testcase_parser_free(TestcaseParser *parser)
  25.109  {
  25.110 -    mem_free(parser->filename);
  25.111 -    mem_free(parser->contents);
  25.112 +    g_free(parser->filename);
  25.113 +    g_free(parser->contents);
  25.114      if (parser->flag)
  25.115 -	string_free(parser->flag,TRUE);
  25.116 -    mem_free(parser->tag);
  25.117 -    mem_free(parser->tag_text);
  25.118 -    mem_free(parser);
  25.119 +	g_string_free(parser->flag,TRUE);
  25.120 +    g_free(parser->tag);
  25.121 +    g_free(parser->tag_text);
  25.122 +    g_free(parser);
  25.123  }
    26.1 --- a/test/harness/testcaseparser.h	Fri Jan 27 10:30:16 2012 +0000
    26.2 +++ b/test/harness/testcaseparser.h	Fri Jan 27 16:18:02 2012 +0000
    26.3 @@ -1,21 +1,22 @@
    26.4  #ifndef TESTCASE_PARSER_H
    26.5  #define TESTCASE_PARSER_H
    26.6  
    26.7 +#include <glib.h>
    26.8  #include <bl/bl.h>
    26.9  
   26.10  typedef struct {
   26.11      char *filename;
   26.12      char *contents;
   26.13 -    String *flag;
   26.14 +    GString *flag;
   26.15      size_t pos;
   26.16      char *tag;
   26.17      char *tag_text;
   26.18  } TestcaseParser;
   26.19  
   26.20  const char *testcase_parser_get_flag(TestcaseParser *parser);
   26.21 -boolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag,
   26.22 +gboolean testcase_parser_get_next_tag(TestcaseParser *parser,const char **tag,
   26.23    const char **text);
   26.24 -boolean testcase_parser_at_eof(TestcaseParser *parser);
   26.25 +gboolean testcase_parser_at_eof(TestcaseParser *parser);
   26.26  TestcaseParser *testcase_parser_new_from_file(const char *filename);
   26.27  void testcase_parser_free(TestcaseParser *parser);
   26.28