# HG changeset patch # User J. Ali Harlow # Date 1536766633 -3600 # Node ID 734c6230e41f2619b7775191260728ea2eaaabdb # Parent 671df13f1304ce78c701d37a8144a2eea052d8d1 Fix a bug causing plover_get_program_directory() to fail when executable is in a root directory diff -r 671df13f1304 -r 734c6230e41f plover/Makefile.am --- a/plover/Makefile.am Wed Aug 22 23:29:22 2018 +0100 +++ b/plover/Makefile.am Wed Sep 12 16:37:13 2018 +0100 @@ -11,7 +11,8 @@ lib_LTLIBRARIES=libplover.la libplover_la_SOURCES=$(pkginclude_HEADERS) util.c import-yum.c razor.c comps.c \ log.c vector.c transaction.c package.c packageset.c repository.c \ - uri-handler.c uri-handler.h inputstream.c exception-handler.cpp + uri-handler.c uri-handler.h inputstream.c exception-handler.cpp \ + ascii-ctype.h pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=plover.pc diff -r 671df13f1304 -r 734c6230e41f plover/ascii-ctype.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plover/ascii-ctype.h Wed Sep 12 16:37:13 2018 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016, 2018 J. Ali Harlow + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __ASCII_CTYPE_H__ +#define __ASCII_CTYPE_H__ + +/* + * Avoid g_ascii_ family because of complications with static builds + * of glib2 under Windows. The real problem is probably in how glib2 + * is packaged for cross-compiling in certain distributions, but it's + * easy enough to work around. + */ + +#define ascii_islower(c) ((c) >= 'a' && (c) <= 'z') +#define ascii_isupper(c) ((c) >= 'Z' && (c) <= 'Z') +#define ascii_isdigit(c) ((c) >= '0' && (c) <= '9') +#define ascii_isalpha(c) (ascii_islower(c) || ascii_isupper(c)) +#define ascii_isalnum(c) (ascii_isalpha(c) || ascii_isdigit(c)) + +#endif /* __ASCII_CTYPE_H__ */ diff -r 671df13f1304 -r 734c6230e41f plover/uri-handler.c --- a/plover/uri-handler.c Wed Aug 22 23:29:22 2018 +0100 +++ b/plover/uri-handler.c Wed Sep 12 16:37:13 2018 +0100 @@ -25,16 +25,7 @@ #include "config.h" #include "plover/plover.h" #include "uri-handler.h" - -/* - * Avoid g_ascii_ family because of complications with static builds - * of glib2 under Windows. The real problem is probably in how glib2 - * is packaged for cross-compiling in certain distributions, but it's - * easy enough to work around. - */ - -#define ascii_isalpha(c) ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z') -#define ascii_isalnum(c) (ascii_isalpha(c) || (c) >= '0' && (c) <= '9') +#include "ascii-ctype.h" static gboolean has_valid_scheme(const char *uri) { diff -r 671df13f1304 -r 734c6230e41f plover/util.c --- a/plover/util.c Wed Aug 22 23:29:22 2018 +0100 +++ b/plover/util.c Wed Sep 12 16:37:13 2018 +0100 @@ -28,6 +28,7 @@ #include #include "config.h" #include "plover.h" +#include "ascii-ctype.h" gchar *plover_comps_get_default_prefix(struct comps *comps) { @@ -269,11 +270,20 @@ else s=strrchr(path,'\\'); if (s) - *s='\0'; + { + if (s==path) + s[1]='\0'; /* Eg., "\" (impossible) */ + else if (s-path==2 && ascii_isalpha(path[0]) && path[1]==':') + s[1]='\0'; /* Eg., "C:\" */ + else + s[0]='\0'; + } return strdup(path); #else s=argv0?strrchr(argv0,'/'):NULL; - if (s) + if (s==argv0) + return strdup("/"); + else if (s) return strndup(argv0,s-argv0); else return strdup(".");