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