[PATCH] Build fisql on VMS

"Craig A. Berry" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
The attached is a slightly revised version of a patch I sent a couple  
of weeks ago but haven't seen applied.  It gets the fisql utility  
built on VMS and is pretty safe in that it does not affect any code  
seen by other platforms and especially doesn't touch the library code.

There are two files modified and one added:

% lsdiff -s --strip=1 001_fisql_for_vms.patch
! vms/descrip_mms.template
+ vms/edit.c
! vms/getpass.c

________________________________________
Craig A. Berry
mailto:[email protected]

"... getting out of a sonnet is much more
  difficult than getting in."
                  Brad Leithauser

_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
001_fisql_for_vms.patch (application/octet-stream, 7.5 KB)
--- b/vms/descrip_mms.template	Wed May 12 11:26:51 2010 -0500
+++ b/vms/descrip_mms.template	Wed May 12 11:29:49 2010 -0500
@@ -187,6 +187,9 @@
 	@ write sysconfh "#define FREETDS_SYSCONFDIR ""/FREETDS_ROOT"""
 	@ close sysconfh
 
+[.include]tds_sysdep_public.h_in : 
+	@ IF F$SEARCH("$(MMS$TARGET)") .EQS. "" THEN COPY [.include]tds_sysdep_public^.h.in $(MMS$TARGET)
+
 [.include]tds_sysdep_public.h : [.include]tds_sysdep_public.h_in
 	@ open/write vmsconfigtmp vmsconfigtmp.com
 	@ write vmsconfigtmp "$ define/user_mode/nolog SYS$OUTPUT _NLA0:"
@@ -221,6 +224,15 @@
 	@ open/write readlineh $(MMS$TARGET)
 	@ write readlineh "char *readline(char *prompt);"
 	@ write readlineh "int rl_inhibit_completion;"
+	@ write readlineh "/* The following are needed for fisql. */"
+	@ write readlineh "FILE **rl_outstream_get_addr(void);"
+	@ write readlineh "#define rl_outstream (*rl_outstream_get_addr())"
+	@ write readlineh "FILE **rl_instream_get_addr(void);"
+	@ write readlineh "#define rl_instream (*rl_instream_get_addr())"
+	@ write readlineh "static const char *rl_readline_name = NULL;"
+	@ write readlineh "#define rl_bind_key(c,f)      do {} while(0)"
+	@ write readlineh "#define rl_reset_line_state() do {} while(0)"
+	@ write readlineh "#define rl_on_new_line()      do {} while(0)"
 	@ close readlineh 
 
 [.include]history.h :
@@ -278,7 +290,7 @@
 
 # Build the utility programs and the pool server
 
-apps : freebcp$(E) tsql$(E) bsqldb$(E) defncopy$(E) tdspool$(E)
+apps : freebcp$(E) tsql$(E) bsqldb$(E) defncopy$(E) tdspool$(E) fisql$(E)
 	@ continue
 
 freebcp$(E) : [.src.apps]freebcp$(OBJ) []libsybdb$(OLB) []libtds$(OLB)
@@ -306,6 +318,19 @@
 tdspool$(E) : $(TDSPOOLOBJS) []libtdssrv$(OLB) []libtds$(OLB)
 	link$(LINKFLAGS)/exe=$(MMS$TARGET) $(TDSPOOLOBJS), []libtdssrv$(OLB)/library, []libtds$(OLB)/library
 
+
+fisql$(E) : [.src.apps.fisql]fisql$(OBJ) [.src.apps.fisql]interrupt$(OBJ) [.src.apps.fisql]handlers$(OBJ) [.vms]edit$(OBJ)
+	link$(LINKFLAGS)/exe=$(MMS$TARGET) $(MMS$SOURCE_LIST),[]libsybdb$(OLB)/library, []libtds$(OLB)/library
+
+[.src.apps.fisql]fisql$(OBJ) : [.src.apps.fisql]fisql.c
+	@ define/nolog/user_mode readline [.include]
+	$(CC) $(CFLAGS)/INCLUDE=($(CINCLUDE)) $(MMS$SOURCE)
+
+[.src.apps.fisql]interrupt$(OBJ) : [.src.apps.fisql]interrupt.c
+
+[.src.apps.fisql]handlers$(OBJ) : [.src.apps.fisql]handlers.c
+
+
 # Run the test suite
 
 check : buildchecks PWD libtdscheck ctlibcheck dblibcheck $(tdsodbccheck)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vms/edit.c	Wed May 12 11:29:49 2010 -0500
