Changeset: 80e68b747391 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=80e68b747391
Modified Files:
        clients/src/mapiclient/Makefile.ag
        clients/src/mapiclient/ReadlineTools.c
        clients/src/mapiclient/ReadlineTools.h
        clients/src/mapiclient/ReadlineTools.mx
        clients/src/mapiclient/mclient.c
        clients/src/mapiclient/mclient.mx
Branch: default
Log Message:

Renamed mclient.mx to mclient.c and ReadlineTools.mx to ReadlineTools.c.


diffs (truncated from 6468 to 300 lines):

diff -r 43b78d87be5c -r 80e68b747391 clients/src/mapiclient/Makefile.ag
--- a/clients/src/mapiclient/Makefile.ag        Mon Aug 30 10:51:47 2010 +0200
+++ b/clients/src/mapiclient/Makefile.ag        Mon Aug 30 11:46:29 2010 +0200
@@ -27,7 +27,7 @@
 
 #Name alignment of tools in M5 context. 
 bin_mclient = {
-       SOURCES = mclient.mx ReadlineTools.mx
+       SOURCES = mclient.c ReadlineTools.c ReadlineTools.h
        LIBS = libmcutil ../mapilib/libMapi $(MAPI_LIBS) $(READLINE_LIBS) \
                $(MONETDB_LIBS) -lmutils -lstream \
                $(ICONV_LIBS)
diff -r 43b78d87be5c -r 80e68b747391 clients/src/mapiclient/ReadlineTools.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/clients/src/mapiclient/ReadlineTools.c    Mon Aug 30 11:46:29 2010 +0200
@@ -0,0 +1,399 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2010 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/*
+ * Readline specific stuff
+ */
+#include "clients_config.h"
+#include <monet_options.h>
+#include "mapilib/Mapi.h"
+
+#ifdef HAVE_LIBREADLINE
+
+#include <readline/readline.h>
+#include <readline/history.h>
+#include "ReadlineTools.h"
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>           /* for strncasecmp */
+#endif
+
+#ifndef NATIVE_WIN32
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#endif
+
+#define PATHLENGTH     256     /* maximum file pathname length. */
+
+static const char *sql_commands[] = {
+       "SELECT",
+       "INSERT",
+       "UPDATE",
+       "SET",
+       "DELETE",
+       "COMMIT",
+       "ROLLBACK",
+       "DROP TABLE",
+       "CREATE",
+       "ALTER",
+       "RELEASE SAVEPOINT",
+       "START TRANSACTION",
+       0,
+};
+
+static Mapi _mid;
+static char _history_file[PATHLENGTH];
+static int _save_history = 0;
+static char *language;
+
+static char *
+sql_tablename_generator(const char *text, int state)
+{
+
+       static int seekpos, len, rowcount;
+       static MapiHdl table_hdl;
+       char *name;
+
+       if (!state) {
+               seekpos = 0;
+               len = strlen(text);
+               if ((table_hdl = mapi_query(_mid, "SELECT name FROM tables")) 
== NULL || mapi_error(_mid)) {
+                       if (table_hdl) {
+                               mapi_explain_query(table_hdl, stderr);
+                               mapi_close_handle(table_hdl);
+                       } else
+                               mapi_explain(_mid, stderr);
+                       return NULL;
+               }
+               mapi_fetch_all_rows(table_hdl);
+               rowcount = mapi_get_row_count(table_hdl);
+       }
+
+       while (seekpos < rowcount) {
+               mapi_seek_row(table_hdl, seekpos++, MAPI_SEEK_SET);
+               mapi_fetch_row(table_hdl);
+               name = mapi_fetch_field(table_hdl, 0);
+               if (strncmp(name, text, len) == 0)
+                       return strdup(name);
+       }
+
+       return NULL;
+}
+
+/* SQL commands (at start of line) */
+static char *
+sql_command_generator(const char *text, int state)
+{
+
+       static int idx, len;
+       const char *name;
+
+       if (!state) {
+               idx = 0;
+               len = strlen(text);
+       }
+
+
+       while ((name = sql_commands[idx++])) {
+#ifdef HAVE_STRNCASECMP
+               if (strncasecmp(name, text, len) == 0)
+#else
+               if (strncmp(name, text, len) == 0)
+#endif
+                       return strdup(name);
+       }
+
+       return NULL;
+}
+
+
+static char **
+sql_completion(const char *text, int start, int end)
+{
+       char **matches;
+
+       matches = (char **) NULL;
+
+       (void) end;
+
+       /* FIXME: Nice, context-sensitive completion strategy should go here */
+       if (strcmp(language, "sql") == 0) {
+               if (start == 0) {
+                       matches = rl_completion_matches(text, 
sql_command_generator);
+               } else {
+                       matches = rl_completion_matches(text, 
sql_tablename_generator);
+               }
+       }
+       if (strcmp(language, "mal") == 0) {
+               matches = rl_completion_matches(text, sql_tablename_generator);
+       }
+
+       return (matches);
+}
+
+static char *
+mil_batname_generator(const char *text, int state)
+{
+
+       static int seekpos, len, rowcount;
+       static MapiHdl table_hdl;
+       char *name;
+
+       if (!state) {
+               seekpos = 0;
+               len = strlen(text);
+               if ((table_hdl = mapi_query(_mid, "ls();")) == NULL || 
mapi_error(_mid)) {
+                       if (table_hdl) {
+                               mapi_explain_query(table_hdl, stderr);
+                               mapi_close_handle(table_hdl);
+                       } else
+                               mapi_explain(_mid, stderr);
+                       return NULL;
+               }
+               mapi_fetch_all_rows(table_hdl);
+               rowcount = mapi_get_row_count(table_hdl);
+       }
+
+       while (seekpos < rowcount) {
+               mapi_seek_row(table_hdl, seekpos++, MAPI_SEEK_SET);
+               mapi_fetch_row(table_hdl);
+               name = mapi_fetch_field(table_hdl, 0);
+               if (strncmp(name, text, len) == 0)
+                       return strdup(name);
+       }
+
+       return NULL;
+}
+
+static char **
+mil_completion(const char *text, int start, int end)
+{
+       (void) start;
+       (void) end;
+
+       /* FIXME: Nice, context-sensitive completion strategy should go here */
+       return rl_completion_matches(text, mil_batname_generator);
+}
+
+/* The MAL completion help */
+
+static char *mal_commands[] = {
+       "address",
+       "atom",
+       "barrier",
+       "catch",
+       "command",
+       "comment",
+       "exit",
+       "end",
+       "function",
+       "factory",
+       "leave",
+       "pattern",
+       "module",
+       "raise",
+       "redo",
+       0
+};
+
+#ifdef illegal_ESC_binding
+/* see also init_readline() below */
+static int
+mal_help(int cnt, int key)
+{
+       char *name, *c, buf[BUFSIZ];
+       int seekpos = 0, rowcount;
+       MapiHdl table_hdl;
+
+       (void) cnt;
+       (void) key;
+
+       c = rl_line_buffer + strlen(rl_line_buffer) - 1;
+       while (c > rl_line_buffer && isspace(*c))
+               c--;
+       while (c > rl_line_buffer && !isspace(*c))
+               c--;
+       snprintf(buf, BUFSIZ, "manual.help(\"%s\");", c);
+       if ((table_hdl = mapi_query(_mid, buf)) == NULL || mapi_error(_mid)) {
+               if (table_hdl) {
+                       mapi_explain_query(table_hdl, stderr);
+                       mapi_close_handle(table_hdl);
+               } else
+                       mapi_explain(_mid, stderr);
+               return 0;
+       }
+       mapi_fetch_all_rows(table_hdl);
+       rowcount = mapi_get_row_count(table_hdl);
+
+       printf("\n");
+       while (seekpos < rowcount) {
+               mapi_seek_row(table_hdl, seekpos++, MAPI_SEEK_SET);
+               mapi_fetch_row(table_hdl);
+               name = mapi_fetch_field(table_hdl, 0);
+               if (name)
+                       printf("%s\n", name);
+       }
+       return key;
+}
+#endif
+
+static char *
+mal_command_generator(const char *text, int state)
+{
+
+       static int idx;
+       static int seekpos, len, rowcount;
+       static MapiHdl table_hdl;
+       char *name, buf[BUFSIZ];
+
+       /* we pick our own portion of the linebuffer */
+       text = rl_line_buffer + strlen(rl_line_buffer) - 1;
+       while (text > rl_line_buffer && !isspace((int) *text))
+               text--;
+       if (!state) {
+               idx = 0;
+               len = strlen(text);
+       }
+
+/*     printf("expand test:%s\n",text);
+       printf("currentline:%s\n",rl_line_buffer); */
+
+       while (mal_commands[idx] && (name = mal_commands[idx++])) {
+#ifdef HAVE_STRNCASECMP
+               if (strncasecmp(name, text, len) == 0)
+#else
+               if (strncmp(name, text, len) == 0)
+#endif
+                       return strdup(name);
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to