Fix a bug causing plover_get_program_directory() to fail when executable is in a root directory
authorJ. Ali Harlow <ali@juiblex.co.uk>
Wed Sep 12 16:37:13 2018 +0100 (2018-09-12)
changeset 81734c6230e41f
parent 80 671df13f1304
child 82 cbb109374de3
Fix a bug causing plover_get_program_directory() to fail when executable is in a root directory
plover/Makefile.am
plover/ascii-ctype.h
plover/uri-handler.c
plover/util.c
     1.1 --- a/plover/Makefile.am	Wed Aug 22 23:29:22 2018 +0100
     1.2 +++ b/plover/Makefile.am	Wed Sep 12 16:37:13 2018 +0100
     1.3 @@ -11,7 +11,8 @@
     1.4  lib_LTLIBRARIES=libplover.la
     1.5  libplover_la_SOURCES=$(pkginclude_HEADERS) util.c import-yum.c razor.c comps.c \
     1.6  	log.c vector.c transaction.c package.c packageset.c repository.c \
     1.7 -	uri-handler.c uri-handler.h inputstream.c exception-handler.cpp
     1.8 +	uri-handler.c uri-handler.h inputstream.c exception-handler.cpp \
     1.9 +	ascii-ctype.h
    1.10  
    1.11  pkgconfigdir=$(libdir)/pkgconfig
    1.12  pkgconfig_DATA=plover.pc
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/plover/ascii-ctype.h	Wed Sep 12 16:37:13 2018 +0100
     2.3 @@ -0,0 +1,35 @@
     2.4 +/*
     2.5 + * Copyright (C) 2016, 2018  J. Ali Harlow <ali@juiblex.co.uk>
     2.6 + *
     2.7 + * This program is free software; you can redistribute it and/or modify
     2.8 + * it under the terms of the GNU General Public License as published by
     2.9 + * the Free Software Foundation; either version 2 of the License, or
    2.10 + * (at your option) any later version.
    2.11 + *
    2.12 + * This program is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 + * GNU General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU General Public License along
    2.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
    2.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    2.20 + */
    2.21 +
    2.22 +#ifndef __ASCII_CTYPE_H__
    2.23 +#define __ASCII_CTYPE_H__
    2.24 +
    2.25 +/*
    2.26 + * Avoid g_ascii_ family because of complications with static builds
    2.27 + * of glib2 under Windows. The real problem is probably in how glib2
    2.28 + * is packaged for cross-compiling in certain distributions, but it's
    2.29 + * easy enough to work around.
    2.30 + */
    2.31 +
    2.32 +#define ascii_islower(c) ((c) >= 'a' && (c) <= 'z')
    2.33 +#define ascii_isupper(c) ((c) >= 'Z' && (c) <= 'Z')
    2.34 +#define ascii_isdigit(c) ((c) >= '0' && (c) <= '9')
    2.35 +#define ascii_isalpha(c) (ascii_islower(c) || ascii_isupper(c))
    2.36 +#define ascii_isalnum(c) (ascii_isalpha(c) || ascii_isdigit(c))
    2.37 +
    2.38 +#endif /* __ASCII_CTYPE_H__ */
     3.1 --- a/plover/uri-handler.c	Wed Aug 22 23:29:22 2018 +0100
     3.2 +++ b/plover/uri-handler.c	Wed Sep 12 16:37:13 2018 +0100
     3.3 @@ -25,16 +25,7 @@
     3.4  #include "config.h"
     3.5  #include "plover/plover.h"
     3.6  #include "uri-handler.h"
     3.7 -
     3.8 -/*
     3.9 - * Avoid g_ascii_ family because of complications with static builds
    3.10 - * of glib2 under Windows. The real problem is probably in how glib2
    3.11 - * is packaged for cross-compiling in certain distributions, but it's
    3.12 - * easy enough to work around.
    3.13 - */
    3.14 -
    3.15 -#define ascii_isalpha(c) ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z')
    3.16 -#define ascii_isalnum(c) (ascii_isalpha(c) || (c) >= '0' && (c) <= '9')
    3.17 +#include "ascii-ctype.h"
    3.18  
    3.19  static gboolean has_valid_scheme(const char *uri)
    3.20  {
     4.1 --- a/plover/util.c	Wed Aug 22 23:29:22 2018 +0100
     4.2 +++ b/plover/util.c	Wed Sep 12 16:37:13 2018 +0100
     4.3 @@ -28,6 +28,7 @@
     4.4  #include <glib/gstdio.h>
     4.5  #include "config.h"
     4.6  #include "plover.h"
     4.7 +#include "ascii-ctype.h"
     4.8  
     4.9  gchar *plover_comps_get_default_prefix(struct comps *comps)
    4.10  {
    4.11 @@ -269,11 +270,20 @@
    4.12      else
    4.13  	s=strrchr(path,'\\');
    4.14      if (s)
    4.15 -	*s='\0';
    4.16 +    {
    4.17 +	if (s==path)
    4.18 +	    s[1]='\0';		/* Eg., "\" (impossible) */
    4.19 +	else if (s-path==2 && ascii_isalpha(path[0]) && path[1]==':')
    4.20 +	    s[1]='\0';		/* Eg., "C:\" */
    4.21 +	else
    4.22 +	    s[0]='\0';
    4.23 +    }
    4.24      return strdup(path);
    4.25  #else
    4.26      s=argv0?strrchr(argv0,'/'):NULL;
    4.27 -    if (s)
    4.28 +    if (s==argv0)
    4.29 +	return strdup("/");
    4.30 +    else if (s)
    4.31  	return strndup(argv0,s-argv0);
    4.32      else
    4.33  	return strdup(".");