-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosql.c
More file actions
70 lines (48 loc) · 1.13 KB
/
osql.c
File metadata and controls
70 lines (48 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <oci.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <wordexp.h>
#include "common.h"
/* another idea taken from psql */
#define NL_IN_HISTORY 0x01
#define COMMENT_CHAR 0x02
void recode_history(char from, char to) {
HIST_ENTRY *hist;
int i;
char *s;
for (i = 1; i <= history_length; i++) {
hist = history_get(i);
s = hist->line;
while (*s != '\0') {
if (*s == from)
*s = to;
s++;
}
}
}
int main(int argc, char *argv[]) {
char histfile[256];
wordexp_t exp;
oinit();
oec_abort(OCIHandleAlloc (oenv, (dvoid **) &ostmt, OCI_HTYPE_STMT, 0, 0),
"OCIHandleAlloc() for statement handle", EX_OSERR);
/* ----- */
obeginsession();
/* ----- */
wordexp("~/.osql_history", &exp, 0);
strncpy(histfile, exp.we_wordv[0], 255);
wordfree(&exp);
history_comment_char = COMMENT_CHAR;
history_write_timestamps = 1;
read_history(histfile);
recode_history(NL_IN_HISTORY, '\n');
input_loop();
fprintf(stdout, "eof.\n");
recode_history('\n', NL_IN_HISTORY);
write_history(histfile);
return (EX_OK);
}