-
Notifications
You must be signed in to change notification settings - Fork 21
/
example.c
50 lines (36 loc) · 1.15 KB
/
example.c
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
/*
Build
# Windows MSVC
cl -D_CRT_SECURE_NO_WARNINGS -W4 User32.Lib crossline.c example.c /Feexample.exe
# Windows Clang
clang -D_CRT_SECURE_NO_WARNINGS -Wall -lUser32 crossline.c example.c -o example.exe
# Linux Clang
clang -Wall crossline.c example.c -o example
# GCC(Linux, MinGW, Cygwin, MSYS2)
gcc -Wall crossline.c example.c -o example
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "crossline.h"
static void completion_hook (char const *buf, crossline_completions_t *pCompletion)
{
int i;
static const char *cmd[] = {"insert", "select", "update", "delete", "create", "drop", "show", "describe", "help", "exit", "history", NULL};
for (i = 0; NULL != cmd[i]; ++i) {
if (0 == strncmp(buf, cmd[i], strlen(buf))) {
crossline_completion_add (pCompletion, cmd[i], NULL);
}
}
}
int main ()
{
char buf[256];
crossline_completion_register (completion_hook);
crossline_history_load ("history.txt");
while (NULL != crossline_readline ("Crossline> ", buf, sizeof(buf))) {
printf ("Read line: \"%s\"\n", buf);
}
crossline_history_save ("history.txt");
return 0;
}