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