annotate src/if_mzsch.c @ 3443:21219ffc9790 v7.3.487

updated for version 7.3.487 Problem: When setting 'timeoutlen' or 'ttimeoutlen' the column for vertical movement is reset unnecessarily. Solution: Do not set w_set_curswant for every option. Add a test for this. (Kana Natsuno) Add the P_CURSWANT flag for options.
author Bram Moolenaar <bram@vim.org>
date Wed, 28 Mar 2012 19:59:04 +0200
parents af4ed13ca541
children 3c072c1cb873
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 *
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
7 * TODO Convert byte-strings to char strings?
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
8 *
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
9 * This consists of six parts:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
10 * 1. MzScheme interpreter main program
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
11 * 2. Routines that handle the external interface between MzScheme and
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
12 * Vim.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
13 * 3. MzScheme input/output handlers: writes output via [e]msg().
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
14 * 4. Implementation of the Vim Features for MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
15 * 5. Vim Window-related Manipulation Functions.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
16 * 6. Vim Buffer-related Manipulation Functions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
17 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
18 * NOTES
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
19 * 1. Memory, allocated with scheme_malloc*, need not to be freed explicitly,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
20 * garbage collector will do it self
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
21 * 2. Requires at least NORMAL features. I can't imagine why one may want
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
22 * to build with SMALL or TINY features but with MzScheme interface.
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
23 * 3. I don't use K&R-style functions. Anyways, MzScheme headers are ANSI.
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
24 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
25
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
26 #include "vim.h"
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
27
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
28 #include "if_mzsch.h"
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
29
800
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
30 /* Only do the following when the feature is enabled. Needed for "make
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
31 * depend". */
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
32 #if defined(FEAT_MZSCHEME) || defined(PROTO)
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
33
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
34 /* Base data structures */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
35 #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
36 #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
37
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
38 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
39 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
40 Scheme_Object so;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
41 buf_T *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
42 } vim_mz_buffer;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
43
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
44 #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
45
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
46 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
47 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
48 Scheme_Object so;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 575
diff changeset
49 win_T *win;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
50 } vim_mz_window;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
51
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
52 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
53
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
54 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
55 * Prims that form MzScheme Vim interface
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
56 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
57 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
58 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
59 Scheme_Closed_Prim *prim;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
60 char *name;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
61 int mina; /* arity information */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
62 int maxa;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
63 } Vim_Prim;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
64
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
65 typedef struct
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
66 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
67 char *name;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
68 Scheme_Object *port;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
69 } Port_Info;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
70
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
71 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
72 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
73 * Vim-Control Commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
74 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
75 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
76 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
77 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
78 * Utility functions for the vim/mzscheme interface
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
79 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
80 */
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
81 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
82 static Scheme_Object *sandbox_file_guard(int, Scheme_Object **);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
83 static Scheme_Object *sandbox_network_guard(int, Scheme_Object **);
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 856
diff changeset
84 static void sandbox_check(void);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
85 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
86 /* Buffer-related commands */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
87 static Scheme_Object *buffer_new(buf_T *buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
88 static Scheme_Object *get_buffer_by_name(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
89 static Scheme_Object *get_buffer_by_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
90 static Scheme_Object *get_buffer_count(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
91 static Scheme_Object *get_buffer_line(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
92 static Scheme_Object *get_buffer_line_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
93 static Scheme_Object *get_buffer_name(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
94 static Scheme_Object *get_buffer_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
95 static Scheme_Object *get_buffer_size(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
96 static Scheme_Object *get_curr_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
97 static Scheme_Object *get_next_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
98 static Scheme_Object *get_prev_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
99 static Scheme_Object *mzscheme_open_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
100 static Scheme_Object *set_buffer_line(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
101 static Scheme_Object *set_buffer_line_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
102 static Scheme_Object *insert_buffer_line_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
103 static Scheme_Object *get_range_start(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
104 static Scheme_Object *get_range_end(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
105 static vim_mz_buffer *get_vim_curr_buffer(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
106
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
107 /* Window-related commands */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
108 static Scheme_Object *window_new(win_T *win);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
109 static Scheme_Object *get_curr_win(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
110 static Scheme_Object *get_window_count(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
111 static Scheme_Object *get_window_by_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
112 static Scheme_Object *get_window_num(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
113 static Scheme_Object *get_window_buffer(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
114 static Scheme_Object *get_window_height(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
115 static Scheme_Object *set_window_height(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
116 #ifdef FEAT_VERTSPLIT
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
117 static Scheme_Object *get_window_width(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
118 static Scheme_Object *set_window_width(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
119 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
120 static Scheme_Object *get_cursor(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
121 static Scheme_Object *set_cursor(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
122 static Scheme_Object *get_window_list(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
123 static vim_mz_window *get_vim_curr_window(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
124
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
125 /* Vim-related commands */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
126 static Scheme_Object *mzscheme_beep(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
127 static Scheme_Object *get_option(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
128 static Scheme_Object *set_option(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
129 static Scheme_Object *vim_command(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
130 static Scheme_Object *vim_eval(void *, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
131 static Scheme_Object *vim_bufferp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
132 static Scheme_Object *vim_windowp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
133 static Scheme_Object *vim_buffer_validp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
134 static Scheme_Object *vim_window_validp(void *data, int, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
135
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
136 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
137 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
138 * Internal Function Prototypes
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
139 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
140 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
141 static int vim_error_check(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
142 static int do_mzscheme_command(exarg_T *, void *, Scheme_Closed_Prim *what);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
143 static void startup_mzscheme(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
144 static char *string_to_line(Scheme_Object *obj);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
145 static void do_output(char *mesg, long len);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
146 static void do_printf(char *format, ...);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
147 static void do_flush(void);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
148 static Scheme_Object *_apply_thunk_catch_exceptions(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
149 Scheme_Object *, Scheme_Object **);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
150 static Scheme_Object *extract_exn_message(Scheme_Object *v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
151 static Scheme_Object *do_eval(void *, int noargc, Scheme_Object **noargv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
152 static Scheme_Object *do_load(void *, int noargc, Scheme_Object **noargv);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
153 static void register_vim_exn(void);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
154 static vim_mz_buffer *get_buffer_arg(const char *fname, int argnum,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
155 int argc, Scheme_Object **argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
156 static vim_mz_window *get_window_arg(const char *fname, int argnum,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
157 int argc, Scheme_Object **argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
158 static int line_in_range(linenr_T, buf_T *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
159 static void check_line_range(linenr_T, buf_T *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
160 static void mz_fix_cursor(int lo, int hi, int extra);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
161
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
162 static int eval_with_exn_handling(void *, Scheme_Closed_Prim *,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
163 Scheme_Object **ret);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
164 static void make_modules(void);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
165 static void init_exn_catching_apply(void);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
166 static int mzscheme_env_main(Scheme_Env *env, int argc, char **argv);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
167 static int mzscheme_init(void);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
168 #ifdef FEAT_EVAL
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
169 static Scheme_Object *vim_to_mzscheme(typval_T *vim_value, int depth,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
170 Scheme_Hash_Table *visited);
2050
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
171 static int mzscheme_to_vim(Scheme_Object *obj, typval_T *tv, int depth,
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
172 Scheme_Hash_Table *visited);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
173 #endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
174
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
175 #ifdef MZ_PRECISE_GC
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
176 static int buffer_size_proc(void *obj UNUSED)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
177 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
178 return gcBYTES_TO_WORDS(sizeof(vim_mz_buffer));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
179 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
180 static int buffer_mark_proc(void *obj)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
181 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
182 return buffer_size_proc(obj);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
183 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
184 static int buffer_fixup_proc(void *obj)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
185 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
186 return buffer_size_proc(obj);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
187 }
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
188 static int window_size_proc(void *obj UNUSED)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
189 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
190 return gcBYTES_TO_WORDS(sizeof(vim_mz_window));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
191 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
192 static int window_mark_proc(void *obj)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
193 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
194 return window_size_proc(obj);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
195 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
196 static int window_fixup_proc(void *obj)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
197 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
198 return window_size_proc(obj);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
199 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
200 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
201
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
202 #ifdef DYNAMIC_MZSCHEME
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
203
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
204 static Scheme_Object *dll_scheme_eof;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
205 static Scheme_Object *dll_scheme_false;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
206 static Scheme_Object *dll_scheme_void;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
207 static Scheme_Object *dll_scheme_null;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
208 static Scheme_Object *dll_scheme_true;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
209
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
210 static Scheme_Thread **dll_scheme_current_thread_ptr;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
211
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
212 static void (**dll_scheme_console_printf_ptr)(char *str, ...);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
213 static void (**dll_scheme_console_output_ptr)(char *str, long len);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
214 static void (**dll_scheme_notify_multithread_ptr)(int on);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
215
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
216 static void *(*dll_GC_malloc)(size_t size_in_bytes);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
217 static void *(*dll_GC_malloc_atomic)(size_t size_in_bytes);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
218 static Scheme_Env *(*dll_scheme_basic_env)(void);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
219 static void (*dll_scheme_check_threads)(void);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
220 static void (*dll_scheme_register_static)(void *ptr, long size);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
221 static void (*dll_scheme_set_stack_base)(void *base, int no_auto_statics);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
222 static void (*dll_scheme_add_global)(const char *name, Scheme_Object *val,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
223 Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
224 static void (*dll_scheme_add_global_symbol)(Scheme_Object *name,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
225 Scheme_Object *val, Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
226 static Scheme_Object *(*dll_scheme_apply)(Scheme_Object *rator, int num_rands,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
227 Scheme_Object **rands);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
228 static Scheme_Object *(*dll_scheme_builtin_value)(const char *name);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
229 # if MZSCHEME_VERSION_MAJOR >= 299
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
230 static Scheme_Object *(*dll_scheme_byte_string_to_char_string)(Scheme_Object *s);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
231 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
232 static void (*dll_scheme_close_input_port)(Scheme_Object *port);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
233 static void (*dll_scheme_count_lines)(Scheme_Object *port);
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
234 #if MZSCHEME_VERSION_MAJOR < 360
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
235 static Scheme_Object *(*dll_scheme_current_continuation_marks)(void);
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
236 #else
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
237 static Scheme_Object *(*dll_scheme_current_continuation_marks)(Scheme_Object *prompt_tag);
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
238 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
239 static void (*dll_scheme_display)(Scheme_Object *obj, Scheme_Object *port);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
240 static char *(*dll_scheme_display_to_string)(Scheme_Object *obj, long *len);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
241 static int (*dll_scheme_eq)(Scheme_Object *obj1, Scheme_Object *obj2);
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
242 static Scheme_Object *(*dll_scheme_do_eval)(Scheme_Object *obj,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
243 int _num_rands, Scheme_Object **rands, int val);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
244 static void (*dll_scheme_dont_gc_ptr)(void *p);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
245 static Scheme_Object *(*dll_scheme_eval)(Scheme_Object *obj, Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
246 static Scheme_Object *(*dll_scheme_eval_string)(const char *str,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
247 Scheme_Env *env);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
248 static Scheme_Object *(*dll_scheme_eval_string_all)(const char *str,
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
249 Scheme_Env *env, int all);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
250 static void (*dll_scheme_finish_primitive_module)(Scheme_Env *env);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
251 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
252 static char *(*dll_scheme_format)(char *format, int flen, int argc,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
253 Scheme_Object **argv, long *rlen);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
254 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
255 static char *(*dll_scheme_format_utf8)(char *format, int flen, int argc,
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
256 Scheme_Object **argv, long *rlen);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
257 static Scheme_Object *(*dll_scheme_get_param)(Scheme_Config *c, int pos);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
258 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
259 static void (*dll_scheme_gc_ptr_ok)(void *p);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
260 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
261 static char *(*dll_scheme_get_sized_string_output)(Scheme_Object *,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
262 long *len);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
263 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
264 static char *(*dll_scheme_get_sized_byte_string_output)(Scheme_Object *,
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
265 long *len);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
266 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
267 static Scheme_Object *(*dll_scheme_intern_symbol)(const char *name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
268 static Scheme_Object *(*dll_scheme_lookup_global)(Scheme_Object *symbol,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
269 Scheme_Env *env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
270 static Scheme_Object *(*dll_scheme_make_closed_prim_w_arity)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
271 (Scheme_Closed_Prim *prim, void *data, const char *name, mzshort mina,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
272 mzshort maxa);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
273 static Scheme_Object *(*dll_scheme_make_integer_value)(long i);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
274 static Scheme_Object *(*dll_scheme_make_pair)(Scheme_Object *car,
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
275 Scheme_Object *cdr);
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
276 static Scheme_Object *(*dll_scheme_make_prim_w_arity)(Scheme_Prim *prim,
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
277 const char *name, mzshort mina, mzshort maxa);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
278 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
279 static Scheme_Object *(*dll_scheme_make_string)(const char *chars);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
280 static Scheme_Object *(*dll_scheme_make_string_output_port)();
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
281 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
282 static Scheme_Object *(*dll_scheme_make_byte_string)(const char *chars);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
283 static Scheme_Object *(*dll_scheme_make_byte_string_output_port)();
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
284 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
285 static Scheme_Object *(*dll_scheme_make_struct_instance)(Scheme_Object *stype,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
286 int argc, Scheme_Object **argv);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
287 static Scheme_Object **(*dll_scheme_make_struct_names)(Scheme_Object *base,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
288 Scheme_Object *field_names, int flags, int *count_out);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
289 static Scheme_Object *(*dll_scheme_make_struct_type)(Scheme_Object *base,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
290 Scheme_Object *parent, Scheme_Object *inspector, int num_fields,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
291 int num_uninit_fields, Scheme_Object *uninit_val,
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
292 Scheme_Object *properties
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
293 # if MZSCHEME_VERSION_MAJOR >= 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
294 , Scheme_Object *guard
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
295 # endif
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
296 );
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
297 static Scheme_Object **(*dll_scheme_make_struct_values)(
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
298 Scheme_Object *struct_type, Scheme_Object **names, int count,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
299 int flags);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
300 static Scheme_Type (*dll_scheme_make_type)(const char *name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
301 static Scheme_Object *(*dll_scheme_make_vector)(int size,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
302 Scheme_Object *fill);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
303 static void *(*dll_scheme_malloc_fail_ok)(void *(*f)(size_t), size_t);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
304 static Scheme_Object *(*dll_scheme_open_input_file)(const char *name,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
305 const char *who);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
306 static Scheme_Env *(*dll_scheme_primitive_module)(Scheme_Object *name,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
307 Scheme_Env *for_env);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
308 static int (*dll_scheme_proper_list_length)(Scheme_Object *list);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
309 static void (*dll_scheme_raise)(Scheme_Object *exn);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
310 static Scheme_Object *(*dll_scheme_read)(Scheme_Object *port);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
311 static void (*dll_scheme_signal_error)(const char *msg, ...);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
312 static void (*dll_scheme_wrong_type)(const char *name, const char *expected,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
313 int which, int argc, Scheme_Object **argv);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
314 # if MZSCHEME_VERSION_MAJOR >= 299
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
315 static void (*dll_scheme_set_param)(Scheme_Config *c, int pos,
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
316 Scheme_Object *o);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
317 static Scheme_Config *(*dll_scheme_current_config)(void);
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
318 static Scheme_Object *(*dll_scheme_char_string_to_byte_string)
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
319 (Scheme_Object *s);
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
320 static Scheme_Object *(*dll_scheme_char_string_to_path)
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
321 (Scheme_Object *s);
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
322 # endif
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
323 static Scheme_Hash_Table *(*dll_scheme_make_hash_table)(int type);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
324 static void (*dll_scheme_hash_set)(Scheme_Hash_Table *table,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
325 Scheme_Object *key, Scheme_Object *value);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
326 static Scheme_Object *(*dll_scheme_hash_get)(Scheme_Hash_Table *table,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
327 Scheme_Object *key);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
328 static Scheme_Object *(*dll_scheme_make_double)(double d);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
329 # ifdef INCLUDE_MZSCHEME_BASE
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
330 static Scheme_Object *(*dll_scheme_make_sized_byte_string)(char *chars,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
331 long len, int copy);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
332 static Scheme_Object *(*dll_scheme_namespace_require)(Scheme_Object *req);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
333 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
334
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
335 /* arrays are imported directly */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
336 # define scheme_eof dll_scheme_eof
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
337 # define scheme_false dll_scheme_false
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
338 # define scheme_void dll_scheme_void
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
339 # define scheme_null dll_scheme_null
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
340 # define scheme_true dll_scheme_true
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
341
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
342 /* pointers are GetProceAddress'ed as pointers to pointer */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
343 # define scheme_current_thread (*dll_scheme_current_thread_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
344 # define scheme_console_printf (*dll_scheme_console_printf_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
345 # define scheme_console_output (*dll_scheme_console_output_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
346 # define scheme_notify_multithread (*dll_scheme_notify_multithread_ptr)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
347
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
348 /* and functions in a usual way */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
349 # define GC_malloc dll_GC_malloc
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
350 # define GC_malloc_atomic dll_GC_malloc_atomic
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
351
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
352 # define scheme_add_global dll_scheme_add_global
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
353 # define scheme_add_global_symbol dll_scheme_add_global_symbol
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
354 # define scheme_apply dll_scheme_apply
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
355 # define scheme_basic_env dll_scheme_basic_env
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
356 # define scheme_builtin_value dll_scheme_builtin_value
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
357 # if MZSCHEME_VERSION_MAJOR >= 299
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
358 # 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
359 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
360 # define scheme_check_threads dll_scheme_check_threads
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
361 # define scheme_close_input_port dll_scheme_close_input_port
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
362 # define scheme_count_lines dll_scheme_count_lines
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
363 # define scheme_current_continuation_marks \
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
364 dll_scheme_current_continuation_marks
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
365 # define scheme_display dll_scheme_display
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
366 # define scheme_display_to_string dll_scheme_display_to_string
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
367 # define scheme_do_eval dll_scheme_do_eval
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
368 # define scheme_dont_gc_ptr dll_scheme_dont_gc_ptr
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
369 # define scheme_eq dll_scheme_eq
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
370 # define scheme_eval dll_scheme_eval
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
371 # define scheme_eval_string dll_scheme_eval_string
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
372 # define scheme_eval_string_all dll_scheme_eval_string_all
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
373 # define scheme_finish_primitive_module dll_scheme_finish_primitive_module
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_format dll_scheme_format
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
376 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
377 # define scheme_format_utf8 dll_scheme_format_utf8
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
378 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
379 # define scheme_gc_ptr_ok dll_scheme_gc_ptr_ok
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
380 # if MZSCHEME_VERSION_MAJOR < 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
381 # define scheme_get_sized_string_output dll_scheme_get_sized_string_output
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
382 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
383 # define scheme_get_sized_byte_string_output \
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
384 dll_scheme_get_sized_byte_string_output
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
385 # define scheme_get_param dll_scheme_get_param
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
386 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
387 # define scheme_intern_symbol dll_scheme_intern_symbol
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
388 # define scheme_lookup_global dll_scheme_lookup_global
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
389 # 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
390 # define scheme_make_integer_value dll_scheme_make_integer_value
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
391 # define scheme_make_pair dll_scheme_make_pair
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
392 # define scheme_make_prim_w_arity dll_scheme_make_prim_w_arity
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
393 # if MZSCHEME_VERSION_MAJOR < 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
394 # define scheme_make_string dll_scheme_make_string
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
395 # define scheme_make_string_output_port dll_scheme_make_string_output_port
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
396 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
397 # define scheme_make_byte_string dll_scheme_make_byte_string
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
398 # define scheme_make_byte_string_output_port \
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
399 dll_scheme_make_byte_string_output_port
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
400 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
401 # define scheme_make_struct_instance dll_scheme_make_struct_instance
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
402 # define scheme_make_struct_names dll_scheme_make_struct_names
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
403 # define scheme_make_struct_type dll_scheme_make_struct_type
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
404 # define scheme_make_struct_values dll_scheme_make_struct_values
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
405 # define scheme_make_type dll_scheme_make_type
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
406 # define scheme_make_vector dll_scheme_make_vector
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
407 # define scheme_malloc_fail_ok dll_scheme_malloc_fail_ok
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
408 # define scheme_open_input_file dll_scheme_open_input_file
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
409 # define scheme_primitive_module dll_scheme_primitive_module
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
410 # define scheme_proper_list_length dll_scheme_proper_list_length
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
411 # define scheme_raise dll_scheme_raise
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
412 # define scheme_read dll_scheme_read
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
413 # define scheme_register_static dll_scheme_register_static
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
414 # define scheme_set_stack_base dll_scheme_set_stack_base
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
415 # define scheme_signal_error dll_scheme_signal_error
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
416 # define scheme_wrong_type dll_scheme_wrong_type
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
417 # if MZSCHEME_VERSION_MAJOR >= 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
418 # define scheme_set_param dll_scheme_set_param
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
419 # define scheme_current_config dll_scheme_current_config
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
420 # define scheme_char_string_to_byte_string \
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
421 dll_scheme_char_string_to_byte_string
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
422 # define scheme_char_string_to_path \
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
423 dll_scheme_char_string_to_path
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
424 # endif
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
425 # define scheme_make_hash_table dll_scheme_make_hash_table
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
426 # define scheme_hash_set dll_scheme_hash_set
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
427 # define scheme_hash_get dll_scheme_hash_get
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
428 # define scheme_make_double dll_scheme_make_double
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
429 # ifdef INCLUDE_MZSCHEME_BASE
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
430 # define scheme_make_sized_byte_string dll_scheme_make_sized_byte_string
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
431 # define scheme_namespace_require dll_scheme_namespace_require
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
432 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
433
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
434 typedef struct
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
435 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
436 char *name;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
437 void **ptr;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
438 } Thunk_Info;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
439
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
440 static Thunk_Info mzgc_imports[] = {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
441 {"GC_malloc", (void **)&dll_GC_malloc},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
442 {"GC_malloc_atomic", (void **)&dll_GC_malloc_atomic},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
443 {NULL, NULL}};
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
444
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
445 static Thunk_Info mzsch_imports[] = {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
446 {"scheme_eof", (void **)&dll_scheme_eof},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
447 {"scheme_false", (void **)&dll_scheme_false},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
448 {"scheme_void", (void **)&dll_scheme_void},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
449 {"scheme_null", (void **)&dll_scheme_null},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
450 {"scheme_true", (void **)&dll_scheme_true},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
451 {"scheme_current_thread", (void **)&dll_scheme_current_thread_ptr},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
452 {"scheme_console_printf", (void **)&dll_scheme_console_printf_ptr},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
453 {"scheme_console_output", (void **)&dll_scheme_console_output_ptr},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
454 {"scheme_notify_multithread",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
455 (void **)&dll_scheme_notify_multithread_ptr},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
456 {"scheme_add_global", (void **)&dll_scheme_add_global},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
457 {"scheme_add_global_symbol", (void **)&dll_scheme_add_global_symbol},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
458 {"scheme_apply", (void **)&dll_scheme_apply},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
459 {"scheme_basic_env", (void **)&dll_scheme_basic_env},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
460 # if MZSCHEME_VERSION_MAJOR >= 299
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
461 {"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
462 # endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
463 {"scheme_builtin_value", (void **)&dll_scheme_builtin_value},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
464 {"scheme_check_threads", (void **)&dll_scheme_check_threads},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
465 {"scheme_close_input_port", (void **)&dll_scheme_close_input_port},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
466 {"scheme_count_lines", (void **)&dll_scheme_count_lines},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
467 {"scheme_current_continuation_marks",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
468 (void **)&dll_scheme_current_continuation_marks},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
469 {"scheme_display", (void **)&dll_scheme_display},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
470 {"scheme_display_to_string", (void **)&dll_scheme_display_to_string},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
471 {"scheme_do_eval", (void **)&dll_scheme_do_eval},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
472 {"scheme_dont_gc_ptr", (void **)&dll_scheme_dont_gc_ptr},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
473 {"scheme_eq", (void **)&dll_scheme_eq},
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
474 {"scheme_eval", (void **)&dll_scheme_eval},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
475 {"scheme_eval_string", (void **)&dll_scheme_eval_string},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
476 {"scheme_eval_string_all", (void **)&dll_scheme_eval_string_all},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
477 {"scheme_finish_primitive_module",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
478 (void **)&dll_scheme_finish_primitive_module},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
479 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
480 {"scheme_format", (void **)&dll_scheme_format},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
481 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
482 {"scheme_format_utf8", (void **)&dll_scheme_format_utf8},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
483 {"scheme_get_param", (void **)&dll_scheme_get_param},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
484 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
485 {"scheme_gc_ptr_ok", (void **)&dll_scheme_gc_ptr_ok},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
486 # if MZSCHEME_VERSION_MAJOR < 299
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
487 {"scheme_get_sized_string_output",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
488 (void **)&dll_scheme_get_sized_string_output},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
489 # else
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
490 {"scheme_get_sized_byte_string_output",
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
491 (void **)&dll_scheme_get_sized_byte_string_output},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
492 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
493 {"scheme_intern_symbol", (void **)&dll_scheme_intern_symbol},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
494 {"scheme_lookup_global", (void **)&dll_scheme_lookup_global},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
495 {"scheme_make_closed_prim_w_arity",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
496 (void **)&dll_scheme_make_closed_prim_w_arity},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
497 {"scheme_make_integer_value", (void **)&dll_scheme_make_integer_value},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
498 {"scheme_make_pair", (void **)&dll_scheme_make_pair},
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
499 {"scheme_make_prim_w_arity", (void **)&dll_scheme_make_prim_w_arity},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
500 # if MZSCHEME_VERSION_MAJOR < 299
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
501 {"scheme_make_string", (void **)&dll_scheme_make_string},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
502 {"scheme_make_string_output_port",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
503 (void **)&dll_scheme_make_string_output_port},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
504 # else
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
505 {"scheme_make_byte_string", (void **)&dll_scheme_make_byte_string},
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
506 {"scheme_make_byte_string_output_port",
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
507 (void **)&dll_scheme_make_byte_string_output_port},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
508 # endif
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
509 {"scheme_make_struct_instance",
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
510 (void **)&dll_scheme_make_struct_instance},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
511 {"scheme_make_struct_names", (void **)&dll_scheme_make_struct_names},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
512 {"scheme_make_struct_type", (void **)&dll_scheme_make_struct_type},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
513 {"scheme_make_struct_values", (void **)&dll_scheme_make_struct_values},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
514 {"scheme_make_type", (void **)&dll_scheme_make_type},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
515 {"scheme_make_vector", (void **)&dll_scheme_make_vector},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
516 {"scheme_malloc_fail_ok", (void **)&dll_scheme_malloc_fail_ok},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
517 {"scheme_open_input_file", (void **)&dll_scheme_open_input_file},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
518 {"scheme_primitive_module", (void **)&dll_scheme_primitive_module},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
519 {"scheme_proper_list_length", (void **)&dll_scheme_proper_list_length},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
520 {"scheme_raise", (void **)&dll_scheme_raise},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
521 {"scheme_read", (void **)&dll_scheme_read},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
522 {"scheme_register_static", (void **)&dll_scheme_register_static},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
523 {"scheme_set_stack_base", (void **)&dll_scheme_set_stack_base},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
524 {"scheme_signal_error", (void **)&dll_scheme_signal_error},
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
525 {"scheme_wrong_type", (void **)&dll_scheme_wrong_type},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
526 # if MZSCHEME_VERSION_MAJOR >= 299
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
527 {"scheme_set_param", (void **)&dll_scheme_set_param},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
528 {"scheme_current_config", (void **)&dll_scheme_current_config},
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
529 {"scheme_char_string_to_byte_string",
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
530 (void **)&dll_scheme_char_string_to_byte_string},
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
531 {"scheme_char_string_to_path", (void **)&dll_scheme_char_string_to_path},
151
40a0699b6c62 updated for version 7.0046
vimboss
parents: 137
diff changeset
532 # endif
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
533 {"scheme_make_hash_table", (void **)&dll_scheme_make_hash_table},
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
534 {"scheme_hash_set", (void **)&dll_scheme_hash_set},
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
535 {"scheme_hash_get", (void **)&dll_scheme_hash_get},
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
536 {"scheme_make_double", (void **)&dll_scheme_make_double},
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
537 # ifdef INCLUDE_MZSCHEME_BASE
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
538 {"scheme_make_sized_byte_string", (void **)&dll_scheme_make_sized_byte_string},
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
539 {"scheme_namespace_require", (void **)&dll_scheme_namespace_require},
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
540 #endif
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
541 {NULL, NULL}};
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
542
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
543 static HINSTANCE hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
544 static HINSTANCE hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
545
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
546 static void dynamic_mzscheme_end(void);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
547 static int mzscheme_runtime_link_init(char *sch_dll, char *gc_dll,
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
548 int verbose);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
549
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
550 static int
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
551 mzscheme_runtime_link_init(char *sch_dll, char *gc_dll, int verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
552 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
553 Thunk_Info *thunk = NULL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
554
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
555 if (hMzGC && hMzSch)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
556 return OK;
2612
fa5dee44df3f updated for version 7.3.034
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
557 hMzSch = vimLoadLib(sch_dll);
fa5dee44df3f updated for version 7.3.034
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
558 hMzGC = vimLoadLib(gc_dll);
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
559
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
560 if (!hMzGC)
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
561 {
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
562 if (verbose)
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
563 EMSG2(_(e_loadlib), gc_dll);
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
564 return FAIL;
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
565 }
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
566
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
567 if (!hMzSch)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
568 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
569 if (verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
570 EMSG2(_(e_loadlib), sch_dll);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
571 return FAIL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
572 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
573
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
574 for (thunk = mzsch_imports; thunk->name; thunk++)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
575 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
576 if ((*thunk->ptr =
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
577 (void *)GetProcAddress(hMzSch, thunk->name)) == NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
578 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
579 FreeLibrary(hMzSch);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
580 hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
581 FreeLibrary(hMzGC);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
582 hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
583 if (verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
584 EMSG2(_(e_loadfunc), thunk->name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
585 return FAIL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
586 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
587 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
588 for (thunk = mzgc_imports; thunk->name; thunk++)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
589 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
590 if ((*thunk->ptr =
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
591 (void *)GetProcAddress(hMzGC, thunk->name)) == NULL)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
592 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
593 FreeLibrary(hMzSch);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
594 hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
595 FreeLibrary(hMzGC);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
596 hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
597 if (verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
598 EMSG2(_(e_loadfunc), thunk->name);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
599 return FAIL;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
600 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
601 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
602 return OK;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
603 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
604
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
605 int
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
606 mzscheme_enabled(int verbose)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
607 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
608 return mzscheme_runtime_link_init(
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
609 DYNAMIC_MZSCH_DLL, DYNAMIC_MZGC_DLL, verbose) == OK;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
610 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
611
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
612 static void
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
613 dynamic_mzscheme_end(void)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
614 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
615 if (hMzSch)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
616 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
617 FreeLibrary(hMzSch);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
618 hMzSch = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
619 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
620 if (hMzGC)
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
621 {
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
622 FreeLibrary(hMzGC);
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
623 hMzGC = 0;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
624 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
625 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
626 #endif /* DYNAMIC_MZSCHEME */
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
627
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
628 /* need to put it here for dynamic stuff to work */
1950
1c64bf25bbcd updated for version 7.2-247
vimboss
parents: 1929
diff changeset
629 #if defined(INCLUDE_MZSCHEME_BASE)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
630 # include "mzscheme_base.c"
1950
1c64bf25bbcd updated for version 7.2-247
vimboss
parents: 1929
diff changeset
631 #elif MZSCHEME_VERSION_MAJOR >= 400
1c64bf25bbcd updated for version 7.2-247
vimboss
parents: 1929
diff changeset
632 # error MzScheme 4.x must include mzscheme_base.c, for MinGW32 you need to define MZSCHEME_GENERATE_BASE=yes
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
633 #endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
634
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
635 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
636 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
637 * 1. MzScheme interpreter startup
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
638 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
639 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
640
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
641 static Scheme_Type mz_buffer_type;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
642 static Scheme_Type mz_window_type;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
643
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
644 static int initialized = FALSE;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
645
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
646 /* global environment */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
647 static Scheme_Env *environment = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
648 /* output/error handlers */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
649 static Scheme_Object *curout = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
650 static Scheme_Object *curerr = NULL;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
651 /* exn:vim exception */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
652 static Scheme_Object *exn_catching_apply = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
653 static Scheme_Object *exn_p = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
654 static Scheme_Object *exn_message = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
655 static Scheme_Object *vim_exn = NULL; /* Vim Error exception */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
656
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
657 #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
658 static void *stack_base = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
659 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
660
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
661 static long range_start;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
662 static long range_end;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
663
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
664 /* MzScheme threads scheduling stuff */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
665 static int mz_threads_allow = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
666
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
667 #if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
668 static void CALLBACK timer_proc(HWND, UINT, UINT, DWORD);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
669 static UINT timer_id = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
670 #elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
671 static gint timer_proc(gpointer);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
672 static guint timer_id = 0;
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 static void timer_proc(XtPointer, XtIntervalId *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
675 static XtIntervalId timer_id = (XtIntervalId)0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
676 #elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
677 pascal void timer_proc(EventLoopTimerRef, void *);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
678 static EventLoopTimerRef timer_id = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
679 static EventLoopTimerUPP timerUPP;
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 #ifndef FEAT_GUI_W32 /* Win32 console and Unix */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
683 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
684 mzvim_check_threads(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
685 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
686 /* Last time MzScheme threads were scheduled */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
687 static time_t mz_last_time = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
688
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
689 if (mz_threads_allow && p_mzq > 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
690 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
691 time_t now = time(NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
692
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
693 if ((now - mz_last_time) * 1000 > p_mzq)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
694 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
695 mz_last_time = now;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
696 scheme_check_threads();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
697 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
698 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
699 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
700 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
701
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
702 #ifdef MZSCHEME_GUI_THREADS
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
703 static void setup_timer(void);
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
704 static void remove_timer(void);
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
705
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
706 /* timers are presented in GUI only */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
707 # if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
708 static void CALLBACK
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
709 timer_proc(HWND hwnd UNUSED, UINT uMsg UNUSED, UINT idEvent UNUSED, DWORD dwTime UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
710 # elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
711 static gint
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
712 timer_proc(gpointer data UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
713 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
714 static void
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
715 timer_proc(XtPointer timed_out UNUSED, XtIntervalId *interval_id UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
716 # elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
717 pascal void
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
718 timer_proc(EventLoopTimerRef theTimer UNUSED, void *userData UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
719 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
720 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
721 scheme_check_threads();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
722 # if defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
723 return TRUE; /* continue receiving notifications */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
724 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
725 /* renew timeout */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
726 if (mz_threads_allow && p_mzq > 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
727 timer_id = XtAppAddTimeOut(app_context, p_mzq,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
728 timer_proc, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
729 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
730 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
731
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
732 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
733 setup_timer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
734 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
735 # if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
736 timer_id = SetTimer(NULL, 0, p_mzq, timer_proc);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
737 # elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
738 timer_id = gtk_timeout_add((guint32)p_mzq, (GtkFunction)timer_proc, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
739 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
740 timer_id = XtAppAddTimeOut(app_context, p_mzq, timer_proc, NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
741 # elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
742 timerUPP = NewEventLoopTimerUPP(timer_proc);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
743 InstallEventLoopTimer(GetMainEventLoop(), p_mzq * kEventDurationMillisecond,
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
744 p_mzq * kEventDurationMillisecond, timerUPP, NULL, &timer_id);
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 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
749 remove_timer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
750 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
751 # if defined(FEAT_GUI_W32)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
752 KillTimer(NULL, timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
753 # elif defined(FEAT_GUI_GTK)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
754 gtk_timeout_remove(timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
755 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
756 XtRemoveTimeOut(timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
757 # elif defined(FEAT_GUI_MAC)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
758 RemoveEventLoopTimer(timer_id);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
759 DisposeEventLoopTimerUPP(timerUPP);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
760 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
761 timer_id = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
762 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
763
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
764 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
765 mzvim_reset_timer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
766 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
767 if (timer_id != 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
768 remove_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
769 if (mz_threads_allow && p_mzq > 0 && gui.in_use)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
770 setup_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
771 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
772
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
773 #endif /* MZSCHEME_GUI_THREADS */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
774
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
775 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
776 notify_multithread(int on)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
777 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
778 mz_threads_allow = on;
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
779 #ifdef MZSCHEME_GUI_THREADS
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
780 if (on && timer_id == 0 && p_mzq > 0 && gui.in_use)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
781 setup_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
782 if (!on && timer_id != 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
783 remove_timer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
784 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
785 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
786
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
787 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
788 mzscheme_end(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
789 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
790 #ifdef DYNAMIC_MZSCHEME
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
791 dynamic_mzscheme_end();
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
792 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
793 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
794
2628
5c4b2fc4f067 updated for version 7.3.049
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
795 #if MZSCHEME_VERSION_MAJOR >= 500 && defined(WIN32) && defined(USE_THREAD_LOCAL)
5c4b2fc4f067 updated for version 7.3.049
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
796 static __declspec(thread) void *tls_space;
5c4b2fc4f067 updated for version 7.3.049
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
797 #endif
5c4b2fc4f067 updated for version 7.3.049
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
798
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
799 /*
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
800 * Since version 4.x precise GC requires trampolined startup.
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
801 * Futures and places in version 5.x need it too.
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
802 */
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
803 #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400 \
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
804 || MZSCHEME_VERSION_MAJOR >= 500 && (defined(MZ_USE_FUTURES) || defined(MZ_USE_PLACES))
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
805 # ifdef DYNAMIC_MZSCHEME
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
806 # error Precise GC v.4+ or Racket with futures/places do not support dynamic MzScheme
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
807 # endif
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
808 # define TRAMPOLINED_MZVIM_STARTUP
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
809 #endif
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
810
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
811 int
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
812 mzscheme_main(int argc, char** argv)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
813 {
2628
5c4b2fc4f067 updated for version 7.3.049
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
814 #if MZSCHEME_VERSION_MAJOR >= 500 && defined(WIN32) && defined(USE_THREAD_LOCAL)
5c4b2fc4f067 updated for version 7.3.049
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
815 scheme_register_tls_space(&tls_space, 0);
5c4b2fc4f067 updated for version 7.3.049
Bram Moolenaar <bram@vim.org>
parents: 2612
diff changeset
816 #endif
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
817 #ifdef TRAMPOLINED_MZVIM_STARTUP
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
818 return scheme_main_setup(TRUE, mzscheme_env_main, argc, argv);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
819 #else
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
820 return mzscheme_env_main(NULL, argc, argv);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
821 #endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
822 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
823
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
824 static int
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
825 mzscheme_env_main(Scheme_Env *env, int argc, char **argv)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
826 {
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
827 int vim_main_result;
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
828 #ifdef TRAMPOLINED_MZVIM_STARTUP
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
829 /* Scheme has created the environment for us */
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
830 environment = env;
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
831 #else
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
832 # ifdef MZ_PRECISE_GC
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
833 Scheme_Object *dummy = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
834 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
835 MZ_GC_VAR_IN_REG(0, dummy);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
836
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
837 stack_base = &__gc_var_stack__;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
838 # else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
839 int dummy = 0;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
840 stack_base = (void *)&dummy;
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
841 # endif
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
842 #endif
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
843
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
844 /* mzscheme_main is called as a trampoline from main.
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
845 * We trampoline into vim_main2
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
846 * Passing argc, argv through from mzscheme_main
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
847 */
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
848 vim_main_result = vim_main2(argc, argv);
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
849 #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
850 /* releasing dummy */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
851 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
852 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
853 #endif
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
854 return vim_main_result;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
855 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
856
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
857 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
858 startup_mzscheme(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
859 {
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
860 #ifndef TRAMPOLINED_MZVIM_STARTUP
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
861 scheme_set_stack_base(stack_base, 1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
862 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
863
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
864 MZ_REGISTER_STATIC(environment);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
865 MZ_REGISTER_STATIC(curout);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
866 MZ_REGISTER_STATIC(curerr);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
867 MZ_REGISTER_STATIC(exn_catching_apply);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
868 MZ_REGISTER_STATIC(exn_p);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
869 MZ_REGISTER_STATIC(exn_message);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
870 MZ_REGISTER_STATIC(vim_exn);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
871
3348
af4ed13ca541 updated for version 7.3.441
Bram Moolenaar <bram@vim.org>
parents: 2628
diff changeset
872 #ifndef TRAMPOLINED_MZVIM_STARTUP
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
873 /* in newer versions of precise GC the initial env has been created */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
874 environment = scheme_basic_env();
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
875 #endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
876 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
877
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
878 #ifdef INCLUDE_MZSCHEME_BASE
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
879 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
880 /*
1950
1c64bf25bbcd updated for version 7.2-247
vimboss
parents: 1929
diff changeset
881 * versions 4.x do not provide Scheme bindings by default
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
882 * we need to add them explicitly
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
883 */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
884 Scheme_Object *scheme_base_symbol = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
885 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
886 MZ_GC_VAR_IN_REG(0, scheme_base_symbol);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
887 MZ_GC_REG();
1950
1c64bf25bbcd updated for version 7.2-247
vimboss
parents: 1929
diff changeset
888 /* invoke function from generated and included mzscheme_base.c */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
889 declare_modules(environment);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
890 scheme_base_symbol = scheme_intern_symbol("scheme/base");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
891 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
892 scheme_namespace_require(scheme_base_symbol);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
893 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
894 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
895 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
896 #endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
897 register_vim_exn();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
898 /* use new environment to initialise exception handling */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
899 init_exn_catching_apply();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
900
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
901 /* redirect output */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
902 scheme_console_output = do_output;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
903 scheme_console_printf = do_printf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
904
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
905 #ifdef MZSCHEME_COLLECTS
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
906 /* setup 'current-library-collection-paths' parameter */
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
907 # if MZSCHEME_VERSION_MAJOR >= 299
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
908 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
909 Scheme_Object *coll_byte_string = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
910 Scheme_Object *coll_char_string = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
911 Scheme_Object *coll_path = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
912 Scheme_Object *coll_pair = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
913 Scheme_Config *config = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
914
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
915 MZ_GC_DECL_REG(5);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
916 MZ_GC_VAR_IN_REG(0, coll_byte_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
917 MZ_GC_VAR_IN_REG(1, coll_char_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
918 MZ_GC_VAR_IN_REG(2, coll_path);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
919 MZ_GC_VAR_IN_REG(3, coll_pair);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
920 MZ_GC_VAR_IN_REG(4, config);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
921 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
922 coll_byte_string = scheme_make_byte_string(MZSCHEME_COLLECTS);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
923 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
924 coll_char_string = scheme_byte_string_to_char_string(coll_byte_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
925 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
926 coll_path = scheme_char_string_to_path(coll_char_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
927 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
928 coll_pair = scheme_make_pair(coll_path, scheme_null);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
929 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
930 config = scheme_config;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
931 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
932 scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
933 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
934 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
935 }
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
936 # else
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
937 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
938 Scheme_Object *coll_string = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
939 Scheme_Object *coll_pair = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
940 Scheme_Config *config = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
941
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
942 MZ_GC_DECL_REG(3);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
943 MZ_GC_VAR_IN_REG(0, coll_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
944 MZ_GC_VAR_IN_REG(1, coll_pair);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
945 MZ_GC_VAR_IN_REG(2, config);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
946 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
947 coll_string = scheme_make_string(MZSCHEME_COLLECTS);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
948 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
949 coll_pair = scheme_make_pair(coll_string, scheme_null);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
950 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
951 config = scheme_config;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
952 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
953 scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
954 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
955 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
956 }
1307
64dd70f176c9 updated for version 7.1-021
vimboss
parents: 1301
diff changeset
957 # endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
958 #endif
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
959 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
960 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
961 Scheme_Object *make_security_guard = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
962 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
963 MZ_GC_VAR_IN_REG(0, make_security_guard);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
964 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
965
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
966 #if MZSCHEME_VERSION_MAJOR < 400
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
967 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
968 Scheme_Object *make_security_guard_symbol = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
969 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
970 MZ_GC_VAR_IN_REG(0, make_security_guard_symbol);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
971 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
972 make_security_guard_symbol = scheme_intern_symbol("make-security-guard");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
973 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
974 make_security_guard = scheme_lookup_global(
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
975 make_security_guard_symbol, environment);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
976 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
977 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
978 #else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
979 make_security_guard = scheme_builtin_value("make-security-guard");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
980 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
981 #endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
982
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
983 /* setup sandbox guards */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
984 if (make_security_guard != NULL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
985 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
986 Scheme_Object *args[3] = {NULL, NULL, NULL};
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
987 Scheme_Object *guard = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
988 Scheme_Config *config = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
989 MZ_GC_DECL_REG(5);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
990 MZ_GC_ARRAY_VAR_IN_REG(0, args, 3);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
991 MZ_GC_VAR_IN_REG(3, guard);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
992 MZ_GC_VAR_IN_REG(4, config);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
993 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
994 config = scheme_config;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
995 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
996 args[0] = scheme_get_param(config, MZCONFIG_SECURITY_GUARD);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
997 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
998 args[1] = scheme_make_prim_w_arity(sandbox_file_guard,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
999 "sandbox-file-guard", 3, 3);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1000 args[2] = scheme_make_prim_w_arity(sandbox_network_guard,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1001 "sandbox-network-guard", 4, 4);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1002 guard = scheme_apply(make_security_guard, 3, args);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1003 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1004 scheme_set_param(config, MZCONFIG_SECURITY_GUARD, guard);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1005 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1006 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1007 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1008 MZ_GC_UNREG();
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1009 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1010 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1011 /* Create buffer and window types for use in Scheme code */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1012 mz_buffer_type = scheme_make_type("<vim-buffer>");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1013 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1014 mz_window_type = scheme_make_type("<vim-window>");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1015 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1016 #ifdef MZ_PRECISE_GC
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1017 GC_register_traversers(mz_buffer_type,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1018 buffer_size_proc, buffer_mark_proc, buffer_fixup_proc,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1019 TRUE, TRUE);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1020 GC_register_traversers(mz_window_type,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1021 window_size_proc, window_mark_proc, window_fixup_proc,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1022 TRUE, TRUE);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1023 #endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1024
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1025 make_modules();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1026
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1027 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1028 * setup callback to receive notifications
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1029 * whether thread scheduling is (or not) required
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1030 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1031 scheme_notify_multithread = notify_multithread;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1032 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1033
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1034 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1035 * This routine is called for each new invocation of MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1036 * to make sure things are properly initialized.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1037 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1038 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1039 mzscheme_init(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1040 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1041 if (!initialized)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1042 {
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
1043 #ifdef DYNAMIC_MZSCHEME
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
1044 if (!mzscheme_enabled(TRUE))
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
1045 {
1919
6e9c10c63e25 updated for version 7.2-216
vimboss
parents: 1894
diff changeset
1046 EMSG(_("E815: Sorry, this command is disabled, the MzScheme libraries could not be loaded."));
137
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
1047 return -1;
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
1048 }
3e7d17e425b0 updated for version 7.0044
vimboss
parents: 16
diff changeset
1049 #endif
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1050 startup_mzscheme();
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1051 initialized = TRUE;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1052 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1053 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1054 Scheme_Config *config = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1055 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1056 MZ_GC_VAR_IN_REG(0, config);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1057 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1058 config = scheme_config;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1059 MZ_GC_CHECK();
2023
db3ca1048f7f updated for version 7.2-320
vimboss
parents: 1950
diff changeset
1060 /* recreate ports each call effectively clearing these ones */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1061 curout = scheme_make_string_output_port();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1062 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1063 curerr = scheme_make_string_output_port();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1064 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1065 scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1066 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1067 scheme_set_param(config, MZCONFIG_ERROR_PORT, curerr);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1068 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1069 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1070 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1071
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1072 return 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1073 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1074
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1075 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1076 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1077 * 2. External Interface
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1078 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1079 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1080
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1081 /*
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1082 * Evaluate command with exception handling
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1083 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1084 static int
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1085 eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1086 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1087 Scheme_Object *value = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1088 Scheme_Object *exn = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1089 Scheme_Object *prim = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1090
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1091 MZ_GC_DECL_REG(3);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1092 MZ_GC_VAR_IN_REG(0, value);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1093 MZ_GC_VAR_IN_REG(1, exn);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1094 MZ_GC_VAR_IN_REG(2, prim);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1095 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1096
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1097 prim = scheme_make_closed_prim_w_arity(what, data, "mzvim", 0, 0);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1098 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1099 value = _apply_thunk_catch_exceptions(prim, &exn);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1100 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1101
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1102 if (!value)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1103 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1104 value = extract_exn_message(exn);
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1105 /* Got an exn? */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1106 if (value)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1107 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1108 scheme_display(value, curerr); /* Send to stderr-vim */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1109 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1110 do_flush();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1111 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1112 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1113 /* `raise' was called on some arbitrary value */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1114 return FAIL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1115 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1116
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1117 if (ret != NULL) /* if pointer to retval supported give it up */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1118 *ret = value;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1119 /* Print any result, as long as it's not a void */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1120 else if (!SCHEME_VOIDP(value))
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1121 {
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1122 scheme_display(value, curout); /* Send to stdout-vim */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1123 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1124 }
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1125
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1126 do_flush();
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1127 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1128 return OK;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1129 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1130
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1131 /* :mzscheme */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1132 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1133 do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1134 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1135 if (mzscheme_init())
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1136 return FAIL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1137
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1138 range_start = eap->line1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1139 range_end = eap->line2;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1140
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1141 return eval_with_exn_handling(data, what, NULL);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1142 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1143
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1144 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1145 * Routine called by VIM when deleting a buffer
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1146 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1147 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1148 mzscheme_buffer_free(buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1149 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1150 if (buf->b_mzscheme_ref)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1151 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1152 vim_mz_buffer *bp;
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1153
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1154 bp = buf->b_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1155 bp->buf = INVALID_BUFFER_VALUE;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1156 buf->b_mzscheme_ref = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1157 scheme_gc_ptr_ok(bp);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1158 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1159 }
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 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1163 * Routine called by VIM when deleting a Window
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1164 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1165 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1166 mzscheme_window_free(win_T *win)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1167 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1168 if (win->w_mzscheme_ref)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1169 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1170 vim_mz_window *wp;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1171 wp = win->w_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1172 wp->win = INVALID_WINDOW_VALUE;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1173 win->w_mzscheme_ref = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1174 scheme_gc_ptr_ok(wp);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1175 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1176 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1177 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1178
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1179 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1180 * ":mzscheme" (or ":mz")
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1181 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1182 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1183 ex_mzscheme(exarg_T *eap)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1184 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1185 char_u *script;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1186
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1187 script = script_get(eap, eap->arg);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1188 if (!eap->skip)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1189 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1190 if (script == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1191 do_mzscheme_command(eap, eap->arg, do_eval);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1192 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1193 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1194 do_mzscheme_command(eap, script, do_eval);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1195 vim_free(script);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1196 }
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
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1200 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1201 do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1202 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1203 Scheme_Object *expr = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1204 Scheme_Object *result = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1205 char *file = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1206 Port_Info *pinfo = (Port_Info *)data;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1207
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1208 MZ_GC_DECL_REG(3);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1209 MZ_GC_VAR_IN_REG(0, expr);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1210 MZ_GC_VAR_IN_REG(1, result);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1211 MZ_GC_VAR_IN_REG(2, file);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1212 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1213
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1214 file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1215 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1216
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1217 /* make Vim expansion */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1218 expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1219 pinfo->port = scheme_open_input_file(file, "mzfile");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1220 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1221 scheme_count_lines(pinfo->port); /* to get accurate read error location*/
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1222 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1223
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1224 /* Like REPL but print only last result */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1225 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port)))
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1226 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1227 result = scheme_eval(expr, environment);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1228 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1229 }
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1230
2023
db3ca1048f7f updated for version 7.2-320
vimboss
parents: 1950
diff changeset
1231 /* errors will be caught in do_mzscheme_command and ex_mzfile */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1232 scheme_close_input_port(pinfo->port);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1233 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1234 pinfo->port = NULL;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1235 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1236 return result;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1237 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1238
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1239 /* :mzfile */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1240 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1241 ex_mzfile(exarg_T *eap)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1242 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1243 Port_Info pinfo = {NULL, NULL};
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1244
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1245 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1246 MZ_GC_VAR_IN_REG(0, pinfo.port);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1247 MZ_GC_REG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1248
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1249 pinfo.name = (char *)eap->arg;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1250 if (do_mzscheme_command(eap, &pinfo, do_load) != OK
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1251 && pinfo.port != NULL) /* looks like port was not closed */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1252 {
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1253 scheme_close_input_port(pinfo.port);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1254 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1255 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1256 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1257 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1258
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1259
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1260 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1261 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1262 * Exception handling code -- cribbed form the MzScheme sources and
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1263 * Matthew Flatt's "Inside PLT MzScheme" document.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1264 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1265 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1266 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1267 init_exn_catching_apply(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1268 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1269 if (!exn_catching_apply)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1270 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1271 char *e =
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1272 "(lambda (thunk) "
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1273 "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1274 "(cons #t (thunk))))";
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1275
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1276 exn_catching_apply = scheme_eval_string(e, environment);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1277 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1278 exn_p = scheme_builtin_value("exn?");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1279 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1280 exn_message = scheme_builtin_value("exn-message");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1281 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1282 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1283 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1284
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1285 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1286 * This function applies a thunk, returning the Scheme value if there's
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1287 * no exception, otherwise returning NULL and setting *exn to the raised
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1288 * value (usually an exn structure).
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1289 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1290 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1291 _apply_thunk_catch_exceptions(Scheme_Object *f, Scheme_Object **exn)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1292 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1293 Scheme_Object *v;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1294
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1295 v = _scheme_apply(exn_catching_apply, 1, &f);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1296 /* v is a pair: (cons #t value) or (cons #f exn) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1297
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1298 if (SCHEME_TRUEP(SCHEME_CAR(v)))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1299 return SCHEME_CDR(v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1300 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1301 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1302 *exn = SCHEME_CDR(v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1303 return NULL;
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
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 extract_exn_message(Scheme_Object *v)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1309 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1310 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v)))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1311 return _scheme_apply(exn_message, 1, &v);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1312 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1313 return NULL; /* Not an exn structure */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1314 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1315
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1316 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1317 do_eval(void *s, int noargc UNUSED, Scheme_Object **noargv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1318 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1319 return scheme_eval_string_all((char *)s, environment, TRUE);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1320 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1321
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1322 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1323 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1324 * 3. MzScheme I/O Handlers
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1325 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1326 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1327 static void
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1328 do_intrnl_output(char *mesg, int error)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1329 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1330 char *p, *prev;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1331
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1332 prev = mesg;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1333 p = strchr(prev, '\n');
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1334 while (p)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1335 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1336 *p = '\0';
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1337 if (error)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1338 EMSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1339 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1340 MSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1341 prev = p + 1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1342 p = strchr(prev, '\n');
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1343 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1344
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1345 if (error)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1346 EMSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1347 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1348 MSG(prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1349 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1350
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1351 static void
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1352 do_output(char *mesg, long len UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1353 {
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1354 do_intrnl_output(mesg, 0);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1355 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1356
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1357 static void
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1358 do_err_output(char *mesg)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1359 {
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1360 do_intrnl_output(mesg, 1);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1361 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1362
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1363 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1364 do_printf(char *format, ...)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1365 {
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1366 do_intrnl_output(format, 1);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1367 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1368
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1369 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1370 do_flush(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1371 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1372 char *buff;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1373 long length;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1374
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1375 buff = scheme_get_sized_string_output(curerr, &length);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1376 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1377 if (length)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1378 {
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1379 do_err_output(buff);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1380 return;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1381 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1382
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1383 buff = scheme_get_sized_string_output(curout, &length);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1384 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1385 if (length)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1386 do_output(buff, length);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1387 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1388
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1389 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1390 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1391 * 4. Implementation of the Vim Features for MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1392 *========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1393 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1394
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1395 /* (command {command-string}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1396 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1397 vim_command(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1398 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1399 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1400 char *cmd = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1401
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1402 /* may be use do_cmdline_cmd? */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1403 do_cmdline((char_u *)cmd, NULL, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1404 update_screen(VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1405
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1406 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1407 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1408 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1409
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1410 /* (eval {expr-string}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1411 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1412 vim_eval(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1413 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1414 #ifdef FEAT_EVAL
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1415 Vim_Prim *prim = (Vim_Prim *)data;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1416 char *expr;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1417 Scheme_Object *result;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1418 /* hash table to store visited values to avoid infinite loops */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1419 Scheme_Hash_Table *visited = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1420 typval_T *vim_result;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1421
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1422 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1423 MZ_GC_VAR_IN_REG(0, visited);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1424 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1425
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1426 visited = scheme_make_hash_table(SCHEME_hash_ptr);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1427 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1428
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1429 expr = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1430 vim_result = eval_expr((char_u *)expr, NULL);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1431
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1432 if (vim_result == NULL)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1433 raise_vim_exn(_("invalid expression"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1434
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1435 result = vim_to_mzscheme(vim_result, 1, visited);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1436 free_tv(vim_result);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1437
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1438 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1439 return result;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1440 #else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1441 raise_vim_exn(_("expressions disabled at compile time"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1442 /* unreachable */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1443 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1444 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1445 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1446
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1447 /* (range-start) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1448 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1449 get_range_start(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1450 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1451 return scheme_make_integer(range_start);
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 /* (range-end) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1455 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1456 get_range_end(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1457 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1458 return scheme_make_integer(range_end);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1459 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1460
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1461 /* (beep) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1462 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1463 mzscheme_beep(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1464 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1465 vim_beep();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1466 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1467 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1468
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1469 static Scheme_Object *M_global = NULL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1470
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1471 /* (get-option {option-name}) [buffer/window] */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1472 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1473 get_option(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1474 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1475 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1476 char_u *name;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1477 long value;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1478 char *strval;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1479 int rc;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1480 Scheme_Object *rval;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1481 int opt_flags = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1482 buf_T *save_curb = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1483 win_T *save_curw = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1484
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1485 name = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1486
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1487 if (argc > 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1488 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1489 if (M_global == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1490 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1491 MZ_REGISTER_STATIC(M_global);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1492 M_global = scheme_intern_symbol("global");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1493 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1494 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1495
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1496 if (argv[1] == M_global)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1497 opt_flags = OPT_GLOBAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1498 else if (SCHEME_VIMBUFFERP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1499 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1500 curbuf = get_valid_buffer(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1501 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1502 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1503 else if (SCHEME_VIMWINDOWP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1504 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1505 win_T *win = get_valid_window(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1506
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1507 curwin = win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1508 curbuf = win->w_buffer;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1509 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1510 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1511 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1512 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1513 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1514
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1515 rc = get_option_value(name, &value, (char_u **)&strval, opt_flags);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1516 curbuf = save_curb;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1517 curwin = save_curw;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1518
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1519 switch (rc)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1520 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1521 case 1:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1522 return scheme_make_integer_value(value);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1523 case 0:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1524 rval = scheme_make_string(strval);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1525 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1526 vim_free(strval);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1527 return rval;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1528 case -1:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1529 case -2:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1530 raise_vim_exn(_("hidden option"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1531 case -3:
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1532 raise_vim_exn(_("unknown option"));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1533 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1534 /* unreachable */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1535 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1536 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1537
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1538 /* (set-option {option-changing-string} [buffer/window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1539 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1540 set_option(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1541 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1542 char_u *cmd;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1543 int opt_flags = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1544 buf_T *save_curb = curbuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1545 win_T *save_curw = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1546 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1547
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1548 GUARANTEE_STRING(prim->name, 0);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1549 if (argc > 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1550 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1551 if (M_global == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1552 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1553 MZ_REGISTER_STATIC(M_global);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1554 M_global = scheme_intern_symbol("global");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1555 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1556 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1557
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1558 if (argv[1] == M_global)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1559 opt_flags = OPT_GLOBAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1560 else if (SCHEME_VIMBUFFERP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1561 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1562 curbuf = get_valid_buffer(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1563 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1564 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1565 else if (SCHEME_VIMWINDOWP(argv[1]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1566 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1567 win_T *win = get_valid_window(argv[1]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1568 curwin = win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1569 curbuf = win->w_buffer;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1570 opt_flags = OPT_LOCAL;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1571 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1572 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1573 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1574 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1575
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1576 /* do_set can modify cmd, make copy */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1577 cmd = vim_strsave((char_u *)SCHEME_STR_VAL(argv[0]));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1578 do_set(cmd, opt_flags);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1579 vim_free(cmd);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1580 update_screen(NOT_VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1581 curbuf = save_curb;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1582 curwin = save_curw;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1583 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1584 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1585 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1586
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1587 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1588 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1589 * 5. Vim Window-related Manipulation Functions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1590 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1591 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1592
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1593 /* (curr-win) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1594 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1595 get_curr_win(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1596 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1597 return (Scheme_Object *)get_vim_curr_window();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1598 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1599
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1600 /* (win-count) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1601 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1602 get_window_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1603 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1604 win_T *w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1605 int n = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1606
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1607 for (w = firstwin; w != NULL; w = w->w_next)
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1608 ++n;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1609 return scheme_make_integer(n);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1610 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1611
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1612 /* (get-win-list [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1613 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1614 get_window_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1615 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1616 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1617 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1618 Scheme_Object *list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1619 win_T *w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1620
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1621 buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1622 list = scheme_null;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1623
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1624 for (w = firstwin; w != NULL; w = w->w_next)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1625 if (w->w_buffer == buf->buf)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1626 {
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1627 list = scheme_make_pair(window_new(w), list);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1628 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1629 }
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1630
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1631 return list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1632 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1633
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1634 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1635 window_new(win_T *win)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1636 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1637 vim_mz_window *self = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1638
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1639 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1640 MZ_GC_VAR_IN_REG(0, self);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1641 MZ_GC_REG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1642
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1643 /* We need to handle deletion of windows underneath us.
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1644 * If we add a "w_mzscheme_ref" field to the win_T structure,
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1645 * then we can get at it in win_free() in vim.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1646 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1647 * On a win_free() we set the Scheme object's win_T *field
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1648 * to an invalid value. We trap all uses of a window
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1649 * object, and reject them if the win_T *field is invalid.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1650 */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1651 if (win->w_mzscheme_ref != NULL)
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1652 return win->w_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1653
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1654 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_window));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1655 vim_memset(self, 0, sizeof(vim_mz_window));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1656 scheme_dont_gc_ptr(self); /* because win isn't visible to GC */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1657 MZ_GC_CHECK();
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1658 win->w_mzscheme_ref = self;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1659 self->win = win;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1660 self->so.type = mz_window_type;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1661
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1662 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1663 return (Scheme_Object *)(self);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1664 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1665
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1666 /* (get-win-num [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1667 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1668 get_window_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1669 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1670 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1671 win_T *win = get_window_arg(prim->name, 0, argc, argv)->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1672 int nr = 1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1673 win_T *wp;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1674
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1675 for (wp = firstwin; wp != win; wp = wp->w_next)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1676 ++nr;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1677
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1678 return scheme_make_integer(nr);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1679 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1680
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1681 /* (get-win-by-num {windownum}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1682 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1683 get_window_by_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1684 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1685 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1686 win_T *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1687 int fnum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1688
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1689 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1690 if (fnum < 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1691 scheme_signal_error(_("window index is out of range"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1692
671
83a006f81bac updated for version 7.0199
vimboss
parents: 667
diff changeset
1693 for (win = firstwin; win != NULL; win = win->w_next, --fnum)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1694 if (fnum == 1) /* to be 1-based */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1695 return window_new(win);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1696
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1697 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1698 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1699
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1700 /* (get-win-buffer [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1701 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1702 get_window_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1703 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1704 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1705 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1706
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1707 return buffer_new(win->win->w_buffer);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1708 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1709
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1710 /* (get-win-height [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1711 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1712 get_window_height(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1713 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1714 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1715 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1716
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1717 return scheme_make_integer(win->win->w_height);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1718 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1719
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1720 /* (set-win-height {height} [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1721 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1722 set_window_height(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1723 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1724 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1725 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1726 win_T *savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1727 int height;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1728
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1729 win = get_window_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1730 height = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1731
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1732 #ifdef FEAT_GUI
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1733 need_mouse_correct = TRUE;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1734 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1735
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1736 savewin = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1737 curwin = win->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1738 win_setheight(height);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1739 curwin = savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1740
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1741 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1742 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1743 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1744
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1745 #ifdef FEAT_VERTSPLIT
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1746 /* (get-win-width [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1747 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1748 get_window_width(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1749 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1750 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1751 vim_mz_window *win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1752
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1753 return scheme_make_integer(W_WIDTH(win->win));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1754 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1755
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1756 /* (set-win-width {width} [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1757 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1758 set_window_width(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1759 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1760 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1761 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1762 win_T *savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1763 int width = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1764
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1765 win = get_window_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1766 width = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1767
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1768 # ifdef FEAT_GUI
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1769 need_mouse_correct = TRUE;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1770 # endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1771
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1772 savewin = curwin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1773 curwin = win->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1774 win_setwidth(width);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1775 curwin = savewin;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1776
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1777 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1778 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1779 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1780 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1781
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1782 /* (get-cursor [window]) -> (line . col) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1783 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1784 get_cursor(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1785 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1786 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1787 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1788 pos_T pos;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1789
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1790 win = get_window_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1791 pos = win->win->w_cursor;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1792 return scheme_make_pair(scheme_make_integer_value((long)pos.lnum),
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1793 scheme_make_integer_value((long)pos.col + 1));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1794 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1795
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1796 /* (set-cursor (line . col) [window]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1797 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1798 set_cursor(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1799 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1800 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1801 vim_mz_window *win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1802 long lnum = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1803 long col = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1804
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1805 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1806 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1807 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1808 win = get_window_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1809 GUARANTEE_PAIR(prim->name, 0);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1810
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1811 if (!SCHEME_INTP(SCHEME_CAR(argv[0]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1812 || !SCHEME_INTP(SCHEME_CDR(argv[0])))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1813 scheme_wrong_type(prim->name, "integer pair", 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1814
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1815 lnum = SCHEME_INT_VAL(SCHEME_CAR(argv[0]));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1816 col = SCHEME_INT_VAL(SCHEME_CDR(argv[0])) - 1;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1817
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1818 check_line_range(lnum, win->win->w_buffer);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1819 /* don't know how to catch invalid column value */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1820
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1821 win->win->w_cursor.lnum = lnum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1822 win->win->w_cursor.col = col;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1823 update_screen(VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1824
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1825 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1826 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1827 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1828 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1829 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1830 * 6. Vim Buffer-related Manipulation Functions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1831 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1832 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1833
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1834 /* (open-buff {filename}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1835 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1836 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1837 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1838 Vim_Prim *prim = (Vim_Prim *)data;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1839 char_u *fname;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1840 int num = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1841 Scheme_Object *onum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1842
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1843 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1844 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
1845 #endif
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1846 fname = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1847 /* TODO make open existing file */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1848 num = buflist_add(fname, BLN_LISTED | BLN_CURBUF);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1849
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1850 if (num == 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1851 raise_vim_exn(_("couldn't open buffer"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1852
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1853 onum = scheme_make_integer(num);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1854 return get_buffer_by_num(data, 1, &onum);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1855 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1856
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1857 /* (get-buff-by-num {buffernum}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1858 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1859 get_buffer_by_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1860 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1861 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1862 buf_T *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1863 int fnum;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1864
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1865 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1866
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1867 for (buf = firstbuf; buf; buf = buf->b_next)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1868 if (buf->b_fnum == fnum)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1869 return buffer_new(buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1870
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1871 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1872 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1873
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1874 /* (get-buff-by-name {buffername}) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1875 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1876 get_buffer_by_name(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1877 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1878 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1879 buf_T *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1880 char_u *fname;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1881
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1882 fname = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1883
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1884 for (buf = firstbuf; buf; buf = buf->b_next)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1885 if (buf->b_ffname == NULL || buf->b_sfname == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1886 /* empty string */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1887 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1888 if (fname[0] == NUL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1889 return buffer_new(buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1890 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1891 else if (!fnamecmp(buf->b_ffname, fname)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1892 || !fnamecmp(buf->b_sfname, fname))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1893 /* either short or long filename matches */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1894 return buffer_new(buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1895
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1896 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1897 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1898
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1899 /* (get-next-buff [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1900 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1901 get_next_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1902 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1903 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1904 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1905
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1906 if (buf->b_next == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1907 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1908 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1909 return buffer_new(buf->b_next);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1910 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1911
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1912 /* (get-prev-buff [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1913 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1914 get_prev_buffer(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1915 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1916 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1917 buf_T *buf = get_buffer_arg(prim->name, 0, argc, argv)->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1918
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1919 if (buf->b_prev == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1920 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1921 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1922 return buffer_new(buf->b_prev);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1923 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1924
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1925 /* (get-buff-num [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1926 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1927 get_buffer_num(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1928 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1929 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1930 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1931
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1932 return scheme_make_integer(buf->buf->b_fnum);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1933 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1934
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1935 /* (buff-count) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1936 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1937 get_buffer_count(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1938 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1939 buf_T *b;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1940 int n = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1941
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1942 for (b = firstbuf; b; b = b->b_next) ++n;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1943 return scheme_make_integer(n);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1944 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1945
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1946 /* (get-buff-name [buffer]) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1947 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1948 get_buffer_name(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1949 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1950 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1951 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1952
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1953 return scheme_make_string((char *)buf->buf->b_ffname);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1954 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1955
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1956 /* (curr-buff) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1957 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
1958 get_curr_buffer(void *data UNUSED, int argc UNUSED, Scheme_Object **argv UNUSED)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1959 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1960 return (Scheme_Object *)get_vim_curr_buffer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1961 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1962
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1963 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1964 buffer_new(buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1965 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1966 vim_mz_buffer *self = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1967
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1968 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1969 MZ_GC_VAR_IN_REG(0, self);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1970 MZ_GC_REG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1971
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1972 /* We need to handle deletion of buffers underneath us.
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1973 * If we add a "b_mzscheme_ref" field to the buf_T structure,
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1974 * then we can get at it in buf_freeall() in vim.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1975 */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1976 if (buf->b_mzscheme_ref)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
1977 return buf->b_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1978
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1979 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1980 vim_memset(self, 0, sizeof(vim_mz_buffer));
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1981 scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1982 MZ_GC_CHECK();
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
1983 buf->b_mzscheme_ref = self;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1984 self->buf = buf;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1985 self->so.type = mz_buffer_type;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1986
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
1987 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1988 return (Scheme_Object *)(self);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1989 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1990
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1991 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1992 * (get-buff-size [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1993 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1994 * Get the size (number of lines) in the current buffer.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1995 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1996 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1997 get_buffer_size(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1998 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
1999 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2000 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2001
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2002 return scheme_make_integer(buf->buf->b_ml.ml_line_count);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2003 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2004
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2005 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2006 * (get-buff-line {linenr} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2007 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2008 * Get a line from the specified buffer. The line number is
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2009 * in Vim format (1-based). The line is returned as a MzScheme
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2010 * string object.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2011 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2012 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2013 get_buffer_line(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2014 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2015 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2016 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2017 int linenr;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2018 char_u *line;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2019
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2020 buf = get_buffer_arg(prim->name, 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2021 linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2022 line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2023
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2024 raise_if_error();
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2025 return scheme_make_string((char *)line);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2026 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2027
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2028
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2029 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2030 * (get-buff-line-list {start} {end} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2031 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2032 * Get a list of lines from the specified buffer. The line numbers
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2033 * 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
2034 * including, hi. The list is returned as a list of string objects.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2035 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2036 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2037 get_buffer_line_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2038 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2039 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2040 vim_mz_buffer *buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2041 int i, hi, lo, n;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2042 Scheme_Object *list = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2043
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2044 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2045 MZ_GC_VAR_IN_REG(0, list);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2046 MZ_GC_REG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2047
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2048 buf = get_buffer_arg(prim->name, 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2049 list = scheme_null;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2050 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2051 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2052
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2053 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2054 * Handle some error conditions
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2055 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2056 if (lo < 0)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2057 lo = 0;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2058
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2059 if (hi < 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2060 hi = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2061 if (hi < lo)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2062 hi = lo;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2063
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2064 n = hi - lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2065
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2066 for (i = n; i >= 0; --i)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2067 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2068 Scheme_Object *str = scheme_make_string(
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2069 (char *)ml_get_buf(buf->buf, (linenr_T)(lo+i), FALSE));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2070 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2071
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2072 /* Set the list item */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2073 list = scheme_make_pair(str, list);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2074 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2075 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2076 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2077 return list;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2078 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2079
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2080 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2081 * (set-buff-line {linenr} {string/#f} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2082 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2083 * Replace a line in the specified buffer. The line number is
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2084 * in Vim format (1-based). The replacement line is given as
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2085 * an MzScheme string object. The object is checked for validity
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2086 * and correct format. An exception is thrown if the values are not
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2087 * the correct format.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2088 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2089 * It returns a Scheme Object that indicates the length of the
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2090 * string changed.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2091 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2092 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2093 set_buffer_line(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2094 {
2023
db3ca1048f7f updated for version 7.2-320
vimboss
parents: 1950
diff changeset
2095 /* First of all, we check the value of the supplied MzScheme object.
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2096 * There are three cases:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2097 * 1. #f - this is a deletion.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2098 * 2. A string - this is a replacement.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2099 * 3. Anything else - this is an error.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2100 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2101 Vim_Prim *prim = (Vim_Prim *)data;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2102 vim_mz_buffer *buf;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2103 Scheme_Object *line = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2104 char *save;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2105 int n;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2106
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2107 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2108 MZ_GC_VAR_IN_REG(0, line);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2109 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2110
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2111 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2112 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2113 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2114 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2115 if (!SCHEME_STRINGP(argv[1]) && !SCHEME_FALSEP(argv[1]))
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2116 scheme_wrong_type(prim->name, "string or #f", 1, argc, argv);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2117 line = argv[1];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2118 buf = get_buffer_arg(prim->name, 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2119
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2120 check_line_range(n, buf->buf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2121
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2122 if (SCHEME_FALSEP(line))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2123 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2124 buf_T *savebuf = curbuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2125
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2126 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2127
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2128 if (u_savedel((linenr_T)n, 1L) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2129 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2130 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2131 raise_vim_exn(_("cannot save undo information"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2132 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2133 else if (ml_delete((linenr_T)n, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2134 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2135 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2136 raise_vim_exn(_("cannot delete line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2137 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2138 if (buf->buf == curwin->w_buffer)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2139 mz_fix_cursor(n, n + 1, -1);
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1919
diff changeset
2140 deleted_lines_mark((linenr_T)n, 1L);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2141
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2142 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2143
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2144 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2145 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2146 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2147 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2148 else
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2149 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2150 /* Otherwise it's a line */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2151 buf_T *savebuf = curbuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2152
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2153 save = string_to_line(line);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2154
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2155 curbuf = buf->buf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2156
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2157 if (u_savesub((linenr_T)n) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2158 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2159 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2160 vim_free(save);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2161 raise_vim_exn(_("cannot save undo information"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2162 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2163 else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2164 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2165 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2166 vim_free(save);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2167 raise_vim_exn(_("cannot replace line"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2168 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2169 else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2170 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2171 vim_free(save);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2172 changed_bytes((linenr_T)n, 0);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2173 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2174
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2175 curbuf = savebuf;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2176
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2177 /* Check that the cursor is not beyond the end of the line now. */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2178 if (buf->buf == curwin->w_buffer)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2179 check_cursor_col();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2180
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2181 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2182 raise_if_error();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2183 return scheme_void;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2184 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2185 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2186
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2187 static void
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2188 free_array(char **array)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2189 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2190 char **curr = array;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2191 while (*curr != NULL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2192 vim_free(*curr++);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2193 vim_free(array);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2194 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2195
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2196 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2197 * (set-buff-line-list {start} {end} {string-list/#f/null} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2198 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2199 * Replace a range of lines in the specified buffer. The line numbers are in
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2200 * 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
2201 * The replacement lines are given as a Scheme list of string objects. The
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2202 * list is checked for validity and correct format.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2203 *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2204 * 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
2205 * 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
2206 * change in the buffer length.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2207 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2208 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2209 set_buffer_line_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2210 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2211 /* First of all, we check the type of the supplied MzScheme object.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2212 * There are three cases:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2213 * 1. #f - this is a deletion.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2214 * 2. A list - this is a replacement.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2215 * 3. Anything else - this is an error.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2216 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2217 Vim_Prim *prim = (Vim_Prim *)data;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2218 vim_mz_buffer *buf = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2219 Scheme_Object *line_list = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2220 int i, old_len, new_len, hi, lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2221 long extra;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2222
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2223 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2224 MZ_GC_VAR_IN_REG(0, line_list);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2225 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2226
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2227 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2228 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2229 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2230 lo = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2231 hi = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 1));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2232 if (!SCHEME_PAIRP(argv[2])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2233 && !SCHEME_FALSEP(argv[2]) && !SCHEME_NULLP(argv[2]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2234 scheme_wrong_type(prim->name, "list or #f", 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2235 line_list = argv[2];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2236 buf = get_buffer_arg(prim->name, 3, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2237 old_len = hi - lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2238 if (old_len < 0) /* process inverse values wisely */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2239 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2240 i = lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2241 lo = hi;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2242 hi = i;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2243 old_len = -old_len;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2244 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2245 extra = 0;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2246
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2247 check_line_range(lo, buf->buf); /* inclusive */
1228
5eb1ac6f92ad updated for version 7.1b
vimboss
parents: 1125
diff changeset
2248 check_line_range(hi - 1, buf->buf); /* exclusive */
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2249
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2250 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2251 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2252 buf_T *savebuf = curbuf;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2253 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2254
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2255 if (u_savedel((linenr_T)lo, (long)old_len) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2256 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2257 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2258 raise_vim_exn(_("cannot save undo information"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2259 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2260 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2261 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2262 for (i = 0; i < old_len; i++)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2263 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2264 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2265 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2266 raise_vim_exn(_("cannot delete line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2267 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2268 if (buf->buf == curwin->w_buffer)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2269 mz_fix_cursor(lo, hi, -old_len);
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1919
diff changeset
2270 deleted_lines_mark((linenr_T)lo, (long)old_len);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2271 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2272
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2273 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2274
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2275 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2276 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2277 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2278 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2279 else
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2280 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2281 buf_T *savebuf = curbuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2282
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2283 /* List */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2284 new_len = scheme_proper_list_length(line_list);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2285 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2286 if (new_len < 0) /* improper or cyclic list */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2287 scheme_wrong_type(prim->name, "proper list",
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2288 2, argc, argv);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2289 else
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2290 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2291 char **array = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2292 Scheme_Object *line = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2293 Scheme_Object *rest = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2294
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2295 MZ_GC_DECL_REG(2);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2296 MZ_GC_VAR_IN_REG(0, line);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2297 MZ_GC_VAR_IN_REG(1, rest);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2298 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2299
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2300 array = (char **)alloc(new_len * sizeof(char *));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2301 vim_memset(array, 0, new_len * sizeof(char *));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2302
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2303 rest = line_list;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2304 for (i = 0; i < new_len; ++i)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2305 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2306 line = SCHEME_CAR(rest);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2307 rest = SCHEME_CDR(rest);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2308 if (!SCHEME_STRINGP(line))
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2309 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2310 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2311 scheme_wrong_type(prim->name, "string-list", 2, argc, argv);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2312 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2313 array[i] = string_to_line(line);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2314 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2315
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2316 curbuf = buf->buf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2317
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2318 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2319 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2320 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2321 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2322 raise_vim_exn(_("cannot save undo information"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2323 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2324
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2325 /*
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2326 * If the size of the range is reducing (ie, new_len < old_len) we
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2327 * need to delete some old_len. We do this at the start, by
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2328 * repeatedly deleting line "lo".
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2329 */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2330 for (i = 0; i < old_len - new_len; ++i)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2331 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2332 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2333 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2334 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2335 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2336 raise_vim_exn(_("cannot delete line"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2337 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2338 extra--;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2339 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2340
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2341 /*
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2342 * For as long as possible, replace the existing old_len with the
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2343 * new old_len. This is a more efficient operation, as it requires
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2344 * less memory allocation and freeing.
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2345 */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2346 for (i = 0; i < old_len && i < new_len; i++)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2347 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2348 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2349 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2350 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2351 raise_vim_exn(_("cannot replace line"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2352 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2353
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2354 /*
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2355 * Now we may need to insert the remaining new_len. We don't need to
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2356 * free the string passed back because MzScheme has control of that
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2357 * memory.
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2358 */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2359 while (i < new_len)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2360 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2361 if (ml_append((linenr_T)(lo + i - 1),
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2362 (char_u *)array[i], 0, FALSE) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2363 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2364 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2365 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2366 raise_vim_exn(_("cannot insert line"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2367 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2368 ++i;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2369 ++extra;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2370 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2371 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2372 free_array(array);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2373 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2374
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2375 /*
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2376 * Adjust marks. Invalidate any which lie in the
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2377 * changed range, and move any in the remainder of the buffer.
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2378 */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2379 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), (long)MAXLNUM, (long)extra);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2380 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2381
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2382 if (buf->buf == curwin->w_buffer)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2383 mz_fix_cursor(lo, hi, extra);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2384 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2385
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2386 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2387 raise_if_error();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2388 return scheme_void;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2389 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2390 }
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 * (insert-buff-line-list {linenr} {string/string-list} [buffer])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2394 *
2023
db3ca1048f7f updated for version 7.2-320
vimboss
parents: 1950
diff changeset
2395 * Insert a number of lines into the specified buffer after the specified line.
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2396 * 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
2397 * 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
2398 * to be added are checked for validity and correct format. Errors are
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2399 * returned as a value of FAIL. The return value is OK on success.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2400 * If OK is returned and len_change is not NULL, *len_change
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2401 * is set to the change in the buffer length.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2402 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2403 static Scheme_Object *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2404 insert_buffer_line_list(void *data, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2405 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2406 Vim_Prim *prim = (Vim_Prim *)data;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2407 vim_mz_buffer *buf = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2408 Scheme_Object *list = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2409 char *str = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2410 int i, n, size;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2411
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2412 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2413 MZ_GC_VAR_IN_REG(0, list);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2414 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2415
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2416 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2417 sandbox_check();
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
2418 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2419 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2420 * First of all, we check the type of the supplied MzScheme object.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2421 * It must be a string or a list, or the call is in error.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2422 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2423 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2424 list = argv[1];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2425
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2426 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2427 scheme_wrong_type(prim->name, "string or list", 1, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2428 buf = get_buffer_arg(prim->name, 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2429
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2430 if (n != 0) /* 0 can be used in insert */
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2431 check_line_range(n, buf->buf);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2432 if (SCHEME_STRINGP(list))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2433 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2434 buf_T *savebuf = curbuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2435
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2436 str = string_to_line(list);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2437 curbuf = buf->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2438
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2439 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2440 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2441 curbuf = savebuf;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2442 vim_free(str);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2443 raise_vim_exn(_("cannot save undo information"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2444 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2445 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2446 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2447 curbuf = savebuf;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2448 vim_free(str);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2449 raise_vim_exn(_("cannot insert line"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2450 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2451 else
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2452 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2453 vim_free(str);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2454 appended_lines_mark((linenr_T)n, 1L);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2455 }
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2456
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2457 curbuf = savebuf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2458 update_screen(VALID);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2459
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2460 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2461 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2462 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2463 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2464
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2465 /* List */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2466 size = scheme_proper_list_length(list);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2467 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2468 if (size < 0) /* improper or cyclic list */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2469 scheme_wrong_type(prim->name, "proper list",
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2470 2, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2471 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2472 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2473 Scheme_Object *line = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2474 Scheme_Object *rest = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2475 char **array;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2476 buf_T *savebuf = curbuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2477
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2478 MZ_GC_DECL_REG(2);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2479 MZ_GC_VAR_IN_REG(0, line);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2480 MZ_GC_VAR_IN_REG(1, rest);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2481 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2482
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2483 array = (char **)alloc(size * sizeof(char *));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2484 vim_memset(array, 0, size * sizeof(char *));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2485
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2486 rest = list;
856
8cd729851562 updated for version 7.0g
vimboss
parents: 800
diff changeset
2487 for (i = 0; i < size; ++i)
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2488 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2489 line = SCHEME_CAR(rest);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2490 rest = SCHEME_CDR(rest);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2491 array[i] = string_to_line(line);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2492 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2493
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2494 curbuf = buf->buf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2495
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2496 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2497 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2498 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2499 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2500 raise_vim_exn(_("cannot save undo information"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2501 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2502 else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2503 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2504 for (i = 0; i < size; ++i)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2505 if (ml_append((linenr_T)(n + i), (char_u *)array[i],
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2506 0, FALSE) == FAIL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2507 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2508 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2509 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2510 raise_vim_exn(_("cannot insert line"));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2511 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2512
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2513 if (i > 0)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2514 appended_lines_mark((linenr_T)n, (long)i);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2515 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2516 free_array(array);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2517 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2518 curbuf = savebuf;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2519 update_screen(VALID);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2520 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2521
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2522 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2523 raise_if_error();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2524 return scheme_void;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2525 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2526
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2527 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2528 * Predicates
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2529 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2530 /* (buff? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2531 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
2532 vim_bufferp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2533 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2534 if (SCHEME_VIMBUFFERP(argv[0]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2535 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2536 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2537 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2538 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2539
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2540 /* (win? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2541 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
2542 vim_windowp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2543 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2544 if (SCHEME_VIMWINDOWP(argv[0]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2545 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2546 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2547 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2548 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2549
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2550 /* (buff-valid? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2551 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
2552 vim_buffer_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2553 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2554 if (SCHEME_VIMBUFFERP(argv[0])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2555 && ((vim_mz_buffer *)argv[0])->buf != INVALID_BUFFER_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2556 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2557 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2558 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2559 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2560
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2561 /* (win-valid? obj) */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2562 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
2563 vim_window_validp(void *data UNUSED, int argc UNUSED, Scheme_Object **argv)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2564 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2565 if (SCHEME_VIMWINDOWP(argv[0])
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2566 && ((vim_mz_window *)argv[0])->win != INVALID_WINDOW_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2567 return scheme_true;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2568 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2569 return scheme_false;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2570 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2571
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2572 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2573 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2574 * Utilities
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2575 *===========================================================================
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2576 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2577
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2578 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2579 * Convert an MzScheme string into a Vim line.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2580 *
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2581 * All internal nulls are replaced by newline characters.
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2582 * It is an error for the string to contain newline characters.
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2583 *
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2584 * Returns pointer to Vim allocated memory
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2585 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2586 static char *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2587 string_to_line(Scheme_Object *obj)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2588 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2589 char *scheme_str = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2590 char *vim_str = NULL;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2591 long len;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2592 int i;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2593
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2594 scheme_str = scheme_display_to_string(obj, &len);
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2595
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2596 /* Error checking: String must not contain newlines, as we
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2597 * are replacing a single line, and we must replace it with
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2598 * a single line.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2599 */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2600 if (memchr(scheme_str, '\n', len))
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2601 scheme_signal_error(_("string cannot contain newlines"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2602
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2603 vim_str = (char *)alloc(len + 1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2604
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2605 /* Create a copy of the string, with internal nulls replaced by
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2606 * newline characters, as is the vim convention.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2607 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2608 for (i = 0; i < len; ++i)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2609 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2610 if (scheme_str[i] == '\0')
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2611 vim_str[i] = '\n';
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2612 else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2613 vim_str[i] = scheme_str[i];
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2614 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2615
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2616 vim_str[i] = '\0';
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2617
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2618 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2619 return vim_str;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2620 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2621
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2622 #ifdef FEAT_EVAL
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2623 /*
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2624 * Convert Vim value into MzScheme, adopted from if_python.c
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2625 */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2626 static Scheme_Object *
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2627 vim_to_mzscheme(typval_T *vim_value, int depth, Scheme_Hash_Table *visited)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2628 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2629 Scheme_Object *result = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2630 int new_value = TRUE;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2631
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2632 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2633 MZ_GC_VAR_IN_REG(0, result);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2634 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2635
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2636 /* Avoid infinite recursion */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2637 if (depth > 100)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2638 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2639 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2640 return scheme_void;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2641 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2642
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2643 /* Check if we run into a recursive loop. The item must be in visited
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2644 * then and we can use it again.
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2645 */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2646 result = scheme_hash_get(visited, (Scheme_Object *)vim_value);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2647 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2648 if (result != NULL) /* found, do nothing */
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2649 new_value = FALSE;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2650 else if (vim_value->v_type == VAR_STRING)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2651 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2652 result = scheme_make_string((char *)vim_value->vval.v_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2653 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2654 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2655 else if (vim_value->v_type == VAR_NUMBER)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2656 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2657 result = scheme_make_integer((long)vim_value->vval.v_number);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2658 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2659 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2660 # ifdef FEAT_FLOAT
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2661 else if (vim_value->v_type == VAR_FLOAT)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2662 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2663 result = scheme_make_double((double)vim_value->vval.v_float);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2664 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2665 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2666 # endif
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2667 else if (vim_value->v_type == VAR_LIST)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2668 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2669 list_T *list = vim_value->vval.v_list;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2670 listitem_T *curr;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2671
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2672 if (list == NULL || list->lv_first == NULL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2673 result = scheme_null;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2674 else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2675 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2676 Scheme_Object *obj = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2677
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2678 MZ_GC_DECL_REG(1);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2679 MZ_GC_VAR_IN_REG(0, obj);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2680 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2681
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2682 curr = list->lv_last;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2683 obj = vim_to_mzscheme(&curr->li_tv, depth + 1, visited);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2684 result = scheme_make_pair(obj, scheme_null);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2685 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2686
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2687 while (curr != list->lv_first)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2688 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2689 curr = curr->li_prev;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2690 obj = vim_to_mzscheme(&curr->li_tv, depth + 1, visited);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2691 result = scheme_make_pair(obj, result);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2692 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2693 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2694 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2695 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2696 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2697 else if (vim_value->v_type == VAR_DICT)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2698 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2699 Scheme_Object *key = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2700 Scheme_Object *obj = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2701
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2702 MZ_GC_DECL_REG(2);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2703 MZ_GC_VAR_IN_REG(0, key);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2704 MZ_GC_VAR_IN_REG(1, obj);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2705 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2706
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2707 result = (Scheme_Object *)scheme_make_hash_table(SCHEME_hash_ptr);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2708 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2709 if (vim_value->vval.v_dict != NULL)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2710 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2711 hashtab_T *ht = &vim_value->vval.v_dict->dv_hashtab;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2712 long_u todo = ht->ht_used;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2713 hashitem_T *hi;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2714 dictitem_T *di;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2715
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2716 for (hi = ht->ht_array; todo > 0; ++hi)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2717 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2718 if (!HASHITEM_EMPTY(hi))
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2719 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2720 --todo;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2721
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2722 di = dict_lookup(hi);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2723 obj = vim_to_mzscheme(&di->di_tv, depth + 1, visited);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2724 key = scheme_make_string((char *)hi->hi_key);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2725 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2726 scheme_hash_set((Scheme_Hash_Table *)result, key, obj);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2727 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2728 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2729 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2730 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2731 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2732 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2733 else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2734 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2735 result = scheme_void;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2736 new_value = FALSE;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2737 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2738 if (new_value)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2739 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2740 scheme_hash_set(visited, (Scheme_Object *)vim_value, result);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2741 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2742 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2743 MZ_GC_UNREG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2744 return result;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2745 }
2050
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2746
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2747 static int
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2748 mzscheme_to_vim(Scheme_Object *obj, typval_T *tv, int depth,
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2749 Scheme_Hash_Table *visited)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2750 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2751 int status = OK;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2752 typval_T *found;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2753 MZ_GC_CHECK();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2754 if (depth > 100) /* limit the deepest recursion level */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2755 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2756 tv->v_type = VAR_NUMBER;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2757 tv->vval.v_number = 0;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2758 return FAIL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2759 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2760
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2761 found = (typval_T *)scheme_hash_get(visited, obj);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2762 if (found != NULL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2763 copy_tv(found, tv);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2764 else if (SCHEME_VOIDP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2765 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2766 tv->v_type = VAR_NUMBER;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2767 tv->vval.v_number = 0;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2768 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2769 else if (SCHEME_INTP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2770 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2771 tv->v_type = VAR_NUMBER;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2772 tv->vval.v_number = SCHEME_INT_VAL(obj);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2773 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2774 else if (SCHEME_BOOLP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2775 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2776 tv->v_type = VAR_NUMBER;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2777 tv->vval.v_number = SCHEME_TRUEP(obj);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2778 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2779 # ifdef FEAT_FLOAT
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2780 else if (SCHEME_DBLP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2781 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2782 tv->v_type = VAR_FLOAT;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2783 tv->vval.v_float = SCHEME_DBL_VAL(obj);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2784 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2785 # endif
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2786 else if (SCHEME_STRINGP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2787 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2788 tv->v_type = VAR_STRING;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2789 tv->vval.v_string = vim_strsave((char_u *)SCHEME_STR_VAL(obj));
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2790 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2791 else if (SCHEME_VECTORP(obj) || SCHEME_NULLP(obj)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2792 || SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2793 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2794 list_T *list = list_alloc();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2795 if (list == NULL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2796 status = FAIL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2797 else
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2798 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2799 int i;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2800 Scheme_Object *curr = NULL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2801 Scheme_Object *cval = NULL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2802 /* temporary var to hold current element of vectors and pairs */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2803 typval_T *v;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2804
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2805 MZ_GC_DECL_REG(2);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2806 MZ_GC_VAR_IN_REG(0, curr);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2807 MZ_GC_VAR_IN_REG(1, cval);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2808 MZ_GC_REG();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2809
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2810 tv->v_type = VAR_LIST;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2811 tv->vval.v_list = list;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2812 ++list->lv_refcount;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2813
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2814 v = (typval_T *)alloc(sizeof(typval_T));
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2815 if (v == NULL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2816 status = FAIL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2817 else
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2818 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2819 /* add the value in advance to allow handling of self-referencial
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2820 * data structures */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2821 typval_T *visited_tv = (typval_T *)alloc(sizeof(typval_T));
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2822 copy_tv(tv, visited_tv);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2823 scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2824
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2825 if (SCHEME_VECTORP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2826 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2827 for (i = 0; i < SCHEME_VEC_SIZE(obj); ++i)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2828 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2829 cval = SCHEME_VEC_ELS(obj)[i];
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2830 status = mzscheme_to_vim(cval, v, depth + 1, visited);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2831 if (status == FAIL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2832 break;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2833 status = list_append_tv(list, v);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2834 clear_tv(v);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2835 if (status == FAIL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2836 break;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2837 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2838 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2839 else if (SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2840 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2841 for (curr = obj;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2842 SCHEME_PAIRP(curr) || SCHEME_MUTABLE_PAIRP(curr);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2843 curr = SCHEME_CDR(curr))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2844 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2845 cval = SCHEME_CAR(curr);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2846 status = mzscheme_to_vim(cval, v, depth + 1, visited);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2847 if (status == FAIL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2848 break;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2849 status = list_append_tv(list, v);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2850 clear_tv(v);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2851 if (status == FAIL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2852 break;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2853 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2854 /* impoper list not terminated with null
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2855 * need to handle the last element */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2856 if (status == OK && !SCHEME_NULLP(curr))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2857 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2858 status = mzscheme_to_vim(cval, v, depth + 1, visited);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2859 if (status == OK)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2860 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2861 status = list_append_tv(list, v);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2862 clear_tv(v);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2863 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2864 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2865 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2866 /* nothing to do for scheme_null */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2867 vim_free(v);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2868 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2869 MZ_GC_UNREG();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2870 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2871 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2872 else if (SCHEME_HASHTP(obj))
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2873 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2874 int i;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2875 dict_T *dict;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2876 Scheme_Object *key = NULL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2877 Scheme_Object *val = NULL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2878
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2879 MZ_GC_DECL_REG(2);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2880 MZ_GC_VAR_IN_REG(0, key);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2881 MZ_GC_VAR_IN_REG(1, val);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2882 MZ_GC_REG();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2883
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2884 dict = dict_alloc();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2885 if (dict == NULL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2886 status = FAIL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2887 else
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2888 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2889 typval_T *visited_tv = (typval_T *)alloc(sizeof(typval_T));
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2890
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2891 tv->v_type = VAR_DICT;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2892 tv->vval.v_dict = dict;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2893 ++dict->dv_refcount;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2894
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2895 copy_tv(tv, visited_tv);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2896 scheme_hash_set(visited, obj, (Scheme_Object *)visited_tv);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2897
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2898 for (i = 0; i < ((Scheme_Hash_Table *)obj)->size; ++i)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2899 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2900 if (((Scheme_Hash_Table *) obj)->vals[i] != NULL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2901 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2902 /* generate item for `diplay'ed Scheme key */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2903 dictitem_T *item = dictitem_alloc((char_u *)string_to_line(
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2904 ((Scheme_Hash_Table *) obj)->keys[i]));
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2905 /* convert Scheme val to Vim and add it to the dict */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2906 if (mzscheme_to_vim(((Scheme_Hash_Table *) obj)->vals[i],
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2907 &item->di_tv, depth + 1, visited) == FAIL
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2908 || dict_add(dict, item) == FAIL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2909 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2910 dictitem_free(item);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2911 status = FAIL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2912 break;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2913 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2914 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2915
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2916 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2917 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2918 MZ_GC_UNREG();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2919 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2920 else
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2921 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2922 /* `display' any other value to string */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2923 tv->v_type = VAR_STRING;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2924 tv->vval.v_string = (char_u *)string_to_line(obj);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2925 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2926 return status;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2927 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2928
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2929 void
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2930 do_mzeval(char_u *str, typval_T *rettv)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2931 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2932 int i;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2933 Scheme_Object *ret = NULL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2934 Scheme_Hash_Table *visited = NULL;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2935
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2936 MZ_GC_DECL_REG(2);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2937 MZ_GC_VAR_IN_REG(0, ret);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2938 MZ_GC_VAR_IN_REG(0, visited);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2939 MZ_GC_REG();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2940
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2941 if (mzscheme_init())
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2942 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2943 MZ_GC_UNREG();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2944 return;
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2945 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2946
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2947 MZ_GC_CHECK();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2948 visited = scheme_make_hash_table(SCHEME_hash_ptr);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2949 MZ_GC_CHECK();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2950
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2951 if (eval_with_exn_handling(str, do_eval, &ret) == OK)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2952 mzscheme_to_vim(ret, rettv, 1, visited);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2953
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2954 for (i = 0; i < visited->size; ++i)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2955 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2956 /* free up remembered objects */
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2957 if (visited->vals[i] != NULL)
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2958 {
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2959 free_tv((typval_T *)visited->vals[i]);
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2960 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2961 }
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2962
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2963 MZ_GC_UNREG();
afcf9db31561 updated for version 7.2.336
Bram Moolenaar <bram@zimbu.org>
parents: 2023
diff changeset
2964 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2965 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2966
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2967 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2968 * Check to see whether a Vim error has been reported, or a keyboard
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2969 * interrupt (from vim --> got_int) has been detected.
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2970 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2971 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2972 vim_error_check(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2973 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2974 return (got_int || did_emsg);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2975 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2976
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2977 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2978 * register Scheme exn:vim
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2979 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2980 static void
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2981 register_vim_exn(void)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2982 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2983 int nc = 0;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2984 int i;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2985 Scheme_Object *struct_exn = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2986 Scheme_Object *exn_name = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2987
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2988 MZ_GC_DECL_REG(2);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2989 MZ_GC_VAR_IN_REG(0, struct_exn);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2990 MZ_GC_VAR_IN_REG(1, exn_name);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2991 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2992
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2993 exn_name = scheme_intern_symbol("exn:vim");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2994 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2995 struct_exn = scheme_builtin_value("struct:exn");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
2996 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2997
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2998 if (vim_exn == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
2999 vim_exn = scheme_make_struct_type(exn_name,
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3000 struct_exn, NULL, 0, 0, NULL, NULL
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3001 #if MZSCHEME_VERSION_MAJOR >= 299
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3002 , NULL
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3003 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3004 );
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3005
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3006
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3007 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3008 Scheme_Object **tmp = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3009 Scheme_Object *exn_names[5] = {NULL, NULL, NULL, NULL, NULL};
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3010 Scheme_Object *exn_values[5] = {NULL, NULL, NULL, NULL, NULL};
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3011 MZ_GC_DECL_REG(6);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3012 MZ_GC_ARRAY_VAR_IN_REG(0, exn_names, 5);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3013 MZ_GC_ARRAY_VAR_IN_REG(3, exn_values, 5);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3014 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3015
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3016 tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3017 mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3018 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3019
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3020 tmp = scheme_make_struct_values(vim_exn, exn_names, nc, 0);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3021 mch_memmove(exn_values, tmp, nc * sizeof(Scheme_Object *));
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3022 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3023
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3024 for (i = 0; i < nc; i++)
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3025 {
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3026 scheme_add_global_symbol(exn_names[i],
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3027 exn_values[i], environment);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3028 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3029 }
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3030 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3031 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3032 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3033 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3034
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3035 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3036 * raise exn:vim, may be with additional info string
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3037 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3038 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3039 raise_vim_exn(const char *add_info)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3040 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3041 char *fmt = _("Vim error: ~a");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3042 Scheme_Object *argv[2] = {NULL, NULL};
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3043 Scheme_Object *exn = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3044
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3045 MZ_GC_DECL_REG(4);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3046 MZ_GC_ARRAY_VAR_IN_REG(0, argv, 2);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3047 MZ_GC_VAR_IN_REG(3, exn);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3048 MZ_GC_REG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3049
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3050 if (add_info != NULL)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3051 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3052 char *c_string = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3053 Scheme_Object *byte_string = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3054 Scheme_Object *info = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3055
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3056 MZ_GC_DECL_REG(3);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3057 MZ_GC_VAR_IN_REG(0, c_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3058 MZ_GC_VAR_IN_REG(1, byte_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3059 MZ_GC_VAR_IN_REG(2, info);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3060 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3061
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3062 info = scheme_make_string(add_info);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3063 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3064 c_string = scheme_format(fmt, STRLEN(fmt), 1, &info, NULL);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3065 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3066 byte_string = scheme_make_string(c_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3067 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3068 argv[0] = scheme_byte_string_to_char_string(byte_string);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3069 MZ_GC_CHECK();
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3070 SCHEME_SET_IMMUTABLE(argv[0]);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3071 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3072 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3073 else
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3074 argv[0] = scheme_make_string(_("Vim error"));
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3075 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3076
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
3077 #if MZSCHEME_VERSION_MAJOR < 360
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
3078 argv[1] = scheme_current_continuation_marks();
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3079 MZ_GC_CHECK();
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
3080 #else
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 856
diff changeset
3081 argv[1] = scheme_current_continuation_marks(NULL);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3082 MZ_GC_CHECK();
1284
30f057789239 updated for version 7.1
vimboss
parents: 1228
diff changeset
3083 #endif
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3084
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3085 exn = scheme_make_struct_instance(vim_exn, 2, argv);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3086 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3087 scheme_raise(exn);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3088 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3089 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3090
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3091 void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3092 raise_if_error(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3093 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3094 if (vim_error_check())
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3095 raise_vim_exn(NULL);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3096 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3097
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3098 /* get buffer:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3099 * either current
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3100 * or passed as argv[argnum] with checks
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3101 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3102 static vim_mz_buffer *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3103 get_buffer_arg(const char *fname, int argnum, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3104 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3105 vim_mz_buffer *b;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3106
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3107 if (argc < argnum + 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3108 return get_vim_curr_buffer();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3109 if (!SCHEME_VIMBUFFERP(argv[argnum]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3110 scheme_wrong_type(fname, "vim-buffer", argnum, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3111 b = (vim_mz_buffer *)argv[argnum];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3112 (void)get_valid_buffer(argv[argnum]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3113 return b;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3114 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3115
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3116 /* get window:
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3117 * either current
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3118 * or passed as argv[argnum] with checks
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3119 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3120 static vim_mz_window *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3121 get_window_arg(const char *fname, int argnum, int argc, Scheme_Object **argv)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3122 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3123 vim_mz_window *w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3124
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3125 if (argc < argnum + 1)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3126 return get_vim_curr_window();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3127 w = (vim_mz_window *)argv[argnum];
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3128 if (!SCHEME_VIMWINDOWP(argv[argnum]))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3129 scheme_wrong_type(fname, "vim-window", argnum, argc, argv);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3130 (void)get_valid_window(argv[argnum]);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3131 return w;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3132 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3133
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3134 /* get valid Vim buffer from Scheme_Object* */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3135 buf_T *get_valid_buffer(void *obj)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3136 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3137 buf_T *buf = ((vim_mz_buffer *)obj)->buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3138
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3139 if (buf == INVALID_BUFFER_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3140 scheme_signal_error(_("buffer is invalid"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3141 return buf;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3142 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3143
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3144 /* get valid Vim window from Scheme_Object* */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3145 win_T *get_valid_window(void *obj)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3146 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3147 win_T *win = ((vim_mz_window *)obj)->win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3148 if (win == INVALID_WINDOW_VALUE)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3149 scheme_signal_error(_("window is invalid"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3150 return win;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3151 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3152
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3153 int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3154 mzthreads_allowed(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3155 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3156 return mz_threads_allow;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3157 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3158
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3159 static int
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3160 line_in_range(linenr_T lnum, buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3161 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3162 return (lnum > 0 && lnum <= buf->b_ml.ml_line_count);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3163 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3164
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3165 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3166 check_line_range(linenr_T lnum, buf_T *buf)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3167 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3168 if (!line_in_range(lnum, buf))
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3169 scheme_signal_error(_("linenr out of range"));
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3170 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3171
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3172 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3173 * Check if deleting lines made the cursor position invalid
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3174 * (or you'll get msg from Vim about invalid linenr).
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3175 * Changed the lines from "lo" to "hi" and added "extra" lines (negative if
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3176 * deleted). Got from if_python.c
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3177 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3178 static void
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3179 mz_fix_cursor(int lo, int hi, int extra)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3180 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3181 if (curwin->w_cursor.lnum >= lo)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3182 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3183 /* Adjust the cursor position if it's in/after the changed
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3184 * lines. */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3185 if (curwin->w_cursor.lnum >= hi)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3186 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3187 curwin->w_cursor.lnum += extra;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3188 check_cursor_col();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3189 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3190 else if (extra < 0)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3191 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3192 curwin->w_cursor.lnum = lo;
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3193 check_cursor();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3194 }
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3195 else
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3196 check_cursor_col();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3197 changed_cline_bef_curs();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3198 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3199 invalidate_botline();
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3200 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3201
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3202 static Vim_Prim prims[]=
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3203 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3204 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3205 * Buffer-related commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3206 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3207 {get_buffer_line, "get-buff-line", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3208 {set_buffer_line, "set-buff-line", 2, 3},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3209 {get_buffer_line_list, "get-buff-line-list", 2, 3},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3210 {get_buffer_name, "get-buff-name", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3211 {get_buffer_num, "get-buff-num", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3212 {get_buffer_size, "get-buff-size", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3213 {set_buffer_line_list, "set-buff-line-list", 3, 4},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3214 {insert_buffer_line_list, "insert-buff-line-list", 2, 3},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3215 {get_curr_buffer, "curr-buff", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3216 {get_buffer_count, "buff-count", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3217 {get_next_buffer, "get-next-buff", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3218 {get_prev_buffer, "get-prev-buff", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3219 {mzscheme_open_buffer, "open-buff", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3220 {get_buffer_by_name, "get-buff-by-name", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3221 {get_buffer_by_num, "get-buff-by-num", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3222 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3223 * Window-related commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3224 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3225 {get_curr_win, "curr-win", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3226 {get_window_count, "win-count", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3227 {get_window_by_num, "get-win-by-num", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3228 {get_window_num, "get-win-num", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3229 {get_window_buffer, "get-win-buffer", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3230 {get_window_height, "get-win-height", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3231 {set_window_height, "set-win-height", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3232 #ifdef FEAT_VERTSPLIT
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3233 {get_window_width, "get-win-width", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3234 {set_window_width, "set-win-width", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3235 #endif
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3236 {get_cursor, "get-cursor", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3237 {set_cursor, "set-cursor", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3238 {get_window_list, "get-win-list", 0, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3239 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3240 * Vim-related commands
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3241 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3242 {vim_command, "command", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3243 {vim_eval, "eval", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3244 {get_range_start, "range-start", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3245 {get_range_end, "range-end", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3246 {mzscheme_beep, "beep", 0, 0},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3247 {get_option, "get-option", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3248 {set_option, "set-option", 1, 2},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3249 /*
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3250 * small utilities
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3251 */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3252 {vim_bufferp, "buff?", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3253 {vim_windowp, "win?", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3254 {vim_buffer_validp, "buff-valid?", 1, 1},
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3255 {vim_window_validp, "win-valid?", 1, 1}
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3256 };
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3257
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3258 /* return MzScheme wrapper for curbuf */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3259 static vim_mz_buffer *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3260 get_vim_curr_buffer(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3261 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
3262 if (curbuf->b_mzscheme_ref == NULL)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3263 return (vim_mz_buffer *)buffer_new(curbuf);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3264 else
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
3265 return (vim_mz_buffer *)curbuf->b_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3266 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3267
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3268 /* return MzScheme wrapper for curwin */
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3269 static vim_mz_window *
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3270 get_vim_curr_window(void)
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3271 {
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
3272 if (curwin->w_mzscheme_ref == NULL)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3273 return (vim_mz_window *)window_new(curwin);
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3274 else
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 344
diff changeset
3275 return (vim_mz_window *)curwin->w_mzscheme_ref;
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3276 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3277
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3278 static void
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3279 make_modules()
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3280 {
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3281 int i;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3282 Scheme_Env *mod = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3283 Scheme_Object *vimext_symbol = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3284 Scheme_Object *closed_prim = NULL;
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3285
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3286 MZ_GC_DECL_REG(3);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3287 MZ_GC_VAR_IN_REG(0, mod);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3288 MZ_GC_VAR_IN_REG(1, vimext_symbol);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3289 MZ_GC_VAR_IN_REG(2, closed_prim);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3290 MZ_GC_REG();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3291
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3292 vimext_symbol = scheme_intern_symbol("vimext");
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3293 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3294 mod = scheme_primitive_module(vimext_symbol, environment);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3295 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3296 /* all prims made closed so they can access their own names */
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3297 for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++)
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3298 {
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3299 Vim_Prim *prim = prims + i;
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3300 closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3301 prim->mina, prim->maxa);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3302 scheme_add_global(prim->name, closed_prim, mod);
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3303 MZ_GC_CHECK();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3304 }
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3305 scheme_finish_primitive_module(mod);
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3306 MZ_GC_CHECK();
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3307 MZ_GC_UNREG();
14
946da5994c01 updated for version 7.0006
vimboss
parents:
diff changeset
3308 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
3309
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3310 #ifdef HAVE_SANDBOX
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3311 static Scheme_Object *M_write = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3312 static Scheme_Object *M_read = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3313 static Scheme_Object *M_execute = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3314 static Scheme_Object *M_delete = NULL;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3315
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3316 static void
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 856
diff changeset
3317 sandbox_check(void)
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3318 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3319 if (sandbox)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3320 raise_vim_exn(_("not allowed in the Vim sandbox"));
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3321 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3322
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 274
diff changeset
3323 /* security guards to force Vim's sandbox restrictions on MzScheme level */
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3324 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
3325 sandbox_file_guard(int argc UNUSED, Scheme_Object **argv)
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3326 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3327 if (sandbox)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3328 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3329 Scheme_Object *requested_access = argv[2];
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3330
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3331 if (M_write == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3332 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3333 MZ_REGISTER_STATIC(M_write);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3334 M_write = scheme_intern_symbol("write");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3335 MZ_GC_CHECK();
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3336 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3337 if (M_read == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3338 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3339 MZ_REGISTER_STATIC(M_read);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3340 M_read = scheme_intern_symbol("read");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3341 MZ_GC_CHECK();
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3342 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3343 if (M_execute == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3344 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3345 MZ_REGISTER_STATIC(M_execute);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3346 M_execute = scheme_intern_symbol("execute");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3347 MZ_GC_CHECK();
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3348 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3349 if (M_delete == NULL)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3350 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3351 MZ_REGISTER_STATIC(M_delete);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3352 M_delete = scheme_intern_symbol("delete");
1894
afb740b5dfab updated for version 7.2-191
vimboss
parents: 1884
diff changeset
3353 MZ_GC_CHECK();
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3354 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3355
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3356 while (!SCHEME_NULLP(requested_access))
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3357 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3358 Scheme_Object *item = SCHEME_CAR(requested_access);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3359 if (scheme_eq(item, M_write) || scheme_eq(item, M_read)
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3360 || scheme_eq(item, M_execute) || scheme_eq(item, M_delete))
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3361 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3362 raise_vim_exn(_("not allowed in the Vim sandbox"));
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3363 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3364 requested_access = SCHEME_CDR(requested_access);
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3365 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3366 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3367 return scheme_void;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3368 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3369
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3370 static Scheme_Object *
2278
0b3be97064e5 Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents: 2050
diff changeset
3371 sandbox_network_guard(int argc UNUSED, Scheme_Object **argv UNUSED)
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3372 {
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3373 return scheme_void;
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3374 }
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 151
diff changeset
3375 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
3376
d8f905020502 updated for version 7.0b
vimboss
parents: 714
diff changeset
3377 #endif