-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
82 lines (71 loc) · 1.73 KB
/
main.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
// This file is part of SmallBASIC
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2020 Chris Warren-Smith
#include "config.h"
#include <string.h>
#include "libclipboard/include/libclipboard.h"
#include "include/var.h"
#include "include/param.h"
clipboard_c *clipboard;
int sblib_init(const char *sourceFile) {
clipboard = clipboard_new(nullptr);
return clipboard != nullptr;
}
void sblib_close(void) {
clipboard_free(clipboard);
}
// clipboard.copy(text)
int sblib_proc_count() {
return 1;
}
int sblib_proc_getname(int index, char *proc_name) {
int result;
if (index < sblib_proc_count()) {
strcpy(proc_name, "COPY");
result = 1;
} else {
result = 0;
}
return result;
}
int sblib_proc_exec(int index, int argc, slib_par_t *params, var_t *retval) {
int result;
if (index == 0 && argc == 1 && is_param_str(argc, params, 0)) {
const char *text = get_param_str(argc, params, 0, "");
result = clipboard_set_text_ex(clipboard, text, -1, LCB_CLIPBOARD);
} else {
result = 0;
}
return result;
}
// let text = clipboard.paste()
int sblib_func_count() {
return 1;
}
int sblib_func_getname(int index, char *proc_name) {
int result;
if (index < sblib_func_count()) {
strcpy(proc_name, "PASTE");
result = 1;
} else {
result = 0;
}
return result;
}
int sblib_func_exec(int index, int argc, slib_par_t *params, var_t *retval) {
int result;
if (index == 0 && argc == 0) {
char *text = clipboard_text_ex(clipboard, NULL, LCB_CLIPBOARD);
if (text != nullptr) {
v_setstr(retval, text);
free(text);
}
result = 1;
} else {
result = 0;
}
return result;
}