home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / sel2path / global.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-18  |  8.0 KB  |  214 lines

  1. /* global.h: extend the standard programming environment a little.  This
  2.    is included from config.h, which everyone includes.
  3.  
  4. Copyright (C) 1992 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef GLOBAL_H
  21. #define GLOBAL_H
  22.  
  23. #include <stdlib.h>
  24.  
  25. #include "types.h"
  26.  
  27. /* Define common sorts of messages.  */
  28.  
  29. /* This should be called only after a system call fails.  */
  30. #define FATAL_PERROR(s) do { perror (s); exit (errno); } 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(x)                            \
  37.   START_FATAL (); fprintf (stderr, "%s", x); END_FATAL ()
  38. #define FATAL1(s, e1)                            \
  39.   START_FATAL (); fprintf (stderr, s, e1); END_FATAL ()
  40. #define FATAL2(s, e1, e2)                        \
  41.   START_FATAL (); fprintf (stderr, s, e1, e2); END_FATAL ()
  42. #define FATAL3(s, e1, e2, e3)                        \
  43.   START_FATAL (); fprintf (stderr, s, e1, e2, e3); END_FATAL ()
  44. #define FATAL4(s, e1, e2, e3, e4)                    \
  45.   START_FATAL (); fprintf (stderr, s, e1, e2, e3, e4); END_FATAL ()
  46.  
  47.  
  48. #define START_WARNING() do { fputs ("warning: ", stderr)
  49. #define END_WARNING() fputs (".\n", stderr); fflush (stderr); } while (0)
  50.  
  51. #define WARNING(x)                            \
  52.   START_WARNING (); fprintf (stderr, "%s", x); END_WARNING ()
  53. #define WARNING1(s, e1)                            \
  54.   START_WARNING (); fprintf (stderr, s, e1); END_WARNING ()
  55. #define WARNING2(s, e1, e2)                        \
  56.   START_WARNING (); fprintf (stderr, s, e1, e2); END_WARNING ()
  57. #define WARNING3(s, e1, e2, e3)                        \
  58.   START_WARNING (); fprintf (stderr, s, e1, e2, e3); END_WARNING ()
  59. #define WARNING4(s, e1, e2, e3, e4)                    \
  60.   START_WARNING (); fprintf (stderr, s, e1, e2, e3, e4); END_WARNING ()
  61.  
  62. /* Define useful abbreviations.  */
  63.  
  64. /* This is the maximum number of numerals that result when a 64-bit
  65.    integer is converted to a string, plus one for a trailing null byte,
  66.    plus one for a sign.  */
  67. #define MAX_INT_LENGTH 21
  68.  
  69. /* Printer's points, as defined by TeX (and good typesetters everywhere).  */
  70. #define POINTS_PER_INCH  72.27
  71.  
  72. /* Convert a number V in pixels to printer's points, and vice versa,
  73.    assuming a resolution of DPI pixels per inch.  */
  74. #define PIXELS_TO_POINTS(v, dpi) (POINTS_PER_INCH * (v) / (dpi))
  75. #define POINTS_TO_REAL_PIXELS(v, dpi) ((v) * (dpi) / POINTS_PER_INCH)
  76. #define POINTS_TO_PIXELS(v, dpi) ((int) (POINTS_TO_REAL_PIXELS (v, dpi) + .5))
  77.  
  78. /* Some simple numeric operations.  It is possible to define these much
  79.    more cleanly in GNU C, but we haven't done that (yet).  */
  80. #define SQUARE(x) ((x) * (x))
  81. #define CUBE(x) ((x) * (x) * (x))
  82. #define    SAME_SIGN(u,v) ((u) >= 0 && (v) >= 0 || (u) < 0 && (v) < 0)
  83. #define SIGN(x) ((x) > 0 ? 1 : (x) < 0 ? -1 : 0)
  84. #define SROUND(x) ((int) ((int) (x) + .5 * SIGN (x)))
  85.  
  86. #ifndef MAX
  87. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  88. #endif
  89. #ifndef MIN
  90. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  91. #endif
  92.  
  93. /* Too bad C doesn't define operators for these.  */
  94. #define MAX_EQUALS(var, expr) if ((expr) > (var)) (var) = (expr)
  95. #define MIN_EQUALS(var, expr) if ((expr) < (var)) (var) = (expr)
  96.  
  97. #define STREQ(s1, s2) (strcmp (s1, s2) == 0)
  98.  
  99. /* Declarations for commonly-used routines we provide ourselves.  The
  100.    ones here are only needed by us, so we do not provide them in
  101.    unprototyped form.  Others are declared both ways in lib.h.  */
  102.  
  103. #if 0                /* These aren't actually defined anywhere */
  104. /* Return the current date and time a la date(1).  */
  105. extern string now (void);
  106.  
  107. /* Check if a string is a valid floating-point or decimal integer.
  108.    Returns false if passed NULL.  */
  109. extern boolean float_ok (string);
  110. extern boolean integer_ok (string);
  111.  
  112. /* Like `atoi', but disallow negative numbers.  */
  113. extern const unsigned atou (string);
  114.  
  115. /* The converses of atoi, atou, and atof.  These all return dynamically
  116.    allocated strings.  `dtoa' is so-named because `ftoa' is a library
  117.    function on some systems (the IBM RT), and the loader complains that
  118.    is defined twice, for reasons I don't understand.  */
  119. extern string itoa (int);
  120. extern string utoa (unsigned);
  121. extern string dtoa (double);
  122.  
  123. #endif
  124.  
  125. /* Like their stdio counterparts, but abort on error, after calling
  126.    perror(3) with FILENAME as its argument.  */
  127. /* extern FILE *xfopen (string filename, string mode); */
  128. /* extern void xfclose (FILE *, string filename); */
  129. /* extern void xfseek (FILE *, long, int, string filename); */
  130. /* extern four_bytes xftell (FILE *, string filename); */
  131.  
  132. /* Copies the file FROM to the file TO, then unlinks FROM.  */
  133. extern void xrename (string from, string to);
  134.  
  135. /* Return NAME with any leading path stripped off.  This returns a
  136.    pointer into NAME.  */
  137. /* ALT extern string basename (string name); */
  138.  
  139.  
  140.  
  141. /* If P or *P is null, abort.  Otherwise, call free(3) on P,
  142.    and then set *P to NULL.  */
  143. extern void safe_free (address *p);
  144.  
  145.  
  146. /* Math functions.  */
  147.  
  148. /* Says whether V1 and V2 are within REAL_EPSILON of each other.
  149.    Fixed-point arithmetic would be better, to guarantee machine
  150.    independence, but it's so much more painful to work with.  The value
  151.    here is smaller than can be represented in either a `fix_word' or a
  152.    `scaled_num', so more precision than this will be lost when we
  153.    output, anyway.  */
  154. #define REAL_EPSILON 0.00001
  155. extern boolean epsilon_equal (real v1, real v2);
  156.  
  157. /* Arc cosine, in degrees.  */
  158. extern real my_acosd (real);
  159.  
  160. /* Return the Euclidean distance between the two points.  */
  161. extern real distance (real_coordinate_type, real_coordinate_type);
  162. extern real int_distance (coordinate_type, coordinate_type);
  163.  
  164. /* Slope between two points (delta y per unit x).  */
  165. extern real slope (real_coordinate_type, real_coordinate_type);
  166.  
  167. /* Make a real coordinate from an integer one, and vice versa.  */
  168. extern real_coordinate_type int_to_real_coord (coordinate_type);
  169. extern coordinate_type real_to_int_coord (real_coordinate_type);
  170.  
  171. /* Test if two integer points are adjacent.  */
  172. extern boolean points_adjacent_p (int row1, int col1, int r2, int c2);
  173.  
  174. /* Find the largest and smallest elements of an array.  */
  175. extern void find_bounds (real values[], unsigned value_count,
  176.                      /* returned: */ real *the_min, real *the_max);
  177.  
  178. /* Make all the elements in the array between zero and one.  */
  179. extern real *map_to_unit (real * values, unsigned value_count);
  180.  
  181.  
  182. /* String functions.  */
  183.  
  184. /* Return (a fresh copy of) SOURCE beginning at START and ending at
  185.    LIMIT.  (Or NULL if LIMIT < START.)  */
  186. extern string substring (string source, const unsigned start,
  187.                          const unsigned limit);
  188.  
  189. /* Change all uppercase letters in S to lowercase.  */
  190. extern string lowercasify (string s);
  191.  
  192.  
  193. /* Character code parsing.  */
  194.  
  195. /* If the string S parses as a character code, this sets *VALID to
  196.    `true' and returns the number.  If it doesn't, it sets *VALID to
  197.    `false' and the return value is garbage.
  198.    
  199.    We allow any of the following possibilies: a single character, as in
  200.    `a' or `0'; a decimal number, as in `21'; an octal number, as in `03'
  201.    or `0177'; a hexadecimal number, as in `0x3' or `0xff'.  */
  202. extern charcode_type parse_charcode (string s, boolean *valid);
  203.  
  204. /* Like `parse_charcode', but gives a fatal error if the string isn't a
  205.    valid character code.  */
  206. extern charcode_type xparse_charcode (string s);
  207.  
  208. /* The environment variable name with which to look up auxiliary files.  */
  209. #ifndef LIB_ENVVAR
  210. #define LIB_ENVVAR "FONTUTIL_LIB"
  211. #endif
  212.  
  213. #endif /* not GLOBAL_H */
  214.