The unified diff between revisions [9a6e8df1..] and [a81fe555..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'src/lsi/vm.c'

#
# old_revision [9a6e8df1d6b102f467702e274d53d90f9151e2c8]
# new_revision [a81fe5550c21fa983b4e344e07c29b9cecdf75ea]
#
# patch "src/lsi/vm.c"
#  from [0d1a3539301653c5f5cad4792072a3f87ee17d29]
#    to [c29bc86ce0d4170f8a0229735384ea9eea76763f]
#
============================================================
--- src/lsi/vm.c	0d1a3539301653c5f5cad4792072a3f87ee17d29
+++ src/lsi/vm.c	c29bc86ce0d4170f8a0229735384ea9eea76763f
@@ -23,6 +23,7 @@
 #include "map3d.h"
 #include "mouse.h"
 #include "cmdsocket.h"
+#include "sql.h"
 
 #define DEBUG 0
 
@@ -482,6 +483,121 @@ int vm_intfn_cmdsocket_write(void)
 	return 1;
 }
 
+#ifdef NOT_YET
+
+#define MIN(a, b) ((a < b) ? a : b)
+
+#define MORE_QUERY_N(x, n) do {						\
+		off = strncpy(buf+off, (x), MIN(VM_STRING_MAX-off, (n)) - buf;\
+		if (off >= VM_STRING_MAX) {				\
+		    printf("Excessive string length - can't perform query\n"); \
+		    return 1;						\
+		}							\
+	} while (0)
+
+#define MORE_QUERY(x) MORE_QUERY_N((x), VM_STRING_MAX)
+
+int vm_intfn_sql_query(void)
+{
+	int nargs = stack_get(vm_current, 1);
+	int len = stack_get(vm_current, nargs+1);
+	char *fmt = stack_getstr(vm_current, len, nargs+1);
+	char buf1[VM_STRING_MAX];
+	char buf2[VM_STRING_MAX];
+	char buf[VM_STRING_MAX];
+	int off = 0;
+	int result;
+	int next;
+	char *p, *p1;
+
+	if (len > VM_STRING_MAX) {
+		printf("Excessive string length - can't perform query\n");
+		return 1;
+	}
+	strncpy(buf1, fmt, len);
+	buf1[len] = '\0';
+	
+	p = buf1;
+	while (p1 = strchr(p, '%') {
+		if (p1) {
+		    *p1 = 0;
+		}
+		if (p != buf1) {
+			switch(*p) {
+			case '%':
+			    MORE_QUERY("%");
+			    break;
+			case 's':
+			    next = (len + sizeof(stkentry)-1) / sizeof(stkentry) + 1;
+
+			    MORE_QUERY_N(stack_getstr(vm_current, slen, nargs));
+			}
+		}
+		MORE_QUERY(p);
+		if (p1)
+		    p = p1;
+		else
+		    break;
+	}
+
+	sql_query(buffer, len, &result);
+	/* XXX what to do with an error here? */
+	stack_poke(vm_current, 0, result); /* return value */
+	return 1;
+}
+#else
+int vm_intfn_sql_query(void)
+{
+	int len = stack_get(vm_current, 1);
+	char *query = stack_getstr(vm_current, len, 1);
+	int result;
+
+	sql_query(query, len, &result);
+	/* XXX what to do with an error here? */
+	stack_poke(vm_current, 0, result); /* return value */
+	return 1;
+}
+
+int vm_intfn_sql_query_1s(void)
+{
+	int len1, len2;
+	char buf1[VM_STRING_MAX];
+	char buf2[VM_STRING_MAX];
+	char query[VM_STRING_MAX];
+	char *arg1;
+	char *arg2;
+	int result;
+	int next;
+
+	next = 1;
+
+	len2 = stack_get(vm_current, next);
+	arg2 = stack_getstr(vm_current, len2, next);
+
+	next += (len2 + sizeof(stkentry)-1) / sizeof(stkentry) + 1;
+
+	len1 = stack_get(vm_current, next);
+	arg1 = stack_getstr(vm_current, len1, next);
+
+	if ((len1 > VM_STRING_MAX) || (len2 > VM_STRING_MAX)) {
+		printf("Excessive string length - can't perform query\n");
+		return 1;
+	}
+	strncpy(buf1, arg1, len1);
+	buf1[len1] = '\0';
+	strncpy(buf2, arg2, len2);
+	buf2[len2] = '\0';
+
+	snprintf(query, VM_STRING_MAX, buf1, buf2);
+
+	sql_query(query, strlen(query), &result);
+
+	/* XXX what to do with an error here? */
+	stack_poke(vm_current, 0, result); /* return value */
+	return 1;
+}
+#endif
+
 int vm_intfn_beatdetect_read(void)
 {
 	if (!beatdetect_read()) {