This fixes an existing bug in urlglob.c where it was not converting the Curl Unix exit code to a VMS DCL compatible exit code. This fix required the enhancement described next.

This also adds an enhancement to main.c so that when curl is run under a Unix shell like Bash on VMS, it will return the standard Unix exit codes and messages.

Regards,
-John
[email protected]
Personal Opinion Only
--- /src_root/curl-7.19.5/src/main.c    Fri May  1 13:14:54 2009
+++ src/main.c  Thu Jun  4 01:13:45 2009
@@ -20,6 +20,10 @@
  *
  * $Id: main.c,v 1.513 2009-05-01 12:39:40 yangtse Exp $
  ***************************************************************************/
+#ifdef __VMS
+#define exit hide_exit_prototype
+#endif
+
 #include "setup.h"
 
 #include <stdio.h>
@@ -200,10 +204,82 @@
 #define mkdir(x,y) (mkdir)(x)
 #endif
 
-#ifdef  VMS
+#ifdef __VMS
 #include "curlmsg_vms.h"
+
+int vms_shell = -1;
+
+/* VMS has a DCL shell and and also has Unix shells ported to it.
+ * When curl is running under a Unix shell, we want it to be as much
+ * like Unix as possible.
+ */
+int static is_vms_shell(void)
+{
+    char *shell;
+
+    /* Have we checked the shell yet? */
+    if (vms_shell >= 0)
+        return vms_shell;
+
+    shell = getenv("SHELL");
+
+    /* No shell, means DCL */
+    if (shell == NULL) {
+        vms_shell = 1;
+        return 1;
+    }
+
+    /* Have to make sure some one did not set shell to DCL */
+    if (strcmp(shell, "DCL") == 0) {
+        vms_shell = 1;
+        return 1;
+    }
+
+    vms_shell = 0;
+    return 0;
+}
+
+/*
+ * VMS has two exit() routines.  When running under a Unix style shell, then
+ * Unix style and the __posix_exit() routine is used.
+ *
+ * When running under the DCL shell, then the VMS encoded codes and decc$exit()
+ * is used.
+ *
+ * We can not use exit() or return a code from main() because the actual
+ * routine called depends on both the compiler version, compile options, and
+ * feature macro settings, and one of the exit routines is hidden at compile
+ * time.
+ *
+ * Since we want Curl to work properly under the VMS DCL shell and Unix
+ * shells under VMS, this routine should compile correctly regardless of
+ * the settings.
+ */
+
+void decc$__posix_exit(int __status);
+void decc$exit(int  __status);
+
+void vms_special_exit(int code, int vms_show)
+{
+    int vms_code;
+
+    /* The Posix exit mode is only available after VMS 7.0 */
+#if __CRTL_VER >= 70000000
+    if (is_vms_shell() == 0) {
+        decc$__posix_exit(code);
+    }
+#endif
+
+    if (code > CURL_LAST) {    /* If CURL_LAST exceeded then */
+        vms_code = CURL_LAST;  /* curlmsg.h is out of sync.  */
+    } else {
+       vms_code = vms_cond[code] | vms_show;
+    }
+    decc$exit(vms_code);
+}
 #endif
 
+
 /*
  * Large file support (>2Gb) using WIN32 functions.
  */
@@ -4996,16 +5072,20 @@
 
 show_error:
 
-#ifdef  VMS
-        if (!config->showerror)  {
-          vms_show = VMSSTS_HIDE;
-        }
-#else
-        if((res!=CURLE_OK) && config->showerror) {
-          fprintf(config->errors, "curl: (%d) %s\n", res,
+#ifdef __VMS
+        if (is_vms_shell()) {
+          /* VMS DCL shell behavior */
+          if (!config->showerror)  {
+            vms_show = VMSSTS_HIDE;
+          }
+        } else
+#endif
+        {
+          if((res!=CURLE_OK) && config->showerror) {
+            fprintf(config->errors, "curl: (%d) %s\n", res,
                   errorbuffer[0]? errorbuffer:
                   curl_easy_strerror((CURLcode)res));
-          if(CURLE_SSL_CACERT == res) {
+            if(CURLE_SSL_CACERT == res) {
 #define CURL_CA_CERT_ERRORMSG1 \
 "More details here: http://curl.haxx.se/docs/sslcerts.html\n\n"; \
 "curl performs SSL certificate verification by default, using a \"bundle\"\n" \
@@ -5021,12 +5101,12 @@
 "If you'd like to turn off curl's verification of the certificate, use\n" \
 " the -k (or --insecure) option.\n"
 
-            fprintf(config->errors, "%s%s",
-                    CURL_CA_CERT_ERRORMSG1,
-                    CURL_CA_CERT_ERRORMSG2 );
+              fprintf(config->errors, "%s%s",
+                      CURL_CA_CERT_ERRORMSG1,
+                      CURL_CA_CERT_ERRORMSG2 );
+            }
           }
         }
-#endif
 
         if (outfile && !curlx_strequal(outfile, "-") && outs.stream)
           fclose(outs.stream);
@@ -5182,9 +5262,8 @@
 #ifdef __NOVELL_LIBC__
   pressanykey();
 #endif
-#ifdef  VMS
-  if (res > CURL_LAST) res = CURL_LAST; /* If CURL_LAST exceeded then */
-  return (vms_cond[res]|vms_show);      /* curlmsg.h is out of sync.  */
+#ifdef  __VMS
+  vms_special_exit(res, vms_show);
 #else
   return res;
 #endif
--- /src_root/curl-7.19.5/src/urlglob.c Tue Oct 14 04:12:44 2008
+++ src/urlglob.c       Tue Jun  2 23:47:27 2009
@@ -39,6 +39,14 @@
 #include "memdebug.h"
 #endif
 
+#ifdef __VMS
+/* Need to intercept the exit call and fix it up */
+/* vms_special_exit is in main.c */
+void vms_special_exit(int code, int vms_show);
+
+#define exit(__code) vms_special_exit(__code, 0);
+#endif
+
 typedef enum {
   GLOB_OK,
   GLOB_ERROR

Reply via email to