@@ -0,0 +1,73 @@
+/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
+ * Copyright (C) 2010  Craig A. Berry	[email protected]
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*      $Id: edit.c,v */
+
+#include <namdef.h>
+#include <descrip.h>
+#include <stsdef.h>
+#include <tpu$routines.h>
+#include <string.h>
+#include <unixlib.h>
+
+#if defined(NAML$C_MAXRSS) && !defined(__VAX)
+#  define VMS_MAXRSS (NAML$C_MAXRSS+1)
+#else
+#  define VMS_MAXRSS (NAM$C_MAXRSS+1)
+#endif
+
+char vms_fnm[VMS_MAXRSS];
+static int get_vms_name(char *, int);
+
+int
+edit(const char *editor, const char *arg)
+{
+    $DESCRIPTOR(fnm_dsc, "");
+    int status;
+
+    decc$to_vms(arg, get_vms_name, 0, 0);
+
+    fnm_dsc.dsc$a_pointer = vms_fnm;
+    fnm_dsc.dsc$w_length = strlen(vms_fnm);
+
+    if (fnm_dsc.dsc$a_pointer == NULL 
+        || fnm_dsc.dsc$w_length == 0)
+        return -1;
+
+    status = TPU$EDIT(&fnm_dsc, &fnm_dsc);
+
+    if ($VMS_STATUS_SUCCESS(status))
+        return 0;
+    else 
+        return -1;
+}
+
+static int
+get_vms_name(char *name, int type)
+{
+    strncpy(vms_fnm, name, VMS_MAXRSS);
+    return 1;
+}
+
+int
+reset_term()
+{
+        return 0;
+}
+
--- a/vms/getpass.c	Wed May 12 11:26:51 2010 -0500
+++ b/vms/getpass.c	Wed May 12 11:29:49 2010 -0500
@@ -1,5 +1,5 @@
 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
- * Copyright (C) 2003  Craig A. Berry	[email protected]	23-JAN-2003
+ * Copyright (C) 2003, 2010  Craig A. Berry	[email protected]
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -42,10 +42,13 @@
 #include <strings.h>
 
 #include <replacements/readpassphrase.h>
+#include "readline.h"
+
+static FILE *tds_rl_instream = NULL;
+static FILE *tds_rl_outstream = NULL;
 
 static char software_version[] = "$Id: getpass.c,v 1.5 2005/12/29 10:24:34 freddy77 Exp $";
 static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
-static char passbuff[128];
 
 /* 
  * A collection of assorted UNIXy input functions for VMS.  The core
@@ -128,14 +131,16 @@
 	prompt_dsc.dsc$a_pointer = myprompt;
 	prompt_dsc.dsc$w_length = strlen(myprompt);
 
-	/* Disable Ctrl-T and Ctrl-Y */
-	ctrl_mask = LIB$M_CLI_CTRLT | LIB$M_CLI_CTRLY;
-	status = LIB$DISABLE_CTRL(&ctrl_mask, &saved_ctrl_mask);
-	if (!$VMS_STATUS_SUCCESS(status)) {
-		errno = EVMSERR;
-		vaxc$errno = status;
-		free(myprompt);
-		return NULL;
+	if (!(flags & RPP_ECHO_ON) && (ttdevclass == DC$_TERM)) {
+		/* Disable Ctrl-T and Ctrl-Y */
+		ctrl_mask = LIB$M_CLI_CTRLT | LIB$M_CLI_CTRLY;
+		status = LIB$DISABLE_CTRL(&ctrl_mask, &saved_ctrl_mask);
+		if (!$VMS_STATUS_SUCCESS(status)) {
+			errno = EVMSERR;
+			vaxc$errno = status;
+			free(myprompt);
+			return NULL;
+		}
 	}
 
 	/* 
@@ -161,7 +166,7 @@
 		status = SYS$ASSIGN(&ttdsc, &ttchan, 0, 0, 0);
 		if ($VMS_STATUS_SUCCESS(status)) {
 
-			unsigned long qio_func = IO$_READPROMPT | IO$M_NOECHO;
+			unsigned long qio_func = IO$_READPROMPT | IO$M_NOECHO | IO$M_PURGE;
 
 			if (!(flags & RPP_TIMEOUT_OFF))
 				qio_func |= IO$M_TIMED;
@@ -239,15 +244,17 @@
 
 	free(myprompt);
 
-	/* 
-	 * Reenable previous control processing.
-	 */
-	status = LIB$ENABLE_CTRL(&saved_ctrl_mask);
-
-	if (!$VMS_STATUS_SUCCESS(status)) {
-		errno = EVMSERR;
-		vaxc$errno = status;
-		return NULL;
+	if (!(flags & RPP_ECHO_ON) && (ttdevclass == DC$_TERM)) {
+		/* 
+		 * Reenable previous control processing.
+		 */
+		status = LIB$ENABLE_CTRL(&saved_ctrl_mask);
+	
+		if (!$VMS_STATUS_SUCCESS(status)) {
+			errno = EVMSERR;
+			vaxc$errno = status;
+			return NULL;
+		}
 	}
 
 	return retval;
@@ -271,10 +278,12 @@
 char *
 readline(char *prompt)
 {
-
-	char *buf = NULL;
-	char *s = readpassphrase((const char *) prompt, passbuf, sizeof(passbuf),
-				 RPP_ECHO_ON | RPP_TIMEOUT_OFF);
+	char *buf = NULL, *s = NULL, *p = NULL;
+	if (tds_rl_instream == NULL)
+		s = readpassphrase((const char *) prompt, passbuf, sizeof(passbuf),
+					 RPP_ECHO_ON | RPP_TIMEOUT_OFF);
+	else
+		s = fgets(passbuf, sizeof(passbuf), tds_rl_instream);
 
 	if (s != NULL) {
 		buf = (char *) malloc(strlen(s) + 1);
@@ -288,3 +297,17 @@
 add_history(const char *s)
 {
 }
+
+
+FILE **
+rl_instream_get_addr(void)
+{
+	return &tds_rl_instream;
+}
+
+FILE **
+rl_outstream_get_addr(void)
+{
+	return &tds_rl_outstream;
+}
+
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.