Mercurial > vim
annotate src/if_perl.xs @ 5278:d96f16667cc4 v7.4b.015
updated for version 7.4b.015
Problem: Can't compile without the 'acd' feature.
Solution: Add #ifdefs. (Kazunobu Kuriyama)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 05 Aug 2013 22:02:20 +0200 |
parents | 585b623a1aa3 |
children | 805ad8488dc8 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 */ | |
8 /* | |
9 * if_perl.xs: Main code for Perl interface support. | |
10 * Mostly written by Sven Verdoolaege. | |
11 */ | |
12 | |
13 #define _memory_h /* avoid memset redeclaration */ | |
14 #define IN_PERL_FILE /* don't include if_perl.pro from proto.h */ | |
15 | |
5261
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
16 /* |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
17 * Currently 32-bit version of ActivePerl is built with VC6. |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
18 * (http://community.activestate.com/faq/windows-compilers-perl-modules) |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
19 * It means that time_t should be 32-bit. However the default size of |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
20 * time_t is 64-bit since VC8. So we have to define _USE_32BIT_TIME_T. |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
21 */ |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
22 #if defined(WIN32) && !defined(_WIN64) |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
23 # define _USE_32BIT_TIME_T |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
24 #endif |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
25 |
7 | 26 #include "vim.h" |
27 | |
5261
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
28 #include <EXTERN.h> |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
29 #include <perl.h> |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
30 #include <XSUB.h> |
b882d4b14e00
updated for version 7.4b.007
Bram Moolenaar <bram@vim.org>
parents:
4905
diff
changeset
|
31 |
7 | 32 |
33 /* | |
34 * Work around clashes between Perl and Vim namespace. proto.h doesn't | |
35 * include if_perl.pro and perlsfio.pro when IN_PERL_FILE is defined, because | |
36 * we need the CV typedef. proto.h can't be moved to after including | |
37 * if_perl.h, because we get all sorts of name clashes then. | |
38 */ | |
39 #ifndef PROTO | |
40 #ifndef __MINGW32__ | |
41 # include "proto/if_perl.pro" | |
42 # include "proto/if_perlsfio.pro" | |
43 #endif | |
44 #endif | |
45 | |
46 /* Perl compatibility stuff. This should ensure compatibility with older | |
47 * versions of Perl. | |
48 */ | |
49 | |
50 #ifndef PERL_VERSION | |
51 # include <patchlevel.h> | |
52 # define PERL_REVISION 5 | |
53 # define PERL_VERSION PATCHLEVEL | |
54 # define PERL_SUBVERSION SUBVERSION | |
55 #endif | |
56 | |
1387 | 57 /* |
58 * Quoting Jan Dubois of Active State: | |
59 * ActivePerl build 822 still identifies itself as 5.8.8 but already | |
60 * contains many of the changes from the upcoming Perl 5.8.9 release. | |
61 * | |
62 * The changes include addition of two symbols (Perl_sv_2iv_flags, | |
63 * Perl_newXS_flags) not present in earlier releases. | |
64 * | |
1395 | 65 * Jan Dubois suggested the following guarding scheme. |
66 * | |
67 * Active State defined ACTIVEPERL_VERSION as a string in versions before | |
68 * 5.8.8; and so the comparison to 822 below needs to be guarded. | |
1387 | 69 */ |
1395 | 70 #if (PERL_REVISION == 5) && (PERL_VERSION == 8) && (PERL_SUBVERSION >= 8) |
71 # if (ACTIVEPERL_VERSION >= 822) || (PERL_SUBVERSION >= 9) | |
72 # define PERL589_OR_LATER | |
73 # endif | |
1387 | 74 #endif |
75 #if (PERL_REVISION == 5) && (PERL_VERSION >= 9) | |
76 # define PERL589_OR_LATER | |
77 #endif | |
78 | |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
79 #if (PERL_REVISION == 5) && ((PERL_VERSION > 10) || \ |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
80 (PERL_VERSION == 10) && (PERL_SUBVERSION >= 1)) |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
81 # define PERL5101_OR_LATER |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
82 #endif |
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
83 |
4905
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
84 #if (PERL_REVISION == 5) && (PERL_VERSION >= 18) |
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
85 # define PERL5180_OR_LATER |
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
86 #endif |
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
87 |
7 | 88 #ifndef pTHX |
89 # define pTHX void | |
90 # define pTHX_ | |
91 #endif | |
92 | |
93 #ifndef EXTERN_C | |
94 # define EXTERN_C | |
95 #endif | |
96 | |
3728 | 97 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) && defined(_MSC_VER) |
98 /* Using PL_errgv to get the error message after perl_eval_sv() causes a crash | |
99 * with MSVC and Perl version 5.14. */ | |
100 # define AVOID_PL_ERRGV | |
101 #endif | |
102 | |
7 | 103 /* Compatibility hacks over */ |
104 | |
105 static PerlInterpreter *perl_interp = NULL; | |
106 static void xs_init __ARGS((pTHX)); | |
107 static void VIM_init __ARGS((void)); | |
108 EXTERN_C void boot_DynaLoader __ARGS((pTHX_ CV*)); | |
109 | |
110 /* | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
111 * For dynamic linked perl. |
7 | 112 */ |
113 #if defined(DYNAMIC_PERL) || defined(PROTO) | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
114 |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
115 #ifndef DYNAMIC_PERL /* just generating prototypes */ |
2372
a42d19b78c93
Fix building with Perl on Windows with MingW. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2370
diff
changeset
|
116 #ifdef WIN3264 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
117 typedef int HANDLE; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
118 #endif |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
119 typedef int XSINIT_t; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
120 typedef int XSUBADDR_t; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
121 typedef int perl_key; |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
122 #endif |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
123 |
2372
a42d19b78c93
Fix building with Perl on Windows with MingW. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2370
diff
changeset
|
124 #ifndef WIN3264 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
125 #include <dlfcn.h> |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
126 #define HANDLE void* |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
127 #define PERL_PROC void* |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
128 #define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL) |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
129 #define symbol_from_dll dlsym |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
130 #define close_dll dlclose |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
131 #else |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
132 #define PERL_PROC FARPROC |
2612 | 133 #define load_dll vimLoadLib |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
134 #define symbol_from_dll GetProcAddress |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
135 #define close_dll FreeLibrary |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
136 #endif |
7 | 137 /* |
138 * Wrapper defines | |
139 */ | |
140 # define perl_alloc dll_perl_alloc | |
141 # define perl_construct dll_perl_construct | |
142 # define perl_parse dll_perl_parse | |
143 # define perl_run dll_perl_run | |
144 # define perl_destruct dll_perl_destruct | |
145 # define perl_free dll_perl_free | |
146 # define Perl_get_context dll_Perl_get_context | |
147 # define Perl_croak dll_Perl_croak | |
4905
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
148 # ifndef PERL5180_OR_LATER |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
149 # ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
150 # define Perl_croak_xs_usage dll_Perl_croak_xs_usage |
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
151 # endif |
4905
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
152 # endif |
7 | 153 # ifndef PROTO |
154 # define Perl_croak_nocontext dll_Perl_croak_nocontext | |
155 # define Perl_call_argv dll_Perl_call_argv | |
156 # define Perl_call_pv dll_Perl_call_pv | |
157 # define Perl_eval_sv dll_Perl_eval_sv | |
158 # define Perl_get_sv dll_Perl_get_sv | |
159 # define Perl_eval_pv dll_Perl_eval_pv | |
160 # define Perl_call_method dll_Perl_call_method | |
161 # endif | |
162 # define Perl_dowantarray dll_Perl_dowantarray | |
163 # define Perl_free_tmps dll_Perl_free_tmps | |
164 # define Perl_gv_stashpv dll_Perl_gv_stashpv | |
165 # define Perl_markstack_grow dll_Perl_markstack_grow | |
166 # define Perl_mg_find dll_Perl_mg_find | |
167 # define Perl_newXS dll_Perl_newXS | |
168 # define Perl_newSV dll_Perl_newSV | |
169 # define Perl_newSViv dll_Perl_newSViv | |
170 # define Perl_newSVpv dll_Perl_newSVpv | |
171 # define Perl_pop_scope dll_Perl_pop_scope | |
172 # define Perl_push_scope dll_Perl_push_scope | |
173 # define Perl_save_int dll_Perl_save_int | |
174 # define Perl_stack_grow dll_Perl_stack_grow | |
175 # define Perl_set_context dll_Perl_set_context | |
3050 | 176 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
177 # define Perl_sv_2bool_flags dll_Perl_sv_2bool_flags | |
3820 | 178 # define Perl_xs_apiversion_bootcheck dll_Perl_xs_apiversion_bootcheck |
3050 | 179 # else |
7 | 180 # define Perl_sv_2bool dll_Perl_sv_2bool |
3050 | 181 # endif |
7 | 182 # define Perl_sv_2iv dll_Perl_sv_2iv |
183 # define Perl_sv_2mortal dll_Perl_sv_2mortal | |
184 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
185 # define Perl_sv_2pv_flags dll_Perl_sv_2pv_flags | |
186 # define Perl_sv_2pv_nolen dll_Perl_sv_2pv_nolen | |
187 # else | |
188 # define Perl_sv_2pv dll_Perl_sv_2pv | |
189 # endif | |
190 # define Perl_sv_bless dll_Perl_sv_bless | |
191 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
192 # define Perl_sv_catpvn_flags dll_Perl_sv_catpvn_flags | |
193 # else | |
194 # define Perl_sv_catpvn dll_Perl_sv_catpvn | |
195 # endif | |
1387 | 196 #ifdef PERL589_OR_LATER |
197 # define Perl_sv_2iv_flags dll_Perl_sv_2iv_flags | |
198 # define Perl_newXS_flags dll_Perl_newXS_flags | |
199 #endif | |
7 | 200 # define Perl_sv_free dll_Perl_sv_free |
1711 | 201 # if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
202 # define Perl_sv_free2 dll_Perl_sv_free2 | |
203 # endif | |
7 | 204 # define Perl_sv_isa dll_Perl_sv_isa |
205 # define Perl_sv_magic dll_Perl_sv_magic | |
206 # define Perl_sv_setiv dll_Perl_sv_setiv | |
207 # define Perl_sv_setpv dll_Perl_sv_setpv | |
208 # define Perl_sv_setpvn dll_Perl_sv_setpvn | |
209 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
210 # define Perl_sv_setsv_flags dll_Perl_sv_setsv_flags | |
211 # else | |
212 # define Perl_sv_setsv dll_Perl_sv_setsv | |
213 # endif | |
214 # define Perl_sv_upgrade dll_Perl_sv_upgrade | |
215 # define Perl_Tstack_sp_ptr dll_Perl_Tstack_sp_ptr | |
216 # define Perl_Top_ptr dll_Perl_Top_ptr | |
217 # define Perl_Tstack_base_ptr dll_Perl_Tstack_base_ptr | |
218 # define Perl_Tstack_max_ptr dll_Perl_Tstack_max_ptr | |
219 # define Perl_Ttmps_ix_ptr dll_Perl_Ttmps_ix_ptr | |
220 # define Perl_Ttmps_floor_ptr dll_Perl_Ttmps_floor_ptr | |
221 # define Perl_Tmarkstack_ptr_ptr dll_Perl_Tmarkstack_ptr_ptr | |
222 # define Perl_Tmarkstack_max_ptr dll_Perl_Tmarkstack_max_ptr | |
223 # define Perl_TSv_ptr dll_Perl_TSv_ptr | |
224 # define Perl_TXpv_ptr dll_Perl_TXpv_ptr | |
225 # define Perl_Tna_ptr dll_Perl_Tna_ptr | |
226 # define Perl_Idefgv_ptr dll_Perl_Idefgv_ptr | |
227 # define Perl_Ierrgv_ptr dll_Perl_Ierrgv_ptr | |
228 # define Perl_Isv_yes_ptr dll_Perl_Isv_yes_ptr | |
229 # define boot_DynaLoader dll_boot_DynaLoader | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
230 # define Perl_Gthr_key_ptr dll_Perl_Gthr_key_ptr |
7 | 231 |
1765 | 232 # define Perl_sys_init dll_Perl_sys_init |
1668 | 233 # define Perl_sys_term dll_Perl_sys_term |
234 # define Perl_ISv_ptr dll_Perl_ISv_ptr | |
235 # define Perl_Istack_max_ptr dll_Perl_Istack_max_ptr | |
236 # define Perl_Istack_base_ptr dll_Perl_Istack_base_ptr | |
237 # define Perl_Itmps_ix_ptr dll_Perl_Itmps_ix_ptr | |
238 # define Perl_Itmps_floor_ptr dll_Perl_Itmps_floor_ptr | |
239 # define Perl_IXpv_ptr dll_Perl_IXpv_ptr | |
240 # define Perl_Ina_ptr dll_Perl_Ina_ptr | |
241 # define Perl_Imarkstack_ptr_ptr dll_Perl_Imarkstack_ptr_ptr | |
242 # define Perl_Imarkstack_max_ptr dll_Perl_Imarkstack_max_ptr | |
243 # define Perl_Istack_sp_ptr dll_Perl_Istack_sp_ptr | |
244 # define Perl_Iop_ptr dll_Perl_Iop_ptr | |
245 # define Perl_call_list dll_Perl_call_list | |
246 # define Perl_Iscopestack_ix_ptr dll_Perl_Iscopestack_ix_ptr | |
247 # define Perl_Iunitcheckav_ptr dll_Perl_Iunitcheckav_ptr | |
3820 | 248 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
249 # define PL_thr_key *dll_PL_thr_key | |
250 # endif | |
1668 | 251 |
7 | 252 /* |
253 * Declare HANDLE for perl.dll and function pointers. | |
254 */ | |
255 static HANDLE hPerlLib = NULL; | |
256 | |
257 static PerlInterpreter* (*perl_alloc)(); | |
258 static void (*perl_construct)(PerlInterpreter*); | |
259 static void (*perl_destruct)(PerlInterpreter*); | |
260 static void (*perl_free)(PerlInterpreter*); | |
261 static int (*perl_run)(PerlInterpreter*); | |
262 static int (*perl_parse)(PerlInterpreter*, XSINIT_t, int, char**, char**); | |
263 static void* (*Perl_get_context)(void); | |
933 | 264 static void (*Perl_croak)(pTHX_ const char*, ...); |
4905
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
265 #ifndef PERL5180_OR_LATER |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
266 #ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
267 static void (*Perl_croak_xs_usage)(pTHX_ const CV *const, const char *const params); |
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
268 #endif |
4905
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
269 #endif |
933 | 270 static void (*Perl_croak_nocontext)(const char*, ...); |
7 | 271 static I32 (*Perl_dowantarray)(pTHX); |
272 static void (*Perl_free_tmps)(pTHX); | |
273 static HV* (*Perl_gv_stashpv)(pTHX_ const char*, I32); | |
274 static void (*Perl_markstack_grow)(pTHX); | |
275 static MAGIC* (*Perl_mg_find)(pTHX_ SV*, int); | |
276 static CV* (*Perl_newXS)(pTHX_ char*, XSUBADDR_t, char*); | |
277 static SV* (*Perl_newSV)(pTHX_ STRLEN); | |
278 static SV* (*Perl_newSViv)(pTHX_ IV); | |
279 static SV* (*Perl_newSVpv)(pTHX_ const char*, STRLEN); | |
280 static I32 (*Perl_call_argv)(pTHX_ const char*, I32, char**); | |
281 static I32 (*Perl_call_pv)(pTHX_ const char*, I32); | |
282 static I32 (*Perl_eval_sv)(pTHX_ SV*, I32); | |
283 static SV* (*Perl_get_sv)(pTHX_ const char*, I32); | |
284 static SV* (*Perl_eval_pv)(pTHX_ const char*, I32); | |
285 static SV* (*Perl_call_method)(pTHX_ const char*, I32); | |
286 static void (*Perl_pop_scope)(pTHX); | |
287 static void (*Perl_push_scope)(pTHX); | |
288 static void (*Perl_save_int)(pTHX_ int*); | |
289 static SV** (*Perl_stack_grow)(pTHX_ SV**, SV**p, int); | |
290 static SV** (*Perl_set_context)(void*); | |
3050 | 291 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
292 static bool (*Perl_sv_2bool_flags)(pTHX_ SV*, I32); | |
293 static void (*Perl_xs_apiversion_bootcheck)(pTHX_ SV *module, const char *api_p, STRLEN api_len); | |
294 #else | |
7 | 295 static bool (*Perl_sv_2bool)(pTHX_ SV*); |
3050 | 296 #endif |
7 | 297 static IV (*Perl_sv_2iv)(pTHX_ SV*); |
298 static SV* (*Perl_sv_2mortal)(pTHX_ SV*); | |
299 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
300 static char* (*Perl_sv_2pv_flags)(pTHX_ SV*, STRLEN*, I32); | |
301 static char* (*Perl_sv_2pv_nolen)(pTHX_ SV*); | |
302 #else | |
303 static char* (*Perl_sv_2pv)(pTHX_ SV*, STRLEN*); | |
304 #endif | |
305 static SV* (*Perl_sv_bless)(pTHX_ SV*, HV*); | |
306 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
307 static void (*Perl_sv_catpvn_flags)(pTHX_ SV* , const char*, STRLEN, I32); | |
308 #else | |
309 static void (*Perl_sv_catpvn)(pTHX_ SV*, const char*, STRLEN); | |
310 #endif | |
1387 | 311 #ifdef PERL589_OR_LATER |
312 static IV (*Perl_sv_2iv_flags)(pTHX_ SV* sv, I32 flags); | |
313 static CV * (*Perl_newXS_flags)(pTHX_ const char *name, XSUBADDR_t subaddr, const char *const filename, const char *const proto, U32 flags); | |
314 #endif | |
7 | 315 static void (*Perl_sv_free)(pTHX_ SV*); |
316 static int (*Perl_sv_isa)(pTHX_ SV*, const char*); | |
317 static void (*Perl_sv_magic)(pTHX_ SV*, SV*, int, const char*, I32); | |
318 static void (*Perl_sv_setiv)(pTHX_ SV*, IV); | |
319 static void (*Perl_sv_setpv)(pTHX_ SV*, const char*); | |
320 static void (*Perl_sv_setpvn)(pTHX_ SV*, const char*, STRLEN); | |
321 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
322 static void (*Perl_sv_setsv_flags)(pTHX_ SV*, SV*, I32); | |
323 #else | |
324 static void (*Perl_sv_setsv)(pTHX_ SV*, SV*); | |
325 #endif | |
326 static bool (*Perl_sv_upgrade)(pTHX_ SV*, U32); | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
327 #if (PERL_REVISION == 5) && (PERL_VERSION < 10) |
7 | 328 static SV*** (*Perl_Tstack_sp_ptr)(register PerlInterpreter*); |
329 static OP** (*Perl_Top_ptr)(register PerlInterpreter*); | |
330 static SV*** (*Perl_Tstack_base_ptr)(register PerlInterpreter*); | |
331 static SV*** (*Perl_Tstack_max_ptr)(register PerlInterpreter*); | |
332 static I32* (*Perl_Ttmps_ix_ptr)(register PerlInterpreter*); | |
333 static I32* (*Perl_Ttmps_floor_ptr)(register PerlInterpreter*); | |
334 static I32** (*Perl_Tmarkstack_ptr_ptr)(register PerlInterpreter*); | |
335 static I32** (*Perl_Tmarkstack_max_ptr)(register PerlInterpreter*); | |
336 static SV** (*Perl_TSv_ptr)(register PerlInterpreter*); | |
337 static XPV** (*Perl_TXpv_ptr)(register PerlInterpreter*); | |
338 static STRLEN* (*Perl_Tna_ptr)(register PerlInterpreter*); | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
339 #else |
1711 | 340 static void (*Perl_sv_free2)(pTHX_ SV*); |
1765 | 341 static void (*Perl_sys_init)(int* argc, char*** argv); |
1668 | 342 static void (*Perl_sys_term)(void); |
3818 | 343 static void (*Perl_call_list)(pTHX_ I32, AV*); |
344 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) | |
345 # else | |
1668 | 346 static SV** (*Perl_ISv_ptr)(register PerlInterpreter*); |
347 static SV*** (*Perl_Istack_max_ptr)(register PerlInterpreter*); | |
348 static SV*** (*Perl_Istack_base_ptr)(register PerlInterpreter*); | |
349 static XPV** (*Perl_IXpv_ptr)(register PerlInterpreter*); | |
350 static I32* (*Perl_Itmps_ix_ptr)(register PerlInterpreter*); | |
351 static I32* (*Perl_Itmps_floor_ptr)(register PerlInterpreter*); | |
352 static STRLEN* (*Perl_Ina_ptr)(register PerlInterpreter*); | |
353 static I32** (*Perl_Imarkstack_ptr_ptr)(register PerlInterpreter*); | |
354 static I32** (*Perl_Imarkstack_max_ptr)(register PerlInterpreter*); | |
355 static SV*** (*Perl_Istack_sp_ptr)(register PerlInterpreter*); | |
356 static OP** (*Perl_Iop_ptr)(register PerlInterpreter*); | |
357 static I32* (*Perl_Iscopestack_ix_ptr)(register PerlInterpreter*); | |
358 static AV** (*Perl_Iunitcheckav_ptr)(register PerlInterpreter*); | |
3818 | 359 # endif |
1668 | 360 #endif |
7 | 361 |
3818 | 362 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
3820 | 363 static perl_key* dll_PL_thr_key; |
3818 | 364 #else |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
365 static GV** (*Perl_Idefgv_ptr)(register PerlInterpreter*); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
366 static GV** (*Perl_Ierrgv_ptr)(register PerlInterpreter*); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
367 static SV* (*Perl_Isv_yes_ptr)(register PerlInterpreter*); |
3818 | 368 static perl_key* (*Perl_Gthr_key_ptr)_((pTHX)); |
369 #endif | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
370 static void (*boot_DynaLoader)_((pTHX_ CV*)); |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
371 |
7 | 372 /* |
373 * Table of name to function pointer of perl. | |
374 */ | |
375 static struct { | |
376 char* name; | |
377 PERL_PROC* ptr; | |
378 } perl_funcname_table[] = { | |
379 {"perl_alloc", (PERL_PROC*)&perl_alloc}, | |
380 {"perl_construct", (PERL_PROC*)&perl_construct}, | |
381 {"perl_destruct", (PERL_PROC*)&perl_destruct}, | |
382 {"perl_free", (PERL_PROC*)&perl_free}, | |
383 {"perl_run", (PERL_PROC*)&perl_run}, | |
384 {"perl_parse", (PERL_PROC*)&perl_parse}, | |
385 {"Perl_get_context", (PERL_PROC*)&Perl_get_context}, | |
386 {"Perl_croak", (PERL_PROC*)&Perl_croak}, | |
4905
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
387 #ifndef PERL5180_OR_LATER |
2096
6510d834609f
updated for version 7.2.380
Bram Moolenaar <bram@zimbu.org>
parents:
2079
diff
changeset
|
388 #ifdef PERL5101_OR_LATER |
2079
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
389 {"Perl_croak_xs_usage", (PERL_PROC*)&Perl_croak_xs_usage}, |
5abd3e3c0085
updated for version 7.2.363
Bram Moolenaar <bram@zimbu.org>
parents:
1990
diff
changeset
|
390 #endif |
4905
517fa1a34c7c
updated for version 7.3.1198
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
391 #endif |
7 | 392 {"Perl_croak_nocontext", (PERL_PROC*)&Perl_croak_nocontext}, |
393 {"Perl_dowantarray", (PERL_PROC*)&Perl_dowantarray}, | |
394 {"Perl_free_tmps", (PERL_PROC*)&Perl_free_tmps}, | |
395 {"Perl_gv_stashpv", (PERL_PROC*)&Perl_gv_stashpv}, | |
396 {"Perl_markstack_grow", (PERL_PROC*)&Perl_markstack_grow}, | |
397 {"Perl_mg_find", (PERL_PROC*)&Perl_mg_find}, | |
398 {"Perl_newXS", (PERL_PROC*)&Perl_newXS}, | |
399 {"Perl_newSV", (PERL_PROC*)&Perl_newSV}, | |
400 {"Perl_newSViv", (PERL_PROC*)&Perl_newSViv}, | |
401 {"Perl_newSVpv", (PERL_PROC*)&Perl_newSVpv}, | |
402 {"Perl_call_argv", (PERL_PROC*)&Perl_call_argv}, | |
403 {"Perl_call_pv", (PERL_PROC*)&Perl_call_pv}, | |
404 {"Perl_eval_sv", (PERL_PROC*)&Perl_eval_sv}, | |
405 {"Perl_get_sv", (PERL_PROC*)&Perl_get_sv}, | |
406 {"Perl_eval_pv", (PERL_PROC*)&Perl_eval_pv}, | |
407 {"Perl_call_method", (PERL_PROC*)&Perl_call_method}, | |
408 {"Perl_pop_scope", (PERL_PROC*)&Perl_pop_scope}, | |
409 {"Perl_push_scope", (PERL_PROC*)&Perl_push_scope}, | |
410 {"Perl_save_int", (PERL_PROC*)&Perl_save_int}, | |
411 {"Perl_stack_grow", (PERL_PROC*)&Perl_stack_grow}, | |
412 {"Perl_set_context", (PERL_PROC*)&Perl_set_context}, | |
3050 | 413 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
414 {"Perl_sv_2bool_flags", (PERL_PROC*)&Perl_sv_2bool_flags}, | |
415 {"Perl_xs_apiversion_bootcheck",(PERL_PROC*)&Perl_xs_apiversion_bootcheck}, | |
416 #else | |
7 | 417 {"Perl_sv_2bool", (PERL_PROC*)&Perl_sv_2bool}, |
3050 | 418 #endif |
7 | 419 {"Perl_sv_2iv", (PERL_PROC*)&Perl_sv_2iv}, |
420 {"Perl_sv_2mortal", (PERL_PROC*)&Perl_sv_2mortal}, | |
421 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
422 {"Perl_sv_2pv_flags", (PERL_PROC*)&Perl_sv_2pv_flags}, | |
423 {"Perl_sv_2pv_nolen", (PERL_PROC*)&Perl_sv_2pv_nolen}, | |
424 #else | |
425 {"Perl_sv_2pv", (PERL_PROC*)&Perl_sv_2pv}, | |
426 #endif | |
1387 | 427 #ifdef PERL589_OR_LATER |
428 {"Perl_sv_2iv_flags", (PERL_PROC*)&Perl_sv_2iv_flags}, | |
429 {"Perl_newXS_flags", (PERL_PROC*)&Perl_newXS_flags}, | |
430 #endif | |
7 | 431 {"Perl_sv_bless", (PERL_PROC*)&Perl_sv_bless}, |
432 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
433 {"Perl_sv_catpvn_flags", (PERL_PROC*)&Perl_sv_catpvn_flags}, | |
434 #else | |
435 {"Perl_sv_catpvn", (PERL_PROC*)&Perl_sv_catpvn}, | |
436 #endif | |
437 {"Perl_sv_free", (PERL_PROC*)&Perl_sv_free}, | |
438 {"Perl_sv_isa", (PERL_PROC*)&Perl_sv_isa}, | |
439 {"Perl_sv_magic", (PERL_PROC*)&Perl_sv_magic}, | |
440 {"Perl_sv_setiv", (PERL_PROC*)&Perl_sv_setiv}, | |
441 {"Perl_sv_setpv", (PERL_PROC*)&Perl_sv_setpv}, | |
442 {"Perl_sv_setpvn", (PERL_PROC*)&Perl_sv_setpvn}, | |
443 #if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
444 {"Perl_sv_setsv_flags", (PERL_PROC*)&Perl_sv_setsv_flags}, | |
445 #else | |
446 {"Perl_sv_setsv", (PERL_PROC*)&Perl_sv_setsv}, | |
447 #endif | |
448 {"Perl_sv_upgrade", (PERL_PROC*)&Perl_sv_upgrade}, | |
1668 | 449 #if (PERL_REVISION == 5) && (PERL_VERSION < 10) |
7 | 450 {"Perl_Tstack_sp_ptr", (PERL_PROC*)&Perl_Tstack_sp_ptr}, |
451 {"Perl_Top_ptr", (PERL_PROC*)&Perl_Top_ptr}, | |
452 {"Perl_Tstack_base_ptr", (PERL_PROC*)&Perl_Tstack_base_ptr}, | |
453 {"Perl_Tstack_max_ptr", (PERL_PROC*)&Perl_Tstack_max_ptr}, | |
454 {"Perl_Ttmps_ix_ptr", (PERL_PROC*)&Perl_Ttmps_ix_ptr}, | |
455 {"Perl_Ttmps_floor_ptr", (PERL_PROC*)&Perl_Ttmps_floor_ptr}, | |
456 {"Perl_Tmarkstack_ptr_ptr", (PERL_PROC*)&Perl_Tmarkstack_ptr_ptr}, | |
457 {"Perl_Tmarkstack_max_ptr", (PERL_PROC*)&Perl_Tmarkstack_max_ptr}, | |
458 {"Perl_TSv_ptr", (PERL_PROC*)&Perl_TSv_ptr}, | |
459 {"Perl_TXpv_ptr", (PERL_PROC*)&Perl_TXpv_ptr}, | |
460 {"Perl_Tna_ptr", (PERL_PROC*)&Perl_Tna_ptr}, | |
1668 | 461 #else |
1711 | 462 {"Perl_sv_free2", (PERL_PROC*)&Perl_sv_free2}, |
1765 | 463 {"Perl_sys_init", (PERL_PROC*)&Perl_sys_init}, |
1668 | 464 {"Perl_sys_term", (PERL_PROC*)&Perl_sys_term}, |
3050 | 465 {"Perl_call_list", (PERL_PROC*)&Perl_call_list}, |
466 # if (PERL_REVISION == 5) && (PERL_VERSION >= 14) | |
467 # else | |
1668 | 468 {"Perl_ISv_ptr", (PERL_PROC*)&Perl_ISv_ptr}, |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
469 {"Perl_Istack_max_ptr", (PERL_PROC*)&Perl_Istack_max_ptr}, |
1668 | 470 {"Perl_Istack_base_ptr", (PERL_PROC*)&Perl_Istack_base_ptr}, |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
471 {"Perl_IXpv_ptr", (PERL_PROC*)&Perl_IXpv_ptr}, |
1668 | 472 {"Perl_Itmps_ix_ptr", (PERL_PROC*)&Perl_Itmps_ix_ptr}, |
473 {"Perl_Itmps_floor_ptr", (PERL_PROC*)&Perl_Itmps_floor_ptr}, | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
474 {"Perl_Ina_ptr", (PERL_PROC*)&Perl_Ina_ptr}, |
1668 | 475 {"Perl_Imarkstack_ptr_ptr", (PERL_PROC*)&Perl_Imarkstack_ptr_ptr}, |
476 {"Perl_Imarkstack_max_ptr", (PERL_PROC*)&Perl_Imarkstack_max_ptr}, | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
477 {"Perl_Istack_sp_ptr", (PERL_PROC*)&Perl_Istack_sp_ptr}, |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
478 {"Perl_Iop_ptr", (PERL_PROC*)&Perl_Iop_ptr}, |
1668 | 479 {"Perl_Iscopestack_ix_ptr", (PERL_PROC*)&Perl_Iscopestack_ix_ptr}, |
480 {"Perl_Iunitcheckav_ptr", (PERL_PROC*)&Perl_Iunitcheckav_ptr}, | |
3050 | 481 # endif |
1668 | 482 #endif |
3050 | 483 #if (PERL_REVISION == 5) && (PERL_VERSION >= 14) |
3820 | 484 {"PL_thr_key", (PERL_PROC*)&dll_PL_thr_key}, |
3050 | 485 #else |
7 | 486 {"Perl_Idefgv_ptr", (PERL_PROC*)&Perl_Idefgv_ptr}, |
487 {"Perl_Ierrgv_ptr", (PERL_PROC*)&Perl_Ierrgv_ptr}, | |
488 {"Perl_Isv_yes_ptr", (PERL_PROC*)&Perl_Isv_yes_ptr}, | |
3050 | 489 {"Perl_Gthr_key_ptr", (PERL_PROC*)&Perl_Gthr_key_ptr}, |
490 #endif | |
7 | 491 {"boot_DynaLoader", (PERL_PROC*)&boot_DynaLoader}, |
492 {"", NULL}, | |
493 }; | |
494 | |
495 /* | |
496 * Make all runtime-links of perl. | |
497 * | |
5267
585b623a1aa3
updated for version 7.4b.010
Bram Moolenaar <bram@vim.org>
parents:
5261
diff
changeset
|
498 * 1. Get module handle using dlopen() or vimLoadLib(). |
7 | 499 * 2. Get pointer to perl function by GetProcAddress. |
500 * 3. Repeat 2, until get all functions will be used. | |
501 * | |
502 * Parameter 'libname' provides name of DLL. | |
503 * Return OK or FAIL. | |
504 */ | |
505 static int | |
506 perl_runtime_link_init(char *libname, int verbose) | |
507 { | |
508 int i; | |
509 | |
510 if (hPerlLib != NULL) | |
511 return OK; | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
512 if ((hPerlLib = load_dll(libname)) == NULL) |
7 | 513 { |
514 if (verbose) | |
515 EMSG2(_("E370: Could not load library %s"), libname); | |
516 return FAIL; | |
517 } | |
518 for (i = 0; perl_funcname_table[i].ptr; ++i) | |
519 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
520 if (!(*perl_funcname_table[i].ptr = symbol_from_dll(hPerlLib, |
7 | 521 perl_funcname_table[i].name))) |
522 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
523 close_dll(hPerlLib); |
7 | 524 hPerlLib = NULL; |
525 if (verbose) | |
526 EMSG2(_(e_loadfunc), perl_funcname_table[i].name); | |
527 return FAIL; | |
528 } | |
529 } | |
530 return OK; | |
531 } | |
532 | |
533 /* | |
534 * If runtime-link-perl(DLL) was loaded successfully, return TRUE. | |
535 * There were no DLL loaded, return FALSE. | |
536 */ | |
537 int | |
538 perl_enabled(verbose) | |
539 int verbose; | |
540 { | |
541 return perl_runtime_link_init(DYNAMIC_PERL_DLL, verbose) == OK; | |
542 } | |
543 #endif /* DYNAMIC_PERL */ | |
544 | |
545 /* | |
546 * perl_init(): initialize perl interpreter | |
547 * We have to call perl_parse to initialize some structures, | |
548 * there's nothing to actually parse. | |
549 */ | |
550 static void | |
551 perl_init() | |
552 { | |
1668 | 553 char *bootargs[] = { "VI", NULL }; |
554 int argc = 3; | |
555 static char *argv[] = { "", "-e", "" }; | |
7 | 556 |
1668 | 557 #if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
1765 | 558 Perl_sys_init(&argc, (char***)&argv); |
1668 | 559 #endif |
7 | 560 perl_interp = perl_alloc(); |
561 perl_construct(perl_interp); | |
1668 | 562 perl_parse(perl_interp, xs_init, argc, argv, 0); |
7 | 563 perl_call_argv("VIM::bootstrap", (long)G_DISCARD, bootargs); |
564 VIM_init(); | |
565 #ifdef USE_SFIO | |
566 sfdisc(PerlIO_stdout(), sfdcnewvim()); | |
567 sfdisc(PerlIO_stderr(), sfdcnewvim()); | |
568 sfsetbuf(PerlIO_stdout(), NULL, 0); | |
569 sfsetbuf(PerlIO_stderr(), NULL, 0); | |
570 #endif | |
571 } | |
572 | |
573 /* | |
574 * perl_end(): clean up after ourselves | |
575 */ | |
576 void | |
577 perl_end() | |
578 { | |
579 if (perl_interp) | |
580 { | |
581 perl_run(perl_interp); | |
582 perl_destruct(perl_interp); | |
583 perl_free(perl_interp); | |
584 perl_interp = NULL; | |
1668 | 585 #if (PERL_REVISION == 5) && (PERL_VERSION >= 10) |
586 Perl_sys_term(); | |
587 #endif | |
7 | 588 } |
589 #ifdef DYNAMIC_PERL | |
590 if (hPerlLib) | |
591 { | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
592 close_dll(hPerlLib); |
7 | 593 hPerlLib = NULL; |
594 } | |
595 #endif | |
596 } | |
597 | |
598 /* | |
599 * msg_split(): send a message to the message handling routines | |
600 * split at '\n' first though. | |
601 */ | |
602 void | |
603 msg_split(s, attr) | |
604 char_u *s; | |
605 int attr; /* highlighting attributes */ | |
606 { | |
607 char *next; | |
608 char *token = (char *)s; | |
609 | |
1423 | 610 while ((next = strchr(token, '\n')) && !got_int) |
7 | 611 { |
612 *next++ = '\0'; /* replace \n with \0 */ | |
613 msg_attr((char_u *)token, attr); | |
614 token = next; | |
615 } | |
1423 | 616 if (*token && !got_int) |
7 | 617 msg_attr((char_u *)token, attr); |
618 } | |
619 | |
620 #ifndef FEAT_EVAL | |
621 /* | |
622 * This stub is needed because an "#ifdef FEAT_EVAL" around Eval() doesn't | |
623 * work properly. | |
624 */ | |
625 char_u * | |
714 | 626 eval_to_string(arg, nextcmd, dolist) |
4135 | 627 char_u *arg UNUSED; |
628 char_u **nextcmd UNUSED; | |
629 int dolist UNUSED; | |
7 | 630 { |
631 return NULL; | |
632 } | |
633 #endif | |
634 | |
635 /* | |
636 * Create a new reference to an SV pointing to the SCR structure | |
502 | 637 * The b_perl_private/w_perl_private part of the SCR structure points to the |
638 * SV, so there can only be one such SV for a particular SCR structure. When | |
639 * the last reference has gone (DESTROY is called), | |
640 * b_perl_private/w_perl_private is reset; When the screen goes away before | |
7 | 641 * all references are gone, the value of the SV is reset; |
642 * any subsequent use of any of those reference will produce | |
643 * a warning. (see typemap) | |
644 */ | |
502 | 645 |
646 static SV * | |
647 newWINrv(rv, ptr) | |
648 SV *rv; | |
649 win_T *ptr; | |
650 { | |
651 sv_upgrade(rv, SVt_RV); | |
652 if (ptr->w_perl_private == NULL) | |
653 { | |
654 ptr->w_perl_private = newSV(0); | |
3344 | 655 sv_setiv(ptr->w_perl_private, PTR2IV(ptr)); |
502 | 656 } |
657 else | |
658 SvREFCNT_inc(ptr->w_perl_private); | |
659 SvRV(rv) = ptr->w_perl_private; | |
660 SvROK_on(rv); | |
661 return sv_bless(rv, gv_stashpv("VIWIN", TRUE)); | |
7 | 662 } |
663 | |
502 | 664 static SV * |
665 newBUFrv(rv, ptr) | |
666 SV *rv; | |
667 buf_T *ptr; | |
668 { | |
669 sv_upgrade(rv, SVt_RV); | |
670 if (ptr->b_perl_private == NULL) | |
671 { | |
672 ptr->b_perl_private = newSV(0); | |
3344 | 673 sv_setiv(ptr->b_perl_private, PTR2IV(ptr)); |
502 | 674 } |
675 else | |
676 SvREFCNT_inc(ptr->b_perl_private); | |
677 SvRV(rv) = ptr->b_perl_private; | |
678 SvROK_on(rv); | |
679 return sv_bless(rv, gv_stashpv("VIBUF", TRUE)); | |
680 } | |
7 | 681 |
682 /* | |
683 * perl_win_free | |
4352 | 684 * Remove all references to the window to be destroyed |
7 | 685 */ |
686 void | |
687 perl_win_free(wp) | |
688 win_T *wp; | |
689 { | |
502 | 690 if (wp->w_perl_private) |
691 sv_setiv((SV *)wp->w_perl_private, 0); | |
7 | 692 return; |
693 } | |
694 | |
695 void | |
696 perl_buf_free(bp) | |
697 buf_T *bp; | |
698 { | |
502 | 699 if (bp->b_perl_private) |
700 sv_setiv((SV *)bp->b_perl_private, 0); | |
7 | 701 return; |
702 } | |
703 | |
704 #ifndef PROTO | |
705 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
706 I32 cur_val(pTHX_ IV iv, SV *sv); | |
707 # else | |
708 I32 cur_val(IV iv, SV *sv); | |
709 #endif | |
710 | |
711 /* | |
712 * Handler for the magic variables $main::curwin and $main::curbuf. | |
713 * The handler is put into the magic vtbl for these variables. | |
714 * (This is effectively a C-level equivalent of a tied variable). | |
715 * There is no "set" function as the variables are read-only. | |
716 */ | |
717 # if (PERL_REVISION == 5) && (PERL_VERSION >= 8) | |
718 I32 cur_val(pTHX_ IV iv, SV *sv) | |
719 # else | |
720 I32 cur_val(IV iv, SV *sv) | |
721 # endif | |
722 { | |
723 SV *rv; | |
724 if (iv == 0) | |
725 rv = newWINrv(newSV(0), curwin); | |
726 else | |
727 rv = newBUFrv(newSV(0), curbuf); | |
728 sv_setsv(sv, rv); | |
729 return 0; | |
730 } | |
731 #endif /* !PROTO */ | |
732 | |
733 struct ufuncs cw_funcs = { cur_val, 0, 0 }; | |
734 struct ufuncs cb_funcs = { cur_val, 0, 1 }; | |
735 | |
736 /* | |
737 * VIM_init(): Vim-specific initialisation. | |
738 * Make the magical main::curwin and main::curbuf variables | |
739 */ | |
740 static void | |
741 VIM_init() | |
742 { | |
743 static char cw[] = "main::curwin"; | |
744 static char cb[] = "main::curbuf"; | |
745 SV *sv; | |
746 | |
747 sv = perl_get_sv(cw, TRUE); | |
748 sv_magic(sv, NULL, 'U', (char *)&cw_funcs, sizeof(cw_funcs)); | |
749 SvREADONLY_on(sv); | |
750 | |
751 sv = perl_get_sv(cb, TRUE); | |
752 sv_magic(sv, NULL, 'U', (char *)&cb_funcs, sizeof(cb_funcs)); | |
753 SvREADONLY_on(sv); | |
754 | |
755 /* | |
756 * Setup the Safe compartment. | |
757 * It shouldn't be a fatal error if the Safe module is missing. | |
758 * XXX: Only shares the 'Msg' routine (which has to be called | |
759 * like 'Msg(...)'). | |
760 */ | |
761 (void)perl_eval_pv( "if ( eval( 'require Safe' ) ) { $VIM::safe = Safe->new(); $VIM::safe->share_from( 'VIM', ['Msg'] ); }", G_DISCARD | G_VOID ); | |
762 | |
763 } | |
764 | |
765 #ifdef DYNAMIC_PERL | |
766 static char *e_noperl = N_("Sorry, this command is disabled: the Perl library could not be loaded."); | |
767 #endif | |
768 | |
769 /* | |
770 * ":perl" | |
771 */ | |
772 void | |
773 ex_perl(eap) | |
774 exarg_T *eap; | |
775 { | |
776 char *err; | |
777 char *script; | |
778 STRLEN length; | |
779 SV *sv; | |
2255 | 780 #ifdef HAVE_SANDBOX |
7 | 781 SV *safe; |
2255 | 782 #endif |
7 | 783 |
784 script = (char *)script_get(eap, eap->arg); | |
785 if (eap->skip) | |
786 { | |
787 vim_free(script); | |
788 return; | |
789 } | |
790 | |
791 if (perl_interp == NULL) | |
792 { | |
793 #ifdef DYNAMIC_PERL | |
794 if (!perl_enabled(TRUE)) | |
795 { | |
796 EMSG(_(e_noperl)); | |
797 vim_free(script); | |
798 return; | |
799 } | |
800 #endif | |
801 perl_init(); | |
802 } | |
803 | |
804 { | |
805 dSP; | |
806 ENTER; | |
807 SAVETMPS; | |
808 | |
809 if (script == NULL) | |
810 sv = newSVpv((char *)eap->arg, 0); | |
811 else | |
812 { | |
813 sv = newSVpv(script, 0); | |
814 vim_free(script); | |
815 } | |
816 | |
817 #ifdef HAVE_SANDBOX | |
818 if (sandbox) | |
819 { | |
2982 | 820 safe = perl_get_sv("VIM::safe", FALSE); |
1934 | 821 # ifndef MAKE_TEST /* avoid a warning for unreachable code */ |
1990 | 822 if (safe == NULL || !SvTRUE(safe)) |
7 | 823 EMSG(_("E299: Perl evaluation forbidden in sandbox without the Safe module")); |
824 else | |
1934 | 825 # endif |
7 | 826 { |
827 PUSHMARK(SP); | |
828 XPUSHs(safe); | |
829 XPUSHs(sv); | |
830 PUTBACK; | |
831 perl_call_method("reval", G_DISCARD); | |
832 } | |
833 } | |
834 else | |
835 #endif | |
836 perl_eval_sv(sv, G_DISCARD | G_NOARGS); | |
837 | |
838 SvREFCNT_dec(sv); | |
839 | |
3728 | 840 #ifdef AVOID_PL_ERRGV |
841 err = SvPV(perl_get_sv("@", GV_ADD), length); | |
842 #else | |
7 | 843 err = SvPV(GvSV(PL_errgv), length); |
3728 | 844 #endif |
7 | 845 |
846 FREETMPS; | |
847 LEAVE; | |
848 | |
849 if (!length) | |
850 return; | |
851 | |
852 msg_split((char_u *)err, highlight_attr[HLF_E]); | |
853 return; | |
854 } | |
855 } | |
856 | |
857 static int | |
858 replace_line(line, end) | |
859 linenr_T *line, *end; | |
860 { | |
861 char *str; | |
862 | |
863 if (SvOK(GvSV(PL_defgv))) | |
864 { | |
865 str = SvPV(GvSV(PL_defgv), PL_na); | |
866 ml_replace(*line, (char_u *)str, 1); | |
867 changed_bytes(*line, 0); | |
868 } | |
869 else | |
870 { | |
871 ml_delete(*line, FALSE); | |
872 deleted_lines_mark(*line, 1L); | |
873 --(*end); | |
874 --(*line); | |
875 } | |
876 return OK; | |
877 } | |
878 | |
879 /* | |
880 * ":perldo". | |
881 */ | |
882 void | |
883 ex_perldo(eap) | |
884 exarg_T *eap; | |
885 { | |
886 STRLEN length; | |
887 SV *sv; | |
888 char *str; | |
889 linenr_T i; | |
890 | |
891 if (bufempty()) | |
892 return; | |
893 | |
894 if (perl_interp == NULL) | |
895 { | |
896 #ifdef DYNAMIC_PERL | |
897 if (!perl_enabled(TRUE)) | |
898 { | |
899 EMSG(_(e_noperl)); | |
900 return; | |
901 } | |
902 #endif | |
903 perl_init(); | |
904 } | |
905 { | |
906 dSP; | |
907 length = strlen((char *)eap->arg); | |
129 | 908 sv = newSV(length + sizeof("sub VIM::perldo {") - 1 + 1); |
909 sv_setpvn(sv, "sub VIM::perldo {", sizeof("sub VIM::perldo {") - 1); | |
7 | 910 sv_catpvn(sv, (char *)eap->arg, length); |
911 sv_catpvn(sv, "}", 1); | |
912 perl_eval_sv(sv, G_DISCARD | G_NOARGS); | |
913 SvREFCNT_dec(sv); | |
3728 | 914 #ifdef AVOID_PL_ERRGV |
915 str = SvPV(perl_get_sv("@", GV_ADD), length); | |
916 #else | |
7 | 917 str = SvPV(GvSV(PL_errgv), length); |
3728 | 918 #endif |
7 | 919 if (length) |
920 goto err; | |
921 | |
922 if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) | |
923 return; | |
924 | |
925 ENTER; | |
926 SAVETMPS; | |
927 for (i = eap->line1; i <= eap->line2; i++) | |
928 { | |
129 | 929 sv_setpv(GvSV(PL_defgv), (char *)ml_get(i)); |
7 | 930 PUSHMARK(sp); |
931 perl_call_pv("VIM::perldo", G_SCALAR | G_EVAL); | |
3728 | 932 #ifdef AVOID_PL_ERRGV |
933 str = SvPV(perl_get_sv("@", GV_ADD), length); | |
934 #else | |
7 | 935 str = SvPV(GvSV(PL_errgv), length); |
3728 | 936 #endif |
7 | 937 if (length) |
938 break; | |
939 SPAGAIN; | |
940 if (SvTRUEx(POPs)) | |
941 { | |
942 if (replace_line(&i, &eap->line2) != OK) | |
943 { | |
944 PUTBACK; | |
945 break; | |
946 } | |
947 } | |
948 PUTBACK; | |
949 } | |
950 FREETMPS; | |
951 LEAVE; | |
952 check_cursor(); | |
953 update_screen(NOT_VALID); | |
954 if (!length) | |
955 return; | |
956 | |
957 err: | |
958 msg_split((char_u *)str, highlight_attr[HLF_E]); | |
959 return; | |
960 } | |
961 } | |
962 | |
1681 | 963 #ifndef FEAT_WINDOWS |
964 int win_valid(win_T *w) { return TRUE; } | |
965 int win_count() { return 1; } | |
966 win_T *win_find_nr(int n) { return curwin; } | |
967 #endif | |
968 | |
7 | 969 XS(boot_VIM); |
970 | |
971 static void | |
972 xs_init(pTHX) | |
973 { | |
974 char *file = __FILE__; | |
975 | |
976 /* DynaLoader is a special case */ | |
977 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); | |
978 newXS("VIM::bootstrap", boot_VIM, file); | |
979 } | |
980 | |
981 typedef win_T * VIWIN; | |
982 typedef buf_T * VIBUF; | |
983 | |
984 MODULE = VIM PACKAGE = VIM | |
985 | |
986 void | |
987 Msg(text, hl=NULL) | |
988 char *text; | |
989 char *hl; | |
990 | |
991 PREINIT: | |
992 int attr; | |
993 int id; | |
994 | |
995 PPCODE: | |
996 if (text != NULL) | |
997 { | |
998 attr = 0; | |
999 if (hl != NULL) | |
1000 { | |
1001 id = syn_name2id((char_u *)hl); | |
1002 if (id != 0) | |
1003 attr = syn_id2attr(id); | |
1004 } | |
1005 msg_split((char_u *)text, attr); | |
1006 } | |
1007 | |
1008 void | |
1009 SetOption(line) | |
1010 char *line; | |
1011 | |
1012 PPCODE: | |
1013 if (line != NULL) | |
1014 do_set((char_u *)line, 0); | |
1015 update_screen(NOT_VALID); | |
1016 | |
1017 void | |
1018 DoCommand(line) | |
1019 char *line; | |
1020 | |
1021 PPCODE: | |
1022 if (line != NULL) | |
1023 do_cmdline_cmd((char_u *)line); | |
1024 | |
1025 void | |
1026 Eval(str) | |
1027 char *str; | |
1028 | |
1029 PREINIT: | |
1030 char_u *value; | |
1031 PPCODE: | |
714 | 1032 value = eval_to_string((char_u *)str, (char_u **)0, TRUE); |
7 | 1033 if (value == NULL) |
1034 { | |
1035 XPUSHs(sv_2mortal(newSViv(0))); | |
1036 XPUSHs(sv_2mortal(newSVpv("", 0))); | |
1037 } | |
1038 else | |
1039 { | |
1040 XPUSHs(sv_2mortal(newSViv(1))); | |
1041 XPUSHs(sv_2mortal(newSVpv((char *)value, 0))); | |
1042 vim_free(value); | |
1043 } | |
1044 | |
1045 void | |
1046 Buffers(...) | |
1047 | |
1048 PREINIT: | |
1049 buf_T *vimbuf; | |
1050 int i, b; | |
1051 | |
1052 PPCODE: | |
1053 if (items == 0) | |
1054 { | |
1055 if (GIMME == G_SCALAR) | |
1056 { | |
1057 i = 0; | |
1058 for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next) | |
1059 ++i; | |
1060 | |
1061 XPUSHs(sv_2mortal(newSViv(i))); | |
1062 } | |
1063 else | |
1064 { | |
1065 for (vimbuf = firstbuf; vimbuf; vimbuf = vimbuf->b_next) | |
1066 XPUSHs(newBUFrv(newSV(0), vimbuf)); | |
1067 } | |
1068 } | |
1069 else | |
1070 { | |
1071 for (i = 0; i < items; i++) | |
1072 { | |
1073 SV *sv = ST(i); | |
1074 if (SvIOK(sv)) | |
4105 | 1075 b = (int) SvIV(ST(i)); |
7 | 1076 else |
1077 { | |
1078 char_u *pat; | |
1079 STRLEN len; | |
1080 | |
1081 pat = (char_u *)SvPV(sv, len); | |
1082 ++emsg_off; | |
4236 | 1083 b = buflist_findpat(pat, pat+len, FALSE, FALSE, FALSE); |
7 | 1084 --emsg_off; |
1085 } | |
1086 | |
1087 if (b >= 0) | |
1088 { | |
1089 vimbuf = buflist_findnr(b); | |
1090 if (vimbuf) | |
1091 XPUSHs(newBUFrv(newSV(0), vimbuf)); | |
1092 } | |
1093 } | |
1094 } | |
1095 | |
1096 void | |
1097 Windows(...) | |
1098 | |
1099 PREINIT: | |
1100 win_T *vimwin; | |
1101 int i, w; | |
1102 | |
1103 PPCODE: | |
1104 if (items == 0) | |
1105 { | |
1106 if (GIMME == G_SCALAR) | |
1107 XPUSHs(sv_2mortal(newSViv(win_count()))); | |
1108 else | |
1109 { | |
1110 for (vimwin = firstwin; vimwin != NULL; vimwin = W_NEXT(vimwin)) | |
1111 XPUSHs(newWINrv(newSV(0), vimwin)); | |
1112 } | |
1113 } | |
1114 else | |
1115 { | |
1116 for (i = 0; i < items; i++) | |
1117 { | |
4105 | 1118 w = (int) SvIV(ST(i)); |
7 | 1119 vimwin = win_find_nr(w); |
1120 if (vimwin) | |
1121 XPUSHs(newWINrv(newSV(0), vimwin)); | |
1122 } | |
1123 } | |
1124 | |
1125 MODULE = VIM PACKAGE = VIWIN | |
1126 | |
1127 void | |
1128 DESTROY(win) | |
1129 VIWIN win | |
1130 | |
1131 CODE: | |
1132 if (win_valid(win)) | |
502 | 1133 win->w_perl_private = 0; |
7 | 1134 |
1135 SV * | |
1136 Buffer(win) | |
1137 VIWIN win | |
1138 | |
1139 CODE: | |
1140 if (!win_valid(win)) | |
1141 win = curwin; | |
1142 RETVAL = newBUFrv(newSV(0), win->w_buffer); | |
1143 OUTPUT: | |
1144 RETVAL | |
1145 | |
1146 void | |
1147 SetHeight(win, height) | |
1148 VIWIN win | |
1149 int height; | |
1150 | |
1151 PREINIT: | |
1152 win_T *savewin; | |
1153 | |
1154 PPCODE: | |
1155 if (!win_valid(win)) | |
1156 win = curwin; | |
1157 savewin = curwin; | |
1158 curwin = win; | |
1159 win_setheight(height); | |
1160 curwin = savewin; | |
1161 | |
1162 void | |
1163 Cursor(win, ...) | |
1164 VIWIN win | |
1165 | |
1166 PPCODE: | |
2982 | 1167 if (items == 1) |
7 | 1168 { |
1169 EXTEND(sp, 2); | |
1170 if (!win_valid(win)) | |
1171 win = curwin; | |
1172 PUSHs(sv_2mortal(newSViv(win->w_cursor.lnum))); | |
1173 PUSHs(sv_2mortal(newSViv(win->w_cursor.col))); | |
1174 } | |
2982 | 1175 else if (items == 3) |
7 | 1176 { |
1177 int lnum, col; | |
1178 | |
1179 if (!win_valid(win)) | |
1180 win = curwin; | |
4105 | 1181 lnum = (int) SvIV(ST(1)); |
1182 col = (int) SvIV(ST(2)); | |
7 | 1183 win->w_cursor.lnum = lnum; |
1184 win->w_cursor.col = col; | |
1185 check_cursor(); /* put cursor on an existing line */ | |
1186 update_screen(NOT_VALID); | |
1187 } | |
1188 | |
1189 MODULE = VIM PACKAGE = VIBUF | |
1190 | |
1191 void | |
1192 DESTROY(vimbuf) | |
1193 VIBUF vimbuf; | |
1194 | |
1195 CODE: | |
1196 if (buf_valid(vimbuf)) | |
502 | 1197 vimbuf->b_perl_private = 0; |
7 | 1198 |
1199 void | |
1200 Name(vimbuf) | |
1201 VIBUF vimbuf; | |
1202 | |
1203 PPCODE: | |
1204 if (!buf_valid(vimbuf)) | |
1205 vimbuf = curbuf; | |
1206 /* No file name returns an empty string */ | |
1207 if (vimbuf->b_fname == NULL) | |
1208 XPUSHs(sv_2mortal(newSVpv("", 0))); | |
1209 else | |
1210 XPUSHs(sv_2mortal(newSVpv((char *)vimbuf->b_fname, 0))); | |
1211 | |
1212 void | |
1213 Number(vimbuf) | |
1214 VIBUF vimbuf; | |
1215 | |
1216 PPCODE: | |
1217 if (!buf_valid(vimbuf)) | |
1218 vimbuf = curbuf; | |
1219 XPUSHs(sv_2mortal(newSViv(vimbuf->b_fnum))); | |
1220 | |
1221 void | |
1222 Count(vimbuf) | |
1223 VIBUF vimbuf; | |
1224 | |
1225 PPCODE: | |
1226 if (!buf_valid(vimbuf)) | |
1227 vimbuf = curbuf; | |
1228 XPUSHs(sv_2mortal(newSViv(vimbuf->b_ml.ml_line_count))); | |
1229 | |
1230 void | |
1231 Get(vimbuf, ...) | |
1232 VIBUF vimbuf; | |
1233 | |
1234 PREINIT: | |
1235 char_u *line; | |
1236 int i; | |
1237 long lnum; | |
1238 PPCODE: | |
1239 if (buf_valid(vimbuf)) | |
1240 { | |
1241 for (i = 1; i < items; i++) | |
1242 { | |
4105 | 1243 lnum = (long) SvIV(ST(i)); |
7 | 1244 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count) |
1245 { | |
1246 line = ml_get_buf(vimbuf, lnum, FALSE); | |
1247 XPUSHs(sv_2mortal(newSVpv((char *)line, 0))); | |
1248 } | |
1249 } | |
1250 } | |
1251 | |
1252 void | |
1253 Set(vimbuf, ...) | |
1254 VIBUF vimbuf; | |
1255 | |
1256 PREINIT: | |
1257 int i; | |
1258 long lnum; | |
1259 char *line; | |
1260 PPCODE: | |
1261 if (buf_valid(vimbuf)) | |
1262 { | |
1263 if (items < 3) | |
1264 croak("Usage: VIBUF::Set(vimbuf, lnum, @lines)"); | |
1265 | |
4105 | 1266 lnum = (long) SvIV(ST(1)); |
7 | 1267 for(i = 2; i < items; i++, lnum++) |
1268 { | |
1269 line = SvPV(ST(i),PL_na); | |
1270 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) | |
1271 { | |
918 | 1272 aco_save_T aco; |
1273 | |
1274 /* set curwin/curbuf for "vimbuf" and save some things */ | |
1275 aucmd_prepbuf(&aco, vimbuf); | |
1276 | |
7 | 1277 if (u_savesub(lnum) == OK) |
1278 { | |
1279 ml_replace(lnum, (char_u *)line, TRUE); | |
1280 changed_bytes(lnum, 0); | |
1281 } | |
934 | 1282 |
918 | 1283 /* restore curwin/curbuf and a few other things */ |
1284 aucmd_restbuf(&aco); | |
1285 /* Careful: autocommands may have made "vimbuf" invalid! */ | |
7 | 1286 } |
1287 } | |
1288 } | |
1289 | |
1290 void | |
1291 Delete(vimbuf, ...) | |
1292 VIBUF vimbuf; | |
1293 | |
1294 PREINIT: | |
1295 long i, lnum = 0, count = 0; | |
1296 PPCODE: | |
1297 if (buf_valid(vimbuf)) | |
1298 { | |
1299 if (items == 2) | |
1300 { | |
4105 | 1301 lnum = (long) SvIV(ST(1)); |
7 | 1302 count = 1; |
1303 } | |
1304 else if (items == 3) | |
1305 { | |
4105 | 1306 lnum = (long) SvIV(ST(1)); |
1307 count = (long) 1 + SvIV(ST(2)) - lnum; | |
2982 | 1308 if (count == 0) |
7 | 1309 count = 1; |
2982 | 1310 if (count < 0) |
7 | 1311 { |
1312 lnum -= count; | |
1313 count = -count; | |
1314 } | |
1315 } | |
1316 if (items >= 2) | |
1317 { | |
1318 for (i = 0; i < count; i++) | |
1319 { | |
1320 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count) | |
1321 { | |
918 | 1322 aco_save_T aco; |
1323 | |
1324 /* set curwin/curbuf for "vimbuf" and save some things */ | |
1325 aucmd_prepbuf(&aco, vimbuf); | |
934 | 1326 |
7 | 1327 if (u_savedel(lnum, 1) == OK) |
1328 { | |
1329 ml_delete(lnum, 0); | |
1929 | 1330 check_cursor(); |
7 | 1331 deleted_lines_mark(lnum, 1L); |
1332 } | |
934 | 1333 |
918 | 1334 /* restore curwin/curbuf and a few other things */ |
1335 aucmd_restbuf(&aco); | |
1336 /* Careful: autocommands may have made "vimbuf" invalid! */ | |
934 | 1337 |
7 | 1338 update_curbuf(VALID); |
1339 } | |
1340 } | |
1341 } | |
1342 } | |
1343 | |
1344 void | |
1345 Append(vimbuf, ...) | |
1346 VIBUF vimbuf; | |
1347 | |
1348 PREINIT: | |
1349 int i; | |
1350 long lnum; | |
1351 char *line; | |
1352 PPCODE: | |
1353 if (buf_valid(vimbuf)) | |
1354 { | |
1355 if (items < 3) | |
1356 croak("Usage: VIBUF::Append(vimbuf, lnum, @lines)"); | |
1357 | |
4105 | 1358 lnum = (long) SvIV(ST(1)); |
7 | 1359 for (i = 2; i < items; i++, lnum++) |
1360 { | |
1361 line = SvPV(ST(i),PL_na); | |
1362 if (lnum >= 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) | |
1363 { | |
918 | 1364 aco_save_T aco; |
1365 | |
1366 /* set curwin/curbuf for "vimbuf" and save some things */ | |
1367 aucmd_prepbuf(&aco, vimbuf); | |
1368 | |
7 | 1369 if (u_inssub(lnum + 1) == OK) |
1370 { | |
1371 ml_append(lnum, (char_u *)line, (colnr_T)0, FALSE); | |
1372 appended_lines_mark(lnum, 1L); | |
1373 } | |
934 | 1374 |
918 | 1375 /* restore curwin/curbuf and a few other things */ |
1376 aucmd_restbuf(&aco); | |
1377 /* Careful: autocommands may have made "vimbuf" invalid! */ | |
934 | 1378 |
7 | 1379 update_curbuf(VALID); |
1380 } | |
1381 } | |
1382 } | |
1383 |