annotate src/if_mzsch.c @ 1379:50f5ac5b90de v7.1.094

updated for version 7.1-094
author vimboss
date Thu, 30 Aug 2007 17:37:40 +0000
parents 64dd70f176c9
children 3dd986bfef63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2 *
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
3 * MzScheme interface by Sergey Khorev <sergey.khorev@gmail.com>
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
4 * Original work by Brent Fulgham <bfulgham@debian.org>
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
5 * (Based on lots of help from Matthew Flatt)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
6 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
7 * This consists of six parts:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
8 * 1. MzScheme interpreter main program
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
9 * 2. Routines that handle the external interface between MzScheme and
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
10 * Vim.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
11 * 3. MzScheme input/output handlers: writes output via [e]msg().
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
12 * 4. Implementation of the Vim Features for MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
13 * 5. Vim Window-related Manipulation Functions.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
14 * 6. Vim Buffer-related Manipulation Functions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
15 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
16 * NOTES
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
17 * 1. Memory, allocated with scheme_malloc*, need not to be freed explicitly,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
18 * garbage collector will do it self
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
19 * 2. Requires at least NORMAL features. I can't imagine why one may want
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
20 * to build with SMALL or TINY features but with MzScheme interface.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
21 * 3. I don't use K&R-style functions. Anyway, MzScheme headers are ANSI.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
22 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
23
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
24 #include "vim.h"
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
25
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
26 #include "if_mzsch.h"
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
27
800
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
28 /* Only do the following when the feature is enabled. Needed for "make
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
29 * depend". */
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
30 #if defined(FEAT_MZSCHEME) || defined(PROTO)
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
31
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
32 /* Base data structures */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
33 #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
34 #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
35
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
36 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
37 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
38 Scheme_Type tag;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
39 Scheme_Env *env;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
40 buf_T *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
41 } vim_mz_buffer;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
42
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
43 #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
44
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
45 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
46 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
47 Scheme_Type tag;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 575
diff changeset
48 win_T *win;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
49 } vim_mz_window;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
50
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
51 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
52
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
53 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
54 * Prims that form MzScheme Vim interface
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
55 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
56 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
57 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
58 Scheme_Closed_Prim *prim;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
59 char *name;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
60 int mina; /* arity information */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
61 int maxa;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
62 } Vim_Prim;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
63
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
64 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
65 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
66 char *name;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
67 Scheme_Object *port;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
68 } Port_Info;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
69
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
70 /* info for closed prim */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
71 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
72 * data have different means:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
73 * for do_eval it is char*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
74 * for do_apply is Apply_Onfo*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
75 * for do_load is Port_Info*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
76 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
77 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
78 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
79 void *data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
80 Scheme_Env *env;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
81 } Cmd_Info;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
82
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
83 /* info for do_apply */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
84 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
85 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
86 Scheme_Object *proc;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
87 int argc;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
88 Scheme_Object **argv;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
89 } Apply_Info;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
90
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
91 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
92 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
93 * Vim-Control Commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
94 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
95 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
96 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
97 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
98 * Utility functions for the vim/mzscheme interface
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
99 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
100 */
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
101 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
102 static Scheme_Object *sandbox_file_guard(int, Scheme_Object **);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
103 static Scheme_Object *sandbox_network_guard(int, Scheme_Object **);
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 856
diff changeset
104 static void sandbox_check(void);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
105 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
106 /* Buffer-related commands */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
107 static Scheme_Object *buffer_new(buf_T *buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
108 static Scheme_Object *get_buffer_by_name(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
109 static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
110 static Scheme_Object *get_buffer_count(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
111 static Scheme_Object *get_buffer_line(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
112 static Scheme_Object *get_buffer_line_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
113 static Scheme_Object *get_buffer_name(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
114 static Scheme_Object *get_buffer_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
115 static Scheme_Object *get_buffer_size(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
116 static Scheme_Object *get_curr_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
117 static Scheme_Object *get_next_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
118 static Scheme_Object *get_prev_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
119 static Scheme_Object *mzscheme_open_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
120 static Scheme_Object *set_buffer_line(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
121 static Scheme_Object *set_buffer_line_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
122 static Scheme_Object *insert_buffer_line_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
123 static Scheme_Object *get_range_start(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
124 static Scheme_Object *get_range_end(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
125 static Scheme_Object *get_buffer_namespace(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
126 static vim_mz_buffer *get_vim_curr_buffer(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
127
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
128 /* Window-related commands */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
129 static Scheme_Object *window_new(win_T *win);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
130 static Scheme_Object *get_curr_win(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
131 static Scheme_Object *get_window_count(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
132 static Scheme_Object *get_window_by_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
133 static Scheme_Object *get_window_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
134 static Scheme_Object *get_window_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
135 static Scheme_Object *get_window_height(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
136 static Scheme_Object *set_window_height(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
137 #ifdef FEAT_VERTSPLIT
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
138 static Scheme_Object *get_window_width(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
139 static Scheme_Object *set_window_width(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
140 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
141 static Scheme_Object *get_cursor(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
142 static Scheme_Object *set_cursor(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
143 static Scheme_Object *get_window_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
144 static vim_mz_window *get_vim_curr_window(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
145
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
146 /* Vim-related commands */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
147 static Scheme_Object *mzscheme_beep(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
148 static Scheme_Object *get_option(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
149 static Scheme_Object *set_option(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
150 static Scheme_Object *vim_command(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
151 static Scheme_Object *vim_eval(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
152 static Scheme_Object *vim_bufferp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
153 static Scheme_Object *vim_windowp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
154 static Scheme_Object *vim_buffer_validp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
155 static Scheme_Object *vim_window_validp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
156
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
157 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
158 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
159 * Internal Function Prototypes
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
160 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
161 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
162 static int vim_error_check(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
163 static int do_mzscheme_command(exarg_T *, void *, Scheme_Closed_Prim *what);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
164 static void startup_mzscheme(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
165 static char *string_to_line(Scheme_Object *obj);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
166 static int mzscheme_io_init(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
167 static void mzscheme_interface_init(vim_mz_buffer *self);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
168 static void do_output(char *mesg, long len);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
169 static void do_printf(char *format, ...);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
170 static void do_flush(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
171 static Scheme_Object *_apply_thunk_catch_exceptions(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
172 Scheme_Object *, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
173 static Scheme_Object *extract_exn_message(Scheme_Object *v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
174 static Scheme_Object *do_eval(void *, int noargc, Scheme_Object **noargv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
175 static Scheme_Object *do_load(void *, int noargc, Scheme_Object **noargv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
176 static Scheme_Object *do_apply(void *, int noargc, Scheme_Object **noargv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
177 static void register_vim_exn(Scheme_Env *env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
178 static vim_mz_buffer *get_buffer_arg(const char *fname, int argnum,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
179 int argc, Scheme_Object **argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
180 static vim_mz_window *get_window_arg(const char *fname, int argnum,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
181 int argc, Scheme_Object **argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
182 static void add_vim_exn(Scheme_Env *env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
183 static int line_in_range(linenr_T, buf_T *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
184 static void check_line_range(linenr_T, buf_T *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
185 static void mz_fix_cursor(int lo, int hi, int extra);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
186
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
187 static int eval_in_namespace(void *, Scheme_Closed_Prim *, Scheme_Env *,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
188 Scheme_Object **ret);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
189 static void make_modules(Scheme_Env *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
190
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
191 #ifdef DYNAMIC_MZSCHEME
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
192
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
193 static Scheme_Object *dll_scheme_eof;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
194 static Scheme_Object *dll_scheme_false;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
195 static Scheme_Object *dll_scheme_void;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
196 static Scheme_Object *dll_scheme_null;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
197 static Scheme_Object *dll_scheme_true;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
198
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
199 static Scheme_Thread **dll_scheme_current_thread_ptr;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
200
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
201 static void (**dll_scheme_console_printf_ptr)(char *str, ...);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
202 static void (**dll_scheme_console_output_ptr)(char *str, long len);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
203 static void (**dll_scheme_notify_multithread_ptr)(int on);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
204
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
205 static void *(*dll_GC_malloc)(size_t size_in_bytes);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
206 static void *(*dll_GC_malloc_atomic)(size_t size_in_bytes);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
207 static Scheme_Env *(*dll_scheme_basic_env)(void);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
208 static void (*dll_scheme_check_threads)(void);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
209 static void (*dll_scheme_register_static)(void *ptr, long size);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
210 static void (*dll_scheme_set_stack_base)(void *base, int no_auto_statics);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
211 static void (*dll_scheme_add_global)(const char *name, Scheme_Object *val,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
212 Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
213 static void (*dll_scheme_add_global_symbol)(Scheme_Object *name,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
214 Scheme_Object *val, Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
215 static Scheme_Object *(*dll_scheme_apply)(Scheme_Object *rator, int num_rands,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
216 Scheme_Object **rands);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
217 static Scheme_Object *(*dll_scheme_builtin_value)(const char *name);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
218 # if MZSCHEME_VERSION_MAJOR >= 299
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
219 static Scheme_Object *(*dll_scheme_byte_string_to_char_string)(Scheme_Object *s);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
220 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
221 static void (*dll_scheme_close_input_port)(Scheme_Object *port);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
222 static void (*dll_scheme_count_lines)(Scheme_Object *port);
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
223 #if MZSCHEME_VERSION_MAJOR < 360
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
224 static Scheme_Object *(*dll_scheme_current_continuation_marks)(void);
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
225 #else
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
226 static Scheme_Object *(*dll_scheme_current_continuation_marks)(Scheme_Object *prompt_tag);
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
227 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
228 static void (*dll_scheme_display)(Scheme_Object *obj, Scheme_Object *port);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
229 static char *(*dll_scheme_display_to_string)(Scheme_Object *obj, long *len);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
230 static int (*dll_scheme_eq)(Scheme_Object *obj1, Scheme_Object *obj2);
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
231 static Scheme_Object *(*dll_scheme_do_eval)(Scheme_Object *obj,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
232 int _num_rands, Scheme_Object **rands, int val);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
233 static void (*dll_scheme_dont_gc_ptr)(void *p);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
234 static Scheme_Object *(*dll_scheme_eval)(Scheme_Object *obj, Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
235 static Scheme_Object *(*dll_scheme_eval_string)(const char *str,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
236 Scheme_Env *env);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
237 static Scheme_Object *(*dll_scheme_eval_string_all)(const char *str,
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
238 Scheme_Env *env, int all);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
239 static void (*dll_scheme_finish_primitive_module)(Scheme_Env *env);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
240 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
241 static char *(*dll_scheme_format)(char *format, int flen, int argc,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
242 Scheme_Object **argv, long *rlen);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
243 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
244 static char *(*dll_scheme_format_utf8)(char *format, int flen, int argc,
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
245 Scheme_Object **argv, long *rlen);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
246 static Scheme_Object *(*dll_scheme_get_param)(Scheme_Config *c, int pos);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
247 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
248 static void (*dll_scheme_gc_ptr_ok)(void *p);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
249 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
250 static char *(*dll_scheme_get_sized_string_output)(Scheme_Object *,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
251 long *len);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
252 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
253 static char *(*dll_scheme_get_sized_byte_string_output)(Scheme_Object *,
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
254 long *len);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
255 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
256 static Scheme_Object *(*dll_scheme_intern_symbol)(const char *name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
257 static Scheme_Object *(*dll_scheme_lookup_global)(Scheme_Object *symbol,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
258 Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
259 static Scheme_Object *(*dll_scheme_make_closed_prim_w_arity)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
260 (Scheme_Closed_Prim *prim, void *data, const char *name, mzshort mina,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
261 mzshort maxa);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
262 static Scheme_Object *(*dll_scheme_make_integer_value)(long i);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
263 static Scheme_Object *(*dll_scheme_make_namespace)(int argc,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
264 Scheme_Object *argv[]);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
265 static Scheme_Object *(*dll_scheme_make_pair)(Scheme_Object *car,
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
266 Scheme_Object *cdr);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
267 static Scheme_Object *(*dll_scheme_make_prim_w_arity)(Scheme_Prim *prim,
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
268 const char *name, mzshort mina, mzshort maxa);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
269 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
270 static Scheme_Object *(*dll_scheme_make_string)(const char *chars);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
271 static Scheme_Object *(*dll_scheme_make_string_output_port)();
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
272 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
273 static Scheme_Object *(*dll_scheme_make_byte_string)(const char *chars);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
274 static Scheme_Object *(*dll_scheme_make_byte_string_output_port)();
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
275 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
276 static Scheme_Object *(*dll_scheme_make_struct_instance)(Scheme_Object *stype,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
277 int argc, Scheme_Object **argv);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
278 static Scheme_Object **(*dll_scheme_make_struct_names)(Scheme_Object *base,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
279 Scheme_Object *field_names, int flags, int *count_out);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
280 static Scheme_Object *(*dll_scheme_make_struct_type)(Scheme_Object *base,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
281 Scheme_Object *parent, Scheme_Object *inspector, int num_fields,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
282 int num_uninit_fields, Scheme_Object *uninit_val,
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
283 Scheme_Object *properties
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
284 # if MZSCHEME_VERSION_MAJOR >= 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
285 , Scheme_Object *guard
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
286 # endif
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
287 );
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
288 static Scheme_Object **(*dll_scheme_make_struct_values)(
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
289 Scheme_Object *struct_type, Scheme_Object **names, int count,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
290 int flags);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
291 static Scheme_Type (*dll_scheme_make_type)(const char *name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
292 static Scheme_Object *(*dll_scheme_make_vector)(int size,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
293 Scheme_Object *fill);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
294 static void *(*dll_scheme_malloc_fail_ok)(void *(*f)(size_t), size_t);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
295 static Scheme_Object *(*dll_scheme_open_input_file)(const char *name,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
296 const char *who);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
297 static Scheme_Env *(*dll_scheme_primitive_module)(Scheme_Object *name,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
298 Scheme_Env *for_env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
299 static int (*dll_scheme_proper_list_length)(Scheme_Object *list);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
300 static void (*dll_scheme_raise)(Scheme_Object *exn);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
301 static Scheme_Object *(*dll_scheme_read)(Scheme_Object *port);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
302 static void (*dll_scheme_signal_error)(const char *msg, ...);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
303 static void (*dll_scheme_wrong_type)(const char *name, const char *expected,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
304 int which, int argc, Scheme_Object **argv);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
305 # if MZSCHEME_VERSION_MAJOR >= 299
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
306 static void (*dll_scheme_set_param)(Scheme_Config *c, int pos,
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
307 Scheme_Object *o);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
308 static Scheme_Config *(*dll_scheme_current_config)(void);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
309 static Scheme_Object *(*dll_scheme_char_string_to_byte_string)
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
310 (Scheme_Object *s);
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
311 static Scheme_Object *(*dll_scheme_char_string_to_path)
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
312 (Scheme_Object *s);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
313 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
314
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
315 /* arrays are imported directly */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
316 # define scheme_eof dll_scheme_eof
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
317 # define scheme_false dll_scheme_false
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
318 # define scheme_void dll_scheme_void
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
319 # define scheme_null dll_scheme_null
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
320 # define scheme_true dll_scheme_true
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
321
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
322 /* pointers are GetProceAddress'ed as pointers to pointer */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
323 # define scheme_current_thread (*dll_scheme_current_thread_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
324 # define scheme_console_printf (*dll_scheme_console_printf_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
325 # define scheme_console_output (*dll_scheme_console_output_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
326 # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
327
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
328 /* and functions in a usual way */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
329 # define GC_malloc dll_GC_malloc
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
330 # define GC_malloc_atomic dll_GC_malloc_atomic
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
331
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
332 # define scheme_add_global dll_scheme_add_global
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
333 # define scheme_add_global_symbol dll_scheme_add_global_symbol
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
334 # define scheme_apply dll_scheme_apply
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
335 # define scheme_basic_env dll_scheme_basic_env
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
336 # define scheme_builtin_value dll_scheme_builtin_value
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
337 # if MZSCHEME_VERSION_MAJOR >= 299
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
338 # define scheme_byte_string_to_char_string dll_scheme_byte_string_to_char_string
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
339 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
340 # define scheme_check_threads dll_scheme_check_threads
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
341 # define scheme_close_input_port dll_scheme_close_input_port
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
342 # define scheme_count_lines dll_scheme_count_lines
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
343 # define scheme_current_continuation_marks \
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
344 dll_scheme_current_continuation_marks
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
345 # define scheme_display dll_scheme_display
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
346 # define scheme_display_to_string dll_scheme_display_to_string
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
347 # define scheme_do_eval dll_scheme_do_eval
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
348 # define scheme_dont_gc_ptr dll_scheme_dont_gc_ptr
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
349 # define scheme_eq dll_scheme_eq
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
350 # define scheme_eval dll_scheme_eval
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
351 # define scheme_eval_string dll_scheme_eval_string
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
352 # define scheme_eval_string_all dll_scheme_eval_string_all
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
353 # define scheme_finish_primitive_module dll_scheme_finish_primitive_module
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
354 # if MZSCHEME_VERSION_MAJOR < 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
355 # define scheme_format dll_scheme_format
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
356 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
357 # define scheme_format_utf8 dll_scheme_format_utf8
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
358 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
359 # define scheme_gc_ptr_ok dll_scheme_gc_ptr_ok
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
360 # if MZSCHEME_VERSION_MAJOR < 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
361 # define scheme_get_sized_string_output dll_scheme_get_sized_string_output
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
362 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
363 # define scheme_get_sized_byte_string_output \
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
364 dll_scheme_get_sized_byte_string_output
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
365 # define scheme_get_param dll_scheme_get_param
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
366 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
367 # define scheme_intern_symbol dll_scheme_intern_symbol
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
368 # define scheme_lookup_global dll_scheme_lookup_global
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
369 # define scheme_make_closed_prim_w_arity dll_scheme_make_closed_prim_w_arity
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
370 # define scheme_make_integer_value dll_scheme_make_integer_value
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
371 # define scheme_make_namespace dll_scheme_make_namespace
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
372 # define scheme_make_pair dll_scheme_make_pair
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
373 # define scheme_make_prim_w_arity dll_scheme_make_prim_w_arity
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
374 # if MZSCHEME_VERSION_MAJOR < 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
375 # define scheme_make_string dll_scheme_make_string
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
376 # define scheme_make_string_output_port dll_scheme_make_string_output_port
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
377 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
378 # define scheme_make_byte_string dll_scheme_make_byte_string
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
379 # define scheme_make_byte_string_output_port \
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
380 dll_scheme_make_byte_string_output_port
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
381 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
382 # define scheme_make_struct_instance dll_scheme_make_struct_instance
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
383 # define scheme_make_struct_names dll_scheme_make_struct_names
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
384 # define scheme_make_struct_type dll_scheme_make_struct_type
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
385 # define scheme_make_struct_values dll_scheme_make_struct_values
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
386 # define scheme_make_type dll_scheme_make_type
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
387 # define scheme_make_vector dll_scheme_make_vector
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
388 # define scheme_malloc_fail_ok dll_scheme_malloc_fail_ok
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
389 # define scheme_open_input_file dll_scheme_open_input_file
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
390 # define scheme_primitive_module dll_scheme_primitive_module
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
391 # define scheme_proper_list_length dll_scheme_proper_list_length
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
392 # define scheme_raise dll_scheme_raise
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
393 # define scheme_read dll_scheme_read
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
394 # define scheme_register_static dll_scheme_register_static
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
395 # define scheme_set_stack_base dll_scheme_set_stack_base
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
396 # define scheme_signal_error dll_scheme_signal_error
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
397 # define scheme_wrong_type dll_scheme_wrong_type
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
398 # if MZSCHEME_VERSION_MAJOR >= 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
399 # define scheme_set_param dll_scheme_set_param
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
400 # define scheme_current_config dll_scheme_current_config
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
401 # define scheme_char_string_to_byte_string \
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
402 dll_scheme_char_string_to_byte_string
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
403 # define scheme_char_string_to_path \
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
404 dll_scheme_char_string_to_path
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
405 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
406
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
407 typedef struct
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
408 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
409 char *name;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
410 void **ptr;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
411 } Thunk_Info;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
412
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
413 static Thunk_Info mzgc_imports[] = {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
414 {"GC_malloc", (void **)&dll_GC_malloc},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
415 {"GC_malloc_atomic", (void **)&dll_GC_malloc_atomic},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
416 {NULL, NULL}};
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
417
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
418 static Thunk_Info mzsch_imports[] = {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
419 {"scheme_eof", (void **)&dll_scheme_eof},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
420 {"scheme_false", (void **)&dll_scheme_false},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
421 {"scheme_void", (void **)&dll_scheme_void},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
422 {"scheme_null", (void **)&dll_scheme_null},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
423 {"scheme_true", (void **)&dll_scheme_true},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
424 {"scheme_current_thread", (void **)&dll_scheme_current_thread_ptr},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
425 {"scheme_console_printf", (void **)&dll_scheme_console_printf_ptr},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
426 {"scheme_console_output", (void **)&dll_scheme_console_output_ptr},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
427 {"scheme_notify_multithread",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
428 (void **)&dll_scheme_notify_multithread_ptr},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
429 {"scheme_add_global", (void **)&dll_scheme_add_global},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
430 {"scheme_add_global_symbol", (void **)&dll_scheme_add_global_symbol},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
431 {"scheme_apply", (void **)&dll_scheme_apply},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
432 {"scheme_basic_env", (void **)&dll_scheme_basic_env},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
433 # if MZSCHEME_VERSION_MAJOR >= 299
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
434 {"scheme_byte_string_to_char_string", (void **)&dll_scheme_byte_string_to_char_string},
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
435 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
436 {"scheme_builtin_value", (void **)&dll_scheme_builtin_value},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
437 {"scheme_check_threads", (void **)&dll_scheme_check_threads},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
438 {"scheme_close_input_port", (void **)&dll_scheme_close_input_port},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
439 {"scheme_count_lines", (void **)&dll_scheme_count_lines},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
440 {"scheme_current_continuation_marks",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
441 (void **)&dll_scheme_current_continuation_marks},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
442 {"scheme_display", (void **)&dll_scheme_display},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
443 {"scheme_display_to_string", (void **)&dll_scheme_display_to_string},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
444 {"scheme_do_eval", (void **)&dll_scheme_do_eval},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
445 {"scheme_dont_gc_ptr", (void **)&dll_scheme_dont_gc_ptr},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
446 {"scheme_eq", (void **)&dll_scheme_eq},
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
447 {"scheme_eval", (void **)&dll_scheme_eval},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
448 {"scheme_eval_string", (void **)&dll_scheme_eval_string},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
449 {"scheme_eval_string_all", (void **)&dll_scheme_eval_string_all},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
450 {"scheme_finish_primitive_module",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
451 (void **)&dll_scheme_finish_primitive_module},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
452 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
453 {"scheme_format", (void **)&dll_scheme_format},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
454 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
455 {"scheme_format_utf8", (void **)&dll_scheme_format_utf8},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
456 {"scheme_get_param", (void **)&dll_scheme_get_param},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
457 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
458 {"scheme_gc_ptr_ok", (void **)&dll_scheme_gc_ptr_ok},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
459 # if MZSCHEME_VERSION_MAJOR < 299
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
460 {"scheme_get_sized_string_output",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
461 (void **)&dll_scheme_get_sized_string_output},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
462 # else
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
463 {"scheme_get_sized_byte_string_output",
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
464 (void **)&dll_scheme_get_sized_byte_string_output},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
465 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
466 {"scheme_intern_symbol", (void **)&dll_scheme_intern_symbol},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
467 {"scheme_lookup_global", (void **)&dll_scheme_lookup_global},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
468 {"scheme_make_closed_prim_w_arity",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
469 (void **)&dll_scheme_make_closed_prim_w_arity},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
470 {"scheme_make_integer_value", (void **)&dll_scheme_make_integer_value},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
471 {"scheme_make_namespace", (void **)&dll_scheme_make_namespace},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
472 {"scheme_make_pair", (void **)&dll_scheme_make_pair},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
473 {"scheme_make_prim_w_arity", (void **)&dll_scheme_make_prim_w_arity},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
474 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
475 {"scheme_make_string", (void **)&dll_scheme_make_string},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
476 {"scheme_make_string_output_port",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
477 (void **)&dll_scheme_make_string_output_port},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
478 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
479 {"scheme_make_byte_string", (void **)&dll_scheme_make_byte_string},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
480 {"scheme_make_byte_string_output_port",
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
481 (void **)&dll_scheme_make_byte_string_output_port},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
482 # endif
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
483 {"scheme_make_struct_instance",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
484 (void **)&dll_scheme_make_struct_instance},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
485 {"scheme_make_struct_names", (void **)&dll_scheme_make_struct_names},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
486 {"scheme_make_struct_type", (void **)&dll_scheme_make_struct_type},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
487 {"scheme_make_struct_values", (void **)&dll_scheme_make_struct_values},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
488 {"scheme_make_type", (void **)&dll_scheme_make_type},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
489 {"scheme_make_vector", (void **)&dll_scheme_make_vector},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
490 {"scheme_malloc_fail_ok", (void **)&dll_scheme_malloc_fail_ok},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
491 {"scheme_open_input_file", (void **)&dll_scheme_open_input_file},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
492 {"scheme_primitive_module", (void **)&dll_scheme_primitive_module},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
493 {"scheme_proper_list_length", (void **)&dll_scheme_proper_list_length},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
494 {"scheme_raise", (void **)&dll_scheme_raise},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
495 {"scheme_read", (void **)&dll_scheme_read},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
496 {"scheme_register_static", (void **)&dll_scheme_register_static},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
497 {"scheme_set_stack_base", (void **)&dll_scheme_set_stack_base},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
498 {"scheme_signal_error", (void **)&dll_scheme_signal_error},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
499 {"scheme_wrong_type", (void **)&dll_scheme_wrong_type},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
500 # if MZSCHEME_VERSION_MAJOR >= 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
501 {"scheme_set_param", (void **)&dll_scheme_set_param},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
502 {"scheme_current_config", (void **)&dll_scheme_current_config},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
503 {"scheme_char_string_to_byte_string",
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
504 (void **)&dll_scheme_char_string_to_byte_string},
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
505 {"scheme_char_string_to_path",
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
506 (void **)&dll_scheme_char_string_to_path},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
507 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
508 {NULL, NULL}};
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
509
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
510 static HINSTANCE hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
511 static HINSTANCE hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
512
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
513 static void dynamic_mzscheme_end(void);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
514 static int mzscheme_runtime_link_init(char *sch_dll, char *gc_dll,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
515 int verbose);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
516
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
517 static int
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
518 mzscheme_runtime_link_init(char *sch_dll, char *gc_dll, int verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
519 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
520 Thunk_Info *thunk = NULL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
521
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
522 if (hMzGC && hMzSch)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
523 return OK;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
524 hMzSch = LoadLibrary(sch_dll);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
525 hMzGC = LoadLibrary(gc_dll);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
526
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
527 if (!hMzSch)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
528 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
529 if (verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
530 EMSG2(_(e_loadlib), sch_dll);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
531 return FAIL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
532 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
533
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
534 if (!hMzGC)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
535 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
536 if (verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
537 EMSG2(_(e_loadlib), gc_dll);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
538 return FAIL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
539 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
540
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
541 for (thunk = mzsch_imports; thunk->name; thunk++)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
542 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
543 if ((*thunk->ptr =
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
544 (void *)GetProcAddress(hMzSch, thunk->name)) == NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
545 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
546 FreeLibrary(hMzSch);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
547 hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
548 FreeLibrary(hMzGC);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
549 hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
550 if (verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
551 EMSG2(_(e_loadfunc), thunk->name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
552 return FAIL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
553 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
554 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
555 for (thunk = mzgc_imports; thunk->name; thunk++)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
556 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
557 if ((*thunk->ptr =
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
558 (void *)GetProcAddress(hMzGC, thunk->name)) == NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
559 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
560 FreeLibrary(hMzSch);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
561 hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
562 FreeLibrary(hMzGC);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
563 hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
564 if (verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
565 EMSG2(_(e_loadfunc), thunk->name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
566 return FAIL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
567 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
568 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
569 return OK;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
570 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
571
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
572 int
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
573 mzscheme_enabled(int verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
574 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
575 return mzscheme_runtime_link_init(
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
576 DYNAMIC_MZSCH_DLL, DYNAMIC_MZGC_DLL, verbose) == OK;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
577 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
578
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
579 static void
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
580 dynamic_mzscheme_end(void)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
581 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
582 if (hMzSch)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
583 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
584 FreeLibrary(hMzSch);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
585 hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
586 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
587 if (hMzGC)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
588 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
589 FreeLibrary(hMzGC);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
590 hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
591 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
592 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
593 #endif /* DYNAMIC_MZSCHEME */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
594
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
595 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
596 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
597 * 1. MzScheme interpreter startup
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
598 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
599 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
600
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
601 static Scheme_Type mz_buffer_type;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
602 static Scheme_Type mz_window_type;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
603
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
604 static int initialized = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
605
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
606 /* global environment */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
607 static Scheme_Env *environment = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
608 /* output/error handlers */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
609 static Scheme_Object *curout = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
610 static Scheme_Object *curerr = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
611 /* vim:exn exception */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
612 static Scheme_Object *exn_catching_apply = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
613 static Scheme_Object *exn_p = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
614 static Scheme_Object *exn_message = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
615 static Scheme_Object *vim_exn = NULL; /* Vim Error exception */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
616 /* values for exn:vim - constructor, predicate, accessors etc */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
617 static Scheme_Object *vim_exn_names = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
618 static Scheme_Object *vim_exn_values = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
619
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
620 static long range_start;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
621 static long range_end;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
622
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
623 /* MzScheme threads scheduling stuff */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
624 static int mz_threads_allow = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
625
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
626 #if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
627 static void CALLBACK timer_proc(HWND, UINT, UINT, DWORD);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
628 static UINT timer_id = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
629 #elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
630 static gint timer_proc(gpointer);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
631 static guint timer_id = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
632 #elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
633 static void timer_proc(XtPointer, XtIntervalId *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
634 static XtIntervalId timer_id = (XtIntervalId)0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
635 #elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
636 pascal void timer_proc(EventLoopTimerRef, void *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
637 static EventLoopTimerRef timer_id = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
638 static EventLoopTimerUPP timerUPP;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
639 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
640
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
641 #ifndef FEAT_GUI_W32 /* Win32 console and Unix */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
642 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
643 mzvim_check_threads(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
644 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
645 /* Last time MzScheme threads were scheduled */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
646 static time_t mz_last_time = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
647
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
648 if (mz_threads_allow && p_mzq > 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
649 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
650 time_t now = time(NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
651
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
652 if ((now - mz_last_time) * 1000 > p_mzq)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
653 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
654 mz_last_time = now;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
655 scheme_check_threads();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
656 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
657 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
658 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
659 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
660
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
661 #ifdef MZSCHEME_GUI_THREADS
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
662 static void setup_timer(void);
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
663 static void remove_timer(void);
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
664
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
665 /* timers are presented in GUI only */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
666 # if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
667 static void CALLBACK
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
668 timer_proc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
669 # elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
670 /*ARGSUSED*/
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
671 static gint
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
672 timer_proc(gpointer data)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
673 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
674 /* ARGSUSED */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
675 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
676 timer_proc(XtPointer timed_out, XtIntervalId *interval_id)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
677 # elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
678 pascal void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
679 timer_proc(EventLoopTimerRef theTimer, void *userData)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
680 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
681 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
682 scheme_check_threads();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
683 # if defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
684 return TRUE; /* continue receiving notifications */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
685 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
686 /* renew timeout */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
687 if (mz_threads_allow && p_mzq > 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
688 timer_id = XtAppAddTimeOut(app_context, p_mzq,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
689 timer_proc, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
690 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
691 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
692
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
693 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
694 setup_timer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
695 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
696 # if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
697 timer_id = SetTimer(NULL, 0, p_mzq, timer_proc);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
698 # elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
699 timer_id = gtk_timeout_add((guint32)p_mzq, (GtkFunction)timer_proc, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
700 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
701 timer_id = XtAppAddTimeOut(app_context, p_mzq, timer_proc, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
702 # elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
703 timerUPP = NewEventLoopTimerUPP(timer_proc);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
704 InstallEventLoopTimer(GetMainEventLoop(), p_mzq * kEventDurationMillisecond,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
705 p_mzq * kEventDurationMillisecond, timerUPP, NULL, &timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
706 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
707 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
708
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
709 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
710 remove_timer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
711 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
712 # if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
713 KillTimer(NULL, timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
714 # elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
715 gtk_timeout_remove(timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
716 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
717 XtRemoveTimeOut(timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
718 # elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
719 RemoveEventLoopTimer(timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
720 DisposeEventLoopTimerUPP(timerUPP);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
721 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
722 timer_id = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
723 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
724
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
725 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
726 mzvim_reset_timer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
727 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
728 if (timer_id != 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
729 remove_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
730 if (mz_threads_allow && p_mzq > 0 && gui.in_use)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
731 setup_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
732 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
733
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
734 #endif /* MZSCHEME_GUI_THREADS */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
735
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
736 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
737 notify_multithread(int on)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
738 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
739 mz_threads_allow = on;
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
740 #ifdef MZSCHEME_GUI_THREADS
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
741 if (on && timer_id == 0 && p_mzq > 0 && gui.in_use)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
742 setup_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
743 if (!on && timer_id != 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
744 remove_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
745 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
746 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
747
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
748 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
749 mzscheme_end(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
750 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
751 #ifdef DYNAMIC_MZSCHEME
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
752 dynamic_mzscheme_end();
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
753 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
754 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
755
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
756 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
757 startup_mzscheme(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
758 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
759 Scheme_Object *proc_make_security_guard;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
760
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
761 scheme_set_stack_base(NULL, 1);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
762
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
763 MZ_REGISTER_STATIC(environment);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
764 MZ_REGISTER_STATIC(curout);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
765 MZ_REGISTER_STATIC(curerr);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
766 MZ_REGISTER_STATIC(exn_catching_apply);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
767 MZ_REGISTER_STATIC(exn_p);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
768 MZ_REGISTER_STATIC(exn_message);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
769 MZ_REGISTER_STATIC(vim_exn);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
770 MZ_REGISTER_STATIC(vim_exn_names);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
771 MZ_REGISTER_STATIC(vim_exn_values);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
772
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
773 environment = scheme_basic_env();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
774
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
775 /* redirect output */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
776 scheme_console_output = do_output;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
777 scheme_console_printf = do_printf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
778
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
779 #ifdef MZSCHEME_COLLECTS
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
780 /* setup 'current-library-collection-paths' parameter */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
781 scheme_set_param(scheme_config, MZCONFIG_COLLECTION_PATHS,
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
782 scheme_make_pair(
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
783 # if MZSCHEME_VERSION_MAJOR >= 299
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
784 scheme_char_string_to_path(
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
785 scheme_byte_string_to_char_string(
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
786 scheme_make_byte_string(MZSCHEME_COLLECTS))),
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
787 # else
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
788 scheme_make_string(MZSCHEME_COLLECTS),
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
789 # endif
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
790 scheme_null));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
791 #endif
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
792 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
793 /* setup sandbox guards */
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
794 proc_make_security_guard = scheme_lookup_global(
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
795 scheme_intern_symbol("make-security-guard"),
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
796 environment);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
797 if (proc_make_security_guard != NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
798 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
799 Scheme_Object *args[3];
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
800 Scheme_Object *guard;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
801 args[0] = scheme_get_param(scheme_config, MZCONFIG_SECURITY_GUARD);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
802 args[1] = scheme_make_prim_w_arity(sandbox_file_guard,
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
803 "sandbox-file-guard", 3, 3);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
804 args[2] = scheme_make_prim_w_arity(sandbox_network_guard,
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
805 "sandbox-network-guard", 4, 4);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
806 guard = scheme_apply(proc_make_security_guard, 3, args);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
807 scheme_set_param(scheme_config, MZCONFIG_SECURITY_GUARD, guard);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
808 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
809 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
810 /* Create buffer and window types for use in Scheme code */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
811 mz_buffer_type = scheme_make_type("<vim-buffer>");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
812 mz_window_type = scheme_make_type("<vim-window>");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
813
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
814 register_vim_exn(environment);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
815 make_modules(environment);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
816
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
817 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
818 * setup callback to receive notifications
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
819 * whether thread scheduling is (or not) required
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
820 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
821 scheme_notify_multithread = notify_multithread;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
822 initialized = 1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
823 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
824
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
825 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
826 * This routine is called for each new invocation of MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
827 * to make sure things are properly initialized.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
828 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
829 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
830 mzscheme_init(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
831 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
832 int do_require = FALSE;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
833
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
834 if (!initialized)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
835 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
836 do_require = TRUE;
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
837 #ifdef DYNAMIC_MZSCHEME
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
838 if (!mzscheme_enabled(TRUE))
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
839 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
840 EMSG(_("???: Sorry, this command is disabled, the MzScheme library could not be loaded."));
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
841 return -1;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
842 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
843 #endif
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
844 startup_mzscheme();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
845
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
846 if (mzscheme_io_init())
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
847 return -1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
848
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
849 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
850 /* recreate ports each call effectivelly clearing these ones */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
851 curout = scheme_make_string_output_port();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
852 curerr = scheme_make_string_output_port();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
853 scheme_set_param(scheme_config, MZCONFIG_OUTPUT_PORT, curout);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
854 scheme_set_param(scheme_config, MZCONFIG_ERROR_PORT, curerr);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
855
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
856 if (do_require)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
857 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
858 /* auto-instantiate in basic env */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
859 eval_in_namespace("(require (prefix vimext: vimext))", do_eval,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
860 environment, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
861 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
862
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
863 return 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
864 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
865
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
866 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
867 * This routine fills the namespace with various important routines that can
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
868 * be used within MzScheme.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
869 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
870 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
871 mzscheme_interface_init(vim_mz_buffer *mzbuff)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
872 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
873 Scheme_Object *attach;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
874
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
875 mzbuff->env = (Scheme_Env *)scheme_make_namespace(0, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
876
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
877 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
878 * attach instantiated modules from global namespace
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
879 * so they can be easily instantiated in the buffer namespace
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
880 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
881 attach = scheme_lookup_global(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
882 scheme_intern_symbol("namespace-attach-module"),
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
883 environment);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
884
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
885 if (attach != NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
886 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
887 Scheme_Object *ret;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
888 Scheme_Object *args[2];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
889
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
890 args[0] = (Scheme_Object *)environment;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
891 args[1] = scheme_intern_symbol("vimext");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
892
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
893 ret = (Scheme_Object *)mzvim_apply(attach, 2, args);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
894 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
895
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
896 add_vim_exn(mzbuff->env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
897 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
898
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
899 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
900 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
901 * 2. External Interface
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
902 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
903 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
904
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
905 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
906 * Evaluate command in namespace with exception handling
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
907 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
908 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
909 eval_in_namespace(void *data, Scheme_Closed_Prim *what, Scheme_Env *env,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
910 Scheme_Object **ret)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
911 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
912 Scheme_Object *value;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
913 Scheme_Object *exn;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
914 Cmd_Info info; /* closure info */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
915
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
916 info.data = data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
917 info.env = env;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
918
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
919 scheme_set_param(scheme_config, MZCONFIG_ENV,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
920 (Scheme_Object *) env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
921 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
922 * ensure all evaluations will be in current buffer namespace,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
923 * the second argument to scheme_eval_string isn't enough!
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
924 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
925 value = _apply_thunk_catch_exceptions(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
926 scheme_make_closed_prim_w_arity(what, &info, "mzvim", 0, 0),
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
927 &exn);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
928
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
929 if (!value)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
930 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
931 value = extract_exn_message(exn);
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
932 /* Got an exn? */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
933 if (value)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
934 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
935 scheme_display(value, curerr); /* Send to stderr-vim */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
936 do_flush();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
937 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
938 /* `raise' was called on some arbitrary value */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
939 return FAIL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
940 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
941
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
942 if (ret != NULL) /* if pointer to retval supported give it up */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
943 *ret = value;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
944 /* Print any result, as long as it's not a void */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
945 else if (!SCHEME_VOIDP(value))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
946 scheme_display(value, curout); /* Send to stdout-vim */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
947
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
948 do_flush();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
949 return OK;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
950 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
951
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
952 /* :mzscheme */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
953 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
954 do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
955 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
956 if (mzscheme_init())
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
957 return FAIL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
958
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
959 range_start = eap->line1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
960 range_end = eap->line2;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
961
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
962 return eval_in_namespace(data, what, get_vim_curr_buffer()->env, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
963 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
964
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
965 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
966 * Routine called by VIM when deleting a buffer
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
967 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
968 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
969 mzscheme_buffer_free(buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
970 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
971 if (buf->b_mzscheme_ref)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
972 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
973 vim_mz_buffer *bp;
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
974
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
975 bp = buf->b_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
976 bp->buf = INVALID_BUFFER_VALUE;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
977 buf->b_mzscheme_ref = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
978 scheme_gc_ptr_ok(bp);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
979 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
980 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
981
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
982 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
983 * Routine called by VIM when deleting a Window
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
984 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
985 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
986 mzscheme_window_free(win_T *win)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
987 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
988 if (win->w_mzscheme_ref)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
989 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
990 vim_mz_window *wp;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
991 wp = win->w_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
992 wp->win = INVALID_WINDOW_VALUE;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
993 win->w_mzscheme_ref = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
994 scheme_gc_ptr_ok(wp);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
995 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
996 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
997
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
998 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
999 * ":mzscheme" (or ":mz")
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1000 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1001 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1002 ex_mzscheme(exarg_T *eap)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1003 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1004 char_u *script;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1005
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1006 script = script_get(eap, eap->arg);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1007 if (!eap->skip)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1008 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1009 if (script == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1010 do_mzscheme_command(eap, eap->arg, do_eval);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1011 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1012 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1013 do_mzscheme_command(eap, script, do_eval);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1014 vim_free(script);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1015 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1016 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1017 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1018
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1019 /* eval MzScheme string */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1020 void *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1021 mzvim_eval_string(char_u *str)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1022 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1023 Scheme_Object *ret = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1024 if (mzscheme_init())
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1025 return FAIL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1026
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1027 eval_in_namespace(str, do_eval, get_vim_curr_buffer()->env, &ret);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1028 return ret;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1029 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1030
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1031 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1032 * apply MzScheme procedure with arguments,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1033 * handling errors
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1034 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1035 Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1036 mzvim_apply(Scheme_Object *proc, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1037 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1038 Apply_Info data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1039 Scheme_Object *ret = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1040
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1041 if (mzscheme_init())
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1042 return FAIL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1043
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1044 data.proc = proc;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1045 data.argc = argc;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1046 data.argv = argv;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1047
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1048 eval_in_namespace(&data, do_apply, get_vim_curr_buffer()->env, &ret);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1049 return ret;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1050 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1051
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1052 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1053 do_load(void *data, int noargc, Scheme_Object **noargv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1054 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1055 Cmd_Info *info = (Cmd_Info *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1056 Scheme_Object *result = scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1057 Scheme_Object *expr;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1058 char_u *file = scheme_malloc_fail_ok(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1059 scheme_malloc_atomic, MAXPATHL + 1);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1060 Port_Info *pinfo = (Port_Info *)(info->data);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1061
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1062 /* make Vim expansion */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1063 expand_env((char_u *)pinfo->name, file, MAXPATHL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1064 /* scheme_load looks strange working with namespaces and error handling*/
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1065 pinfo->port = scheme_open_input_file(file, "mzfile");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1066 scheme_count_lines(pinfo->port); /* to get accurate read error location*/
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1067
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1068 /* Like REPL but print only last result */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1069 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port)))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1070 result = scheme_eval(expr, info->env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1071
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1072 /* errors will be caught in do_mzscheme_comamnd and ex_mzfile */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1073 scheme_close_input_port(pinfo->port);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1074 pinfo->port = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1075 return result;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1076 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1077
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1078 /* :mzfile */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1079 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1080 ex_mzfile(exarg_T *eap)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1081 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1082 Port_Info pinfo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1083
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1084 pinfo.name = (char *)eap->arg;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1085 pinfo.port = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1086 if (do_mzscheme_command(eap, &pinfo, do_load) != OK
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1087 && pinfo.port != NULL) /* looks like port was not closed */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1088 scheme_close_input_port(pinfo.port);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1089 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1090
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1091
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1092 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1093 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1094 * Exception handling code -- cribbed form the MzScheme sources and
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1095 * Matthew Flatt's "Inside PLT MzScheme" document.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1096 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1097 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1098 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1099 init_exn_catching_apply(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1100 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1101 if (!exn_catching_apply)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1102 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1103 char *e =
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1104 "(lambda (thunk) "
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1105 "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1106 "(cons #t (thunk))))";
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1107
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1108 /* make sure we have a namespace with the standard syntax: */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1109 Scheme_Env *env = (Scheme_Env *)scheme_make_namespace(0, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1110 add_vim_exn(env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1111
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1112 exn_catching_apply = scheme_eval_string(e, env);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1113 exn_p = scheme_lookup_global(scheme_intern_symbol("exn?"), env);
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1114 exn_message = scheme_lookup_global(
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1115 scheme_intern_symbol("exn-message"), env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1116 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1117 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1118
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1119 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1120 * This function applies a thunk, returning the Scheme value if there's
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1121 * no exception, otherwise returning NULL and setting *exn to the raised
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1122 * value (usually an exn structure).
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1123 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1124 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1125 _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1126 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1127 Scheme_Object *v;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1128
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1129 init_exn_catching_apply();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1130
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1131 v = _scheme_apply(exn_catching_apply, 1, &f);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1132 /* v is a pair: (cons #t value) or (cons #f exn) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1133
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1134 if (SCHEME_TRUEP(SCHEME_CAR(v)))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1135 return SCHEME_CDR(v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1136 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1137 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1138 *exn = SCHEME_CDR(v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1139 return NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1140 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1141 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1142
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1143 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1144 extract_exn_message(Scheme_Object *v)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1145 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1146 init_exn_catching_apply();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1147
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1148 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v)))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1149 return _scheme_apply(exn_message, 1, &v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1150 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1151 return NULL; /* Not an exn structure */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1152 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1153
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1154 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1155 do_eval(void *s, int noargc, Scheme_Object **noargv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1156 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1157 Cmd_Info *info = (Cmd_Info *)s;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1158
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1159 return scheme_eval_string_all((char *)(info->data), info->env, TRUE);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1160 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1161
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1162 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1163 do_apply(void *a, int noargc, Scheme_Object **noargv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1164 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1165 Apply_Info *info = (Apply_Info *)(((Cmd_Info *)a)->data);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1166
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1167 return scheme_apply(info->proc, info->argc, info->argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1168 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1169
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1170 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1171 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1172 * 3. MzScheme I/O Handlers
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1173 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1174 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1175 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1176 do_intrnl_output(char *mesg, long len, int error)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1177 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1178 char *p, *prev;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1179
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1180 prev = mesg;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1181 p = strchr(prev, '\n');
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1182 while (p)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1183 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1184 *p = '\0';
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1185 if (error)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1186 EMSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1187 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1188 MSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1189 prev = p + 1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1190 p = strchr(prev, '\n');
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1191 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1192
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1193 if (error)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1194 EMSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1195 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1196 MSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1197 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1198
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1199 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1200 do_output(char *mesg, long len)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1201 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1202 do_intrnl_output(mesg, len, 0);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1203 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1204
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1205 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1206 do_err_output(char *mesg, long len)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1207 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1208 do_intrnl_output(mesg, len, 1);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1209 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1210
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1211 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1212 do_printf(char *format, ...)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1213 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1214 do_intrnl_output(format, STRLEN(format), 1);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1215 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1216
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1217 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1218 do_flush(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1219 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1220 char *buff;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1221 long length;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1222
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1223 buff = scheme_get_sized_string_output(curerr, &length);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1224 if (length)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1225 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1226 do_err_output(buff, length);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1227 return;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1228 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1229
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1230 buff = scheme_get_sized_string_output(curout, &length);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1231 if (length)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1232 do_output(buff, length);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1233 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1234
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1235 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1236 mzscheme_io_init(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1237 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1238 /* Nothing needed so far... */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1239 return 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1240 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1241
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1242 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1243 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1244 * 4. Implementation of the Vim Features for MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1245 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1246 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1247
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1248 /* (command {command-string}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1249 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1250 vim_command(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1251 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1252 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1253 char *cmd = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1254
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1255 /* may be use do_cmdline_cmd? */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1256 do_cmdline((char_u *)cmd, NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1257 update_screen(VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1258
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1259 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1260 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1261 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1262
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1263 /* (eval {expr-string}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1264 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1265 vim_eval(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1266 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1267 #ifdef FEAT_EVAL
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1268 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1269 char *expr;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1270 char *str;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1271 Scheme_Object *result;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1272
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1273 expr = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1274
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 671
diff changeset
1275 str = (char *)eval_to_string((char_u *)expr, NULL, TRUE);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1276
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1277 if (str == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1278 raise_vim_exn(_("invalid expression"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1279
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1280 result = scheme_make_string(str);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1281
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1282 vim_free(str);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1283
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1284 return result;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1285 #else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1286 raise_vim_exn(_("expressions disabled at compile time"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1287 /* unreachable */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1288 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1289 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1290 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1291
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1292 /* (range-start) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1293 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1294 get_range_start(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1295 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1296 return scheme_make_integer(range_start);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1297 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1298
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1299 /* (range-end) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1300 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1301 get_range_end(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1302 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1303 return scheme_make_integer(range_end);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1304 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1305
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1306 /* (beep) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1307 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1308 mzscheme_beep(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1309 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1310 vim_beep();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1311 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1312 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1313
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1314 static Scheme_Object *M_global = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1315
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1316 /* (get-option {option-name}) [buffer/window] */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1317 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1318 get_option(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1319 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1320 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1321 char_u *name;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1322 long value;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1323 char_u *strval;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1324 int rc;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1325 Scheme_Object *rval;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1326 int opt_flags = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1327 buf_T *save_curb = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1328 win_T *save_curw = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1329
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1330 name = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1331
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1332 if (argc > 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1333 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1334 if (M_global == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1335 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1336 MZ_REGISTER_STATIC(M_global);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1337 M_global = scheme_intern_symbol("global");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1338 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1339
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1340 if (argv[1] == M_global)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1341 opt_flags = OPT_GLOBAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1342 else if (SCHEME_VIMBUFFERP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1343 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1344 curbuf = get_valid_buffer(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1345 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1346 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1347 else if (SCHEME_VIMWINDOWP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1348 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1349 win_T *win = get_valid_window(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1350
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1351 curwin = win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1352 curbuf = win->w_buffer;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1353 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1354 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1355 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1356 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1357 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1358
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1359 rc = get_option_value(name, &value, &strval, opt_flags);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1360 curbuf = save_curb;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1361 curwin = save_curw;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1362
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1363 switch (rc)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1364 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1365 case 1:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1366 return scheme_make_integer_value(value);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1367 case 0:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1368 rval = scheme_make_string(strval);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1369 vim_free(strval);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1370 return rval;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1371 case -1:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1372 case -2:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1373 raise_vim_exn(_("hidden option"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1374 case -3:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1375 raise_vim_exn(_("unknown option"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1376 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1377 /* unreachable */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1378 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1379 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1380
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1381 /* (set-option {option-changing-string} [buffer/window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1382 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1383 set_option(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1384 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1385 char_u *cmd;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1386 int opt_flags = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1387 buf_T *save_curb = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1388 win_T *save_curw = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1389 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1390
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1391 GUARANTEE_STRING(prim->name, 0);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1392 if (argc > 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1393 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1394 if (M_global == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1395 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1396 MZ_REGISTER_STATIC(M_global);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1397 M_global = scheme_intern_symbol("global");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1398 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1399
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1400 if (argv[1] == M_global)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1401 opt_flags = OPT_GLOBAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1402 else if (SCHEME_VIMBUFFERP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1403 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1404 curbuf = get_valid_buffer(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1405 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1406 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1407 else if (SCHEME_VIMWINDOWP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1408 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1409 win_T *win = get_valid_window(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1410 curwin = win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1411 curbuf = win->w_buffer;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1412 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1413 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1414 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1415 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1416 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1417
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1418 /* do_set can modify cmd, make copy */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1419 cmd = vim_strsave((char_u *)SCHEME_STR_VAL(argv[0]));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1420 do_set(cmd, opt_flags);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1421 vim_free(cmd);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1422 update_screen(NOT_VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1423 curbuf = save_curb;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1424 curwin = save_curw;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1425 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1426 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1427 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1428
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1429 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1430 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1431 * 5. Vim Window-related Manipulation Functions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1432 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1433 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1434
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1435 /* (curr-win) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1436 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1437 get_curr_win(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1438 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1439 return (Scheme_Object *)get_vim_curr_window();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1440 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1441
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1442 /* (win-count) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1443 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1444 get_window_count(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1445 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1446 win_T *w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1447 int n = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1448
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1449 for (w = firstwin; w != NULL; w = w->w_next)
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1450 ++n;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1451 return scheme_make_integer(n);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1452 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1453
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1454 /* (get-win-list [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1455 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1456 get_window_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1457 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1458 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1459 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1460 Scheme_Object *list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1461 win_T *w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1462
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1463 buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1464 list = scheme_null;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1465
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1466 for (w = firstwin; w != NULL; w = w->w_next)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1467 if (w->w_buffer == buf->buf)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1468 list = scheme_make_pair(window_new(w), list);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1469
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1470 return list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1471 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1472
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1473 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1474 window_new(win_T *win)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1475 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1476 vim_mz_window *self;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1477
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1478 /* We need to handle deletion of windows underneath us.
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1479 * If we add a "w_mzscheme_ref" field to the win_T structure,
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1480 * then we can get at it in win_free() in vim.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1481 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1482 * On a win_free() we set the Scheme object's win_T *field
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1483 * to an invalid value. We trap all uses of a window
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1484 * object, and reject them if the win_T *field is invalid.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1485 */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1486 if (win->w_mzscheme_ref != NULL)
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1487 return win->w_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1488
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1489 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_window));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1490
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1491 vim_memset(self, 0, sizeof(vim_mz_window));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1492 scheme_dont_gc_ptr(self); /* because win isn't visible to GC */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1493 win->w_mzscheme_ref = self;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1494 self->win = win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1495 self->tag = mz_window_type;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1496
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1497 return (Scheme_Object *)(self);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1498 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1499
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1500 /* (get-win-num [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1501 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1502 get_window_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1503 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1504 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1505 win_T *win = get_window_arg(prim->name, 0, argc, argv)->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1506 int nr = 1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1507 win_T *wp;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1508
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1509 for (wp = firstwin; wp != win; wp = wp->w_next)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1510 ++nr;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1511
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1512 return scheme_make_integer(nr);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1513 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1514
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1515 /* (get-win-by-num {windownum}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1516 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1517 get_window_by_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1518 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1519 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1520 win_T *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1521 int fnum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1522
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1523 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1524 if (fnum < 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1525 scheme_signal_error(_("window index is out of range"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1526
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1527 for (win = firstwin; win != NULL; win = win->w_next, --fnum)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1528 if (fnum == 1) /* to be 1-based */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1529 return window_new(win);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1530
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1531 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1532 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1533
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1534 /* (get-win-buffer [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1535 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1536 get_window_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1537 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1538 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1539 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1540
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1541 return buffer_new(win->win->w_buffer);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1542 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1543
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1544 /* (get-win-height [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1545 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1546 get_window_height(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1547 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1548 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1549 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1550
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1551 return scheme_make_integer(win->win->w_height);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1552 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1553
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1554 /* (set-win-height {height} [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1555 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1556 set_window_height(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1557 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1558 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1559 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1560 win_T *savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1561 int height;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1562
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1563 win = get_window_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1564 height = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1565
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1566 #ifdef FEAT_GUI
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1567 need_mouse_correct = TRUE;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1568 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1569
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1570 savewin = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1571 curwin = win->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1572 win_setheight(height);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1573 curwin = savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1574
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1575 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1576 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1577 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1578
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1579 #ifdef FEAT_VERTSPLIT
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1580 /* (get-win-width [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1581 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1582 get_window_width(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1583 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1584 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1585 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1586
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1587 return scheme_make_integer(W_WIDTH(win->win));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1588 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1589
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1590 /* (set-win-width {width} [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1591 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1592 set_window_width(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1593 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1594 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1595 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1596 win_T *savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1597 int width = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1598
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1599 win = get_window_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1600 width = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1601
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1602 # ifdef FEAT_GUI
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1603 need_mouse_correct = TRUE;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1604 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1605
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1606 savewin = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1607 curwin = win->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1608 win_setwidth(width);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1609 curwin = savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1610
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1611 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1612 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1613 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1614 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1615
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1616 /* (get-cursor [window]) -> (line . col) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1617 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1618 get_cursor(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1619 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1620 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1621 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1622 pos_T pos;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1623
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1624 win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1625 pos = win->win->w_cursor;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1626 return scheme_make_pair(scheme_make_integer_value((long)pos.lnum),
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1627 scheme_make_integer_value((long)pos.col + 1));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1628 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1629
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1630 /* (set-cursor (line . col) [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1631 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1632 set_cursor(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1633 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1634 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1635 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1636 long lnum = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1637 long col = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1638
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1639 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1640 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1641 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1642 win = get_window_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1643 GUARANTEE_PAIR(prim->name, 0);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1644
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1645 if (!SCHEME_INTP(SCHEME_CAR(argv[0]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1646 || !SCHEME_INTP(SCHEME_CDR(argv[0])))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1647 scheme_wrong_type(prim->name, "integer pair", 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1648
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1649 lnum = SCHEME_INT_VAL(SCHEME_CAR(argv[0]));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1650 col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1651
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1652 check_line_range(lnum, win->win->w_buffer);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1653 /* don't know how to catch invalid column value */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1654
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1655 win->win->w_cursor.lnum = lnum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1656 win->win->w_cursor.col = col;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1657 update_screen(VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1658
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1659 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1660 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1661 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1662 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1663 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1664 * 6. Vim Buffer-related Manipulation Functions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1665 * Note that each buffer should have its own private namespace.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1666 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1667 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1668
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1669 /* (open-buff {filename}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1670 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1671 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1672 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1673 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1674 char *fname;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1675 int num = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1676 Scheme_Object *onum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1677
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1678 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1679 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1680 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1681 fname = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1682 /* TODO make open existing file */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1683 num = buflist_add(fname, BLN_LISTED | BLN_CURBUF);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1684
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1685 if (num == 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1686 raise_vim_exn(_("couldn't open buffer"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1687
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1688 onum = scheme_make_integer(num);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1689 return get_buffer_by_num(data, 1, &onum);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1690 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1691
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1692 /* (get-buff-by-num {buffernum}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1693 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1694 get_buffer_by_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1695 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1696 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1697 buf_T *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1698 int fnum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1699
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1700 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1701
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1702 for (buf = firstbuf; buf; buf = buf->b_next)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1703 if (buf->b_fnum == fnum)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1704 return buffer_new(buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1705
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1706 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1707 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1708
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1709 /* (get-buff-by-name {buffername}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1710 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1711 get_buffer_by_name(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1712 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1713 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1714 buf_T *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1715 char_u *fname;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1716
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1717 fname = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1718
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1719 for (buf = firstbuf; buf; buf = buf->b_next)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1720 if (buf->b_ffname == NULL || buf->b_sfname == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1721 /* empty string */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1722 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1723 if (fname[0] == NUL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1724 return buffer_new(buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1725 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1726 else if (!fnamecmp(buf->b_ffname, fname)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1727 || !fnamecmp(buf->b_sfname, fname))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1728 /* either short or long filename matches */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1729 return buffer_new(buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1730
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1731 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1732 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1733
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1734 /* (get-next-buff [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1735 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1736 get_next_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1737 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1738 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1739 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1740
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1741 if (buf->b_next == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1742 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1743 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1744 return buffer_new(buf->b_next);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1745 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1746
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1747 /* (get-prev-buff [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1748 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1749 get_prev_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1750 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1751 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1752 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1753
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1754 if (buf->b_prev == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1755 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1756 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1757 return buffer_new(buf->b_prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1758 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1759
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1760 /* (get-buff-num [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1761 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1762 get_buffer_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1763 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1764 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1765 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1766
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1767 return scheme_make_integer(buf->buf->b_fnum);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1768 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1769
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1770 /* (buff-count) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1771 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1772 get_buffer_count(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1773 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1774 buf_T *b;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1775 int n = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1776
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1777 for (b = firstbuf; b; b = b->b_next) ++n;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1778 return scheme_make_integer(n);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1779 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1780
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1781 /* (get-buff-name [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1782 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1783 get_buffer_name(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1784 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1785 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1786 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1787
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1788 return scheme_make_string(buf->buf->b_ffname);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1789 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1790
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1791 /* (curr-buff) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1792 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1793 get_curr_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1794 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1795 return (Scheme_Object *)get_vim_curr_buffer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1796 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1797
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1798 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1799 buffer_new(buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1800 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1801 vim_mz_buffer *self;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1802
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1803 /* We need to handle deletion of buffers underneath us.
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1804 * If we add a "b_mzscheme_ref" field to the buf_T structure,
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1805 * then we can get at it in buf_freeall() in vim.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1806 */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1807 if (buf->b_mzscheme_ref)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1808 return buf->b_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1809
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1810 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1811
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1812 vim_memset(self, 0, sizeof(vim_mz_buffer));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1813 scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1814 buf->b_mzscheme_ref = self;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1815 self->buf = buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1816 self->tag = mz_buffer_type;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1817
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1818 mzscheme_interface_init(self); /* Set up namespace */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1819
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1820 return (Scheme_Object *)(self);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1821 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1822
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1823 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1824 * (get-buff-size [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1825 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1826 * Get the size (number of lines) in the current buffer.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1827 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1828 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1829 get_buffer_size(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1830 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1831 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1832 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1833
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1834 return scheme_make_integer(buf->buf->b_ml.ml_line_count);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1835 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1836
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1837 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1838 * (get-buff-line {linenr} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1839 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1840 * Get a line from the specified buffer. The line number is
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1841 * in Vim format (1-based). The line is returned as a MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1842 * string object.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1843 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1844 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1845 get_buffer_line(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1846 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1847 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1848 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1849 int linenr;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1850 char *line;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1851
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1852 buf = get_buffer_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1853 linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1854 line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1855
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1856 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1857 return scheme_make_string(line);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1858 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1859
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1860
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1861 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1862 * (get-buff-line-list {start} {end} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1863 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1864 * Get a list of lines from the specified buffer. The line numbers
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1865 * are in Vim format (1-based). The range is from lo up to, but not
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1866 * including, hi. The list is returned as a list of string objects.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1867 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1868 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1869 get_buffer_line_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1870 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1871 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1872 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1873 int i, hi, lo, n;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1874 Scheme_Object *list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1875
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1876 buf = get_buffer_arg(prim->name, 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1877 list = scheme_null;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1878 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1879 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1880
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1881 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1882 * Handle some error conditions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1883 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1884 if (lo < 0)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1885 lo = 0;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1886
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1887 if (hi < 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1888 hi = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1889 if (hi < lo)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1890 hi = lo;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1891
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1892 n = hi - lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1893
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1894 for (i = n; i >= 0; --i)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1895 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1896 Scheme_Object *str = scheme_make_string(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1897 (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1898 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1899
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1900 /* Set the list item */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1901 list = scheme_make_pair(str, list);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1902 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1903
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1904 return list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1905 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1906
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1907 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1908 * (set-buff-line {linenr} {string/#f} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1909 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1910 * Replace a line in the specified buffer. The line number is
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1911 * in Vim format (1-based). The replacement line is given as
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1912 * an MzScheme string object. The object is checked for validity
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1913 * and correct format. An exception is thrown if the values are not
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1914 * the correct format.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1915 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1916 * It returns a Scheme Object that indicates the length of the
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1917 * string changed.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1918 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1919 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1920 set_buffer_line(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1921 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1922 /* First of all, we check the the of the supplied MzScheme object.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1923 * There are three cases:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1924 * 1. #f - this is a deletion.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1925 * 2. A string - this is a replacement.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1926 * 3. Anything else - this is an error.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1927 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1928 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1929 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1930 Scheme_Object *line;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1931 char *save;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1932 buf_T *savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1933 int n;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1934
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1935 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1936 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1937 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1938 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1939 if (!SCHEME_STRINGP(argv[1]) && !SCHEME_FALSEP(argv[1]))
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1940 scheme_wrong_type(prim->name, "string or #f", 1, argc, argv);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1941 line = argv[1];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1942 buf = get_buffer_arg(prim->name, 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1943
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1944 check_line_range(n, buf->buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1945
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1946 if (SCHEME_FALSEP(line))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1947 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1948 savebuf = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1949 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1950
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1951 if (u_savedel((linenr_T)n, 1L) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1952 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1953 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1954 raise_vim_exn(_("cannot save undo information"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1955 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1956 else if (ml_delete((linenr_T)n, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1957 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1958 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1959 raise_vim_exn(_("cannot delete line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1960 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1961 deleted_lines_mark((linenr_T)n, 1L);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1962 if (buf->buf == curwin->w_buffer)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1963 mz_fix_cursor(n, n + 1, -1);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1964
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1965 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1966
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1967 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1968 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1969 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1970
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1971 /* Otherwise it's a line */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1972 save = string_to_line(line);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1973 savebuf = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1974
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1975 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1976
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1977 if (u_savesub((linenr_T)n) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1978 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1979 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1980 raise_vim_exn(_("cannot save undo information"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1981 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1982 else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1983 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1984 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1985 raise_vim_exn(_("cannot replace line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1986 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1987 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1988 changed_bytes((linenr_T)n, 0);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1989
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1990 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1991
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1992 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1993 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1994 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1995
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1996 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1997 * (set-buff-line-list {start} {end} {string-list/#f/null} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1998 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1999 * Replace a range of lines in the specified buffer. The line numbers are in
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2000 * Vim format (1-based). The range is from lo up to, but not including, hi.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2001 * The replacement lines are given as a Scheme list of string objects. The
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2002 * list is checked for validity and correct format.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2003 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2004 * Errors are returned as a value of FAIL. The return value is OK on success.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2005 * If OK is returned and len_change is not NULL, *len_change is set to the
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2006 * change in the buffer length.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2007 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2008 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2009 set_buffer_line_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2010 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2011 /* First of all, we check the type of the supplied MzScheme object.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2012 * There are three cases:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2013 * 1. #f - this is a deletion.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2014 * 2. A list - this is a replacement.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2015 * 3. Anything else - this is an error.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2016 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2017 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2018 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2019 Scheme_Object *line_list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2020 Scheme_Object *line;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2021 Scheme_Object *rest;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2022 char **array;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2023 buf_T *savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2024 int i, old_len, new_len, hi, lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2025 long extra;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2026
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2027 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2028 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2029 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2030 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2031 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2032 if (!SCHEME_PAIRP(argv[2])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2033 && !SCHEME_FALSEP(argv[2]) && !SCHEME_NULLP(argv[2]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2034 scheme_wrong_type(prim->name, "list or #f", 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2035 line_list = argv[2];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2036 buf = get_buffer_arg(prim->name, 3, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2037 old_len = hi - lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2038 if (old_len < 0) /* process inverse values wisely */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2039 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2040 i = lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2041 lo = hi;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2042 hi = i;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2043 old_len = -old_len;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2044 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2045 extra = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2046
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2047 check_line_range(lo, buf->buf); /* inclusive */
1228
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1125
diff changeset
2048 check_line_range(hi - 1, buf->buf); /* exclusive */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2049
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2050 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2051 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2052 savebuf = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2053 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2054
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2055 if (u_savedel((linenr_T)lo, (long)old_len) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2056 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2057 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2058 raise_vim_exn(_("cannot save undo information"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2059 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2060 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2061 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2062 for (i = 0; i < old_len; i++)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2063 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2064 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2065 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2066 raise_vim_exn(_("cannot delete line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2067 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2068 deleted_lines_mark((linenr_T)lo, (long)old_len);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2069 if (buf->buf == curwin->w_buffer)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2070 mz_fix_cursor(lo, hi, -old_len);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2071 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2072
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2073 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2074
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2075 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2076 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2077 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2078
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2079 /* List */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2080 new_len = scheme_proper_list_length(line_list);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2081 if (new_len < 0) /* improper or cyclic list */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2082 scheme_wrong_type(prim->name, "proper list",
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2083 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2084
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2085 /* Using MzScheme allocator, so we don't need to free this and
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2086 * can safely keep pointers to GC collected strings
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2087 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2088 array = (char **)scheme_malloc_fail_ok(scheme_malloc,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2089 (unsigned)(new_len * sizeof(char *)));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2090
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2091 rest = line_list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2092 for (i = 0; i < new_len; ++i)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2093 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2094 line = SCHEME_CAR(rest);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2095 rest = SCHEME_CDR(rest);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2096 if (!SCHEME_STRINGP(line))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2097 scheme_wrong_type(prim->name, "string-list", 2, argc, argv);
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2098 array[i] = string_to_line(line);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2099 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2100
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2101 savebuf = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2102 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2103
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2104 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2105 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2106 curbuf = savebuf;
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2107 raise_vim_exn(_("cannot save undo information"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2108 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2109
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2110 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2111 * If the size of the range is reducing (ie, new_len < old_len) we
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2112 * need to delete some old_len. We do this at the start, by
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2113 * repeatedly deleting line "lo".
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2114 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2115 for (i = 0; i < old_len - new_len; ++i)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2116 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2117 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2118 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2119 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2120 raise_vim_exn(_("cannot delete line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2121 }
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2122 extra--;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2123 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2124
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2125 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2126 * For as long as possible, replace the existing old_len with the
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2127 * new old_len. This is a more efficient operation, as it requires
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2128 * less memory allocation and freeing.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2129 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2130 for (i = 0; i < old_len && i < new_len; i++)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2131 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2132 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2133 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2134 raise_vim_exn(_("cannot replace line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2135 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2136
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2137 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2138 * Now we may need to insert the remaining new_len. We don't need to
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2139 * free the string passed back because MzScheme has control of that
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2140 * memory.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2141 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2142 while (i < new_len)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2143 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2144 if (ml_append((linenr_T)(lo + i - 1),
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2145 (char_u *)array[i], 0, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2146 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2147 curbuf = savebuf;
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2148 raise_vim_exn(_("cannot insert line"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2149 }
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2150 ++i;
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2151 ++extra;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2152 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2153
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2154 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2155 * Adjust marks. Invalidate any which lie in the
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2156 * changed range, and move any in the remainder of the buffer.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2157 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2158 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), (long)MAXLNUM, (long)extra);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2159 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2160
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2161 if (buf->buf == curwin->w_buffer)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2162 mz_fix_cursor(lo, hi, extra);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2163 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2164
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2165 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2166 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2167 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2168
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2169 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2170 * (insert-buff-line-list {linenr} {string/string-list} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2171 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2172 * Insert a number of lines into the specified buffer after the specifed line.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2173 * The line number is in Vim format (1-based). The lines to be inserted are
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2174 * given as an MzScheme list of string objects or as a single string. The lines
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2175 * to be added are checked for validity and correct format. Errors are
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2176 * returned as a value of FAIL. The return value is OK on success.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2177 * If OK is returned and len_change is not NULL, *len_change
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2178 * is set to the change in the buffer length.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2179 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2180 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2181 insert_buffer_line_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2182 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2183 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2184 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2185 Scheme_Object *list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2186 Scheme_Object *line;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2187 Scheme_Object *rest;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2188 char **array;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2189 char *str;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2190 buf_T *savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2191 int i, n, size;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2192
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2193 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2194 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2195 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2196 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2197 * First of all, we check the type of the supplied MzScheme object.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2198 * It must be a string or a list, or the call is in error.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2199 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2200 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2201 list = argv[1];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2202
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2203 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2204 scheme_wrong_type(prim->name, "string or list", 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2205 buf = get_buffer_arg(prim->name, 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2206
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2207 if (n != 0) /* 0 can be used in insert */
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2208 check_line_range(n, buf->buf);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2209 if (SCHEME_STRINGP(list))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2210 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2211 str = string_to_line(list);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2212
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2213 savebuf = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2214 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2215
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2216 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2217 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2218 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2219 raise_vim_exn(_("cannot save undo information"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2220 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2221 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2222 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2223 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2224 raise_vim_exn(_("cannot insert line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2225 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2226 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2227 appended_lines_mark((linenr_T)n, 1L);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2228
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2229 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2230 update_screen(VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2231
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2232 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2233 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2234 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2235
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2236 /* List */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2237 size = scheme_proper_list_length(list);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2238 if (size < 0) /* improper or cyclic list */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2239 scheme_wrong_type(prim->name, "proper list",
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2240 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2241
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2242 /* Using MzScheme allocator, so we don't need to free this and
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2243 * can safely keep pointers to GC collected strings
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2244 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2245 array = (char **)scheme_malloc_fail_ok(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2246 scheme_malloc, (unsigned)(size * sizeof(char *)));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2247
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2248 rest = list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2249 for (i = 0; i < size; ++i)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2250 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2251 line = SCHEME_CAR(rest);
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2252 rest = SCHEME_CDR(rest);
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2253 array[i] = string_to_line(line);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2254 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2255
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2256 savebuf = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2257 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2258
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2259 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2260 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2261 curbuf = savebuf;
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2262 raise_vim_exn(_("cannot save undo information"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2263 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2264 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2265 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2266 for (i = 0; i < size; ++i)
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2267 if (ml_append((linenr_T)(n + i), (char_u *)array[i],
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2268 0, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2269 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2270 curbuf = savebuf;
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2271 raise_vim_exn(_("cannot insert line"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2272 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2273
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2274 if (i > 0)
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2275 appended_lines_mark((linenr_T)n, (long)i);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2276 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2277
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2278 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2279 update_screen(VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2280
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2281 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2282 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2283 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2284
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2285 /* (get-buff-namespace [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2286 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2287 get_buffer_namespace(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2288 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2289 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2290
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2291 return (Scheme_Object *)get_buffer_arg(prim->name, 0, argc, argv)->env;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2292 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2293
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2294 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2295 * Predicates
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2296 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2297 /* (buff? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2298 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2299 vim_bufferp(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2300 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2301 if (SCHEME_VIMBUFFERP(argv[0]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2302 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2303 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2304 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2305 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2306
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2307 /* (win? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2308 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2309 vim_windowp(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2310 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2311 if (SCHEME_VIMWINDOWP(argv[0]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2312 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2313 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2314 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2315 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2316
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2317 /* (buff-valid? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2318 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2319 vim_buffer_validp(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2320 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2321 if (SCHEME_VIMBUFFERP(argv[0])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2322 && ((vim_mz_buffer *)argv[0])->buf != INVALID_BUFFER_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2323 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2324 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2325 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2326 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2327
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2328 /* (win-valid? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2329 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2330 vim_window_validp(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2331 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2332 if (SCHEME_VIMWINDOWP(argv[0])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2333 && ((vim_mz_window *)argv[0])->win != INVALID_WINDOW_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2334 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2335 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2336 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2337 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2338
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2339 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2340 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2341 * Utilities
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2342 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2343 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2344
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2345 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2346 * Convert an MzScheme string into a Vim line.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2347 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2348 * The result is in allocated memory. All internal nulls are replaced by
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2349 * newline characters. It is an error for the string to contain newline
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2350 * characters.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2351 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2352 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2353 static char *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2354 string_to_line(Scheme_Object *obj)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2355 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2356 char *str;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2357 long len;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2358 int i;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2359
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2360 str = scheme_display_to_string(obj, &len);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2361
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2362 /* Error checking: String must not contain newlines, as we
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2363 * are replacing a single line, and we must replace it with
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2364 * a single line.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2365 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2366 if (memchr(str, '\n', len))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2367 scheme_signal_error(_("string cannot contain newlines"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2368
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2369 /* Create a copy of the string, with internal nulls replaced by
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2370 * newline characters, as is the vim convention.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2371 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2372 for (i = 0; i < len; ++i)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2373 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2374 if (str[i] == '\0')
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2375 str[i] = '\n';
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2376 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2377
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2378 str[i] = '\0';
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2379
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2380 return str;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2381 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2382
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2383 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2384 * Check to see whether a Vim error has been reported, or a keyboard
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2385 * interrupt (from vim --> got_int) has been detected.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2386 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2387 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2388 vim_error_check(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2389 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2390 return (got_int || did_emsg);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2391 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2392
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2393 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2394 * register Scheme exn:vim
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2395 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2396 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2397 register_vim_exn(Scheme_Env *env)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2398 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2399 Scheme_Object *exn_name = scheme_intern_symbol("exn:vim");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2400
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2401 if (vim_exn == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2402 vim_exn = scheme_make_struct_type(exn_name,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2403 scheme_builtin_value("struct:exn"), NULL, 0, 0, NULL, NULL
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2404 #if MZSCHEME_VERSION_MAJOR >= 299
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2405 , NULL
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2406 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2407 );
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2408
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2409 if (vim_exn_values == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2410 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2411 int nc = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2412
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2413 Scheme_Object **exn_names = scheme_make_struct_names(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2414 exn_name, scheme_null, 0, &nc);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2415 Scheme_Object **exn_values = scheme_make_struct_values(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2416 vim_exn, exn_names, nc, 0);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2417
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2418 vim_exn_names = scheme_make_vector(nc, scheme_false);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2419 vim_exn_values = scheme_make_vector(nc, scheme_false);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2420 /* remember names and values */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2421 mch_memmove(SCHEME_VEC_ELS(vim_exn_names), exn_names,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2422 nc * sizeof(Scheme_Object *));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2423 mch_memmove(SCHEME_VEC_ELS(vim_exn_values), exn_values,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2424 nc * sizeof(Scheme_Object *));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2425 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2426
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2427 add_vim_exn(env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2428 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2429
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2430 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2431 * Add stuff of exn:vim to env
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2432 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2433 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2434 add_vim_exn(Scheme_Env *env)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2435 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2436 int i;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2437
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2438 for (i = 0; i < SCHEME_VEC_SIZE(vim_exn_values); i++)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2439 scheme_add_global_symbol(SCHEME_VEC_ELS(vim_exn_names)[i],
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2440 SCHEME_VEC_ELS(vim_exn_values)[i], env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2441 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2442
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2443 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2444 * raise exn:vim, may be with additional info string
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2445 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2446 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2447 raise_vim_exn(const char *add_info)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2448 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2449 Scheme_Object *argv[2];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2450 char_u *fmt = _("Vim error: ~a");
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2451
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2452 if (add_info != NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2453 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2454 Scheme_Object *info = scheme_make_string(add_info);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2455 argv[0] = scheme_byte_string_to_char_string(scheme_make_string(
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2456 scheme_format(fmt, strlen(fmt), 1, &info, NULL)));
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2457 SCHEME_SET_IMMUTABLE(argv[0]);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2458 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2459 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2460 argv[0] = scheme_make_string(_("Vim error"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2461
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
2462 #if MZSCHEME_VERSION_MAJOR < 360
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
2463 argv[1] = scheme_current_continuation_marks();
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
2464 #else
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 856
diff changeset
2465 argv[1] = scheme_current_continuation_marks(NULL);
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
2466 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2467
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2468 scheme_raise(scheme_make_struct_instance(vim_exn, 2, argv));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2469 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2470
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2471 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2472 raise_if_error(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2473 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2474 if (vim_error_check())
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2475 raise_vim_exn(NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2476 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2477
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2478 /* get buffer:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2479 * either current
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2480 * or passed as argv[argnum] with checks
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2481 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2482 static vim_mz_buffer *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2483 get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2484 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2485 vim_mz_buffer *b;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2486
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2487 if (argc < argnum + 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2488 return get_vim_curr_buffer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2489 if (!SCHEME_VIMBUFFERP(argv[argnum]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2490 scheme_wrong_type(fname, "vim-buffer", argnum, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2491 b = (vim_mz_buffer *)argv[argnum];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2492 (void)get_valid_buffer(argv[argnum]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2493 return b;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2494 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2495
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2496 /* get window:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2497 * either current
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2498 * or passed as argv[argnum] with checks
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2499 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2500 static vim_mz_window *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2501 get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2502 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2503 vim_mz_window *w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2504
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2505 if (argc < argnum + 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2506 return get_vim_curr_window();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2507 w = (vim_mz_window *)argv[argnum];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2508 if (!SCHEME_VIMWINDOWP(argv[argnum]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2509 scheme_wrong_type(fname, "vim-window", argnum, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2510 (void)get_valid_window(argv[argnum]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2511 return w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2512 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2513
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2514 /* get valid Vim buffer from Scheme_Object* */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2515 buf_T *get_valid_buffer(void *obj)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2516 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2517 buf_T *buf = ((vim_mz_buffer *)obj)->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2518
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2519 if (buf == INVALID_BUFFER_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2520 scheme_signal_error(_("buffer is invalid"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2521 return buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2522 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2523
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2524 /* get valid Vim window from Scheme_Object* */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2525 win_T *get_valid_window(void *obj)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2526 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2527 win_T *win = ((vim_mz_window *)obj)->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2528 if (win == INVALID_WINDOW_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2529 scheme_signal_error(_("window is invalid"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2530 return win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2531 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2532
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2533 int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2534 mzthreads_allowed(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2535 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2536 return mz_threads_allow;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2537 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2538
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2539 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2540 line_in_range(linenr_T lnum, buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2541 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2542 return (lnum > 0 && lnum <= buf->b_ml.ml_line_count);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2543 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2544
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2545 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2546 check_line_range(linenr_T lnum, buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2547 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2548 if (!line_in_range(lnum, buf))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2549 scheme_signal_error(_("linenr out of range"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2550 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2551
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2552 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2553 * Check if deleting lines made the cursor position invalid
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2554 * (or you'll get msg from Vim about invalid linenr).
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2555 * Changed the lines from "lo" to "hi" and added "extra" lines (negative if
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2556 * deleted). Got from if_python.c
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2557 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2558 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2559 mz_fix_cursor(int lo, int hi, int extra)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2560 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2561 if (curwin->w_cursor.lnum >= lo)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2562 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2563 /* Adjust the cursor position if it's in/after the changed
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2564 * lines. */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2565 if (curwin->w_cursor.lnum >= hi)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2566 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2567 curwin->w_cursor.lnum += extra;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2568 check_cursor_col();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2569 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2570 else if (extra < 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2571 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2572 curwin->w_cursor.lnum = lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2573 check_cursor();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2574 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2575 changed_cline_bef_curs();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2576 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2577 invalidate_botline();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2578 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2579
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2580 static Vim_Prim prims[]=
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2581 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2582 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2583 * Buffer-related commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2584 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2585 {get_buffer_line, "get-buff-line", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2586 {set_buffer_line, "set-buff-line", 2, 3},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2587 {get_buffer_line_list, "get-buff-line-list", 2, 3},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2588 {get_buffer_name, "get-buff-name", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2589 {get_buffer_num, "get-buff-num", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2590 {get_buffer_size, "get-buff-size", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2591 {set_buffer_line_list, "set-buff-line-list", 3, 4},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2592 {insert_buffer_line_list, "insert-buff-line-list", 2, 3},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2593 {get_curr_buffer, "curr-buff", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2594 {get_buffer_count, "buff-count", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2595 {get_next_buffer, "get-next-buff", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2596 {get_prev_buffer, "get-prev-buff", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2597 {mzscheme_open_buffer, "open-buff", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2598 {get_buffer_by_name, "get-buff-by-name", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2599 {get_buffer_by_num, "get-buff-by-num", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2600 {get_buffer_namespace, "get-buff-namespace", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2601 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2602 * Window-related commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2603 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2604 {get_curr_win, "curr-win", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2605 {get_window_count, "win-count", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2606 {get_window_by_num, "get-win-by-num", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2607 {get_window_num, "get-win-num", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2608 {get_window_buffer, "get-win-buffer", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2609 {get_window_height, "get-win-height", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2610 {set_window_height, "set-win-height", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2611 #ifdef FEAT_VERTSPLIT
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2612 {get_window_width, "get-win-width", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2613 {set_window_width, "set-win-width", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2614 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2615 {get_cursor, "get-cursor", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2616 {set_cursor, "set-cursor", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2617 {get_window_list, "get-win-list", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2618 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2619 * Vim-related commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2620 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2621 {vim_command, "command", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2622 {vim_eval, "eval", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2623 {get_range_start, "range-start", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2624 {get_range_end, "range-end", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2625 {mzscheme_beep, "beep", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2626 {get_option, "get-option", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2627 {set_option, "set-option", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2628 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2629 * small utilities
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2630 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2631 {vim_bufferp, "buff?", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2632 {vim_windowp, "win?", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2633 {vim_buffer_validp, "buff-valid?", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2634 {vim_window_validp, "win-valid?", 1, 1}
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2635 };
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2636
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2637 /* return MzScheme wrapper for curbuf */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2638 static vim_mz_buffer *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2639 get_vim_curr_buffer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2640 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
2641 if (curbuf->b_mzscheme_ref == NULL)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2642 return (vim_mz_buffer *)buffer_new(curbuf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2643 else
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
2644 return (vim_mz_buffer *)curbuf->b_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2645 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2646
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2647 /* return MzScheme wrapper for curwin */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2648 static vim_mz_window *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2649 get_vim_curr_window(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2650 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
2651 if (curwin->w_mzscheme_ref == NULL)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2652 return (vim_mz_window *)window_new(curwin);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2653 else
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
2654 return (vim_mz_window *)curwin->w_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2655 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2656
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2657 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2658 make_modules(Scheme_Env *env)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2659 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2660 int i;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2661 Scheme_Env *mod;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2662
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2663 mod = scheme_primitive_module(scheme_intern_symbol("vimext"), env);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2664 /* all prims made closed so they can access their own names */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2665 for (i = 0; i < sizeof(prims)/sizeof(prims[0]); i++)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2666 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2667 Vim_Prim *prim = prims + i;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2668 scheme_add_global(prim->name,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2669 scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2670 prim->mina, prim->maxa),
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2671 mod);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2672 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2673 scheme_add_global("global-namespace", (Scheme_Object *)environment, mod);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2674 scheme_finish_primitive_module(mod);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2675 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
2676
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2677 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2678 static Scheme_Object *M_write = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2679 static Scheme_Object *M_read = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2680 static Scheme_Object *M_execute = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2681 static Scheme_Object *M_delete = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2682
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2683 static void
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 856
diff changeset
2684 sandbox_check(void)
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2685 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2686 if (sandbox)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2687 raise_vim_exn(_("not allowed in the Vim sandbox"));
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2688 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2689
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
2690 /* security guards to force Vim's sandbox restrictions on MzScheme level */
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2691 static Scheme_Object *
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2692 sandbox_file_guard(int argc, Scheme_Object **argv)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2693 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2694 if (sandbox)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2695 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2696 Scheme_Object *requested_access = argv[2];
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2697
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2698 if (M_write == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2699 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2700 MZ_REGISTER_STATIC(M_write);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2701 M_write = scheme_intern_symbol("write");
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2702 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2703 if (M_read == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2704 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2705 MZ_REGISTER_STATIC(M_read);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2706 M_read = scheme_intern_symbol("read");
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2707 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2708 if (M_execute == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2709 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2710 MZ_REGISTER_STATIC(M_execute);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2711 M_execute = scheme_intern_symbol("execute");
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2712 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2713 if (M_delete == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2714 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2715 MZ_REGISTER_STATIC(M_delete);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2716 M_delete = scheme_intern_symbol("delete");
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2717 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2718
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2719 while (!SCHEME_NULLP(requested_access))
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2720 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2721 Scheme_Object *item = SCHEME_CAR(requested_access);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2722 if (scheme_eq(item, M_write) || scheme_eq(item, M_read)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2723 || scheme_eq(item, M_execute) || scheme_eq(item, M_delete))
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2724 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2725 raise_vim_exn(_("not allowed in the Vim sandbox"));
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2726 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2727 requested_access = SCHEME_CDR(requested_access);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2728 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2729 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2730 return scheme_void;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2731 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2732
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2733 static Scheme_Object *
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2734 sandbox_network_guard(int argc, Scheme_Object **argv)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2735 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2736 return scheme_void;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2737 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2738 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
2739
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
2740 #endif