Changeset: 161ccd48db57 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=161ccd48db57
Modified Files:
clients/mapiclient/stethoscope.c
Branch: default
Log Message:
Read the .monetdb file
The convenience file .monetDB and environment variable DOTMONETDBFILE
are also used by the stethoscope from now on.
diffs (144 lines):
diff --git a/clients/mapiclient/stethoscope.c b/clients/mapiclient/stethoscope.c
--- a/clients/mapiclient/stethoscope.c
+++ b/clients/mapiclient/stethoscope.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
@@ -44,6 +45,12 @@
# endif
#endif
+enum modes {
+ MAL,
+ SQL
+};
+static enum modes mode = SQL;
+
#define COUNTERSDEFAULT "ISTest"
static struct {
@@ -318,8 +325,18 @@ main(int argc, char **argv)
char *dbname = NULL;
char *user = NULL;
char *password = NULL;
+ char *language = NULL;
+
+ /* some .monetdb properties are used by mclient, perhaps we need them
as well later */
+ int pagewidth = -1; /* -1: take whatever is necessary, >0: limit */
+ int pagewidthset = 0; /* whether the user set the width explicitly */
+ struct stat statb;
+ int save_history;
+ char *output;
+
char **alts, **oalts;
wthread *walk;
+ stream * config;
static struct option long_options[8] = {
{ "dbname", 1, 0, 'd' },
@@ -330,6 +347,100 @@ main(int argc, char **argv)
{ "help", 0, 0, '?' },
{ 0, 0, 0, 0 }
};
+
+ /* parse config file first, command line options override */
+ if (getenv("DOTMONETDBFILE") == NULL) {
+ if (stat(".monetdb", &statb) == 0) {
+ config = open_rastream(".monetdb");
+ } else if (getenv("HOME") != NULL) {
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "%s/.monetdb",
getenv("HOME"));
+ if (stat(buf, &statb) == 0) {
+ config = open_rastream(buf);
+ }
+ }
+ } else {
+ char *cfile = getenv("DOTMONETDBFILE");
+ if (strcmp(cfile, "") != 0) {
+ if (stat(cfile, &statb) == 0) {
+ config = open_rastream(cfile);
+ } else {
+ fprintf(stderr,
+ "failed to open file '%s': %s\n",
+ cfile, strerror(errno));
+ }
+ }
+ }
+
+ if (config != NULL) {
+ char buf[1024];
+ char *q;
+ ssize_t len;
+ int line = 0;
+ while ((len = mnstr_readline(config, buf, sizeof(buf) - 1)) >
0) {
+ line++;
+ buf[len - 1] = '\0'; /* drop newline */
+ if (buf[0] == '#' || buf[0] == '\0')
+ continue;
+ if ((q = strchr(buf, '=')) == NULL) {
+ fprintf(stderr, "%s:%d: syntax error: %s\n",
mnstr_name(config), line, buf);
+ continue;
+ }
+ *q++ = '\0';
+ /* this basically sucks big time, as I can't easily set
+ * a default, hence I only do things I think are useful
+ * for now, needs a better solution */
+ if (strcmp(buf, "user") == 0) {
+ user = strdup(q); /* leak */
+ q = NULL;
+ } else if (strcmp(buf, "password") == 0 || strcmp(buf,
"passwd") == 0) {
+ password = strdup(q); /* leak */
+ q = NULL;
+ } else if (strcmp(buf, "language") == 0) {
+ language = strdup(q); /* leak */
+ if (strcmp(language, "sql") == 0) {
+ mode = SQL;
+ q = NULL;
+ } else if (strcmp(language, "mal") == 0) {
+ mode = MAL;
+ q = NULL;
+ } else {
+ /* make sure we don't set garbage */
+ fprintf(stderr,
+ "%s:%d: unsupported "
+ "language: %s\n",
+ mnstr_name(config),
+ line, q);
+ free(language);
+ language = NULL;
+ q = NULL;
+ }
+ } else if (strcmp(buf, "save_history") == 0) {
+ if (strcmp(q, "true") == 0 ||
+ strcmp(q, "on") == 0)
+ {
+ save_history = 1;
+ q = NULL;
+ } else if (strcmp(q, "false") == 0 ||
+ strcmp(q, "off") == 0)
+ {
+ save_history = 0;
+ q = NULL;
+ }
+ } else if (strcmp(buf, "format") == 0) {
+ output = strdup(q);
+ } else if (strcmp(buf, "width") == 0) {
+ pagewidth = atoi(q);
+ pagewidthset = pagewidth != 0;
+ }
+ if (q != NULL)
+ fprintf(stderr,
+ "%s:%d: unknown property: %s\n",
+ mnstr_name(config), line, buf);
+ }
+ mnstr_destroy(config);
+ }
+
while (1) {
int option_index = 0;
int c = getopt_long(argc, argv, "d:u:P:p:?:h:g",
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list