tool_vms.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "tool_setup.h"
00023 
00024 #ifdef __VMS
00025 
00026 #if defined(__DECC) && !defined(__VAX) && \
00027     defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
00028 #include <unixlib.h>
00029 #endif
00030 
00031 #define ENABLE_CURLX_PRINTF
00032 #include "curlx.h"
00033 
00034 #include "curlmsg_vms.h"
00035 #include "tool_vms.h"
00036 
00037 #include "memdebug.h" /* keep this as LAST include */
00038 
00039 void decc$__posix_exit(int __status);
00040 void decc$exit(int __status);
00041 
00042 static int vms_shell = -1;
00043 
00044 /* VMS has a DCL shell and and also has Unix shells ported to it.
00045  * When curl is running under a Unix shell, we want it to be as much
00046  * like Unix as possible.
00047  */
00048 int is_vms_shell(void)
00049 {
00050   char *shell;
00051 
00052   /* Have we checked the shell yet? */
00053   if(vms_shell >= 0)
00054     return vms_shell;
00055 
00056   shell = getenv("SHELL");
00057 
00058   /* No shell, means DCL */
00059   if(shell == NULL) {
00060     vms_shell = 1;
00061     return 1;
00062   }
00063 
00064   /* Have to make sure some one did not set shell to DCL */
00065   if(strcmp(shell, "DCL") == 0) {
00066     vms_shell = 1;
00067     return 1;
00068   }
00069 
00070   vms_shell = 0;
00071   return 0;
00072 }
00073 
00074 /*
00075  * VMS has two exit() routines.  When running under a Unix style shell, then
00076  * Unix style and the __posix_exit() routine is used.
00077  *
00078  * When running under the DCL shell, then the VMS encoded codes and decc$exit()
00079  * is used.
00080  *
00081  * We can not use exit() or return a code from main() because the actual
00082  * routine called depends on both the compiler version, compile options, and
00083  * feature macro settings, and one of the exit routines is hidden at compile
00084  * time.
00085  *
00086  * Since we want Curl to work properly under the VMS DCL shell and Unix
00087  * shells under VMS, this routine should compile correctly regardless of
00088  * the settings.
00089  */
00090 
00091 void vms_special_exit(int code, int vms_show)
00092 {
00093   int vms_code;
00094 
00095   /* The Posix exit mode is only available after VMS 7.0 */
00096 #if __CRTL_VER >= 70000000
00097   if(is_vms_shell() == 0) {
00098     decc$__posix_exit(code);
00099   }
00100 #endif
00101 
00102   if(code > CURL_LAST) {   /* If CURL_LAST exceeded then */
00103     vms_code = CURL_LAST;  /* curlmsg.h is out of sync.  */
00104   }
00105   else {
00106     vms_code = vms_cond[code] | vms_show;
00107   }
00108   decc$exit(vms_code);
00109 }
00110 
00111 #if defined(__DECC) && !defined(__VAX) && \
00112     defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
00113 
00114 /*
00115  * 2004-09-19 SMS.
00116  *
00117  * decc_init()
00118  *
00119  * On non-VAX systems, use LIB$INITIALIZE to set a collection of C
00120  * RTL features without using the DECC$* logical name method, nor
00121  * requiring the user to define the corresponding logical names.
00122  */
00123 
00124 /* Structure to hold a DECC$* feature name and its desired value. */
00125 typedef struct {
00126   char *name;
00127   int value;
00128 } decc_feat_t;
00129 
00130 /* Array of DECC$* feature names and their desired values. */
00131 static decc_feat_t decc_feat_array[] = {
00132   /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
00133   { "DECC$ARGV_PARSE_STYLE", 1 },
00134   /* Preserve case for file names on ODS5 disks. */
00135   { "DECC$EFS_CASE_PRESERVE", 1 },
00136   /* Enable multiple dots (and most characters) in ODS5 file names,
00137      while preserving VMS-ness of ";version". */
00138   { "DECC$EFS_CHARSET", 1 },
00139   /* List terminator. */
00140   { (char *)NULL, 0 }
00141 };
00142 
00143 /* Flag to sense if decc_init() was called. */
00144 static int decc_init_done = -1;
00145 
00146 /* LIB$INITIALIZE initialization function. */
00147 static void decc_init(void)
00148 {
00149   int feat_index;
00150   int feat_value;
00151   int feat_value_max;
00152   int feat_value_min;
00153   int i;
00154   int sts;
00155 
00156   /* Set the global flag to indicate that LIB$INITIALIZE worked. */
00157   decc_init_done = 1;
00158 
00159   /* Loop through all items in the decc_feat_array[]. */
00160   for(i = 0; decc_feat_array[i].name != NULL; i++) {
00161 
00162     /* Get the feature index. */
00163     feat_index = decc$feature_get_index(decc_feat_array[i].name);
00164 
00165     if(feat_index >= 0) {
00166       /* Valid item.  Collect its properties. */
00167       feat_value = decc$feature_get_value(feat_index, 1);
00168       feat_value_min = decc$feature_get_value(feat_index, 2);
00169       feat_value_max = decc$feature_get_value(feat_index, 3);
00170 
00171       if((decc_feat_array[i].value >= feat_value_min) &&
00172          (decc_feat_array[i].value <= feat_value_max)) {
00173         /* Valid value.  Set it if necessary. */
00174         if(feat_value != decc_feat_array[i].value) {
00175           sts = decc$feature_set_value(feat_index, 1,
00176                                        decc_feat_array[i].value);
00177         }
00178       }
00179       else {
00180         /* Invalid DECC feature value. */
00181         printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n",
00182                feat_value,
00183                feat_value_min, decc_feat_array[i].name, feat_value_max);
00184       }
00185     }
00186     else {
00187       /* Invalid DECC feature name. */
00188       printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name);
00189     }
00190 
00191   }
00192 }
00193 
00194 /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
00195 
00196 #pragma nostandard
00197 
00198 /* Establish the LIB$INITIALIZE PSECTs, with proper alignment and
00199    other attributes.  Note that "nopic" is significant only on VAX. */
00200 #pragma extern_model save
00201 #pragma extern_model strict_refdef "LIB$INITIALIZ" 2, nopic, nowrt
00202 const int spare[8] = {0};
00203 #pragma extern_model strict_refdef "LIB$INITIALIZE" 2, nopic, nowrt
00204 void (*const x_decc_init)() = decc_init;
00205 #pragma extern_model restore
00206 
00207 /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
00208 #pragma extern_model save
00209 int LIB$INITIALIZE(void);
00210 #pragma extern_model strict_refdef
00211 int dmy_lib$initialize = (int) LIB$INITIALIZE;
00212 #pragma extern_model restore
00213 
00214 #pragma standard
00215 
00216 #endif /* __DECC && !__VAX && __CRTL_VER && __CRTL_VER >= 70301000 */
00217 
00218 #endif /* __VMS */
00219 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07