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