This commit is contained in:
Gregory Burd 2009-09-01 09:50:10 -04:00
parent 119ffe556f
commit f157b8d0e4

View file

@ -145,7 +145,7 @@ local_getline(prompt, in)
* attempt to use "readline" for command-line editing. If "isatty" * attempt to use "readline" for command-line editing. If "isatty"
* is false, use "local_getline" instead of "readline" and issue no prompt. * is false, use "local_getline" instead of "readline" and issue no prompt.
* *
* zPrior is a string of prior text retrieved. If not the empty * prior is a string of prior text retrieved. If not the empty
* string, then issue a continuation prompt. * string, then issue a continuation prompt.
*/ */
static char * static char *
@ -865,6 +865,7 @@ do_meta_command(line, p)
if (p->db) { if (p->db) {
p->db->close(p->db); p->db->close(p->db);
} }
free(line);
g.dbenv->close(g.dbenv, 0); g.dbenv->close(g.dbenv, 0);
exit(0); exit(0);
} else if (c == 'r' && strncmp(args[0], "read", n) == 0 && } else if (c == 'r' && strncmp(args[0], "read", n) == 0 &&
@ -1134,9 +1135,9 @@ process_input(p, in)
continue; continue;
if (line && line[0] == '.' && line_len == 0) { if (line && line[0] == '.' && line_len == 0) {
int rc = do_meta_command(line, p); int rc = do_meta_command(line, p);
free(line);
if (rc) if (rc)
break; break;
free(line);
continue; continue;
} }
if (_is_command_terminator(line)) { if (_is_command_terminator(line)) {
@ -1194,7 +1195,7 @@ process_input(p, in)
/* /*
* Return a pathname which is the user's home directory. A * Return a pathname which is the user's home directory. A
* 0 return indicates an error of some kind. Space to hold the * NULL return indicates an error of some kind. Space to hold the
* resulting string is obtained from malloc(). The calling * resulting string is obtained from malloc(). The calling
* function should free the result. * function should free the result.
*/ */
@ -1234,44 +1235,40 @@ find_home_dir(void)
} }
/* /*
* Read input from the file given by rc_override. Or if that * Read input from the file given by 'path'. Or if that
* parameter is NULL, take input from ~/.dbsqlrc * parameter is NULL, take input from ~/.dbsqlrc
*/ */
static void static void
process_rc(p, rc_override) process_rc(p, path)
struct callback_data *p; /* Configuration data */ struct callback_data *p; /* Configuration data */
const char *rc_override; /* Name of config file. NULL to use const char *path; /* Path to custom config file,
default */ NULL to use default '~/.dbsqlrc' */
{ {
char *home_dir = NULL; char *home_dir = NULL;
const char *rc = rc_override;
char *buf; char *buf;
FILE *in = NULL; FILE *in = NULL;
if (rc == NULL) { if (path == NULL) {
home_dir = find_home_dir(); home_dir = find_home_dir();
if (home_dir == 0) {
fprintf(stderr,"%s: unable to locate home directory\n",
g.progname);
return;
}
buf = malloc(strlen(home_dir) + 15); buf = malloc(strlen(home_dir) + 15);
if (buf == 0) { if (buf == NULL) {
fprintf(stderr,"%s: out of memory\n", g.progname); fprintf(stderr,"%s: out of memory\n", g.progname);
exit(1); exit(1);
} }
sprintf(buf,"%s/.dbsqlrc", home_dir); sprintf(buf,"%s/.dbsqlrc", home_dir);
free(home_dir); free(home_dir);
rc = (const char*)buf; path = (const char*)buf;
} }
in = fopen(rc, "r"); in = fopen(path, "r");
if (in) { if (in) {
if (isatty(fileno(stdout))) { if (isatty(fileno(stdout))) {
printf("Loading resources from %s\n", rc); printf("Loading resources from %s\n", path);
} }
process_input(p, in); process_input(p, in);
fclose(in); fclose(in);
} }
if (buf == path)
free(buf);
return; return;
} }
@ -1462,9 +1459,13 @@ main(argc, argv)
printf("%s\nEnter \".help\" for instructions\n", printf("%s\nEnter \".help\" for instructions\n",
dbsql_version(&major, &minor, &patch)); dbsql_version(&major, &minor, &patch));
home = find_home_dir(); home = find_home_dir();
if (home && if (home) {
(history = malloc(strlen(home) + 20)) != 0) { history = malloc(strlen(home) + 20);
sprintf(history, "%s/.dbsql_history", home); if (history) {
sprintf(history, "%s/.dbsql_history",
home);
}
free(home);
} }
if (history) if (history)
read_history(history); read_history(history);