home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / kpathsea / lib.h < prev    next >
C/C++ Source or Header  |  1993-10-28  |  6KB  |  143 lines

  1. /* lib.h: declarations for common, low-level routines in kpathsea.
  2.  
  3. Copyright (C) 1992, 93 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #ifndef KPATHSEA_LIB_H
  20. #define KPATHSEA_LIB_H
  21.  
  22.  
  23. #include <kpathsea/types.h>
  24.  
  25. /* Define common sorts of messages.  */
  26.  
  27. /* This should be called only after a system call fails.  Don't exit
  28.    with status `errno', because that might be 256, which would mean
  29.    success (exit statuses are truncated to eight bits).  */
  30. #define FATAL_PERROR(s) do { perror (s); exit (EXIT_FAILURE); } while (0)
  31.  
  32.  
  33. #define START_FATAL() do { fputs ("fatal: ", stderr)
  34. #define END_FATAL() fputs (".\n", stderr); exit (1); } while (0)
  35.  
  36. #define FATAL(str)                            \
  37.   START_FATAL (); fprintf (stderr, "%s", str); END_FATAL ()
  38. #define FATAL1(str, e1)                            \
  39.   START_FATAL (); fprintf (stderr, str, e1); END_FATAL ()
  40. #define FATAL2(str, e1, e2)                        \
  41.   START_FATAL (); fprintf (stderr, str, e1, e2); END_FATAL ()
  42. #define FATAL3(str, e1, e2, e3)                        \
  43.   START_FATAL (); fprintf (stderr, str, e1, e2, e3); END_FATAL ()
  44. #define FATAL4(str, e1, e2, e3, e4)                    \
  45.   START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4); END_FATAL ()
  46. #define FATAL6(str, e1, e2, e3, e4, e5, e6)                \
  47.   START_FATAL (); fprintf (stderr, str, e1, e2, e3, e4, e5, e6); END_FATAL ()
  48.  
  49.  
  50. #define START_WARNING() do { fputs ("warning: ", stderr)
  51. #define END_WARNING() fputs (".\n", stderr); fflush (stderr); } while (0)
  52.  
  53. #define WARNING(str)                            \
  54.   START_WARNING (); fprintf (stderr, "%s", str); END_WARNING ()
  55. #define WARNING1(str, e1)                        \
  56.   START_WARNING (); fprintf (stderr, str, e1); END_WARNING ()
  57. #define WARNING2(str, e1, e2)                        \
  58.   START_WARNING (); fprintf (stderr, str, e1, e2); END_WARNING ()
  59. #define WARNING3(str, e1, e2, e3)                    \
  60.   START_WARNING (); fprintf (stderr, str, e1, e2, e3); END_WARNING ()
  61. #define WARNING4(str, e1, e2, e3, e4)                    \
  62.   START_WARNING (); fprintf (stderr, str, e1, e2, e3, e4); END_WARNING ()
  63.  
  64.  
  65. /* I find this easier to read.  */
  66. #define STREQ(s1, s2) (strcmp (s1, s2) == 0)
  67.  
  68. /* This is the maximum number of numerals that result when a 64-bit
  69.    integer is converted to a string, plus one for a trailing null byte,
  70.    plus one for a sign.  */
  71. #define MAX_INT_LENGTH 21
  72.  
  73. /* If the environment variable TEST is set, return it; otherwise,
  74.    DEFAULT.  This is useful for paths that use more than one envvar.  */
  75. #define ENVVAR(test, default) (getenv (test) ? (test) : (default))
  76.  
  77. /* Return a fresh copy of S1 followed by S2, et al.  */
  78. extern string concat P2H(const_string s1, const_string s2);
  79. extern string concat3 P3H(const_string, const_string, const_string);
  80. /* `concatn' is declared in its own include file, to avoid pulling in
  81.    all the varargs stuff.  */
  82.  
  83. /* A fresh copy of just S.  */
  84. extern string xstrdup P1H(const_string s);
  85.  
  86. /* Convert all lowercase characters in S to uppercase.  */
  87. extern string uppercasify P1H(const_string s);
  88.  
  89. /* Convert the integer I to a string.  */
  90. extern string itoa P1H(int i);
  91.  
  92. /* True if FILENAME1 and FILENAME2 are the same file.  If stat fails on
  93.    either name, returns false, with no error message.  Cf.
  94.    the `SAME_FILE_P' macro in xstat.h.  */
  95. extern boolean same_file_p P2H(const_string filename1, const_string filename2);
  96.  
  97. /* If NAME has a suffix, return a pointer to its first character (i.e.,
  98.    the one after the `.'); otherwise, return NULL.  */
  99. extern string find_suffix P1H(const_string name);
  100.  
  101. /* Return NAME with any suffix removed.  */
  102. extern string remove_suffix P1H(const_string name);
  103.  
  104. /* Return S with the suffix SUFFIX, removing any suffix already present.
  105.    For example, `make_suffix ("/foo/bar.baz", "karl")' returns
  106.    `/foo/bar.karl'.  Returns a string allocated with malloc.  */
  107. extern string make_suffix P2H(const_string s,  const_string suffix);
  108.  
  109. /* Return NAME with STEM_PREFIX prepended to the stem. For example,
  110.    `make_prefix ("/foo/bar.baz", "x")' returns `/foo/xbar.baz'.
  111.    Returns a string allocated with malloc.  */
  112. extern string make_prefix P2H(string stem_prefix, string name);
  113.  
  114. /* If NAME has a suffix, simply return it; otherwise, return
  115.    `NAME.SUFFIX'.  */
  116. extern string extend_filename P2H(const_string name, const_string suffix);
  117.  
  118. /* Call putenv with the string `VAR=VALUE' and abort on error.  */
  119. extern void xputenv P2H(const_string var, const_string value);
  120. extern void xputenv_int P2H(const_string var, int value);
  121.  
  122. /* Like their stdio counterparts, but abort on error, after calling
  123.    perror(3) with FILENAME as its argument.  */
  124. extern FILE *xfopen P2H(const_string filename, const_string mode);
  125. extern void xfclose P2H(FILE *, const_string filename);
  126. extern void xfseek P4H(FILE *, long, int, string filename);
  127. extern unsigned long xftell P2H(FILE *, string filename);
  128.  
  129.  
  130. /* These call the corresponding function in the standard library, and
  131.    abort if those routines fail.  Also, `xrealloc' calls `xmalloc' if
  132.    OLD_ADDRESS is null.  */
  133. extern address xmalloc P1H(unsigned size);
  134. extern address xrealloc P2H(address old_address, unsigned new_size);
  135. extern address xcalloc P2H(unsigned nelem, unsigned elsize);
  136.  
  137. /* (Re)Allocate N items of type T using xmalloc/xrealloc.  */
  138. #define XTALLOC(n, t) ((t *) xmalloc ((n) * sizeof (t)))
  139. #define XTALLOC1(t) XTALLOC (1, t)
  140. #define XRETALLOC(addr, n, t) ((addr) = (t *) xrealloc (addr, (n) * sizeof(t)))
  141.  
  142. #endif /* not KPATHSEA_LIB_H */
  143.