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 26#ifdef __VMS 27 28#if defined(__DECC) && !defined(__VAX) && \ 29 defined(__CRTL_VER) && (__CRTL_VER >= 70301000) 30#include <unixlib.h> 31#endif 32 33#define ENABLE_CURLX_PRINTF 34#include "curlx.h" 35 36#include "curlmsg_vms.h" 37#include "tool_vms.h" 38 39#include "memdebug.h" /* keep this as LAST include */ 40 41void decc$__posix_exit(int __status); 42void decc$exit(int __status); 43 44static int vms_shell = -1; 45 46/* VMS has a DCL shell and also has Unix shells ported to it. 47 * When curl is running under a Unix shell, we want it to be as much 48 * like Unix as possible. 49 */ 50int is_vms_shell(void) 51{ 52 char *shell; 53 54 /* Have we checked the shell yet? */ 55 if(vms_shell >= 0) 56 return vms_shell; 57 58 shell = getenv("SHELL"); 59 60 /* No shell, means DCL */ 61 if(!shell) { 62 vms_shell = 1; 63 return 1; 64 } 65 66 /* Have to make sure some one did not set shell to DCL */ 67 if(strcmp(shell, "DCL") == 0) { 68 vms_shell = 1; 69 return 1; 70 } 71 72 vms_shell = 0; 73 return 0; 74} 75 76/* 77 * VMS has two exit() routines. When running under a Unix style shell, then 78 * Unix style and the __posix_exit() routine is used. 79 * 80 * When running under the DCL shell, then the VMS encoded codes and decc$exit() 81 * is used. 82 * 83 * We can not use exit() or return a code from main() because the actual 84 * routine called depends on both the compiler version, compile options, and 85 * feature macro settings, and one of the exit routines is hidden at compile 86 * time. 87 * 88 * Since we want Curl to work properly under the VMS DCL shell and Unix 89 * shells under VMS, this routine should compile correctly regardless of 90 * the settings. 91 */ 92 93void vms_special_exit(int code, int vms_show) 94{ 95 int vms_code; 96 97 /* The Posix exit mode is only available after VMS 7.0 */ 98#if __CRTL_VER >= 70000000 99 if(is_vms_shell() == 0) { 100 decc$__posix_exit(code); 101 } 102#endif 103 104 if(code > CURL_LAST) { /* If CURL_LAST exceeded then */ 105 vms_code = CURL_LAST; /* curlmsg.h is out of sync. */ 106 } 107 else { 108 vms_code = vms_cond[code] | vms_show; 109 } 110 decc$exit(vms_code); 111} 112 113#if defined(__DECC) && !defined(__VAX) && \ 114 defined(__CRTL_VER) && (__CRTL_VER >= 70301000) 115 116/* 117 * 2004-09-19 SMS. 118 * 119 * decc_init() 120 * 121 * On non-VAX systems, use LIB$INITIALIZE to set a collection of C 122 * RTL features without using the DECC$* logical name method, nor 123 * requiring the user to define the corresponding logical names. 124 */ 125 126/* Structure to hold a DECC$* feature name and its desired value. */ 127struct decc_feat_t { 128 char *name; 129 int value; 130}; 131 132/* Array of DECC$* feature names and their desired values. */ 133static const struct decc_feat_t decc_feat_array[] = { 134 /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */ 135 { "DECC$ARGV_PARSE_STYLE", 1 }, 136 /* Preserve case for file names on ODS5 disks. */ 137 { "DECC$EFS_CASE_PRESERVE", 1 }, 138 /* Enable multiple dots (and most characters) in ODS5 file names, 139 while preserving VMS-ness of ";version". */ 140 { "DECC$EFS_CHARSET", 1 }, 141 /* List terminator. */ 142 { (char *)NULL, 0 } 143}; 144 145/* Flag to sense if decc_init() was called. */ 146static int decc_init_done = -1; 147 148/* LIB$INITIALIZE initialization function. */ 149static void decc_init(void) 150{ 151 int feat_index; 152 int feat_value; 153 int feat_value_max; 154 int feat_value_min; 155 int i; 156 int sts; 157 158 /* Set the global flag to indicate that LIB$INITIALIZE worked. */ 159 decc_init_done = 1; 160 161 /* Loop through all items in the decc_feat_array[]. */ 162 for(i = 0; decc_feat_array[i].name != NULL; i++) { 163 164 /* Get the feature index. */ 165 feat_index = decc$feature_get_index(decc_feat_array[i].name); 166 167 if(feat_index >= 0) { 168 /* Valid item. Collect its properties. */ 169 feat_value = decc$feature_get_value(feat_index, 1); 170 feat_value_min = decc$feature_get_value(feat_index, 2); 171 feat_value_max = decc$feature_get_value(feat_index, 3); 172 173 if((decc_feat_array[i].value >= feat_value_min) && 174 (decc_feat_array[i].value <= feat_value_max)) { 175 /* Valid value. Set it if necessary. */ 176 if(feat_value != decc_feat_array[i].value) { 177 sts = decc$feature_set_value(feat_index, 1, 178 decc_feat_array[i].value); 179 } 180 } 181 else { 182 /* Invalid DECC feature value. */ 183 printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n", 184 feat_value, 185 feat_value_min, decc_feat_array[i].name, feat_value_max); 186 } 187 } 188 else { 189 /* Invalid DECC feature name. */ 190 printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name); 191 } 192 193 } 194} 195 196/* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */ 197 198#pragma nostandard 199 200/* Establish the LIB$INITIALIZE PSECTs, with proper alignment and 201 other attributes. Note that "nopic" is significant only on VAX. */ 202#pragma extern_model save 203#pragma extern_model strict_refdef "LIB$INITIALIZ" 2, nopic, nowrt 204const int spare[8] = {0}; 205#pragma extern_model strict_refdef "LIB$INITIALIZE" 2, nopic, nowrt 206void (*const x_decc_init)() = decc_init; 207#pragma extern_model restore 208 209/* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */ 210#pragma extern_model save 211int LIB$INITIALIZE(void); 212#pragma extern_model strict_refdef 213int dmy_lib$initialize = (int) LIB$INITIALIZE; 214#pragma extern_model restore 215 216#pragma standard 217 218#endif /* __DECC && !__VAX && __CRTL_VER && __CRTL_VER >= 70301000 */ 219 220#endif /* __VMS */ 221