Mercurial > vim
annotate src/workshop.c @ 15298:4aea6c2f56a8 v8.1.0657
patch 8.1.0657: get error for using regexp recursively
commit https://github.com/vim/vim/commit/01e51e5b305c13c68b5ea2b9e14779e1e88664ef
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 29 13:09:46 2018 +0100
patch 8.1.0657: get error for using regexp recursively
Problem: Get error for using regexp recursively. (Dominique Pelle)
Solution: Do no check if connection is desired.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 29 Dec 2018 13:15:05 +0100 |
parents | 3a99b2e6d136 |
children |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * Visual Workshop integration by Gordon Prieur | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 */ | |
10 | |
14736
3e9b24eac417
patch 8.1.0380: "make proto" doesn't work well
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
11 #include "protodef.h" |
7 | 12 #ifdef HAVE_CONFIG_H |
13 # include "auto/config.h" | |
14 #endif | |
15 #include <stdio.h> | |
16 #include <stdlib.h> | |
44 | 17 #include <sys/types.h> |
7 | 18 #include <netdb.h> |
19 #include <netinet/in.h> | |
20 #include <sys/socket.h> | |
21 #ifdef HAVE_LIBGEN_H | |
22 # include <libgen.h> | |
23 #endif | |
24 #include <unistd.h> | |
25 #include <string.h> | |
26 #include <stdlib.h> | |
27 #include <ctype.h> | |
28 | |
29 #include <X11/Intrinsic.h> | |
30 #include <Xm/Xm.h> | |
31 #include <Xm/PushB.h> | |
32 | |
33 #include "integration.h" /* <EditPlugin/integration.h> */ | |
34 | |
35 #include "vim.h" | |
36 #include "version.h" | |
37 #include "workshop.h" | |
38 | |
39 void workshop_hotkeys(Boolean); | |
40 | |
41 static Boolean isShowing(int); | |
42 static win_T *get_window(buf_T *); | |
43 static void updatePriority(Boolean); | |
44 static char *addUniqueMnemonic(char *, char *); | |
45 static char *fixup(char *); | |
46 static char *get_selection(buf_T *); | |
47 static char *append_selection(int, char *, int *, int *); | |
48 static void load_window(char *, int lnum); | |
49 static void warp_to_pc(int); | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
50 #ifdef FEAT_BEVAL_GUI |
2031
07de57cbcb25
updated for version 7.2.327
Bram Moolenaar <bram@zimbu.org>
parents:
1887
diff
changeset
|
51 void workshop_beval_cb(BalloonEval *, int); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
52 # ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
53 static int computeIndex(int, char_u *, int, int *); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
54 # else |
2031
07de57cbcb25
updated for version 7.2.327
Bram Moolenaar <bram@zimbu.org>
parents:
1887
diff
changeset
|
55 static int computeIndex(int, char_u *, int); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
56 # endif |
7 | 57 #endif |
58 static char *fixAccelText(char *); | |
59 static void addMenu(char *, char *, char *); | |
60 static char *lookupVerb(char *, int); | |
61 static void coloncmd(char *, Boolean); | |
62 | |
63 extern Widget vimShell; | |
64 extern Widget textArea; | |
65 extern XtAppContext app_context; | |
66 | |
67 static int tbpri; /* ToolBar priority */ | |
68 int usingSunWorkShop = 0; /* set if -ws flag is used */ | |
69 char curMenuName[BUFSIZ]; | |
70 char curMenuPriority[BUFSIZ]; | |
71 | |
72 static Boolean workshopInitDone = False; | |
73 static Boolean workshopHotKeysEnabled = False; | |
74 | |
75 /* | |
76 * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it | |
10226
7a4fb555c83a
commit https://github.com/vim/vim/commit/9af418427652562384744648d7d173a4bfebba95
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
77 * here because it's C++. |
7 | 78 */ |
79 enum | |
80 { | |
81 GPLineEval_EVALUATE, /* evaluate expression */ | |
82 GPLineEval_INDIRECT, /* evaluate *<expression> */ | |
83 GPLineEval_TYPE /* type of expression */ | |
84 }; | |
85 | |
86 /* | |
87 * Store each verb in the MenuMap. This lets us map from a verb to a menu. | |
88 * There may be multiple matches for a single verb in this table. | |
89 */ | |
90 #define MENU_INC 50 /* menuMap incremental size increases */ | |
91 typedef struct | |
92 { | |
93 char *name; /* name of the menu */ | |
94 char *accel; /* optional accelerator key */ | |
95 char *verb; /* menu verb */ | |
96 } MenuMap; | |
97 static MenuMap *menuMap; /* list of verb/menu mappings */ | |
98 static int menuMapSize; /* current size of menuMap */ | |
99 static int menuMapMax; /* allocated size of menuMap */ | |
100 static char *initialFileCmd; /* save command but defer doing it */ | |
101 | |
102 | |
103 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
104 workshop_init(void) |
7 | 105 { |
106 char_u buf[64]; | |
107 int is_dirty = FALSE; | |
108 int width, height; | |
109 XtInputMask mask; | |
110 | |
111 /* | |
112 * Turn on MenuBar, ToolBar, and Footer. | |
113 */ | |
114 STRCPY(buf, p_go); | |
115 if (vim_strchr(p_go, GO_MENUS) == NULL) | |
116 { | |
117 STRCAT(buf, "m"); | |
118 is_dirty = TRUE; | |
119 } | |
120 if (vim_strchr(p_go, GO_TOOLBAR) == NULL) | |
121 { | |
122 STRCAT(buf, "T"); | |
123 is_dirty = TRUE; | |
124 } | |
125 if (vim_strchr(p_go, GO_FOOTER) == NULL) | |
126 { | |
127 STRCAT(buf, "F"); | |
128 is_dirty = TRUE; | |
129 } | |
130 if (is_dirty) | |
131 set_option_value((char_u *)"go", 0L, buf, 0); | |
132 | |
133 /* | |
134 * Set size from workshop_get_width_height(). | |
135 */ | |
136 width = height = 0; | |
137 if (workshop_get_width_height(&width, &height)) | |
138 { | |
139 XtVaSetValues(vimShell, | |
140 XmNwidth, width, | |
141 XmNheight, height, | |
142 NULL); | |
143 } | |
144 | |
145 /* | |
146 * Now read in the initial messages from eserve. | |
147 */ | |
148 while ((mask = XtAppPending(app_context)) | |
149 && (mask & XtIMAlternateInput) && !workshopInitDone) | |
150 XtAppProcessEvent(app_context, (XtInputMask)XtIMAlternateInput); | |
151 } | |
152 | |
153 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
154 workshop_postinit(void) |
7 | 155 { |
156 do_cmdline_cmd((char_u *)initialFileCmd); | |
157 ALT_INPUT_LOCK_OFF; | |
158 free(initialFileCmd); | |
159 initialFileCmd = NULL; | |
160 } | |
161 | |
162 void | |
163 ex_wsverb(exarg_T *eap) | |
164 { | |
165 msg_clr_cmdline(); | |
166 workshop_perform_verb((char *) eap->arg, NULL); | |
167 } | |
168 | |
169 /* | |
170 * Editor name | |
171 * This string is recognized by eserve and should be all lower case. | |
172 * This is how the editor detects that it is talking to gvim instead | |
173 * of NEdit, for example, when the connection is initiated from the editor. | |
174 */ | |
175 char * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
176 workshop_get_editor_name(void) |
7 | 177 { |
178 return "gvim"; | |
179 } | |
180 | |
181 /* | |
182 * Version number of the editor. | |
183 * This number is communicated along with the protocol | |
184 * version to the application. | |
185 */ | |
186 char * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
187 workshop_get_editor_version(void) |
7 | 188 { |
189 return Version; | |
190 } | |
191 | |
192 /* | |
193 * Answer functions: called by eserve | |
194 */ | |
195 | |
196 /* | |
197 * Name: | |
198 * workshop_load_file | |
199 * | |
200 * Function: | |
201 * Load a given file into the WorkShop buffer. | |
202 */ | |
203 void | |
204 workshop_load_file( | |
205 char *filename, /* the file to load */ | |
206 int line, /* an optional line number (or 0) */ | |
1887 | 207 char *frameid UNUSED) /* used for multi-frame support */ |
7 | 208 { |
209 #ifdef WSDEBUG_TRACE | |
210 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
211 wstrace("workshop_load_file(%s, %d)\n", filename, line); | |
212 #endif | |
213 | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
214 #ifdef FEAT_BEVAL_GUI |
189 | 215 bevalServers |= BEVAL_WORKSHOP; |
7 | 216 #endif |
217 | |
218 load_window(filename, line); | |
219 } | |
220 | |
221 /* | |
222 * Reload the WorkShop buffer | |
223 */ | |
224 void | |
225 workshop_reload_file( | |
226 char *filename, | |
227 int line) | |
228 { | |
229 #ifdef WSDEBUG_TRACE | |
230 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
231 wstrace("workshop_reload_file(%s, %d)\n", filename, line); | |
232 #endif | |
233 load_window(filename, line); | |
234 } | |
235 | |
236 void | |
237 workshop_show_file( | |
238 char *filename) | |
239 { | |
240 #ifdef WSDEBUG_TRACE | |
241 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
242 wstrace("workshop_show_file(%s)\n", filename); | |
243 #endif | |
244 | |
245 load_window(filename, 0); | |
246 } | |
247 | |
248 void | |
249 workshop_goto_line( | |
250 char *filename, | |
251 int lineno) | |
252 { | |
253 #ifdef WSDEBUG_TRACE | |
254 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
255 wstrace("workshop_goto_line(%s, %d)\n", filename, lineno); | |
256 #endif | |
257 | |
258 load_window(filename, lineno); | |
259 } | |
260 | |
261 void | |
262 workshop_front_file( | |
1887 | 263 char *filename UNUSED) |
7 | 264 { |
265 #ifdef WSDEBUG_TRACE | |
266 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
267 wstrace("workshop_front_file()\n"); | |
268 #endif | |
269 /* | |
270 * Assumption: This function will always be called after a call to | |
271 * workshop_show_file(), so the file is always showing. | |
272 */ | |
273 if (vimShell != NULL) | |
274 XRaiseWindow(gui.dpy, XtWindow(vimShell)); | |
275 } | |
276 | |
277 void | |
278 workshop_save_file( | |
279 char *filename) | |
280 { | |
281 char cbuf[BUFSIZ]; /* build vim command here */ | |
282 | |
283 #ifdef WSDEBUG_TRACE | |
284 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
285 wstrace("workshop_save_file(%s)\n", filename); | |
286 #endif | |
287 | |
288 /* Save the given file */ | |
273 | 289 vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename); |
7 | 290 coloncmd(cbuf, TRUE); |
291 } | |
292 | |
293 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
294 workshop_save_files(void) |
7 | 295 { |
296 /* Save the given file */ | |
297 #ifdef WSDEBUG_TRACE | |
298 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
299 wstrace("workshop_save_files()\n"); | |
300 #endif | |
301 | |
302 add_to_input_buf((char_u *) ":wall\n", 6); | |
303 } | |
304 | |
305 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
306 workshop_quit(void) |
7 | 307 { |
308 #ifdef WSDEBUG_TRACE | |
309 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
310 wstrace("workshop_quit()\n"); | |
311 #endif | |
312 | |
313 add_to_input_buf((char_u *) ":qall\n", 6); | |
314 } | |
315 | |
316 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
317 workshop_minimize(void) |
7 | 318 { |
319 #ifdef WSDEBUG_TRACE | |
320 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
321 wstrace("workshop_minimize()\n"); | |
322 #endif | |
323 workshop_minimize_shell(vimShell); | |
324 } | |
325 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
326 workshop_maximize(void) |
7 | 327 { |
328 #ifdef WSDEBUG_TRACE | |
329 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
330 wstrace("workshop_maximize()\n"); | |
331 #endif | |
332 | |
333 workshop_maximize_shell(vimShell); | |
334 } | |
335 | |
336 void | |
337 workshop_add_mark_type( | |
338 int idx, | |
339 char *colorspec, | |
340 char *sign) | |
341 { | |
342 char gbuf[BUFSIZ]; /* buffer for sign name */ | |
343 char cibuf[BUFSIZ]; /* color information */ | |
344 char cbuf[BUFSIZ]; /* command buffer */ | |
345 char *bp; | |
346 | |
347 #ifdef WSDEBUG_TRACE | |
348 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
349 { | |
350 char *cp; | |
351 | |
352 cp = strrchr(sign, '/'); | |
353 if (cp == NULL) | |
354 cp = sign; | |
355 else | |
356 cp++; /* skip '/' character */ | |
357 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx, | |
358 colorspec && *colorspec ? colorspec : "<None>", cp); | |
359 } | |
360 #endif | |
361 | |
362 /* | |
363 * Isolate the basename of sign in gbuf. We will use this for the | |
364 * GroupName in the highlight command sent to vim. | |
365 */ | |
366 STRCPY(gbuf, gettail((char_u *)sign)); | |
367 bp = strrchr(gbuf, '.'); | |
368 if (bp != NULL) | |
369 *bp = NUL; | |
370 | |
371 if (gbuf[0] != '-' && gbuf[1] != NUL) | |
372 { | |
373 if (colorspec != NULL && *colorspec) | |
374 { | |
273 | 375 vim_snprintf(cbuf, sizeof(cbuf), |
376 "highlight WS%s guibg=%s", gbuf, colorspec); | |
7 | 377 coloncmd(cbuf, FALSE); |
273 | 378 vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf); |
7 | 379 } |
380 else | |
381 cibuf[0] = NUL; | |
382 | |
273 | 383 vim_snprintf(cbuf, sizeof(cbuf), |
384 "sign define %d %s icon=%s", idx, cibuf, sign); | |
7 | 385 coloncmd(cbuf, TRUE); |
386 } | |
387 } | |
388 | |
389 void | |
390 workshop_set_mark( | |
391 char *filename, /* filename which gets the mark */ | |
392 int lineno, /* line number which gets the mark */ | |
393 int markId, /* unique mark identifier */ | |
394 int idx) /* which mark to use */ | |
395 { | |
396 char cbuf[BUFSIZ]; /* command buffer */ | |
397 | |
398 /* Set mark in a given file */ | |
399 #ifdef WSDEBUG_TRACE | |
400 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
401 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n", | |
402 filename, lineno, markId, idx); | |
403 #endif | |
404 | |
273 | 405 vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s", |
7 | 406 markId, lineno, idx, filename); |
407 coloncmd(cbuf, TRUE); | |
408 } | |
409 | |
410 void | |
411 workshop_change_mark_type( | |
412 char *filename, /* filename which gets the mark */ | |
413 int markId, /* unique mark identifier */ | |
414 int idx) /* which mark to use */ | |
415 { | |
416 char cbuf[BUFSIZ]; /* command buffer */ | |
417 | |
418 /* Change mark type */ | |
419 #ifdef WSDEBUG_TRACE | |
420 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
421 wstrace("workshop_change_mark_type(%s, %d, %d)\n", | |
422 filename, markId, idx); | |
423 #endif | |
424 | |
273 | 425 vim_snprintf(cbuf, sizeof(cbuf), |
426 "sign place %d name=%d file=%s", markId, idx, filename); | |
7 | 427 coloncmd(cbuf, TRUE); |
428 } | |
429 | |
430 /* | |
431 * Goto the given mark in a file (e.g. show it). | |
432 * If message is not null, display it in the footer. | |
433 */ | |
434 void | |
435 workshop_goto_mark( | |
436 char *filename, | |
437 int markId, | |
438 char *message) | |
439 { | |
440 char cbuf[BUFSIZ]; /* command buffer */ | |
441 | |
442 /* Goto mark */ | |
443 #ifdef WSDEBUG_TRACE | |
444 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
445 wstrace("workshop_goto_mark(%s, %d (id), %s)\n", | |
446 filename, markId, message && *message && | |
447 !(*message == ' ' && message[1] == NULL) ? | |
448 message : "<None>"); | |
449 #endif | |
450 | |
273 | 451 vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename); |
7 | 452 coloncmd(cbuf, TRUE); |
453 if (message != NULL && *message != NUL) | |
454 gui_mch_set_footer((char_u *)message); | |
455 } | |
456 | |
457 void | |
458 workshop_delete_mark( | |
459 char *filename, | |
460 int markId) | |
461 { | |
462 char cbuf[BUFSIZ]; /* command buffer */ | |
463 | |
464 /* Delete mark */ | |
465 #ifdef WSDEBUG_TRACE | |
466 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
467 wstrace("workshop_delete_mark(%s, %d (id))\n", | |
468 filename, markId); | |
469 #endif | |
470 | |
273 | 471 vim_snprintf(cbuf, sizeof(cbuf), |
472 "sign unplace %d file=%s", markId, filename); | |
7 | 473 coloncmd(cbuf, TRUE); |
474 } | |
475 | |
476 int | |
477 workshop_get_mark_lineno( | |
478 char *filename, | |
479 int markId) | |
480 { | |
481 buf_T *buf; /* buffer containing filename */ | |
482 int lineno; /* line number of filename in buf */ | |
483 | |
484 /* Get mark line number */ | |
485 #ifdef WSDEBUG_TRACE | |
486 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
487 wstrace("workshop_get_mark_lineno(%s, %d)\n", | |
488 filename, markId); | |
489 #endif | |
490 | |
491 lineno = 0; | |
492 buf = buflist_findname((char_u *)filename); | |
493 if (buf != NULL) | |
15209
3a99b2e6d136
patch 8.1.0614: placing signs can be complicated
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
494 lineno = buf_findsign(buf, markId, NULL); |
7 | 495 |
496 return lineno; | |
497 } | |
498 | |
499 | |
500 /* | |
501 * Are there any moved marks? If so, call workshop_move_mark on | |
502 * each of them now. This is how eserve can find out if for example | |
503 * breakpoints have moved when a program has been recompiled and | |
504 * reloaded into dbx. | |
505 */ | |
506 void | |
1887 | 507 workshop_moved_marks(char *filename UNUSED) |
7 | 508 { |
509 #ifdef WSDEBUG_TRACE | |
510 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
511 wstrace("XXXworkshop_moved_marks(%s)\n", filename); | |
512 #endif | |
513 } | |
514 | |
515 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
516 workshop_get_font_height(void) |
7 | 517 { |
518 XmFontList fontList; /* fontList made from gui.norm_font */ | |
519 XmString str; | |
520 Dimension w; | |
521 Dimension h; | |
522 | |
523 #ifdef WSDEBUG_TRACE | |
524 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
525 wstrace("workshop_get_font_height()\n"); | |
526 #endif | |
527 | |
528 /* Pick the proper signs for this font size */ | |
529 fontList = gui_motif_create_fontlist((XFontStruct *)gui.norm_font); | |
530 h = 0; | |
531 if (fontList != NULL) | |
532 { | |
533 str = XmStringCreateLocalized("A"); | |
534 XmStringExtent(fontList, str, &w, &h); | |
535 XmStringFree(str); | |
536 XmFontListFree(fontList); | |
537 } | |
538 | |
539 return (int)h; | |
540 } | |
541 | |
542 void | |
543 workshop_footer_message( | |
1887 | 544 char *message, |
545 int severity UNUSED) /* severity is currently unused */ | |
7 | 546 { |
547 #ifdef WSDEBUG_TRACE | |
548 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
549 wstrace("workshop_footer_message(%s, %d)\n", message, severity); | |
550 #endif | |
551 | |
552 gui_mch_set_footer((char_u *) message); | |
553 } | |
554 | |
555 /* | |
556 * workshop_menu_begin() is passed the menu name. We determine its mnemonic | |
557 * here and store its name and priority. | |
558 */ | |
559 void | |
560 workshop_menu_begin( | |
561 char *label) | |
562 { | |
563 vimmenu_T *menu; /* pointer to last menu */ | |
564 int menuPriority = 0; /* priority of new menu */ | |
565 char mnembuf[64]; /* store menubar mnemonics here */ | |
566 char *name; /* label with a mnemonic */ | |
567 char *p; /* used to find mnemonics */ | |
568 int idx; /* index into mnembuf */ | |
569 | |
570 #ifdef WSDEBUG_TRACE | |
571 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
572 wstrace("workshop_menu_begin()\n"); | |
573 #endif | |
574 | |
575 /* | |
576 * Look through all existing (non-PopUp and non-Toolbar) menus | |
577 * and gather their mnemonics. Use this list to decide what | |
578 * mnemonic should be used for label. | |
579 */ | |
580 | |
581 idx = 0; | |
582 mnembuf[idx++] = 'H'; /* H is mnemonic for Help */ | |
583 for (menu = root_menu; menu != NULL; menu = menu->next) | |
584 { | |
585 if (menu_is_menubar(menu->name)) | |
586 { | |
587 p = strchr((char *)menu->name, '&'); | |
588 if (p != NULL) | |
589 mnembuf[idx++] = *++p; | |
590 } | |
591 if (menu->next != NULL | |
592 && strcmp((char *) menu->next->dname, "Help") == 0) | |
593 { | |
594 menuPriority = menu->priority + 10; | |
595 break; | |
596 } | |
597 } | |
598 mnembuf[idx++] = NUL; | |
599 name = addUniqueMnemonic(mnembuf, label); | |
600 | |
273 | 601 vim_snprintf(curMenuName, sizeof(curMenuName), "%s", name); |
7 | 602 sprintf(curMenuPriority, "%d.0", menuPriority); |
603 } | |
604 | |
605 /* | |
606 * Append the name and priority to strings to be used in vim menu commands. | |
607 */ | |
608 void | |
609 workshop_submenu_begin( | |
610 char *label) | |
611 { | |
612 #ifdef WSDEBUG_TRACE | |
613 if (ws_debug && ws_dlevel & WS_TRACE | |
614 && strncmp(curMenuName, "ToolBar", 7) != 0) | |
615 wstrace("workshop_submenu_begin(%s)\n", label); | |
616 #endif | |
617 | |
618 strcat(curMenuName, "."); | |
619 strcat(curMenuName, fixup(label)); | |
620 | |
621 updatePriority(True); | |
622 } | |
623 | |
624 /* | |
625 * Remove the submenu name and priority from curMenu*. | |
626 */ | |
627 | |
628 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
629 workshop_submenu_end(void) |
7 | 630 { |
631 char *p; | |
632 | |
633 #ifdef WSDEBUG_TRACE | |
634 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE) | |
635 && strncmp(curMenuName, "ToolBar", 7) != 0) | |
636 wstrace("workshop_submenu_end()\n"); | |
637 #endif | |
638 | |
639 p = strrchr(curMenuPriority, '.'); | |
640 ASSERT(p != NULL); | |
641 *p = NUL; | |
642 | |
643 p = strrchr(curMenuName, '.'); | |
644 ASSERT(p != NULL); | |
645 *p = NUL; | |
646 } | |
647 | |
648 /* | |
649 * This is where menus are really made. Each item will generate an amenu vim | |
650 * command. The globals curMenuName and curMenuPriority contain the name and | |
651 * priority of the parent menu tree. | |
652 */ | |
653 void | |
654 workshop_menu_item( | |
655 char *label, | |
656 char *verb, | |
1887 | 657 char *accelerator UNUSED, |
7 | 658 char *acceleratorText, |
1887 | 659 char *name UNUSED, |
660 char *filepos UNUSED, | |
7 | 661 char *sensitive) |
662 { | |
663 char cbuf[BUFSIZ]; | |
664 char namebuf[BUFSIZ]; | |
665 char accText[BUFSIZ]; | |
666 | |
667 #ifdef WSDEBUG_TRACE | |
668 if (WSDLEVEL(WS_TRACE_VERBOSE) | |
669 && strncmp(curMenuName, "ToolBar", 7) != 0) | |
670 { | |
671 if (ws_dlevel & WS_TRACE_VERBOSE) | |
672 wsdebug("workshop_menu_item(\n" | |
673 "\tlabel = \"%s\",\n" | |
674 "\tverb = %s,\n" | |
675 "\taccelerator = %s,\n" | |
676 "\tacceleratorText = \"%s\",\n" | |
677 "\tname = %s,\n" | |
678 "\tfilepos = %s,\n" | |
679 "\tsensitive = %s)\n", | |
680 label && *label ? label : "<None>", | |
681 verb && *verb ? verb : "<None>", | |
682 accelerator && *accelerator ? | |
683 accelerator : "<None>", | |
684 acceleratorText && *acceleratorText ? | |
685 acceleratorText : "<None>", | |
686 name && *name ? name : "<None>", | |
687 filepos && *filepos ? filepos : "<None>", | |
688 sensitive); | |
689 else if (ws_dlevel & WS_TRACE) | |
690 wstrace("workshop_menu_item(\"%s\", %s)\n", | |
691 label && *label ? label : "<None>", | |
692 verb && *verb ? verb : "<None>", sensitive); | |
693 } | |
694 #endif | |
695 #ifdef WSDEBUG_SENSE | |
696 if (ws_debug) | |
697 wstrace("menu: %-21.20s%-21.20s(%s)\n", label, verb, | |
698 *sensitive == '1' ? "Sensitive" : "Insensitive"); | |
699 #endif | |
700 | |
701 if (acceleratorText != NULL) | |
273 | 702 vim_snprintf(accText, sizeof(accText), "<Tab>%s", acceleratorText); |
7 | 703 else |
704 accText[0] = NUL; | |
705 updatePriority(False); | |
273 | 706 vim_snprintf(namebuf, sizeof(namebuf), "%s.%s", curMenuName, fixup(label)); |
707 vim_snprintf(cbuf, sizeof(cbuf), "amenu %s %s%s\t:wsverb %s<CR>", | |
7 | 708 curMenuPriority, namebuf, accText, verb); |
709 | |
710 coloncmd(cbuf, TRUE); | |
711 addMenu(namebuf, fixAccelText(acceleratorText), verb); | |
712 | |
713 if (*sensitive == '0') | |
714 { | |
273 | 715 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf); |
7 | 716 coloncmd(cbuf, TRUE); |
717 } | |
718 } | |
719 | |
720 /* | |
721 * This function is called when a complete WorkShop menu description has been | |
722 * sent over from eserve. We do some menu cleanup. | |
723 */ | |
724 | |
725 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
726 workshop_menu_end(void) |
7 | 727 { |
728 Boolean using_tearoff; /* set per current option setting */ | |
729 | |
730 #ifdef WSDEBUG_TRACE | |
731 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
732 wstrace("workshop_menu_end()\n"); | |
733 #endif | |
734 | |
735 using_tearoff = vim_strchr(p_go, GO_TEAROFF) != NULL; | |
736 gui_mch_toggle_tearoffs(using_tearoff); | |
737 } | |
738 | |
739 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
740 workshop_toolbar_begin(void) |
7 | 741 { |
742 #ifdef WSDEBUG_TRACE | |
743 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
744 wstrace("workshop_toolbar_begin()\n"); | |
745 #endif | |
746 | |
747 coloncmd("aunmenu ToolBar", True); | |
748 tbpri = 10; | |
749 } | |
750 | |
751 void | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
752 workshop_toolbar_end(void) |
7 | 753 { |
754 char_u buf[64]; | |
755 | |
756 #ifdef WSDEBUG_TRACE | |
757 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
758 { | |
759 wstrace("workshop_toolbar_end()\n"); | |
760 } | |
761 #endif | |
762 | |
763 /* | |
764 * Turn on ToolBar. | |
765 */ | |
766 STRCPY(buf, p_go); | |
767 if (vim_strchr(p_go, 'T') == NULL) | |
768 { | |
769 STRCAT(buf, "T"); | |
770 set_option_value((char_u *)"go", 0L, buf, 0); | |
771 } | |
772 workshopInitDone = True; | |
773 } | |
774 | |
775 void | |
776 workshop_toolbar_button( | |
777 char *label, | |
778 char *verb, | |
1887 | 779 char *senseVerb UNUSED, |
780 char *filepos UNUSED, | |
7 | 781 char *help, |
782 char *sense, | |
783 char *file, | |
784 char *left) | |
785 { | |
786 char cbuf[BUFSIZ + MAXPATHLEN]; | |
787 char namebuf[BUFSIZ]; | |
788 static int tbid = 1; | |
789 char_u *p; | |
790 | |
791 #ifdef WSDEBUG_TRACE | |
792 if (WSDLEVEL(WS_TRACE_VERBOSE)) | |
793 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n" | |
794 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n", | |
795 label && *label ? label : "<None>", | |
796 verb && *verb ? verb : "<None>", | |
797 senseVerb && *senseVerb ? senseVerb : "<None>", | |
798 filepos && *filepos ? filepos : "<None>", | |
799 help && *help ? help : "<None>", | |
800 sense && *sense ? sense : "<None>", | |
801 file && *file ? file : "<None>", | |
802 left && *left ? left : "<None>"); | |
803 else if (WSDLEVEL(WS_TRACE)) | |
804 wstrace("workshop_toolbar_button(\"%s\", %s)\n", | |
805 label && *label ? label : "<None>", | |
806 verb && *verb ? verb : "<None>"); | |
807 #endif | |
808 #ifdef WSDEBUG_SENSE | |
809 if (ws_debug) | |
810 wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb, | |
811 *sense == '1' ? "Sensitive" : "Insensitive"); | |
812 #endif | |
813 | |
814 if (left && *left && atoi(left) > 0) | |
815 { | |
816 /* Add a separator (but pass the width passed after the ':') */ | |
817 sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>", | |
818 tbpri - 5, tbid++, left); | |
819 | |
820 coloncmd(cbuf, True); | |
821 } | |
822 | |
823 p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. "); | |
273 | 824 vim_snprintf(namebuf, sizeof(namebuf), "ToolBar.%s", p); |
7 | 825 vim_free(p); |
826 STRCPY(cbuf, "amenu <silent> "); | |
827 if (file != NULL && *file != NUL) | |
828 { | |
829 p = vim_strsave_escaped((char_u *)file, (char_u *)" "); | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
830 vim_snprintf_add(cbuf, sizeof(cbuf), "icon=%s ", p); |
7 | 831 vim_free(p); |
832 } | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
833 vim_snprintf_add(cbuf, sizeof(cbuf),"1.%d %s :wsverb %s<CR>", |
7 | 834 tbpri, namebuf, verb); |
835 | |
836 /* Define the menu item */ | |
837 coloncmd(cbuf, True); | |
838 | |
839 if (*sense == '0') | |
840 { | |
841 /* If menu isn't sensitive at startup... */ | |
273 | 842 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf); |
7 | 843 coloncmd(cbuf, True); |
844 } | |
845 | |
846 if (help && *help) | |
847 { | |
848 /* Do the tooltip */ | |
273 | 849 vim_snprintf(cbuf, sizeof(cbuf), "tmenu %s %s", namebuf, help); |
7 | 850 coloncmd(cbuf, True); |
851 } | |
852 | |
853 addMenu(namebuf, NULL, verb); | |
854 tbpri += 10; | |
855 } | |
856 | |
857 void | |
858 workshop_frame_sensitivities( | |
859 VerbSense *vs) /* list of verbs to (de)sensitize */ | |
860 { | |
861 VerbSense *vp; /* iterate through vs */ | |
862 char *menu_name; /* used in menu lookup */ | |
863 int cnt; /* count of verbs to skip */ | |
864 int len; /* length of nonvariant part of command */ | |
865 char cbuf[4096]; | |
866 | |
867 #ifdef WSDEBUG_TRACE | |
868 if (WSDLEVEL(WS_TRACE_VERBOSE) || WSDLEVEL(4)) | |
869 { | |
870 wsdebug("workshop_frame_sensitivities(\n"); | |
871 for (vp = vs; vp->verb != NULL; vp++) | |
872 wsdebug("\t%-25s%d\n", vp->verb, vp->sense); | |
873 wsdebug(")\n"); | |
874 } | |
875 else if (WSDLEVEL(WS_TRACE)) | |
876 wstrace("workshop_frame_sensitivities()\n"); | |
877 #endif | |
878 #ifdef WSDEBUG_SENSE | |
879 if (ws_debug) | |
880 for (vp = vs; vp->verb != NULL; vp++) | |
881 wsdebug("change: %-21.20s%-21.20s(%s)\n", | |
882 "", vp->verb, vp->sense == 1 ? | |
883 "Sensitive" : "Insensitive"); | |
884 #endif | |
885 | |
886 /* | |
887 * Look for all matching menu entries for the verb. There may be more | |
888 * than one if the verb has both a menu and toolbar entry. | |
889 */ | |
890 for (vp = vs; vp->verb != NULL; vp++) | |
891 { | |
892 cnt = 0; | |
893 strcpy(cbuf, "amenu"); | |
894 strcat(cbuf, " "); | |
895 strcat(cbuf, vp->sense ? "enable" : "disable"); | |
896 strcat(cbuf, " "); | |
897 len = strlen(cbuf); | |
898 while ((menu_name = lookupVerb(vp->verb, cnt++)) != NULL) | |
899 { | |
900 strcpy(&cbuf[len], menu_name); | |
901 coloncmd(cbuf, FALSE); | |
902 } | |
903 } | |
904 gui_update_menus(0); | |
905 gui_mch_flush(); | |
906 } | |
907 | |
908 void | |
909 workshop_set_option( | |
910 char *option, /* name of a supported option */ | |
911 char *value) /* value to set option to */ | |
912 { | |
913 char cbuf[BUFSIZ]; /* command buffer */ | |
914 | |
915 #ifdef WSDEBUG_TRACE | |
916 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
917 { | |
918 wstrace("workshop_set_option(%s, %s)\n", option, value); | |
919 } | |
920 #endif | |
921 | |
922 cbuf[0] = NUL; | |
923 switch (*option) /* switch on 1st letter */ | |
924 { | |
925 case 's': | |
926 if (strcmp(option, "syntax") == 0) | |
273 | 927 vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value); |
7 | 928 else if (strcmp(option, "savefiles") == 0) |
1887 | 929 { |
930 /* XXX - Not yet implemented */ | |
931 } | |
7 | 932 break; |
933 | |
934 case 'l': | |
935 if (strcmp(option, "lineno") == 0) | |
936 sprintf(cbuf, "set %snu", | |
937 (strcmp(value, "on") == 0) ? "" : "no"); | |
938 break; | |
939 | |
940 case 'p': | |
941 if (strcmp(option, "parentheses") == 0) | |
942 sprintf(cbuf, "set %ssm", | |
943 (strcmp(value, "on") == 0) ? "" : "no"); | |
944 break; | |
945 | |
946 case 'w': | |
947 /* this option is set by a direct call */ | |
948 #ifdef WSDEBUG | |
949 wsdebug("workshop_set_option: " | |
950 "Got unexpected workshopkeys option"); | |
951 #endif | |
952 break; | |
953 | |
954 case 'b': /* these options are set from direct calls */ | |
955 if (option[7] == NUL && strcmp(option, "balloon") == 0) | |
956 { | |
957 #ifdef WSDEBUG | |
958 /* set by direct call to workshop_balloon_mode */ | |
959 wsdebug("workshop_set_option: " | |
960 "Got unexpected ballooneval option"); | |
961 #endif | |
962 } | |
963 else if (strcmp(option, "balloondelay") == 0) | |
964 { | |
965 #ifdef WSDEBUG | |
966 /* set by direct call to workshop_balloon_delay */ | |
967 wsdebug("workshop_set_option: " | |
968 "Got unexpected balloondelay option"); | |
969 #endif | |
970 } | |
971 break; | |
972 } | |
973 if (cbuf[0] != NUL) | |
974 coloncmd(cbuf, TRUE); | |
975 } | |
976 | |
977 | |
978 void | |
979 workshop_balloon_mode( | |
980 Boolean on) | |
981 { | |
982 char cbuf[BUFSIZ]; /* command buffer */ | |
983 | |
984 #ifdef WSDEBUG_TRACE | |
985 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
986 wstrace("workshop_balloon_mode(%s)\n", on ? "True" : "False"); | |
987 #endif | |
988 | |
989 sprintf(cbuf, "set %sbeval", on ? "" : "no"); | |
990 coloncmd(cbuf, TRUE); | |
991 } | |
992 | |
993 | |
994 void | |
995 workshop_balloon_delay( | |
996 int delay) | |
997 { | |
998 char cbuf[BUFSIZ]; /* command buffer */ | |
999 | |
1000 #ifdef WSDEBUG_TRACE | |
1001 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
1002 wstrace("workshop_balloon_delay(%d)\n", delay); | |
1003 #endif | |
1004 | |
1005 sprintf(cbuf, "set bdlay=%d", delay); | |
1006 coloncmd(cbuf, TRUE); | |
1007 } | |
1008 | |
1009 | |
1010 void | |
1011 workshop_show_balloon_tip( | |
1012 char *tip) | |
1013 { | |
1014 #ifdef WSDEBUG_TRACE | |
1015 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
1016 wstrace("workshop_show_balloon_tip(%s)\n", tip); | |
1017 #endif | |
1018 | |
1019 if (balloonEval != NULL) | |
1020 gui_mch_post_balloon(balloonEval, (char_u *)tip); | |
1021 } | |
1022 | |
1023 | |
1024 void | |
1025 workshop_hotkeys( | |
1026 Boolean on) | |
1027 { | |
1028 char cbuf[BUFSIZ]; /* command buffer */ | |
1029 MenuMap *mp; /* iterate over menuMap entries */ | |
1030 | |
1031 #ifdef WSDEBUG_TRACE | |
1032 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
1033 wstrace("workshop_hotkeys(%s)\n", on ? "True" : "False"); | |
1034 #endif | |
1035 | |
1036 workshopHotKeysEnabled = on; | |
1037 if (workshopHotKeysEnabled) | |
1038 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) | |
1039 { | |
1040 if (mp->accel != NULL) | |
1041 { | |
273 | 1042 vim_snprintf(cbuf, sizeof(cbuf), |
1043 "map %s :wsverb %s<CR>", mp->accel, mp->verb); | |
7 | 1044 coloncmd(cbuf, TRUE); |
1045 } | |
1046 } | |
1047 else | |
1048 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) | |
1049 { | |
1050 if (mp->accel != NULL) | |
1051 { | |
273 | 1052 vim_snprintf(cbuf, sizeof(cbuf), "unmap %s", mp->accel); |
7 | 1053 coloncmd(cbuf, TRUE); |
1054 } | |
1055 } | |
1056 } | |
1057 | |
1058 /* | |
1059 * A button in the toolbar has been pushed. | |
1060 */ | |
1061 int | |
1062 workshop_get_positions( | |
1887 | 1063 void *clientData UNUSED, |
7 | 1064 char **filename, /* output data */ |
1065 int *curLine, /* output data */ | |
1066 int *curCol, /* output data */ | |
1067 int *selStartLine, /* output data */ | |
1068 int *selStartCol, /* output data */ | |
1069 int *selEndLine, /* output data */ | |
1070 int *selEndCol, /* output data */ | |
1071 int *selLength, /* output data */ | |
1072 char **selection) /* output data */ | |
1073 { | |
1074 static char ffname[MAXPATHLEN]; | |
1075 | |
1076 #ifdef WSDEBUG_TRACE | |
1077 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) | |
1078 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n", | |
1079 clientData, (curbuf && curbuf->b_sfname != NULL) | |
1080 ? (char *)curbuf->b_sfname : "<None>"); | |
1081 #endif | |
1082 | |
1756 | 1083 if (curbuf->b_ffname == NULL) |
1084 ffname[0] = NUL; | |
1085 else | |
1086 /* copy so nobody can change b_ffname */ | |
1087 strcpy(ffname, (char *) curbuf->b_ffname); | |
1088 *filename = ffname; | |
7 | 1089 *curLine = curwin->w_cursor.lnum; |
1090 *curCol = curwin->w_cursor.col; | |
1091 | |
692 | 1092 if (curbuf->b_visual.vi_mode == 'v' && |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10226
diff
changeset
|
1093 EQUAL_POS(curwin->w_cursor, curbuf->b_visual.vi_end)) |
7 | 1094 { |
692 | 1095 *selStartLine = curbuf->b_visual.vi_start.lnum; |
1096 *selStartCol = curbuf->b_visual.vi_start.col; | |
1097 *selEndLine = curbuf->b_visual.vi_end.lnum; | |
1098 *selEndCol = curbuf->b_visual.vi_end.col; | |
7 | 1099 *selection = get_selection(curbuf); |
1100 if (*selection) | |
1101 *selLength = strlen(*selection); | |
1102 else | |
1103 *selLength = 0; | |
1104 } | |
1105 else | |
1106 { | |
1107 *selStartLine = *selEndLine = -1; | |
1108 *selStartCol = *selEndCol = -1; | |
1109 *selLength = 0; | |
1110 *selection = ""; | |
1111 } | |
1112 | |
1113 return True; | |
1114 } | |
1115 | |
1116 | |
1117 | |
1118 /************************************************************************ | |
1119 * Utility functions | |
1120 ************************************************************************/ | |
1121 | |
1122 static char * | |
1123 get_selection( | |
1124 buf_T *buf) /* buffer whose selection we want */ | |
1125 { | |
1126 pos_T *start; /* start of the selection */ | |
1127 pos_T *end; /* end of the selection */ | |
1128 char *lp; /* pointer to actual line data */ | |
1129 int llen; /* length of actual line data */ | |
1130 char *sp; /* pointer to selection buffer */ | |
1131 int slen; /* string length in selection buffer */ | |
1132 int size; /* size of selection buffer */ | |
1133 char *new_sp; /* temp pointer to new sp */ | |
1134 int lnum; /* line number we are appending */ | |
1135 | |
692 | 1136 if (buf->b_visual.vi_mode == 'v') |
7 | 1137 { |
692 | 1138 start = &buf->b_visual.vi_start; |
1139 end = &buf->b_visual.vi_end; | |
7 | 1140 if (start->lnum == end->lnum) |
1141 { | |
1142 /* selection is all on one line */ | |
1143 lp = (char *) ml_get_pos(start); | |
1144 llen = end->col - start->col + 1; | |
1145 sp = (char *) malloc(llen + 1); | |
1146 if (sp != NULL) | |
1147 { | |
1148 strncpy(sp, lp, llen); | |
1149 sp[llen] = NUL; | |
1150 } | |
1151 } | |
1152 else | |
1153 { | |
1154 /* multi-line selection */ | |
1155 lp = (char *) ml_get_pos(start); | |
1156 llen = strlen(lp); | |
1157 sp = (char *) malloc(BUFSIZ + llen); | |
1158 if (sp != NULL) | |
1159 { | |
1160 size = BUFSIZ + llen; | |
1161 strcpy(sp, lp); | |
1162 sp[llen] = '\n'; | |
1163 slen = llen + 1; | |
1164 | |
1165 lnum = start->lnum + 1; | |
1166 while (lnum < end->lnum) | |
1167 sp = append_selection(lnum++, sp, &size, &slen); | |
1168 | |
1169 lp = (char *) ml_get(end->lnum); | |
1170 llen = end->col + 1; | |
1171 if ((slen + llen) >= size) | |
1172 { | |
1173 new_sp = (char *) | |
1174 realloc(sp, slen + llen + 1); | |
1175 if (new_sp != NULL) | |
1176 { | |
1177 size += llen + 1; | |
1178 sp = new_sp; | |
1179 } | |
1180 } | |
1181 if ((slen + llen) < size) | |
1182 { | |
1183 strncpy(&sp[slen], lp, llen); | |
1184 sp[slen + llen] = NUL; | |
1185 } | |
1186 | |
1187 } | |
1188 } | |
1189 } | |
1190 else | |
1191 sp = NULL; | |
1192 | |
1193 return sp; | |
1194 } | |
1195 | |
1196 static char * | |
1197 append_selection( | |
1198 int lnum, /* line number to append */ | |
1199 char *sp, /* pointer to selection buffer */ | |
1200 int *size, /* ptr to size of sp */ | |
1201 int *slen) /* ptr to length of selection string */ | |
1202 { | |
1203 char *lp; /* line of data from buffer */ | |
1204 int llen; /* strlen of lp */ | |
1205 char *new_sp; /* temp pointer to new sp */ | |
1206 | |
1207 lp = (char *)ml_get((linenr_T)lnum); | |
1208 llen = strlen(lp); | |
1209 | |
1210 if ((*slen + llen) <= *size) | |
1211 { | |
1212 new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen); | |
1213 if (*new_sp != NUL) | |
1214 { | |
1215 *size = BUFSIZ + *slen + llen; | |
1216 sp = new_sp; | |
1217 } | |
1218 } | |
1219 if ((*slen + llen) > *size) | |
1220 { | |
1221 strcat(&sp[*slen], lp); | |
1222 *slen += llen; | |
1223 sp[*slen++] = '\n'; | |
1224 } | |
1225 | |
1226 return sp; | |
1227 } | |
1228 | |
1229 | |
1230 static void | |
1231 load_buffer_by_name( | |
1232 char *filename, /* the file to load */ | |
1233 int lnum) /* an optional line number (or 0) */ | |
1234 { | |
1235 char lnumbuf[16]; /* make line number option for :e */ | |
1236 char cbuf[BUFSIZ]; /* command buffer */ | |
1237 | |
1238 if (lnum > 0) | |
1239 sprintf(lnumbuf, "+%d", lnum); | |
1240 else | |
1241 lnumbuf[0] = NUL; | |
1242 | |
273 | 1243 vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename); |
7 | 1244 coloncmd(cbuf, False); |
1245 } | |
1246 | |
1247 | |
1248 static void | |
1249 load_window( | |
1250 char *filename, /* filename to load */ | |
1251 int lnum) /* linenumber to go to */ | |
1252 { | |
1253 buf_T *buf; /* buffer filename is stored in */ | |
1254 win_T *win; /* window filenme is displayed in */ | |
1255 | |
1256 /* | |
1257 * Make sure filename is displayed and is the current window. | |
1258 */ | |
1259 | |
1260 buf = buflist_findname((char_u *)filename); | |
1261 if (buf == NULL || (win = get_window(buf)) == NULL) | |
1262 { | |
1263 /* No buffer or buffer is not in current window */ | |
1264 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n", | |
1265 filename, lnum); */ | |
1266 load_buffer_by_name(filename, lnum); | |
1267 } | |
1268 else | |
1269 { | |
1270 /* buf is in a window */ | |
1271 if (win != curwin) | |
1272 { | |
1273 win_enter(win, False); | |
2267 | 1274 /* wsdebug("load_window: window enter %s\n", |
7 | 1275 win->w_buffer->b_sfname); */ |
1276 } | |
1277 if (lnum > 0 && win->w_cursor.lnum != lnum) | |
1278 { | |
1279 warp_to_pc(lnum); | |
1280 /* wsdebug("load_window: warp to %s[%d]\n", | |
1281 win->w_buffer->b_sfname, lnum); */ | |
1282 } | |
1283 } | |
1284 out_flush(); | |
1285 } | |
1286 | |
1287 | |
1288 | |
1289 static void | |
1290 warp_to_pc( | |
1291 int lnum) /* line number to warp to */ | |
1292 { | |
1212 | 1293 char lbuf[256]; /* build line command here */ |
7 | 1294 |
1295 if (lnum > 0) | |
1296 { | |
1297 if (State & INSERT) | |
1298 add_to_input_buf((char_u *) "\033", 1); | |
1299 if (isShowing(lnum)) | |
1300 sprintf(lbuf, "%dG", lnum); | |
1301 else | |
1302 sprintf(lbuf, "%dz.", lnum); | |
1303 add_to_input_buf((char_u *) lbuf, strlen(lbuf)); | |
1304 } | |
1305 } | |
1306 | |
1307 static Boolean | |
1308 isShowing( | |
1309 int lnum) /* tell if line number is showing */ | |
1310 { | |
1311 return lnum >= curwin->w_topline && lnum < curwin->w_botline; | |
1312 } | |
1313 | |
1314 | |
1315 | |
1316 static win_T * | |
1317 get_window( | |
1318 buf_T *buf) /* buffer to find window for */ | |
1319 { | |
1320 win_T *wp = NULL; /* window filename is in */ | |
1321 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
7837
diff
changeset
|
1322 FOR_ALL_WINDOWS(wp) |
7 | 1323 if (buf == wp->w_buffer) |
1324 break; | |
1325 return wp; | |
1326 } | |
1327 | |
1328 | |
1329 static void | |
1330 updatePriority( | |
1331 Boolean subMenu) /* if True then start new submenu pri */ | |
1332 { | |
1333 int pri; /* priority of this menu/item */ | |
1334 char *p; | |
1335 | |
1336 p = strrchr(curMenuPriority, '.'); | |
1337 ASSERT(p != NULL); | |
1338 *p++ = NUL; | |
1339 | |
1340 pri = atoi(p) + 10; /* our new priority */ | |
1341 | |
1342 if (subMenu) | |
273 | 1343 vim_snprintf(curMenuPriority, sizeof(curMenuPriority), |
1344 "%s.%d.0", curMenuPriority, pri); | |
7 | 1345 else |
273 | 1346 vim_snprintf(curMenuPriority, sizeof(curMenuPriority), |
1347 "%s.%d", curMenuPriority, pri); | |
7 | 1348 } |
1349 | |
1350 static char * | |
1351 addUniqueMnemonic( | |
1352 char *mnemonics, /* currently used mnemonics */ | |
1353 char *label) /* label of menu needing mnemonic */ | |
1354 { | |
1355 static char name[BUFSIZ]; /* buffer for the updated name */ | |
1356 char *p; /* pointer into label */ | |
1357 char *found; /* pointer to possible mnemonic */ | |
1358 | |
1359 found = NULL; | |
1360 for (p = label; *p != NUL; p++) | |
1361 if (strchr(mnemonics, *p) == 0) | |
1362 if (found == NULL || (isupper((int)*p) && islower((int)*found))) | |
1363 found = p; | |
1364 | |
1365 if (found != NULL) | |
1366 { | |
1367 strncpy(name, label, (found - label)); | |
1368 strcat(name, "&"); | |
1369 strcat(name, found); | |
1370 } | |
1371 else | |
1372 strcpy(name, label); | |
1373 | |
1374 return name; | |
1375 } | |
1376 | |
1377 /* | |
1378 * Some characters in a menu name must be escaped in vim. Since this is vim | |
1379 * specific, it must be done on this side. | |
1380 */ | |
1381 static char * | |
1382 fixup( | |
1383 char *label) | |
1384 { | |
1385 static char buf[BUFSIZ]; | |
1386 char *bp; /* pointer into buf */ | |
1387 char *lp; /* pointer into label */ | |
1388 | |
1389 lp = label; | |
1390 bp = buf; | |
1391 while (*lp != NUL) | |
1392 { | |
1393 if (*lp == ' ' || *lp == '.') | |
1394 *bp++ = '\\'; | |
1395 *bp++ = *lp++; | |
1396 } | |
1397 *bp = NUL; | |
1398 | |
1399 return buf; | |
1400 } | |
1401 | |
1402 | |
1403 #ifdef NOHANDS_SUPPORT_FUNCTIONS | |
1404 | |
1405 /* For the NoHands test suite */ | |
1406 | |
1407 char * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
1408 workshop_test_getcurrentfile(void) |
7 | 1409 { |
1410 char *filename, *selection; | |
1411 int curLine, curCol, selStartLine, selStartCol, selEndLine; | |
1412 int selEndCol, selLength; | |
1413 | |
1414 if (workshop_get_positions( | |
1415 NULL, &filename, &curLine, &curCol, &selStartLine, | |
1416 &selStartCol, &selEndLine, &selEndCol, &selLength, | |
1417 &selection)) | |
1418 return filename; | |
1419 else | |
1420 return NULL; | |
1421 } | |
1422 | |
1423 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
1424 workshop_test_getcursorrow(void) |
7 | 1425 { |
1426 return 0; | |
1427 } | |
1428 | |
1429 int | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
1430 workshop_test_getcursorcol(void) |
7 | 1431 { |
1432 char *filename, *selection; | |
1433 int curLine, curCol, selStartLine, selStartCol, selEndLine; | |
1434 int selEndCol, selLength; | |
1435 | |
1436 if (workshop_get_positions( | |
1437 NULL, &filename, &curLine, &curCol, &selStartLine, | |
1438 &selStartCol, &selEndLine, &selEndCol, &selLength, | |
1439 &selection)) | |
1440 return curCol; | |
1441 else | |
1442 return -1; | |
1443 } | |
1444 | |
1445 char * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
1446 workshop_test_getcursorrowtext(void) |
7 | 1447 { |
1448 return NULL; | |
1449 } | |
1450 | |
1451 char * | |
7837
33ba2adb6065
commit https://github.com/vim/vim/commit/b638a7be952544ceb03052c25b84224577a6494b
Christian Brabandt <cb@256bit.org>
parents:
2668
diff
changeset
|
1452 workshop_test_getselectedtext(void) |
7 | 1453 { |
1454 char *filename, *selection; | |
1455 int curLine, curCol, selStartLine, selStartCol, selEndLine; | |
1456 int selEndCol, selLength; | |
1457 | |
1458 if (workshop_get_positions( | |
1459 NULL, &filename, &curLine, &curCol, &selStartLine, | |
1460 &selStartCol, &selEndLine, &selEndCol, &selLength, | |
1461 &selection)) | |
1462 return selection; | |
1463 else | |
1464 return NULL; | |
1465 } | |
1466 | |
1467 void | |
1887 | 1468 workshop_save_sensitivity(char *filename UNUSED) |
7 | 1469 { |
1470 } | |
1471 | |
1472 #endif | |
1473 | |
1474 static char * | |
1475 fixAccelText( | |
1476 char *ap) /* original acceleratorText */ | |
1477 { | |
1478 char buf[256]; /* build in temp buffer */ | |
1479 char *shift; /* shift string of "" */ | |
1480 | |
1481 if (ap == NULL) | |
1482 return NULL; | |
1483 | |
1484 /* If the accelerator is shifted use the vim form */ | |
1485 if (strncmp("Shift+", ap, 6) == 0) | |
1486 { | |
1487 shift = "S-"; | |
1488 ap += 6; | |
1489 } | |
1490 else | |
1491 shift = ""; | |
1492 | |
1493 if (*ap == 'F' && atoi(&ap[1]) > 0) | |
1494 { | |
273 | 1495 vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap); |
7 | 1496 return strdup(buf); |
1497 } | |
1498 else | |
1499 return NULL; | |
1500 } | |
1501 | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1502 #ifdef FEAT_BEVAL_GUI |
189 | 1503 void |
1504 workshop_beval_cb( | |
7 | 1505 BalloonEval *beval, |
1506 int state) | |
1507 { | |
189 | 1508 win_T *wp; |
7 | 1509 char_u *text; |
1510 int type; | |
189 | 1511 linenr_T lnum; |
7 | 1512 int col; |
1513 int idx; | |
1514 char buf[MAXPATHLEN * 2]; | |
1515 static int serialNo = -1; | |
1516 | |
1517 if (!p_beval) | |
1518 return; | |
1519 | |
189 | 1520 if (get_beval_info(beval, FALSE, &wp, &lnum, &text, &col) == OK) |
7 | 1521 { |
1522 if (text && text[0]) | |
1523 { | |
1524 /* Send debugger request */ | |
1525 if (strlen((char *) text) > (MAXPATHLEN/2)) | |
1526 { | |
1527 /* | |
1528 * The user has probably selected the entire | |
1529 * buffer or something like that - don't attempt | |
1530 * to evaluate it | |
1531 */ | |
1532 return; | |
1533 } | |
1534 | |
1535 /* | |
1536 * WorkShop expects the col to be a character index, not | |
1537 * a column number. Compute the index from col. Also set | |
1538 * line to 0 because thats what dbx expects. | |
1539 */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1540 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1541 idx = computeIndex(col, text, beval->ts, beval->vts); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1542 #else |
14736
3e9b24eac417
patch 8.1.0380: "make proto" doesn't work well
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
1543 idx = computeIndex(col, text, beval->ts, 0); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1544 #endif |
7 | 1545 if (idx > 0) |
1546 { | |
189 | 1547 lnum = 0; |
7 | 1548 |
1549 /* | |
1550 * If successful, it will respond with a balloon cmd. | |
1551 */ | |
1552 if (state & ControlMask) | |
1553 /* Evaluate *(expression) */ | |
1554 type = (int)GPLineEval_INDIRECT; | |
1555 else if (state & ShiftMask) | |
1556 /* Evaluate type(expression) */ | |
1557 type = (int)GPLineEval_TYPE; | |
1558 else | |
1559 /* Evaluate value(expression) */ | |
1560 type = (int)GPLineEval_EVALUATE; | |
1561 | |
1562 /* Send request to dbx */ | |
273 | 1563 vim_snprintf(buf, sizeof(buf), "toolVerb debug.balloonEval " |
189 | 1564 "%s %ld,0 %d,0 %d,%d %ld %s\n", |
1565 (char *)wp->w_buffer->b_ffname, | |
1566 (long)lnum, idx, type, serialNo++, | |
1567 (long)strlen((char *)text), (char *)text); | |
7 | 1568 balloonEval = beval; |
1569 workshop_send_message(buf); | |
1570 } | |
1571 } | |
1572 } | |
1573 } | |
1574 | |
1575 static int | |
1576 computeIndex( | |
1577 int wantedCol, | |
1578 char_u *line, | |
14736
3e9b24eac417
patch 8.1.0380: "make proto" doesn't work well
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
1579 int ts, |
3e9b24eac417
patch 8.1.0380: "make proto" doesn't work well
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
1580 int *vts UNUSED) |
7 | 1581 { |
1582 int col = 0; | |
1583 int idx = 0; | |
1584 | |
1585 while (line[idx]) | |
1586 { | |
1587 if (line[idx] == '\t') | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1588 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1589 col += tabstop_padding(col, ts, vts); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1590 #else |
7 | 1591 col += ts - (col % ts); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1592 #endif |
7 | 1593 else |
1594 col++; | |
1595 idx++; | |
1596 if (col >= wantedCol) | |
1597 return idx; | |
1598 } | |
1599 | |
1600 return -1; | |
1601 } | |
2031
07de57cbcb25
updated for version 7.2.327
Bram Moolenaar <bram@zimbu.org>
parents:
1887
diff
changeset
|
1602 #endif |
7 | 1603 |
1604 static void | |
1605 addMenu( | |
1606 char *menu, /* menu name */ | |
1607 char *accel, /* accelerator text (optional) */ | |
1608 char *verb) /* WorkShop action-verb */ | |
1609 { | |
1610 MenuMap *newMap; | |
1611 char cbuf[BUFSIZ]; | |
1612 | |
1613 if (menuMapSize >= menuMapMax) | |
1614 { | |
1615 newMap = realloc(menuMap, | |
1616 sizeof(MenuMap) * (menuMapMax + MENU_INC)); | |
1617 if (newMap != NULL) | |
1618 { | |
1619 menuMap = newMap; | |
1620 menuMapMax += MENU_INC; | |
1621 } | |
1622 } | |
1623 if (menuMapSize < menuMapMax) | |
1624 { | |
1625 menuMap[menuMapSize].name = strdup(menu); | |
1626 menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL; | |
1627 menuMap[menuMapSize++].verb = strdup(verb); | |
1628 if (accel && workshopHotKeysEnabled) | |
1629 { | |
273 | 1630 vim_snprintf(cbuf, sizeof(cbuf), |
1631 "map %s :wsverb %s<CR>", accel, verb); | |
7 | 1632 coloncmd(cbuf, TRUE); |
1633 } | |
1634 } | |
1635 } | |
1636 | |
1637 static char * | |
1638 nameStrip( | |
1639 char *raw) /* menu name, possibly with & chars */ | |
1640 { | |
1641 static char buf[BUFSIZ]; /* build stripped name here */ | |
1642 char *bp = buf; | |
1643 | |
1644 while (*raw) | |
1645 { | |
1646 if (*raw != '&') | |
1647 *bp++ = *raw; | |
1648 raw++; | |
1649 } | |
1650 *bp = NUL; | |
1651 return buf; | |
1652 } | |
1653 | |
1654 | |
1655 static char * | |
1656 lookupVerb( | |
1657 char *verb, | |
1658 int skip) /* number of matches to skip */ | |
1659 { | |
1660 int i; /* loop iterator */ | |
1661 | |
1662 for (i = 0; i < menuMapSize; i++) | |
1663 if (strcmp(menuMap[i].verb, verb) == 0 && skip-- == 0) | |
1664 return nameStrip(menuMap[i].name); | |
1665 | |
1666 return NULL; | |
1667 } | |
1668 | |
1669 | |
1670 static void | |
1671 coloncmd( | |
1672 char *cmd, /* the command to print */ | |
1673 Boolean force) /* force cursor update */ | |
1674 { | |
1675 char_u *cpo_save = p_cpo; | |
1676 | |
1677 #ifdef WSDEBUG | |
1678 if (WSDLEVEL(WS_TRACE_COLONCMD)) | |
1679 wsdebug("Cmd: %s\n", cmd); | |
1680 #endif | |
1681 | |
1682 p_cpo = empty_option; | |
1683 | |
1684 ALT_INPUT_LOCK_ON; | |
1685 do_cmdline_cmd((char_u *)cmd); | |
1686 ALT_INPUT_LOCK_OFF; | |
1687 | |
1688 p_cpo = cpo_save; | |
1689 | |
1690 if (force) | |
1691 gui_update_screen(); | |
1692 } | |
1693 | |
1694 /* | |
1695 * setDollarVim - Given the run directory, search for the vim install | |
1696 * directory and set $VIM. | |
1697 * | |
1698 * We can be running out of SUNWspro/bin or out of | |
1699 * SUNWspro/contrib/contrib6/vim5.6/bin so we check | |
1700 * relative to both of these directories. | |
1701 */ | |
1702 static void | |
1703 setDollarVim( | |
1704 char *rundir) | |
1705 { | |
1706 char buf[MAXPATHLEN]; | |
1707 char *cp; | |
1708 | |
1709 /* | |
1710 * First case: Running from <install-dir>/SUNWspro/bin | |
1711 */ | |
1712 strcpy(buf, rundir); | |
1713 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/" | |
1714 VIM_VERSION_NODOT "/syntax/syntax.vim"); | |
1715 if (access(buf, R_OK) == 0) | |
1716 { | |
1717 strcpy(buf, "SPRO_WSDIR="); | |
1718 strcat(buf, rundir); | |
1719 cp = strrchr(buf, '/'); | |
1720 if (cp != NULL) | |
1721 strcpy(cp, "/WS6U2"); | |
1722 putenv(strdup(buf)); | |
1723 | |
1724 strcpy(buf, "VIM="); | |
1725 strcat(buf, rundir); | |
1726 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/" | |
1727 VIM_VERSION_NODOT); | |
1728 putenv(strdup(buf)); | |
1729 return; | |
1730 } | |
1731 | |
1732 /* | |
1733 * Second case: Probably running from | |
1734 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin | |
1735 */ | |
1736 strcpy(buf, rundir); | |
1737 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT | |
1738 "/share/vim/" VIM_VERSION_NODOT "/syntax/syntax.vim"); | |
1739 if (access(buf, R_OK) == 0) | |
1740 { | |
1741 strcpy(buf, "SPRO_WSDIR="); | |
1742 strcat(buf, rundir); | |
1743 cp = strrchr(buf, '/'); | |
1744 if (cp != NULL) | |
1745 strcpy(cp, "../../../../WS6U2"); | |
1746 putenv(strdup(buf)); | |
1747 | |
1748 strcpy(buf, "VIM="); | |
1749 strcat(buf, rundir); | |
1750 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT | |
1751 "/share/vim/" VIM_VERSION_NODOT); | |
1752 putenv(strdup(buf)); | |
1753 return; | |
1754 } | |
1755 } | |
1756 | |
1757 /* | |
1758 * findYourself - Find the directory we are running from. This is used to | |
1759 * set $VIM. We need to set this because users can install | |
1760 * the package in a different directory than the compiled | |
1761 * directory. This is a Sun Visual WorkShop requirement! | |
1762 * | |
1763 * Note: We override a user's $VIM because it won't have the | |
10226
7a4fb555c83a
commit https://github.com/vim/vim/commit/9af418427652562384744648d7d173a4bfebba95
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1764 * WorkShop specific files. S/he may not like this but it's |
7 | 1765 * better than getting the wrong files (especially as the |
1766 * user is likely to have $VIM set to 5.4 or later). | |
1767 */ | |
1768 void | |
1769 findYourself( | |
1770 char *argv0) | |
1771 { | |
1772 char *runpath = NULL; | |
1773 char *path; | |
1774 char *pathbuf; | |
1775 | |
1776 if (*argv0 == '/') | |
1777 runpath = strdup(argv0); | |
1778 else if (*argv0 == '.' || strchr(argv0, '/')) | |
1779 { | |
1780 runpath = (char *) malloc(MAXPATHLEN); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2245
diff
changeset
|
1781 if (getcwd(runpath, MAXPATHLEN) == NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2245
diff
changeset
|
1782 runpath[0] = NUL; |
7 | 1783 strcat(runpath, "/"); |
1784 strcat(runpath, argv0); | |
1785 } | |
1786 else | |
1787 { | |
1788 path = getenv("PATH"); | |
1789 if (path != NULL) | |
1790 { | |
1791 runpath = (char *) malloc(MAXPATHLEN); | |
1792 pathbuf = strdup(path); | |
1793 path = strtok(pathbuf, ":"); | |
1794 do | |
1795 { | |
1796 strcpy(runpath, path); | |
1797 strcat(runpath, "/"); | |
1798 strcat(runpath, argv0); | |
1799 if (access(runpath, X_OK) == 0) | |
1800 break; | |
1801 } while ((path = strtok(NULL, ":")) != NULL); | |
1802 free(pathbuf); | |
1803 } | |
1804 } | |
1805 | |
1806 if (runpath != NULL) | |
1807 { | |
1808 char runbuf[MAXPATHLEN]; | |
1809 | |
1810 /* | |
1811 * We found the run directory. Now find the install dir. | |
1812 */ | |
1813 (void)vim_FullName((char_u *)runpath, (char_u *)runbuf, MAXPATHLEN, 1); | |
1814 path = strrchr(runbuf, '/'); | |
1815 if (path != NULL) | |
1816 *path = NUL; /* remove the vim/gvim name */ | |
1817 path = strrchr(runbuf, '/'); | |
1818 if (path != NULL) | |
1819 { | |
1820 if (strncmp(path, "/bin", 4) == 0) | |
1821 setDollarVim(runbuf); | |
1822 else if (strncmp(path, "/src", 4) == 0) | |
1823 { | |
1824 *path = NUL; /* development tree */ | |
1825 setDollarVim(runbuf); | |
1826 } | |
1827 } | |
1828 free(runpath); | |
1829 } | |
1830 } |