summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2001-03-09 13:24:42 +0000
committerBruno Haible <bruno@clisp.org>2001-03-09 13:24:42 +0000
commit3947315a75d75d41e152e36ec9a657a7cc229f0c (patch)
treeb00ca0ccbc267067a12899d6b22d3f7d0c49deac /lib
parent658874b92b49954a6f8f3d8640efee298294b2bf (diff)
downloadexternal_gettext-3947315a75d75d41e152e36ec9a657a7cc229f0c.zip
external_gettext-3947315a75d75d41e152e36ec9a657a7cc229f0c.tar.gz
external_gettext-3947315a75d75d41e152e36ec9a657a7cc229f0c.tar.bz2
Support for Win32, OS/2, DOS pathnames, and other things needed for DJGPP.
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog9
-rw-r--r--lib/Makefile.am5
-rw-r--r--lib/concatpath.c67
-rw-r--r--lib/system.h42
4 files changed, 120 insertions, 3 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 973a85e..6dc88b5 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,12 @@
+2001-03-04 Bruno Haible <haible@clisp.cons.org>
+
+ * system.h (ISSLASH, HAS_DEVICE, IS_ABSOLUTE_PATH, IS_PATH_WITH_DIR,
+ FILESYSTEM_PREFIX_LEN): New macros.
+ (concatenated_pathname): New declaration.
+ (SET_BINARY): New macro.
+ * concatpath.c: New file.
+ * Makefile.am (libnlsut_a_SOURCES): Add concatpath.c.
+
2001-03-03 Bruno Haible <haible@clisp.cons.org>
* gen-lbrkprop.c: New file.
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9059a5a..4df9dd6 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -26,8 +26,9 @@ printf-prs.c ref-add.sin ref-del.sin stpcpy.c stpncpy.c strcasecmp.c \
strcspn.c strncasecmp.c strstr.c strtol.c strtoul.c vasprintf.c \
gen-lbrkprop.c 3level.h
-libnlsut_a_SOURCES = basename.c c-ctype.c fstrcmp.c getopt.c getopt1.c \
-hash.c linebreak.c localcharset.c obstack.c xgetcwd.c xmalloc.c xstrdup.c
+libnlsut_a_SOURCES = basename.c c-ctype.c concatpath.c fstrcmp.c \
+getopt.c getopt1.c hash.c linebreak.c localcharset.c obstack.c xgetcwd.c \
+xmalloc.c xstrdup.c
libnlsut_a_LIBADD = @ALLOCA@ @LIBOBJS@
diff --git a/lib/concatpath.c b/lib/concatpath.c
new file mode 100644
index 0000000..e229cdb
--- /dev/null
+++ b/lib/concatpath.c
@@ -0,0 +1,67 @@
+/* Construct a full pathname from a directory and a filename.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+
+ 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
+
+/* Written by Bruno Haible <haible@clisp.cons.org>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "system.h"
+
+/* Concatenate a directory pathname, a relative pathname and an optional
+ suffix. The directory may end with the directory separator. The second
+ argument may not start with the directory separator (it is relative).
+ Return a freshly allocated pathname. */
+char *
+concatenated_pathname (directory, filename, suffix)
+ const char *directory;
+ const char *filename;
+ const char *suffix;
+{
+ char *result;
+ char *p;
+
+ if (strcmp (directory, ".") == 0)
+ {
+ /* No need to prepend the directory. */
+ result = (char *) xmalloc (strlen (filename)
+ + (suffix != NULL ? strlen (suffix) : 0)
+ + 1);
+ p = result;
+ }
+ else
+ {
+ size_t directory_len = strlen (directory);
+ int need_slash =
+ (directory_len > FILESYSTEM_PREFIX_LEN (directory)
+ && !ISSLASH (directory[directory_len - 1]));
+ result = (char *) xmalloc (directory_len + need_slash
+ + strlen (filename)
+ + (suffix != NULL ? strlen (suffix) : 0)
+ + 1);
+ memcpy (result, directory, directory_len);
+ p = result + directory_len;
+ if (need_slash)
+ *p++ = '/';
+ }
+ p = stpcpy (p, filename);
+ if (suffix != NULL)
+ stpcpy (p, suffix);
+ return result;
+}
diff --git a/lib/system.h b/lib/system.h
index 1708a49..0971ea5 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -121,6 +121,36 @@ char *alloca ();
#endif
+/* Pathname support.
+ ISSLASH(C) tests whether C is a directory separator character.
+ IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not,
+ it may be concatenated to a directory pathname.
+ IS_PATH_WITH_DIR(P) tests whether P contains a directory specification.
+ */
+#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
+ /* Win32, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+# define HAS_DEVICE(P) \
+ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+ && (P)[1] == ':')
+# define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
+# define IS_PATH_WITH_DIR(P) \
+ (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
+# define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
+#else
+ /* Unix */
+# define ISSLASH(C) ((C) == '/')
+# define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
+# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
+# define FILESYSTEM_PREFIX_LEN(P) 0
+#endif
+
+/* Concatenate a directory pathname, a relative pathname and an optional
+ suffix. Return a freshly allocated pathname. */
+extern char *concatenated_pathname PARAMS ((const char *directory,
+ const char *filename,
+ const char *suffix));
+
/* When not using the GNU libc we use the basename implementation we
provide here. */
#ifndef __GNU_LIBRARY__
@@ -147,8 +177,18 @@ extern char *gnu_basename PARAMS ((const char *));
# define setmode _setmode
# define fileno _fileno
# endif
+# ifdef __DJGPP__
+# include <io.h> /* declares setmode() */
+# include <unistd.h> /* declares isatty() */
+# /* Avoid putting stdin/stdout in binary mode if it is connected to the
+# console, because that would make it impossible for the user to
+# interrupt the program through Ctrl-C or Ctrl-Break. */
+# define SET_BINARY(fd) (!isatty(fd) ? (setmode(fd,O_BINARY), 0) : 0)
+# else
+# define SET_BINARY(fd) setmode(fd,O_BINARY)
+# endif
#else
-# define setmode(fd, mode) /* nothing */
+# define SET_BINARY(fd) /* nothing */
#endif
#endif