progs.priv.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /****************************************************************************
  2. * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
  3. * *
  4. * Permission is hereby granted, free of charge, to any person obtaining a *
  5. * copy of this software and associated documentation files (the *
  6. * "Software"), to deal in the Software without restriction, including *
  7. * without limitation the rights to use, copy, modify, merge, publish, *
  8. * distribute, distribute with modifications, sublicense, and/or sell *
  9. * copies of the Software, and to permit persons to whom the Software is *
  10. * furnished to do so, subject to the following conditions: *
  11. * *
  12. * The above copyright notice and this permission notice shall be included *
  13. * in all copies or substantial portions of the Software. *
  14. * *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  18. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  21. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  22. * *
  23. * Except as contained in this notice, the name(s) of the above copyright *
  24. * holders shall not be used in advertising or otherwise to promote the *
  25. * sale, use or other dealings in this Software without prior written *
  26. * authorization. *
  27. ****************************************************************************/
  28. /****************************************************************************
  29. * Author: Thomas E. Dickey 1997-on *
  30. ****************************************************************************/
  31. /*
  32. * $Id: progs.priv.h,v 1.34 2008/08/03 17:43:05 tom Exp $
  33. *
  34. * progs.priv.h
  35. *
  36. * Header file for curses utility programs
  37. */
  38. #include <ncurses_cfg.h>
  39. #if USE_RCS_IDS
  40. #define MODULE_ID(id) static const char Ident[] = id;
  41. #else
  42. #define MODULE_ID(id) /*nothing*/
  43. #endif
  44. #include <stdlib.h>
  45. #include <ctype.h>
  46. #include <string.h>
  47. #include <sys/types.h>
  48. #if HAVE_UNISTD_H
  49. #include <unistd.h>
  50. #endif
  51. #if HAVE_SYS_BSDTYPES_H
  52. #include <sys/bsdtypes.h> /* needed for ISC */
  53. #endif
  54. #if HAVE_LIMITS_H
  55. # include <limits.h>
  56. #elif HAVE_SYS_PARAM_H
  57. # include <sys/param.h>
  58. #endif
  59. #if HAVE_DIRENT_H
  60. # include <dirent.h>
  61. # define NAMLEN(dirent) strlen((dirent)->d_name)
  62. # if defined(_FILE_OFFSET_BITS) && defined(HAVE_STRUCT_DIRENT64)
  63. # if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
  64. # define DIRENT struct dirent64
  65. # else
  66. # define DIRENT struct dirent
  67. # endif
  68. # else
  69. # define DIRENT struct dirent
  70. # endif
  71. #else
  72. # define DIRENT struct direct
  73. # define NAMLEN(dirent) (dirent)->d_namlen
  74. # if HAVE_SYS_NDIR_H
  75. # include <sys/ndir.h>
  76. # endif
  77. # if HAVE_SYS_DIR_H
  78. # include <sys/dir.h>
  79. # endif
  80. # if HAVE_NDIR_H
  81. # include <ndir.h>
  82. # endif
  83. #endif
  84. #include <assert.h>
  85. #include <errno.h>
  86. #if DECL_ERRNO
  87. extern int errno;
  88. #endif
  89. #if HAVE_GETOPT_H
  90. #include <getopt.h>
  91. #else
  92. /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its
  93. * variables doesn't hurt.
  94. */
  95. extern char *optarg;
  96. extern int optind;
  97. #endif /* HAVE_GETOPT_H */
  98. #include <curses.h>
  99. #include <term_entry.h>
  100. #include <tic.h>
  101. #include <nc_tparm.h>
  102. #include <nc_alloc.h>
  103. #if HAVE_NC_FREEALL
  104. #undef ExitProgram
  105. #ifdef USE_LIBTINFO
  106. #define ExitProgram(code) _nc_free_tinfo(code)
  107. #else
  108. #define ExitProgram(code) _nc_free_tic(code)
  109. #endif
  110. #endif
  111. /* usually in <unistd.h> */
  112. #ifndef STDOUT_FILENO
  113. #define STDOUT_FILENO 1
  114. #endif
  115. #ifndef STDERR_FILENO
  116. #define STDERR_FILENO 2
  117. #endif
  118. #ifndef EXIT_SUCCESS
  119. #define EXIT_SUCCESS 0
  120. #endif
  121. #ifndef EXIT_FAILURE
  122. #define EXIT_FAILURE 1
  123. #endif
  124. #ifndef R_OK
  125. #define R_OK 4 /* Test for readable. */
  126. #endif
  127. #ifndef W_OK
  128. #define W_OK 2 /* Test for writable. */
  129. #endif
  130. #ifndef X_OK
  131. #define X_OK 1 /* Test for executable. */
  132. #endif
  133. #ifndef F_OK
  134. #define F_OK 0 /* Test for existence. */
  135. #endif
  136. /* usually in <unistd.h> */
  137. #ifndef STDOUT_FILENO
  138. #define STDOUT_FILENO 1
  139. #endif
  140. #ifndef STDERR_FILENO
  141. #define STDERR_FILENO 2
  142. #endif
  143. /* may be in limits.h, included from various places */
  144. #ifndef PATH_MAX
  145. # if defined(_POSIX_PATH_MAX)
  146. # define PATH_MAX _POSIX_PATH_MAX
  147. # elif defined(MAXPATHLEN)
  148. # define PATH_MAX MAXPATHLEN
  149. # else
  150. # define PATH_MAX 255 /* the Posix minimum pathsize */
  151. # endif
  152. #endif
  153. /* We use isascii only to guard against use of 7-bit ctype tables in the
  154. * isprint test in infocmp.
  155. */
  156. #if !HAVE_ISASCII
  157. # undef isascii
  158. # if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
  159. # define isascii(c) (UChar(c) <= 127)
  160. # else
  161. # define isascii(c) 1 /* not really ascii anyway */
  162. # endif
  163. #endif
  164. #define UChar(c) ((unsigned char)(c))
  165. #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))