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