generate_cpp_c_headers.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. # This Python script creates a full set of C++ C header files that
  2. # are missing on some platforms.
  3. #
  4. # Usage:
  5. # mkdir cpp_c_headers
  6. # cd cpp_c_headers
  7. # python generate_cpp_c_headers.py
  8. #
  9. # The files created by this script are in the directory:
  10. # root/boost/compatibility/cpp_c_headers
  11. #
  12. # Supported platforms:
  13. # Compaq Alpha, RedHat 6.2 Linux, Compaq C++ V6.3 (cxx)
  14. # Compaq Alpha, Tru64 Unix V5.0, Compaq C++ V6.2 (cxx)
  15. # Silicon Graphics, IRIX 6.5, MIPSpro Compilers: Version 7.3.1.1m (CC)
  16. #
  17. # Support for additional platforms can be added by extending the
  18. # "defines" Python dictionary below.
  19. #
  20. # Python is available at:
  21. # http://www.python.org/
  22. #
  23. # Copyright (c) 2001 Ralf W. Grosse-Kunstleve.
  24. # Distributed under the Boost Software License, Version 1.0. (See accompany-
  25. # ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  26. #
  27. # Revision history:
  28. # 16 Apr 01 moved to boost CVS tree (R.W. Grosse-Kunstleve)
  29. # 17 Jan 01 Alpha Linux cxx V6.3 support (R.W. Grosse-Kunstleve)
  30. # 15 Dec 00 posted to boost e-group file upload area (R.W. Grosse-Kunstleve)
  31. # Definition of platform specific exclusion of identifiers.
  32. defines = {
  33. 'defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 740': (
  34. 'btowc', 'fwide', 'fwprintf', 'fwscanf', 'mbrlen', 'mbrtowc',
  35. 'mbsinit', 'mbsrtowcs', 'swprintf', 'swscanf', 'towctrans', 'vfwprintf',
  36. 'vswprintf', 'vwprintf', 'wcrtomb', 'wcsrtombs', 'wctob', 'wctrans',
  37. 'wctrans_t', 'wmemchr', 'wmemcmp', 'wmemcpy', 'wmemmove', 'wmemset',
  38. 'wprintf', 'wscanf',
  39. ),
  40. 'defined(__DECCXX_VER) && __DECCXX_VER <= 60290024': (
  41. 'fwide',
  42. ),
  43. 'defined(__linux) && defined(__DECCXX_VER) && __DECCXX_VER <= 60390005': (
  44. 'getwchar', 'ungetwc', 'fgetwc', 'vfwprintf', 'fgetws', 'vswprintf',
  45. 'wcsftime', 'fputwc', 'vwprintf', 'fputws', 'fwide', 'putwc',
  46. 'wprintf', 'fwprintf', 'putwchar', 'wscanf', 'fwscanf', 'swprintf',
  47. 'getwc', 'swscanf',
  48. ),
  49. }
  50. # The information below was copied directly from the file:
  51. # ISO+IEC+14882-1998.pdf
  52. # The exact source of the information is given in the format
  53. # PDF #, p. #, Table #
  54. # Where
  55. # PDF # = page number as shown by the Acrobat Reader
  56. # p. # = page number printed at the bottom of the page
  57. # Table # = number printed in caption of table
  58. hfiles = {
  59. 'cassert': ( # PDF 378, p. 352, Table 25
  60. # Macro: assert
  61. ),
  62. 'cctype': ( # PDF 431, p. 405, Table 45
  63. # Functions:
  64. 'isalnum', 'isdigit', 'isprint', 'isupper', 'tolower',
  65. 'isalpha', 'isgraph', 'ispunct', 'isxdigit', 'toupper',
  66. 'iscntrl', 'islower', 'isspace',
  67. ),
  68. 'cerrno': ( # PDF 378, p. 352, Table 26
  69. # Macros: EDOM ERANGE errno
  70. ),
  71. 'cfloat': ( # PDF 361, p. 335, Table 17
  72. # Macros: DBL_DIG DBL_MIN_EXP FLT_MIN_10_EXP LDBL_MAX_10_EXP
  73. # DBL_EPSILON FLT_DIG FLT_MIN_EXP LDBL_MAX_EXP
  74. # DBL_MANT_DIG FLT_EPSILON FLT_RADIX LDBL_MIN
  75. # DBL_MAX FLT_MANT_DIG FLT_ROUNDS LDBL_MIN_10_EXP
  76. # DBL_MAX_10_EXP FLT_MAX LDBL_DIG LDBL_MIN_EXP
  77. # DBL_MAX_EXP FLT_MAX_10_EXP LDBL_EPSILON
  78. # DBL_MIN FLT_MAX_EXP LDBL_MANT_DIG
  79. # DBL_MIN_10_EXP FLT_MIN LDBL_MAX
  80. ),
  81. #'ciso646': (
  82. #),
  83. 'climits': ( # PDF 361, p. 335, Table 16
  84. # Macros: CHAR_BIT INT_MAX LONG_MIN SCHAR_MIN UCHAR_MAX USHRT_MAX
  85. # CHAR_MAX INT_MIN MB_LEN_MAX SHRT_MAX UINT_MAX
  86. # CHAR_MIN LONG_MAX SCHAR_MAX SHRT_MIN ULONG_MAX
  87. ),
  88. 'clocale': ( # PDF 483, p. 457, Table 62
  89. # Macros: LC_ALL LC_COLLATE LC_CTYPE
  90. # LC_MONETARY LC_NUMERIC LC_TIME
  91. # NULL
  92. # Struct:
  93. 'lconv',
  94. # Functions:
  95. 'localeconv', 'setlocale',
  96. ),
  97. 'cmath': ( # PDF 622, p. 596, Table 80
  98. # Macro: HUGE_VAL
  99. # Functions:
  100. 'acos', 'cos', 'fmod', 'modf', 'tan',
  101. 'asin', 'cosh', 'frexp', 'pow', 'tanh',
  102. 'atan', 'exp', 'ldexp', 'sin',
  103. 'atan2', 'fabs', 'log', 'sinh',
  104. 'ceil', 'floor', 'log10', 'sqrt',
  105. ),
  106. 'csetjmp': ( # PDF 372, p. 346, Table 20
  107. # Macro: setjmp
  108. # Type:
  109. 'jmp_buf',
  110. # Function:
  111. 'longjmp',
  112. ),
  113. 'csignal': ( # PDF 372, p. 346, Table 22
  114. # Macros: SIGABRT SIGILL SIGSEGV SIG_DFL
  115. # SIG_IGN SIGFPE SIGINT SIGTERM SIG_ERR
  116. # Type:
  117. 'sig_atomic_t',
  118. # Functions:
  119. 'raise', 'signal',
  120. ),
  121. 'cstdarg': ( # PDF 372, p. 346, Table 19
  122. # Macros: va_arg va_end va_start
  123. # Type:
  124. 'va_list',
  125. ),
  126. 'cstddef': ( # PDF 353, p. 327, Table 15
  127. # Macros: NULL offsetof
  128. # Types:
  129. 'ptrdiff_t', 'size_t',
  130. ),
  131. 'cstdio': ( # PDF 692, p. 666, Table 94
  132. # Macros: BUFSIZ FOPEN_MAX SEEK_CUR TMP_MAX _IONBF stdout
  133. # EOF L_tmpnam SEEK_END _IOFBF stderr
  134. # FILENAME_MAX NULL <cstdio> SEEK_SET _IOLBF stdin
  135. # Types:
  136. 'FILE', 'fpos_t', 'size_t',
  137. # Functions:
  138. 'clearerr', 'fgets', 'fscanf', 'gets', 'rename', 'tmpfile',
  139. 'fclose', 'fopen', 'fseek', 'perror', 'rewind', 'tmpnam',
  140. 'feof', 'fprintf', 'fsetpos', 'printf', 'scanf', 'ungetc',
  141. 'ferror', 'fputc', 'ftell', 'putc', 'setbuf', 'vfprintf',
  142. 'fflush', 'fputs', 'fwrite', 'putchar', 'setvbuf', 'vprintf',
  143. 'fgetc', 'fread', 'getc', 'puts', 'sprintf', 'vsprintf',
  144. 'fgetpos', 'freopen', 'getchar', 'remove', 'sscanf',
  145. ),
  146. 'cstdlib': ( # PDF 362, p. 336, Table 18
  147. # Macros: EXIT_FAILURE EXIT_SUCCESS
  148. # Functions:
  149. 'abort', 'atexit', 'exit',
  150. # PDF 373, p. 347, Table 23
  151. # Functions:
  152. 'getenv', 'system',
  153. # PDF 400, p. 374, Table 33
  154. # Functions:
  155. 'calloc', 'malloc',
  156. 'free', 'realloc',
  157. # PDF 433, p. 417, Table 49
  158. # Macros: MB_CUR_MAX
  159. # Functions:
  160. 'atol', 'mblen', 'strtod', 'wctomb',
  161. 'atof', 'mbstowcs', 'strtol', 'wcstombs',
  162. 'atoi', 'mbtowc', 'strtoul',
  163. # PDF 589, p. 563, Table 78
  164. # Functions:
  165. 'bsearch', 'qsort',
  166. # PDF 622, p. 596, Table 81
  167. # Macros: RAND_MAX
  168. # Types:
  169. 'div_t', 'ldiv_t',
  170. # Functions:
  171. 'abs', 'labs', 'srand',
  172. 'div', 'ldiv', 'rand',
  173. ),
  174. 'cstring': ( # PDF 401, p. 375, Table 34
  175. # Macro: NULL
  176. # Type: size_t
  177. # Functions:
  178. # 'memchr', 'memcmp',
  179. # 'memcpy', 'memmove', 'memset',
  180. # PDF 432, p. 406, Table 47
  181. # Macro: NULL
  182. # Type:
  183. 'size_t',
  184. # Functions:
  185. 'memchr', 'strcat', 'strcspn', 'strncpy', 'strtok',
  186. 'memcmp', 'strchr', 'strerror', 'strpbrk', 'strxfrm',
  187. 'memcpy', 'strcmp', 'strlen', 'strrchr',
  188. 'memmove', 'strcoll', 'strncat', 'strspn',
  189. 'memset', 'strcpy', 'strncmp', 'strstr',
  190. ),
  191. 'ctime': ( # PDF 372, p. 346, Table 21
  192. # Macros: CLOCKS_PER_SEC
  193. # Types:
  194. # 'clock_t',
  195. # Functions:
  196. # 'clock',
  197. # PDF 401, p. 375, Table 35
  198. # Macros: NULL
  199. # Types:
  200. 'size_t', 'clock_t', 'time_t',
  201. # Struct:
  202. 'tm',
  203. # Functions:
  204. 'asctime', 'clock', 'difftime', 'localtime', 'strftime',
  205. 'ctime', 'gmtime', 'mktime', 'time',
  206. ),
  207. 'cwchar': ( # PDF 432, p. 406, Table 48
  208. # Macros: NULL WCHAR_MAX WCHAR_MIN WEOF
  209. # Types:
  210. 'mbstate_t', 'wint_t', 'size_t',
  211. # Functions:
  212. 'btowc', 'getwchar', 'ungetwc', 'wcscpy', 'wcsrtombs', 'wmemchr',
  213. 'fgetwc', 'mbrlen', 'vfwprintf', 'wcscspn', 'wcsspn', 'wmemcmp',
  214. 'fgetws', 'mbrtowc', 'vswprintf', 'wcsftime', 'wcsstr', 'wmemcpy',
  215. 'fputwc', 'mbsinit', 'vwprintf', 'wcslen', 'wcstod', 'wmemmove',
  216. 'fputws', 'mbsrtowcs', 'wcrtomb', 'wcsncat', 'wcstok', 'wmemset',
  217. 'fwide', 'putwc', 'wcscat', 'wcsncmp', 'wcstol', 'wprintf',
  218. 'fwprintf', 'putwchar', 'wcschr', 'wcsncpy', 'wcstoul', 'wscanf',
  219. 'fwscanf', 'swprintf', 'wcscmp', 'wcspbrk', 'wcsxfrm',
  220. 'getwc', 'swscanf', 'wcscoll', 'wcsrchr', 'wctob',
  221. ),
  222. 'cwctype': ( # PDF 432, p. 406, Table 46
  223. # Macro: WEOF
  224. # Types:
  225. 'wctrans_t', 'wctype_t', 'wint_t',
  226. # Functions:
  227. 'iswalnum', 'iswctype', 'iswlower', 'iswspace', 'towctrans', 'wctrans',
  228. 'iswalpha', 'iswdigit', 'iswprint', 'iswupper', 'towlower', 'wctype',
  229. 'iswcntrl', 'iswgraph', 'iswpunct', 'iswxdigit', 'towupper',
  230. ),
  231. }
  232. if (__name__ == "__main__"):
  233. import sys, string, time
  234. now = time.asctime(time.localtime(time.time())) + ' ' + str(time.tzname)
  235. for hfile in hfiles.keys():
  236. HFILE = string.upper(hfile)
  237. f = open(hfile, 'w')
  238. sys.stdout = f
  239. print '// This file is automatically generated. Do not edit.'
  240. print '//', sys.argv
  241. print '//', now
  242. print
  243. print '#ifndef __' + HFILE + '_HEADER'
  244. print '#define __' + HFILE + '_HEADER'
  245. print ''
  246. print '#include <' + hfile[1:] + '.h>'
  247. print ''
  248. if (len(hfiles[hfile]) > 0):
  249. print 'namespace std {'
  250. for s in hfiles[hfile]:
  251. n_endif = 0
  252. for d in defines.keys():
  253. if (s in defines[d]):
  254. print '#if !(' + d + ')'
  255. n_endif = n_endif + 1
  256. print ' using ::' + s + ';'
  257. for i in xrange(n_endif): print '#endif'
  258. print '}'
  259. print ''
  260. print '#endif // ' + HFILE + '_HEADER'
  261. sys.stdout = sys.__stdout__