summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjflick <mjflick>2004-05-16 06:36:14 +0000
committermjflick <mjflick>2004-05-16 06:36:14 +0000
commit7ebb5a4b07a33cbcfdc923e13bb90e6d49ac32a6 (patch)
tree7db7af35b24bc20b51b8e8aa495546afa8c94699
parente81fc7f0fc1e84438da5fca54fc4448880aee5c9 (diff)
downloadfontutils-7ebb5a4b07a33cbcfdc923e13bb90e6d49ac32a6.tar.gz
Primarily needed for XTALLOC macros.
-rw-r--r--include/lib.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/include/lib.h b/include/lib.h
new file mode 100644
index 0000000..218106e
--- /dev/null
+++ b/include/lib.h
@@ -0,0 +1,98 @@
+/* lib.h: declarations for common, low-level routines in kpathsea.
+
+Copyright (C) 1992, 93, 94, 95, 96, 2000 Free Software Foundation, Inc.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef KPATHSEA_LIB_H
+#define KPATHSEA_LIB_H
+
+#include "types.h"
+
+/* Define common sorts of messages. */
+
+/* This should be called only after a system call fails. Don't exit
+ with status `errno', because that might be 256, which would mean
+ success (exit statuses are truncated to eight bits). */
+#define FATAL_PERROR(str) do { \
+ fprintf (stderr, "%s: ", program_invocation_name); \
+ perror (str); exit (EXIT_FAILURE); } while (0)
+
+#define START_FATAL() do { \
+ fprintf (stderr, "%s: fatal: ", program_invocation_name);
+#define END_FATAL() fputs (".\n", stderr); exit (1); } while (0)
+
+#define FATAL(str) \
+ START_FATAL (); fputs (str, stderr); END_FATAL ()
+#define FATAL1(str, e1) \
+ START_FATAL (); fprintf (stderr, str, e1); END_FATAL ()
+#define FATAL2(str, e1, e2) \
+ START_FATAL (); fprintf (stderr, str, e1, e2); END_FATAL ()
+#define FATAL3(str, e1, e2, e3) \
+ START_FATAL (); fprintf (stderr, str, e1, e2, e3); END_FATAL ()
+#define FATAL4(str, e1, e2, e3, e4) \
+ START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4); END_FATAL ()
+#define FATAL5(str, e1, e2, e3, e4, e5) \
+ START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4, e5); END_FATAL ()
+#define FATAL6(str, e1, e2, e3, e4, e5, e6) \
+ START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4, e5, e6); END_FATAL ()
+
+
+#define START_WARNING() do { fputs ("warning: ", stderr)
+#define END_WARNING() fputs (".\n", stderr); fflush (stderr); } while (0)
+
+#define WARNING(str) \
+ START_WARNING (); fputs (str, stderr); END_WARNING ()
+#define WARNING1(str, e1) \
+ START_WARNING (); fprintf (stderr, str, e1); END_WARNING ()
+#define WARNING2(str, e1, e2) \
+ START_WARNING (); fprintf (stderr, str, e1, e2); END_WARNING ()
+#define WARNING3(str, e1, e2, e3) \
+ START_WARNING (); fprintf (stderr, str, e1, e2, e3); END_WARNING ()
+#define WARNING4(str, e1, e2, e3, e4) \
+ START_WARNING (); fprintf (stderr, str, e1, e2, e3, e4); END_WARNING ()
+
+
+/* I find this easier to read. */
+#define STREQ(s1, s2) ((s1) && (s2) && (strcmp (s1, s2) == 0))
+#define STRNEQ(s1, s2, n) ((s1) && (s2) && (strncmp (s1, s2, n) == 0))
+
+/* Support for FAT/ISO-9660 filesystems. Theoretically this should be
+ done at runtime, per filesystem, but that's painful to program. */
+#ifdef MONOCASE_FILENAMES
+#define FILESTRCASEEQ(s1, s2) ((s1) && (s2) && (strcasecmp (s1, s2) == 0))
+#define FILESTRNCASEEQ(s1, s2, l) ((s1) && (s2) && (strncasecmp (s1, s2, l) == 0))
+#define FILECHARCASEEQ(c1, c2) (toupper (c1) == toupper (c2))
+#else
+#define FILESTRCASEEQ STREQ
+#define FILESTRNCASEEQ STRNEQ
+#define FILECHARCASEEQ(c1, c2) ((c1) == (c2))
+#endif
+
+/* This is the maximum number of numerals that result when a 64-bit
+ integer is converted to a string, plus one for a trailing null byte,
+ plus one for a sign. */
+#define MAX_INT_LENGTH 21
+
+/* If the environment variable TEST is set, return it; otherwise,
+ DEFAULT. This is useful for paths that use more than one envvar. */
+#define ENVVAR(test, default) (getenv (test) ? (test) : (default))
+
+/* (Re)Allocate N items of type T using xmalloc/xrealloc. */
+#define XTALLOC(n, t) ((t *) xmalloc ((n) * sizeof (t)))
+#define XTALLOC1(t) XTALLOC (1, t)
+#define XRETALLOC(addr, n, t) ((addr) = (t *) xrealloc (addr, (n) * sizeof(t)))
+
+#endif