home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / sysdeps / unix / errnos-tmpl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-12  |  2.3 KB  |  93 lines

  1. /* Copyright (C) 1991 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with the GNU C Library; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <errno.h>
  19.  
  20. static char iferrno[] = "#ifdef _ERRNO_H";
  21. static char endiferrno[] = "#endif /* <errno.h> included.  */";
  22. static char ifEmath[] = "#if !defined(__Emath_defined) && \
  23.  (defined(_ERRNO_H) || defined(__need_Emath))";
  24. static char endifEmath[] = "#endif /* Emath not defined and <errno.h> \
  25. included or need Emath.  */";
  26.  
  27. static int biggest_value = 0;
  28. static int done_ENOSYS = 0;
  29. static int done_ERANGE = 0, done_EDOM = 0;
  30.  
  31. static void
  32. DO(name, value)
  33.      char *name;
  34.      int value;
  35. {
  36.   int is_ERANGE = !done_ERANGE && !strcmp(name, "ERANGE");
  37.   int is_EDOM = !done_EDOM && !strcmp(name, "EDOM");
  38.   int is_Emath = is_ERANGE || is_EDOM;
  39.  
  40.   if (is_Emath)
  41.     {
  42.       puts(endiferrno);
  43.       puts(ifEmath);
  44.     }
  45.  
  46.   printf("#define %s %d\n", name, value);
  47.  
  48.   if (is_Emath)
  49.     {
  50.       puts(endifEmath);
  51.       puts(iferrno);
  52.     }
  53.  
  54.   if (value > biggest_value)
  55.     biggest_value = value;
  56.  
  57.   if (is_ERANGE)
  58.     done_ERANGE = 1;
  59.   else if (is_EDOM)
  60.     done_EDOM = 1;
  61.   else if (!done_ENOSYS && !strcmp(name, "ENOSYS"))
  62.     done_ENOSYS = 1;
  63. }
  64.  
  65. int
  66. main()
  67. {
  68.   puts(iferrno);
  69.  
  70.   ERRNOS;
  71.  
  72.   if (!done_EDOM || !done_ERANGE)
  73.     {
  74.       puts(endiferrno);
  75.       puts(ifEmath);
  76.       if (!done_EDOM)
  77.     printf("#define EDOM %d\n", ++biggest_value);
  78.       if (!done_ERANGE)
  79.     printf("#define ERANGE %d\n", ++biggest_value);
  80.       puts(endifEmath);
  81.     }
  82.  
  83.   if (!done_ENOSYS)
  84.     printf("#define ENOSYS %d\n", ++biggest_value);
  85.  
  86.   puts(endiferrno);
  87.  
  88.   puts("#undef __need_Emath");
  89.   puts("#ifndef __Emath_defined\n#define __Emath_defined 1\n#endif");
  90.  
  91.   exit(0);
  92. }
  93.