quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

tool_vms.c (6358B)


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