tool_vms.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "tool_setup.h"
  25. #ifdef __VMS
  26. #if defined(__DECC) && !defined(__VAX) && \
  27. defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
  28. #include <unixlib.h>
  29. #endif
  30. #define ENABLE_CURLX_PRINTF
  31. #include "curlx.h"
  32. #include "curlmsg_vms.h"
  33. #include "tool_vms.h"
  34. #include "memdebug.h" /* keep this as LAST include */
  35. void decc$__posix_exit(int __status);
  36. void decc$exit(int __status);
  37. static int vms_shell = -1;
  38. /* VMS has a DCL shell and also has Unix shells ported to it.
  39. * When curl is running under a Unix shell, we want it to be as much
  40. * like Unix as possible.
  41. */
  42. int is_vms_shell(void)
  43. {
  44. char *shell;
  45. /* Have we checked the shell yet? */
  46. if(vms_shell >= 0)
  47. return vms_shell;
  48. shell = getenv("SHELL");
  49. /* No shell, means DCL */
  50. if(!shell) {
  51. vms_shell = 1;
  52. return 1;
  53. }
  54. /* Have to make sure some one did not set shell to DCL */
  55. if(strcmp(shell, "DCL") == 0) {
  56. vms_shell = 1;
  57. return 1;
  58. }
  59. vms_shell = 0;
  60. return 0;
  61. }
  62. /*
  63. * VMS has two exit() routines. When running under a Unix style shell, then
  64. * Unix style and the __posix_exit() routine is used.
  65. *
  66. * When running under the DCL shell, then the VMS encoded codes and decc$exit()
  67. * is used.
  68. *
  69. * We can not use exit() or return a code from main() because the actual
  70. * routine called depends on both the compiler version, compile options, and
  71. * feature macro settings, and one of the exit routines is hidden at compile
  72. * time.
  73. *
  74. * Since we want Curl to work properly under the VMS DCL shell and Unix
  75. * shells under VMS, this routine should compile correctly regardless of
  76. * the settings.
  77. */
  78. void vms_special_exit(int code, int vms_show)
  79. {
  80. int vms_code;
  81. /* The Posix exit mode is only available after VMS 7.0 */
  82. #if __CRTL_VER >= 70000000
  83. if(is_vms_shell() == 0) {
  84. decc$__posix_exit(code);
  85. }
  86. #endif
  87. if(code > CURL_LAST) { /* If CURL_LAST exceeded then */
  88. vms_code = CURL_LAST; /* curlmsg.h is out of sync. */
  89. }
  90. else {
  91. vms_code = vms_cond[code] | vms_show;
  92. }
  93. decc$exit(vms_code);
  94. }
  95. #if defined(__DECC) && !defined(__VAX) && \
  96. defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
  97. /*
  98. * 2004-09-19 SMS.
  99. *
  100. * decc_init()
  101. *
  102. * On non-VAX systems, use LIB$INITIALIZE to set a collection of C
  103. * RTL features without using the DECC$* logical name method, nor
  104. * requiring the user to define the corresponding logical names.
  105. */
  106. /* Structure to hold a DECC$* feature name and its desired value. */
  107. struct decc_feat_t {
  108. char *name;
  109. int value;
  110. };
  111. /* Array of DECC$* feature names and their desired values. */
  112. static const struct decc_feat_t decc_feat_array[] = {
  113. /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
  114. { "DECC$ARGV_PARSE_STYLE", 1 },
  115. /* Preserve case for file names on ODS5 disks. */
  116. { "DECC$EFS_CASE_PRESERVE", 1 },
  117. /* Enable multiple dots (and most characters) in ODS5 file names,
  118. while preserving VMS-ness of ";version". */
  119. { "DECC$EFS_CHARSET", 1 },
  120. /* List terminator. */
  121. { (char *)NULL, 0 }
  122. };
  123. /* Flag to sense if decc_init() was called. */
  124. static int decc_init_done = -1;
  125. /* LIB$INITIALIZE initialization function. */
  126. static void decc_init(void)
  127. {
  128. int feat_index;
  129. int feat_value;
  130. int feat_value_max;
  131. int feat_value_min;
  132. int i;
  133. int sts;
  134. /* Set the global flag to indicate that LIB$INITIALIZE worked. */
  135. decc_init_done = 1;
  136. /* Loop through all items in the decc_feat_array[]. */
  137. for(i = 0; decc_feat_array[i].name != NULL; i++) {
  138. /* Get the feature index. */
  139. feat_index = decc$feature_get_index(decc_feat_array[i].name);
  140. if(feat_index >= 0) {
  141. /* Valid item. Collect its properties. */
  142. feat_value = decc$feature_get_value(feat_index, 1);
  143. feat_value_min = decc$feature_get_value(feat_index, 2);
  144. feat_value_max = decc$feature_get_value(feat_index, 3);
  145. if((decc_feat_array[i].value >= feat_value_min) &&
  146. (decc_feat_array[i].value <= feat_value_max)) {
  147. /* Valid value. Set it if necessary. */
  148. if(feat_value != decc_feat_array[i].value) {
  149. sts = decc$feature_set_value(feat_index, 1,
  150. decc_feat_array[i].value);
  151. }
  152. }
  153. else {
  154. /* Invalid DECC feature value. */
  155. printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n",
  156. feat_value,
  157. feat_value_min, decc_feat_array[i].name, feat_value_max);
  158. }
  159. }
  160. else {
  161. /* Invalid DECC feature name. */
  162. printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name);
  163. }
  164. }
  165. }
  166. /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
  167. #pragma nostandard
  168. /* Establish the LIB$INITIALIZE PSECTs, with proper alignment and
  169. other attributes. Note that "nopic" is significant only on VAX. */
  170. #pragma extern_model save
  171. #pragma extern_model strict_refdef "LIB$INITIALIZ" 2, nopic, nowrt
  172. const int spare[8] = {0};
  173. #pragma extern_model strict_refdef "LIB$INITIALIZE" 2, nopic, nowrt
  174. void (*const x_decc_init)() = decc_init;
  175. #pragma extern_model restore
  176. /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
  177. #pragma extern_model save
  178. int LIB$INITIALIZE(void);
  179. #pragma extern_model strict_refdef
  180. int dmy_lib$initialize = (int) LIB$INITIALIZE;
  181. #pragma extern_model restore
  182. #pragma standard
  183. #endif /* __DECC && !__VAX && __CRTL_VER && __CRTL_VER >= 70301000 */
  184. #endif /* __VMS */