Merge branch 'vim-with-runtime' into feat/var-tabstops
[vim_extended.git] / src / workshop.c
blob2743dc02f867a962de242cd035e26cda3eea7416
1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * Visual Workshop integration by Gordon Prieur
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 */
11 #ifdef HAVE_CONFIG_H
12 # include "auto/config.h"
13 #endif
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <sys/types.h>
17 #include <netdb.h>
18 #include <netinet/in.h>
19 #include <errno.h>
20 #include <sys/socket.h>
21 #ifdef HAVE_LIBGEN_H
22 # include <libgen.h>
23 #endif
24 #include <unistd.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <ctype.h>
29 #include <X11/Intrinsic.h>
30 #include <Xm/Xm.h>
31 #include <Xm/PushB.h>
33 #include "integration.h" /* <EditPlugin/integration.h> */
35 #include "vim.h"
36 #include "version.h"
37 #include "gui_beval.h"
38 #include "workshop.h"
40 void workshop_hotkeys(Boolean);
42 static Boolean isShowing(int);
43 static win_T *get_window(buf_T *);
44 #if 0
45 static int get_buffer_number(buf_T *);
46 #endif
47 static void updatePriority(Boolean);
48 static char *addUniqueMnemonic(char *, char *);
49 static char *fixup(char *);
50 static char *get_selection(buf_T *);
51 static char *append_selection(int, char *, int *, int *);
52 static void load_buffer_by_name(char *, int);
53 #if 0
54 static void load_buffer_by_number(int, int);
55 #endif
56 static void load_window(char *, int lnum);
57 static void warp_to_pc(int);
58 #ifdef FEAT_BEVAL
59 void workshop_beval_cb(BalloonEval *, int);
60 # ifdef FEAT_VARTABS
61 static int computeIndex(int, char_u *, int, int *);
62 # else
63 static int computeIndex(int, char_u *, int);
64 # endif
65 #endif
66 static char *fixAccelText(char *);
67 static void addMenu(char *, char *, char *);
68 static char *lookupVerb(char *, int);
69 static void coloncmd(char *, Boolean);
71 extern Widget vimShell;
72 extern Widget textArea;
73 extern XtAppContext app_context;
75 static int tbpri; /* ToolBar priority */
76 int usingSunWorkShop = 0; /* set if -ws flag is used */
77 char curMenuName[BUFSIZ];
78 char curMenuPriority[BUFSIZ];
80 static Boolean workshopInitDone = False;
81 static Boolean workshopHotKeysEnabled = False;
84 * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it
85 * here because its C++.
87 enum
89 GPLineEval_EVALUATE, /* evaluate expression */
90 GPLineEval_INDIRECT, /* evaluate *<expression> */
91 GPLineEval_TYPE /* type of expression */
95 * Store each verb in the MenuMap. This lets us map from a verb to a menu.
96 * There may be multiple matches for a single verb in this table.
98 #define MENU_INC 50 /* menuMap incremental size increases */
99 typedef struct
101 char *name; /* name of the menu */
102 char *accel; /* optional accelerator key */
103 char *verb; /* menu verb */
104 } MenuMap;
105 static MenuMap *menuMap; /* list of verb/menu mappings */
106 static int menuMapSize; /* current size of menuMap */
107 static int menuMapMax; /* allocated size of menuMap */
108 static char *initialFileCmd; /* save command but defer doing it */
111 void
112 workshop_init()
114 char_u buf[64];
115 int is_dirty = FALSE;
116 int width, height;
117 XtInputMask mask;
120 * Turn on MenuBar, ToolBar, and Footer.
122 STRCPY(buf, p_go);
123 if (vim_strchr(p_go, GO_MENUS) == NULL)
125 STRCAT(buf, "m");
126 is_dirty = TRUE;
128 if (vim_strchr(p_go, GO_TOOLBAR) == NULL)
130 STRCAT(buf, "T");
131 is_dirty = TRUE;
133 if (vim_strchr(p_go, GO_FOOTER) == NULL)
135 STRCAT(buf, "F");
136 is_dirty = TRUE;
138 if (is_dirty)
139 set_option_value((char_u *)"go", 0L, buf, 0);
142 * Set size from workshop_get_width_height().
144 width = height = 0;
145 if (workshop_get_width_height(&width, &height))
147 XtVaSetValues(vimShell,
148 XmNwidth, width,
149 XmNheight, height,
150 NULL);
154 * Now read in the initial messages from eserve.
156 while ((mask = XtAppPending(app_context))
157 && (mask & XtIMAlternateInput) && !workshopInitDone)
158 XtAppProcessEvent(app_context, (XtInputMask)XtIMAlternateInput);
161 void
162 workshop_postinit()
164 do_cmdline_cmd((char_u *)initialFileCmd);
165 ALT_INPUT_LOCK_OFF;
166 free(initialFileCmd);
167 initialFileCmd = NULL;
170 void
171 ex_wsverb(exarg_T *eap)
173 msg_clr_cmdline();
174 workshop_perform_verb((char *) eap->arg, NULL);
178 * Editor name
179 * This string is recognized by eserve and should be all lower case.
180 * This is how the editor detects that it is talking to gvim instead
181 * of NEdit, for example, when the connection is initiated from the editor.
183 char *
184 workshop_get_editor_name()
186 return "gvim";
190 * Version number of the editor.
191 * This number is communicated along with the protocol
192 * version to the application.
194 char *
195 workshop_get_editor_version()
197 return Version;
201 * Answer functions: called by eserve
205 * Name:
206 * workshop_load_file
208 * Function:
209 * Load a given file into the WorkShop buffer.
211 void
212 workshop_load_file(
213 char *filename, /* the file to load */
214 int line, /* an optional line number (or 0) */
215 char *frameid UNUSED) /* used for multi-frame support */
217 #ifdef WSDEBUG_TRACE
218 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
219 wstrace("workshop_load_file(%s, %d)\n", filename, line);
220 #endif
222 #ifdef FEAT_BEVAL
223 bevalServers |= BEVAL_WORKSHOP;
224 #endif
226 load_window(filename, line);
230 * Reload the WorkShop buffer
232 void
233 workshop_reload_file(
234 char *filename,
235 int line)
237 #ifdef WSDEBUG_TRACE
238 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
239 wstrace("workshop_reload_file(%s, %d)\n", filename, line);
240 #endif
241 load_window(filename, line);
244 void
245 workshop_show_file(
246 char *filename)
248 #ifdef WSDEBUG_TRACE
249 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
250 wstrace("workshop_show_file(%s)\n", filename);
251 #endif
253 load_window(filename, 0);
256 void
257 workshop_goto_line(
258 char *filename,
259 int lineno)
261 #ifdef WSDEBUG_TRACE
262 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
263 wstrace("workshop_goto_line(%s, %d)\n", filename, lineno);
264 #endif
266 load_window(filename, lineno);
269 void
270 workshop_front_file(
271 char *filename UNUSED)
273 #ifdef WSDEBUG_TRACE
274 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
275 wstrace("workshop_front_file()\n");
276 #endif
278 * Assumption: This function will always be called after a call to
279 * workshop_show_file(), so the file is always showing.
281 if (vimShell != NULL)
282 XRaiseWindow(gui.dpy, XtWindow(vimShell));
285 void
286 workshop_save_file(
287 char *filename)
289 char cbuf[BUFSIZ]; /* build vim command here */
291 #ifdef WSDEBUG_TRACE
292 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
293 wstrace("workshop_save_file(%s)\n", filename);
294 #endif
296 /* Save the given file */
297 vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename);
298 coloncmd(cbuf, TRUE);
301 void
302 workshop_save_files()
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
310 add_to_input_buf((char_u *) ":wall\n", 6);
313 void
314 workshop_quit()
316 #ifdef WSDEBUG_TRACE
317 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
318 wstrace("workshop_quit()\n");
319 #endif
321 add_to_input_buf((char_u *) ":qall\n", 6);
324 void
325 workshop_minimize()
327 #ifdef WSDEBUG_TRACE
328 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
329 wstrace("workshop_minimize()\n");
330 #endif
331 workshop_minimize_shell(vimShell);
333 void
334 workshop_maximize()
336 #ifdef WSDEBUG_TRACE
337 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
338 wstrace("workshop_maximize()\n");
339 #endif
341 workshop_maximize_shell(vimShell);
344 void
345 workshop_add_mark_type(
346 int idx,
347 char *colorspec,
348 char *sign)
350 char gbuf[BUFSIZ]; /* buffer for sign name */
351 char cibuf[BUFSIZ]; /* color information */
352 char cbuf[BUFSIZ]; /* command buffer */
353 char *bp;
355 #ifdef WSDEBUG_TRACE
356 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
358 char *cp;
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);
368 #endif
371 * Isolate the basename of sign in gbuf. We will use this for the
372 * GroupName in the highlight command sent to vim.
374 STRCPY(gbuf, gettail((char_u *)sign));
375 bp = strrchr(gbuf, '.');
376 if (bp != NULL)
377 *bp = NUL;
379 if (gbuf[0] != '-' && gbuf[1] != NUL)
381 if (colorspec != NULL && *colorspec)
383 vim_snprintf(cbuf, sizeof(cbuf),
384 "highlight WS%s guibg=%s", gbuf, colorspec);
385 coloncmd(cbuf, FALSE);
386 vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf);
388 else
389 cibuf[0] = NUL;
391 vim_snprintf(cbuf, sizeof(cbuf),
392 "sign define %d %s icon=%s", idx, cibuf, sign);
393 coloncmd(cbuf, TRUE);
397 void
398 workshop_set_mark(
399 char *filename, /* filename which gets the mark */
400 int lineno, /* line number which gets the mark */
401 int markId, /* unique mark identifier */
402 int idx) /* which mark to use */
404 char cbuf[BUFSIZ]; /* command buffer */
406 /* Set mark in a given file */
407 #ifdef WSDEBUG_TRACE
408 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
409 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n",
410 filename, lineno, markId, idx);
411 #endif
413 vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s",
414 markId, lineno, idx, filename);
415 coloncmd(cbuf, TRUE);
418 void
419 workshop_change_mark_type(
420 char *filename, /* filename which gets the mark */
421 int markId, /* unique mark identifier */
422 int idx) /* which mark to use */
424 char cbuf[BUFSIZ]; /* command buffer */
426 /* Change mark type */
427 #ifdef WSDEBUG_TRACE
428 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
429 wstrace("workshop_change_mark_type(%s, %d, %d)\n",
430 filename, markId, idx);
431 #endif
433 vim_snprintf(cbuf, sizeof(cbuf),
434 "sign place %d name=%d file=%s", markId, idx, filename);
435 coloncmd(cbuf, TRUE);
439 * Goto the given mark in a file (e.g. show it).
440 * If message is not null, display it in the footer.
442 void
443 workshop_goto_mark(
444 char *filename,
445 int markId,
446 char *message)
448 char cbuf[BUFSIZ]; /* command buffer */
450 /* Goto mark */
451 #ifdef WSDEBUG_TRACE
452 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
453 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
454 filename, markId, message && *message &&
455 !(*message == ' ' && message[1] == NULL) ?
456 message : "<None>");
457 #endif
459 vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename);
460 coloncmd(cbuf, TRUE);
461 if (message != NULL && *message != NUL)
462 gui_mch_set_footer((char_u *)message);
465 void
466 workshop_delete_mark(
467 char *filename,
468 int markId)
470 char cbuf[BUFSIZ]; /* command buffer */
472 /* Delete mark */
473 #ifdef WSDEBUG_TRACE
474 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
475 wstrace("workshop_delete_mark(%s, %d (id))\n",
476 filename, markId);
477 #endif
479 vim_snprintf(cbuf, sizeof(cbuf),
480 "sign unplace %d file=%s", markId, filename);
481 coloncmd(cbuf, TRUE);
484 #if 0 /* not used */
485 void
486 workshop_delete_all_marks(
487 void *window,
488 Boolean doRefresh)
490 #ifdef WSDEBUG_TRACE
491 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
492 wstrace("workshop_delete_all_marks(%#x, %s)\n",
493 window, doRefresh ? "True" : "False");
494 #endif
496 coloncmd("sign unplace *", TRUE);
498 #endif
501 workshop_get_mark_lineno(
502 char *filename,
503 int markId)
505 buf_T *buf; /* buffer containing filename */
506 int lineno; /* line number of filename in buf */
508 /* Get mark line number */
509 #ifdef WSDEBUG_TRACE
510 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
511 wstrace("workshop_get_mark_lineno(%s, %d)\n",
512 filename, markId);
513 #endif
515 lineno = 0;
516 buf = buflist_findname((char_u *)filename);
517 if (buf != NULL)
518 lineno = buf_findsign(buf, markId);
520 return lineno;
524 #if 0 /* not used */
525 void
526 workshop_adjust_marks(Widget *window, int pos,
527 int inserted, int deleted)
529 #ifdef WSDEBUG_TRACE
530 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
531 wstrace("XXXworkshop_adjust_marks(%s, %d, %d, %d)\n",
532 window ? XtName(window) : "<None>", pos, inserted, deleted);
533 #endif
535 #endif
538 * Are there any moved marks? If so, call workshop_move_mark on
539 * each of them now. This is how eserve can find out if for example
540 * breakpoints have moved when a program has been recompiled and
541 * reloaded into dbx.
543 void
544 workshop_moved_marks(char *filename UNUSED)
546 #ifdef WSDEBUG_TRACE
547 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
548 wstrace("XXXworkshop_moved_marks(%s)\n", filename);
549 #endif
553 workshop_get_font_height()
555 XmFontList fontList; /* fontList made from gui.norm_font */
556 XmString str;
557 Dimension w;
558 Dimension h;
560 #ifdef WSDEBUG_TRACE
561 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
562 wstrace("workshop_get_font_height()\n");
563 #endif
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)
570 str = XmStringCreateLocalized("A");
571 XmStringExtent(fontList, str, &w, &h);
572 XmStringFree(str);
573 XmFontListFree(fontList);
576 return (int)h;
579 void
580 workshop_footer_message(
581 char *message,
582 int severity UNUSED) /* severity is currently unused */
584 #ifdef WSDEBUG_TRACE
585 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
586 wstrace("workshop_footer_message(%s, %d)\n", message, severity);
587 #endif
589 gui_mch_set_footer((char_u *) message);
593 * workshop_menu_begin() is passed the menu name. We determine its mnemonic
594 * here and store its name and priority.
596 void
597 workshop_menu_begin(
598 char *label)
600 vimmenu_T *menu; /* pointer to last menu */
601 int menuPriority = 0; /* priority of new menu */
602 char mnembuf[64]; /* store menubar mnemonics here */
603 char *name; /* label with a mnemonic */
604 char *p; /* used to find mnemonics */
605 int idx; /* index into mnembuf */
607 #ifdef WSDEBUG_TRACE
608 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
609 wstrace("workshop_menu_begin()\n");
610 #endif
613 * Look through all existing (non-PopUp and non-Toolbar) menus
614 * and gather their mnemonics. Use this list to decide what
615 * mnemonic should be used for label.
618 idx = 0;
619 mnembuf[idx++] = 'H'; /* H is mnemonic for Help */
620 for (menu = root_menu; menu != NULL; menu = menu->next)
622 if (menu_is_menubar(menu->name))
624 p = strchr((char *)menu->name, '&');
625 if (p != NULL)
626 mnembuf[idx++] = *++p;
628 if (menu->next != NULL
629 && strcmp((char *) menu->next->dname, "Help") == 0)
631 menuPriority = menu->priority + 10;
632 break;
635 mnembuf[idx++] = NUL;
636 name = addUniqueMnemonic(mnembuf, label);
638 vim_snprintf(curMenuName, sizeof(curMenuName), "%s", name);
639 sprintf(curMenuPriority, "%d.0", menuPriority);
643 * Append the name and priority to strings to be used in vim menu commands.
645 void
646 workshop_submenu_begin(
647 char *label)
649 #ifdef WSDEBUG_TRACE
650 if (ws_debug && ws_dlevel & WS_TRACE
651 && strncmp(curMenuName, "ToolBar", 7) != 0)
652 wstrace("workshop_submenu_begin(%s)\n", label);
653 #endif
655 strcat(curMenuName, ".");
656 strcat(curMenuName, fixup(label));
658 updatePriority(True);
662 * Remove the submenu name and priority from curMenu*.
665 void
666 workshop_submenu_end()
668 char *p;
670 #ifdef WSDEBUG_TRACE
671 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)
672 && strncmp(curMenuName, "ToolBar", 7) != 0)
673 wstrace("workshop_submenu_end()\n");
674 #endif
676 p = strrchr(curMenuPriority, '.');
677 ASSERT(p != NULL);
678 *p = NUL;
680 p = strrchr(curMenuName, '.');
681 ASSERT(p != NULL);
682 *p = NUL;
686 * This is where menus are really made. Each item will generate an amenu vim
687 * command. The globals curMenuName and curMenuPriority contain the name and
688 * priority of the parent menu tree.
690 void
691 workshop_menu_item(
692 char *label,
693 char *verb,
694 char *accelerator UNUSED,
695 char *acceleratorText,
696 char *name UNUSED,
697 char *filepos UNUSED,
698 char *sensitive)
700 char cbuf[BUFSIZ];
701 char namebuf[BUFSIZ];
702 char accText[BUFSIZ];
704 #ifdef WSDEBUG_TRACE
705 if (WSDLEVEL(WS_TRACE_VERBOSE)
706 && strncmp(curMenuName, "ToolBar", 7) != 0)
708 if (ws_dlevel & WS_TRACE_VERBOSE)
709 wsdebug("workshop_menu_item(\n"
710 "\tlabel = \"%s\",\n"
711 "\tverb = %s,\n"
712 "\taccelerator = %s,\n"
713 "\tacceleratorText = \"%s\",\n"
714 "\tname = %s,\n"
715 "\tfilepos = %s,\n"
716 "\tsensitive = %s)\n",
717 label && *label ? label : "<None>",
718 verb && *verb ? verb : "<None>",
719 accelerator && *accelerator ?
720 accelerator : "<None>",
721 acceleratorText && *acceleratorText ?
722 acceleratorText : "<None>",
723 name && *name ? name : "<None>",
724 filepos && *filepos ? filepos : "<None>",
725 sensitive);
726 else if (ws_dlevel & WS_TRACE)
727 wstrace("workshop_menu_item(\"%s\", %s)\n",
728 label && *label ? label : "<None>",
729 verb && *verb ? verb : "<None>", sensitive);
731 #endif
732 #ifdef WSDEBUG_SENSE
733 if (ws_debug)
734 wstrace("menu: %-21.20s%-21.20s(%s)\n", label, verb,
735 *sensitive == '1' ? "Sensitive" : "Insensitive");
736 #endif
738 if (acceleratorText != NULL)
739 vim_snprintf(accText, sizeof(accText), "<Tab>%s", acceleratorText);
740 else
741 accText[0] = NUL;
742 updatePriority(False);
743 vim_snprintf(namebuf, sizeof(namebuf), "%s.%s", curMenuName, fixup(label));
744 vim_snprintf(cbuf, sizeof(cbuf), "amenu %s %s%s\t:wsverb %s<CR>",
745 curMenuPriority, namebuf, accText, verb);
747 coloncmd(cbuf, TRUE);
748 addMenu(namebuf, fixAccelText(acceleratorText), verb);
750 if (*sensitive == '0')
752 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
753 coloncmd(cbuf, TRUE);
758 * This function is called when a complete WorkShop menu description has been
759 * sent over from eserve. We do some menu cleanup.
762 void
763 workshop_menu_end()
765 Boolean using_tearoff; /* set per current option setting */
767 #ifdef WSDEBUG_TRACE
768 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
769 wstrace("workshop_menu_end()\n");
770 #endif
772 using_tearoff = vim_strchr(p_go, GO_TEAROFF) != NULL;
773 gui_mch_toggle_tearoffs(using_tearoff);
776 void
777 workshop_toolbar_begin()
779 #ifdef WSDEBUG_TRACE
780 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
781 wstrace("workshop_toolbar_begin()\n");
782 #endif
784 coloncmd("aunmenu ToolBar", True);
785 tbpri = 10;
788 void
789 workshop_toolbar_end()
791 char_u buf[64];
793 #ifdef WSDEBUG_TRACE
794 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
796 wstrace("workshop_toolbar_end()\n");
798 #endif
801 * Turn on ToolBar.
803 STRCPY(buf, p_go);
804 if (vim_strchr(p_go, 'T') == NULL)
806 STRCAT(buf, "T");
807 set_option_value((char_u *)"go", 0L, buf, 0);
809 workshopInitDone = True;
812 void
813 workshop_toolbar_button(
814 char *label,
815 char *verb,
816 char *senseVerb UNUSED,
817 char *filepos UNUSED,
818 char *help,
819 char *sense,
820 char *file,
821 char *left)
823 char cbuf[BUFSIZ + MAXPATHLEN];
824 char namebuf[BUFSIZ];
825 static int tbid = 1;
826 char_u *p;
827 int len;
829 #ifdef WSDEBUG_TRACE
830 if (WSDLEVEL(WS_TRACE_VERBOSE))
831 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
832 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
833 label && *label ? label : "<None>",
834 verb && *verb ? verb : "<None>",
835 senseVerb && *senseVerb ? senseVerb : "<None>",
836 filepos && *filepos ? filepos : "<None>",
837 help && *help ? help : "<None>",
838 sense && *sense ? sense : "<None>",
839 file && *file ? file : "<None>",
840 left && *left ? left : "<None>");
841 else if (WSDLEVEL(WS_TRACE))
842 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
843 label && *label ? label : "<None>",
844 verb && *verb ? verb : "<None>");
845 #endif
846 #ifdef WSDEBUG_SENSE
847 if (ws_debug)
848 wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb,
849 *sense == '1' ? "Sensitive" : "Insensitive");
850 #endif
852 if (left && *left && atoi(left) > 0)
854 /* Add a separator (but pass the width passed after the ':') */
855 sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
856 tbpri - 5, tbid++, left);
858 coloncmd(cbuf, True);
861 p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. ");
862 vim_snprintf(namebuf, sizeof(namebuf), "ToolBar.%s", p);
863 vim_free(p);
864 STRCPY(cbuf, "amenu <silent> ");
865 if (file != NULL && *file != NUL)
867 p = vim_strsave_escaped((char_u *)file, (char_u *)" ");
868 len = STRLEN(cbuf);
869 vim_snprintf(cbuf + len, sizeof(cbuf) - len, "icon=%s ", p);
870 vim_free(p);
872 len = STRLEN(cbuf);
873 vim_snprintf(cbuf + len, sizeof(cbuf) - len,"1.%d %s :wsverb %s<CR>",
874 tbpri, namebuf, verb);
876 /* Define the menu item */
877 coloncmd(cbuf, True);
879 if (*sense == '0')
881 /* If menu isn't sensitive at startup... */
882 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
883 coloncmd(cbuf, True);
886 if (help && *help)
888 /* Do the tooltip */
889 vim_snprintf(cbuf, sizeof(cbuf), "tmenu %s %s", namebuf, help);
890 coloncmd(cbuf, True);
893 addMenu(namebuf, NULL, verb);
894 tbpri += 10;
897 void
898 workshop_frame_sensitivities(
899 VerbSense *vs) /* list of verbs to (de)sensitize */
901 VerbSense *vp; /* iterate through vs */
902 char *menu_name; /* used in menu lookup */
903 int cnt; /* count of verbs to skip */
904 int len; /* length of nonvariant part of command */
905 char cbuf[4096];
907 #ifdef WSDEBUG_TRACE
908 if (WSDLEVEL(WS_TRACE_VERBOSE) || WSDLEVEL(4))
910 wsdebug("workshop_frame_sensitivities(\n");
911 for (vp = vs; vp->verb != NULL; vp++)
912 wsdebug("\t%-25s%d\n", vp->verb, vp->sense);
913 wsdebug(")\n");
915 else if (WSDLEVEL(WS_TRACE))
916 wstrace("workshop_frame_sensitivities()\n");
917 #endif
918 #ifdef WSDEBUG_SENSE
919 if (ws_debug)
920 for (vp = vs; vp->verb != NULL; vp++)
921 wsdebug("change: %-21.20s%-21.20s(%s)\n",
922 "", vp->verb, vp->sense == 1 ?
923 "Sensitive" : "Insensitive");
924 #endif
927 * Look for all matching menu entries for the verb. There may be more
928 * than one if the verb has both a menu and toolbar entry.
930 for (vp = vs; vp->verb != NULL; vp++)
932 cnt = 0;
933 strcpy(cbuf, "amenu");
934 strcat(cbuf, " ");
935 strcat(cbuf, vp->sense ? "enable" : "disable");
936 strcat(cbuf, " ");
937 len = strlen(cbuf);
938 while ((menu_name = lookupVerb(vp->verb, cnt++)) != NULL)
940 strcpy(&cbuf[len], menu_name);
941 coloncmd(cbuf, FALSE);
944 gui_update_menus(0);
945 gui_mch_flush();
948 void
949 workshop_set_option(
950 char *option, /* name of a supported option */
951 char *value) /* value to set option to */
953 char cbuf[BUFSIZ]; /* command buffer */
955 #ifdef WSDEBUG_TRACE
956 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
958 wstrace("workshop_set_option(%s, %s)\n", option, value);
960 #endif
962 cbuf[0] = NUL;
963 switch (*option) /* switch on 1st letter */
965 case 's':
966 if (strcmp(option, "syntax") == 0)
967 vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value);
968 else if (strcmp(option, "savefiles") == 0)
970 /* XXX - Not yet implemented */
972 break;
974 case 'l':
975 if (strcmp(option, "lineno") == 0)
976 sprintf(cbuf, "set %snu",
977 (strcmp(value, "on") == 0) ? "" : "no");
978 break;
980 case 'p':
981 if (strcmp(option, "parentheses") == 0)
982 sprintf(cbuf, "set %ssm",
983 (strcmp(value, "on") == 0) ? "" : "no");
984 break;
986 case 'w':
987 /* this option is set by a direct call */
988 #ifdef WSDEBUG
989 wsdebug("workshop_set_option: "
990 "Got unexpected workshopkeys option");
991 #endif
992 break;
994 case 'b': /* these options are set from direct calls */
995 if (option[7] == NUL && strcmp(option, "balloon") == 0)
997 #ifdef WSDEBUG
998 /* set by direct call to workshop_balloon_mode */
999 wsdebug("workshop_set_option: "
1000 "Got unexpected ballooneval option");
1001 #endif
1003 else if (strcmp(option, "balloondelay") == 0)
1005 #ifdef WSDEBUG
1006 /* set by direct call to workshop_balloon_delay */
1007 wsdebug("workshop_set_option: "
1008 "Got unexpected balloondelay option");
1009 #endif
1011 break;
1013 if (cbuf[0] != NUL)
1014 coloncmd(cbuf, TRUE);
1018 void
1019 workshop_balloon_mode(
1020 Boolean on)
1022 char cbuf[BUFSIZ]; /* command buffer */
1024 #ifdef WSDEBUG_TRACE
1025 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1026 wstrace("workshop_balloon_mode(%s)\n", on ? "True" : "False");
1027 #endif
1029 sprintf(cbuf, "set %sbeval", on ? "" : "no");
1030 coloncmd(cbuf, TRUE);
1034 void
1035 workshop_balloon_delay(
1036 int delay)
1038 char cbuf[BUFSIZ]; /* command buffer */
1040 #ifdef WSDEBUG_TRACE
1041 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1042 wstrace("workshop_balloon_delay(%d)\n", delay);
1043 #endif
1045 sprintf(cbuf, "set bdlay=%d", delay);
1046 coloncmd(cbuf, TRUE);
1050 void
1051 workshop_show_balloon_tip(
1052 char *tip)
1054 #ifdef WSDEBUG_TRACE
1055 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1056 wstrace("workshop_show_balloon_tip(%s)\n", tip);
1057 #endif
1059 if (balloonEval != NULL)
1060 gui_mch_post_balloon(balloonEval, (char_u *)tip);
1064 void
1065 workshop_hotkeys(
1066 Boolean on)
1068 char cbuf[BUFSIZ]; /* command buffer */
1069 MenuMap *mp; /* iterate over menuMap entries */
1071 #ifdef WSDEBUG_TRACE
1072 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1073 wstrace("workshop_hotkeys(%s)\n", on ? "True" : "False");
1074 #endif
1076 workshopHotKeysEnabled = on;
1077 if (workshopHotKeysEnabled)
1078 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++)
1080 if (mp->accel != NULL)
1082 vim_snprintf(cbuf, sizeof(cbuf),
1083 "map %s :wsverb %s<CR>", mp->accel, mp->verb);
1084 coloncmd(cbuf, TRUE);
1087 else
1088 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++)
1090 if (mp->accel != NULL)
1092 vim_snprintf(cbuf, sizeof(cbuf), "unmap %s", mp->accel);
1093 coloncmd(cbuf, TRUE);
1099 * A button in the toolbar has been pushed.
1102 workshop_get_positions(
1103 void *clientData UNUSED,
1104 char **filename, /* output data */
1105 int *curLine, /* output data */
1106 int *curCol, /* output data */
1107 int *selStartLine, /* output data */
1108 int *selStartCol, /* output data */
1109 int *selEndLine, /* output data */
1110 int *selEndCol, /* output data */
1111 int *selLength, /* output data */
1112 char **selection) /* output data */
1114 static char ffname[MAXPATHLEN];
1116 #ifdef WSDEBUG_TRACE
1117 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1118 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1119 clientData, (curbuf && curbuf->b_sfname != NULL)
1120 ? (char *)curbuf->b_sfname : "<None>");
1121 #endif
1123 if (curbuf->b_ffname == NULL)
1124 ffname[0] = NUL;
1125 else
1126 /* copy so nobody can change b_ffname */
1127 strcpy(ffname, (char *) curbuf->b_ffname);
1128 *filename = ffname;
1129 *curLine = curwin->w_cursor.lnum;
1130 *curCol = curwin->w_cursor.col;
1132 if (curbuf->b_visual.vi_mode == 'v' &&
1133 equalpos(curwin->w_cursor, curbuf->b_visual.vi_end))
1135 *selStartLine = curbuf->b_visual.vi_start.lnum;
1136 *selStartCol = curbuf->b_visual.vi_start.col;
1137 *selEndLine = curbuf->b_visual.vi_end.lnum;
1138 *selEndCol = curbuf->b_visual.vi_end.col;
1139 *selection = get_selection(curbuf);
1140 if (*selection)
1141 *selLength = strlen(*selection);
1142 else
1143 *selLength = 0;
1145 else
1147 *selStartLine = *selEndLine = -1;
1148 *selStartCol = *selEndCol = -1;
1149 *selLength = 0;
1150 *selection = "";
1153 return True;
1158 /************************************************************************
1159 * Utility functions
1160 ************************************************************************/
1162 static char *
1163 get_selection(
1164 buf_T *buf) /* buffer whose selection we want */
1166 pos_T *start; /* start of the selection */
1167 pos_T *end; /* end of the selection */
1168 char *lp; /* pointer to actual line data */
1169 int llen; /* length of actual line data */
1170 char *sp; /* pointer to selection buffer */
1171 int slen; /* string length in selection buffer */
1172 int size; /* size of selection buffer */
1173 char *new_sp; /* temp pointer to new sp */
1174 int lnum; /* line number we are appending */
1176 if (buf->b_visual.vi_mode == 'v')
1178 start = &buf->b_visual.vi_start;
1179 end = &buf->b_visual.vi_end;
1180 if (start->lnum == end->lnum)
1182 /* selection is all on one line */
1183 lp = (char *) ml_get_pos(start);
1184 llen = end->col - start->col + 1;
1185 sp = (char *) malloc(llen + 1);
1186 if (sp != NULL)
1188 strncpy(sp, lp, llen);
1189 sp[llen] = NUL;
1192 else
1194 /* multi-line selection */
1195 lp = (char *) ml_get_pos(start);
1196 llen = strlen(lp);
1197 sp = (char *) malloc(BUFSIZ + llen);
1198 if (sp != NULL)
1200 size = BUFSIZ + llen;
1201 strcpy(sp, lp);
1202 sp[llen] = '\n';
1203 slen = llen + 1;
1205 lnum = start->lnum + 1;
1206 while (lnum < end->lnum)
1207 sp = append_selection(lnum++, sp, &size, &slen);
1209 lp = (char *) ml_get(end->lnum);
1210 llen = end->col + 1;
1211 if ((slen + llen) >= size)
1213 new_sp = (char *)
1214 realloc(sp, slen + llen + 1);
1215 if (new_sp != NULL)
1217 size += llen + 1;
1218 sp = new_sp;
1221 if ((slen + llen) < size)
1223 strncpy(&sp[slen], lp, llen);
1224 sp[slen + llen] = NUL;
1230 else
1231 sp = NULL;
1233 return sp;
1236 static char *
1237 append_selection(
1238 int lnum, /* line number to append */
1239 char *sp, /* pointer to selection buffer */
1240 int *size, /* ptr to size of sp */
1241 int *slen) /* ptr to length of selection string */
1243 char *lp; /* line of data from buffer */
1244 int llen; /* strlen of lp */
1245 char *new_sp; /* temp pointer to new sp */
1247 lp = (char *)ml_get((linenr_T)lnum);
1248 llen = strlen(lp);
1250 if ((*slen + llen) <= *size)
1252 new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen);
1253 if (*new_sp != NUL)
1255 *size = BUFSIZ + *slen + llen;
1256 sp = new_sp;
1259 if ((*slen + llen) > *size)
1261 strcat(&sp[*slen], lp);
1262 *slen += llen;
1263 sp[*slen++] = '\n';
1266 return sp;
1271 static void
1272 load_buffer_by_name(
1273 char *filename, /* the file to load */
1274 int lnum) /* an optional line number (or 0) */
1276 char lnumbuf[16]; /* make line number option for :e */
1277 char cbuf[BUFSIZ]; /* command buffer */
1279 if (lnum > 0)
1280 sprintf(lnumbuf, "+%d", lnum);
1281 else
1282 lnumbuf[0] = NUL;
1284 vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename);
1285 coloncmd(cbuf, False);
1289 static void
1290 load_window(
1291 char *filename, /* filename to load */
1292 int lnum) /* linenumber to go to */
1294 buf_T *buf; /* buffer filename is stored in */
1295 win_T *win; /* window filenme is displayed in */
1298 * Make sure filename is displayed and is the current window.
1301 buf = buflist_findname((char_u *)filename);
1302 if (buf == NULL || (win = get_window(buf)) == NULL)
1304 /* No buffer or buffer is not in current window */
1305 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1306 filename, lnum); */
1307 load_buffer_by_name(filename, lnum);
1309 else
1311 /* buf is in a window */
1312 if (win != curwin)
1314 win_enter(win, False);
1315 /* wsdebug("load_window: window endter %s\n",
1316 win->w_buffer->b_sfname); */
1318 if (lnum > 0 && win->w_cursor.lnum != lnum)
1320 warp_to_pc(lnum);
1321 /* wsdebug("load_window: warp to %s[%d]\n",
1322 win->w_buffer->b_sfname, lnum); */
1325 out_flush();
1330 static void
1331 warp_to_pc(
1332 int lnum) /* line number to warp to */
1334 char lbuf[256]; /* build line command here */
1336 if (lnum > 0)
1338 if (State & INSERT)
1339 add_to_input_buf((char_u *) "\033", 1);
1340 if (isShowing(lnum))
1341 sprintf(lbuf, "%dG", lnum);
1342 else
1343 sprintf(lbuf, "%dz.", lnum);
1344 add_to_input_buf((char_u *) lbuf, strlen(lbuf));
1348 static Boolean
1349 isShowing(
1350 int lnum) /* tell if line number is showing */
1352 return lnum >= curwin->w_topline && lnum < curwin->w_botline;
1357 static win_T *
1358 get_window(
1359 buf_T *buf) /* buffer to find window for */
1361 win_T *wp = NULL; /* window filename is in */
1363 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
1364 if (buf == wp->w_buffer)
1365 break;
1366 return wp;
1370 #if 0 /* not used */
1371 static int
1372 get_buffer_number(
1373 buf_T *buf) /* buffer to get position of */
1375 buf_T *bp; /* iterate over buffer list */
1376 int pos; /* the position in the buffer list */
1378 pos = 1;
1379 for (bp = firstbuf; bp != NULL; bp = bp->b_next)
1381 if (bp == buf)
1382 return pos;
1383 pos++;
1386 return 1;
1388 #endif
1390 static void
1391 updatePriority(
1392 Boolean subMenu) /* if True then start new submenu pri */
1394 int pri; /* priority of this menu/item */
1395 char *p;
1397 p = strrchr(curMenuPriority, '.');
1398 ASSERT(p != NULL);
1399 *p++ = NUL;
1401 pri = atoi(p) + 10; /* our new priority */
1403 if (subMenu)
1404 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1405 "%s.%d.0", curMenuPriority, pri);
1406 else
1407 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1408 "%s.%d", curMenuPriority, pri);
1411 static char *
1412 addUniqueMnemonic(
1413 char *mnemonics, /* currently used mnemonics */
1414 char *label) /* label of menu needing mnemonic */
1416 static char name[BUFSIZ]; /* buffer for the updated name */
1417 char *p; /* pointer into label */
1418 char *found; /* pointer to possible mnemonic */
1420 found = NULL;
1421 for (p = label; *p != NUL; p++)
1422 if (strchr(mnemonics, *p) == 0)
1423 if (found == NULL || (isupper((int)*p) && islower((int)*found)))
1424 found = p;
1426 if (found != NULL)
1428 strncpy(name, label, (found - label));
1429 strcat(name, "&");
1430 strcat(name, found);
1432 else
1433 strcpy(name, label);
1435 return name;
1439 * Some characters in a menu name must be escaped in vim. Since this is vim
1440 * specific, it must be done on this side.
1442 static char *
1443 fixup(
1444 char *label)
1446 static char buf[BUFSIZ];
1447 char *bp; /* pointer into buf */
1448 char *lp; /* pointer into label */
1450 lp = label;
1451 bp = buf;
1452 while (*lp != NUL)
1454 if (*lp == ' ' || *lp == '.')
1455 *bp++ = '\\';
1456 *bp++ = *lp++;
1458 *bp = NUL;
1460 return buf;
1464 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1466 /* For the NoHands test suite */
1468 char *
1469 workshop_test_getcurrentfile()
1471 char *filename, *selection;
1472 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1473 int selEndCol, selLength;
1475 if (workshop_get_positions(
1476 NULL, &filename, &curLine, &curCol, &selStartLine,
1477 &selStartCol, &selEndLine, &selEndCol, &selLength,
1478 &selection))
1479 return filename;
1480 else
1481 return NULL;
1485 workshop_test_getcursorrow()
1487 return 0;
1491 workshop_test_getcursorcol()
1493 char *filename, *selection;
1494 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1495 int selEndCol, selLength;
1497 if (workshop_get_positions(
1498 NULL, &filename, &curLine, &curCol, &selStartLine,
1499 &selStartCol, &selEndLine, &selEndCol, &selLength,
1500 &selection))
1501 return curCol;
1502 else
1503 return -1;
1506 char *
1507 workshop_test_getcursorrowtext()
1509 return NULL;
1512 char *
1513 workshop_test_getselectedtext()
1515 char *filename, *selection;
1516 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1517 int selEndCol, selLength;
1519 if (workshop_get_positions(
1520 NULL, &filename, &curLine, &curCol, &selStartLine,
1521 &selStartCol, &selEndLine, &selEndCol, &selLength,
1522 &selection))
1523 return selection;
1524 else
1525 return NULL;
1528 void
1529 workshop_save_sensitivity(char *filename UNUSED)
1533 #endif
1535 static char *
1536 fixAccelText(
1537 char *ap) /* original acceleratorText */
1539 char buf[256]; /* build in temp buffer */
1540 char *shift; /* shift string of "" */
1542 if (ap == NULL)
1543 return NULL;
1545 /* If the accelerator is shifted use the vim form */
1546 if (strncmp("Shift+", ap, 6) == 0)
1548 shift = "S-";
1549 ap += 6;
1551 else
1552 shift = "";
1554 if (*ap == 'F' && atoi(&ap[1]) > 0)
1556 vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap);
1557 return strdup(buf);
1559 else
1560 return NULL;
1563 #ifdef FEAT_BEVAL
1564 void
1565 workshop_beval_cb(
1566 BalloonEval *beval,
1567 int state)
1569 win_T *wp;
1570 char_u *text;
1571 int type;
1572 linenr_T lnum;
1573 int col;
1574 int idx;
1575 char buf[MAXPATHLEN * 2];
1576 static int serialNo = -1;
1578 if (!p_beval)
1579 return;
1581 if (get_beval_info(beval, FALSE, &wp, &lnum, &text, &col) == OK)
1583 if (text && text[0])
1585 /* Send debugger request */
1586 if (strlen((char *) text) > (MAXPATHLEN/2))
1589 * The user has probably selected the entire
1590 * buffer or something like that - don't attempt
1591 * to evaluate it
1593 return;
1597 * WorkShop expects the col to be a character index, not
1598 * a column number. Compute the index from col. Also set
1599 * line to 0 because thats what dbx expects.
1601 #ifdef FEAT_VARTABS
1602 idx = computeIndex(col, text, beval->ts, beval->vts);
1603 #else
1604 idx = computeIndex(col, text, beval->ts);
1605 #endif
1606 if (idx > 0)
1608 lnum = 0;
1611 * If successful, it will respond with a balloon cmd.
1613 if (state & ControlMask)
1614 /* Evaluate *(expression) */
1615 type = (int)GPLineEval_INDIRECT;
1616 else if (state & ShiftMask)
1617 /* Evaluate type(expression) */
1618 type = (int)GPLineEval_TYPE;
1619 else
1620 /* Evaluate value(expression) */
1621 type = (int)GPLineEval_EVALUATE;
1623 /* Send request to dbx */
1624 vim_snprintf(buf, sizeof(buf), "toolVerb debug.balloonEval "
1625 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1626 (char *)wp->w_buffer->b_ffname,
1627 (long)lnum, idx, type, serialNo++,
1628 (long)strlen((char *)text), (char *)text);
1629 balloonEval = beval;
1630 workshop_send_message(buf);
1636 static int
1637 computeIndex(
1638 int wantedCol,
1639 char_u *line,
1640 int ts
1641 #ifdef FEAT_VARTABS
1642 int *vts
1643 #else
1646 int col = 0;
1647 int idx = 0;
1649 while (line[idx])
1651 if (line[idx] == '\t')
1652 #ifdef FEAT_VARTABS
1653 col += tabstop_padding(col, ts, vts);
1654 #else
1655 col += ts - (col % ts);
1656 #endif
1657 else
1658 col++;
1659 idx++;
1660 if (col >= wantedCol)
1661 return idx;
1664 return -1;
1666 #endif
1668 static void
1669 addMenu(
1670 char *menu, /* menu name */
1671 char *accel, /* accelerator text (optional) */
1672 char *verb) /* WorkShop action-verb */
1674 MenuMap *newMap;
1675 char cbuf[BUFSIZ];
1677 if (menuMapSize >= menuMapMax)
1679 newMap = realloc(menuMap,
1680 sizeof(MenuMap) * (menuMapMax + MENU_INC));
1681 if (newMap != NULL)
1683 menuMap = newMap;
1684 menuMapMax += MENU_INC;
1687 if (menuMapSize < menuMapMax)
1689 menuMap[menuMapSize].name = strdup(menu);
1690 menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL;
1691 menuMap[menuMapSize++].verb = strdup(verb);
1692 if (accel && workshopHotKeysEnabled)
1694 vim_snprintf(cbuf, sizeof(cbuf),
1695 "map %s :wsverb %s<CR>", accel, verb);
1696 coloncmd(cbuf, TRUE);
1701 static char *
1702 nameStrip(
1703 char *raw) /* menu name, possibly with & chars */
1705 static char buf[BUFSIZ]; /* build stripped name here */
1706 char *bp = buf;
1708 while (*raw)
1710 if (*raw != '&')
1711 *bp++ = *raw;
1712 raw++;
1714 *bp = NUL;
1715 return buf;
1719 static char *
1720 lookupVerb(
1721 char *verb,
1722 int skip) /* number of matches to skip */
1724 int i; /* loop iterator */
1726 for (i = 0; i < menuMapSize; i++)
1727 if (strcmp(menuMap[i].verb, verb) == 0 && skip-- == 0)
1728 return nameStrip(menuMap[i].name);
1730 return NULL;
1734 static void
1735 coloncmd(
1736 char *cmd, /* the command to print */
1737 Boolean force) /* force cursor update */
1739 char_u *cpo_save = p_cpo;
1741 #ifdef WSDEBUG
1742 if (WSDLEVEL(WS_TRACE_COLONCMD))
1743 wsdebug("Cmd: %s\n", cmd);
1744 #endif
1746 p_cpo = empty_option;
1748 ALT_INPUT_LOCK_ON;
1749 do_cmdline_cmd((char_u *)cmd);
1750 ALT_INPUT_LOCK_OFF;
1752 p_cpo = cpo_save;
1754 if (force)
1755 gui_update_screen();
1759 * setDollarVim - Given the run directory, search for the vim install
1760 * directory and set $VIM.
1762 * We can be running out of SUNWspro/bin or out of
1763 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1764 * relative to both of these directories.
1766 static void
1767 setDollarVim(
1768 char *rundir)
1770 char buf[MAXPATHLEN];
1771 char *cp;
1774 * First case: Running from <install-dir>/SUNWspro/bin
1776 strcpy(buf, rundir);
1777 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1778 VIM_VERSION_NODOT "/syntax/syntax.vim");
1779 if (access(buf, R_OK) == 0)
1781 strcpy(buf, "SPRO_WSDIR=");
1782 strcat(buf, rundir);
1783 cp = strrchr(buf, '/');
1784 if (cp != NULL)
1785 strcpy(cp, "/WS6U2");
1786 putenv(strdup(buf));
1788 strcpy(buf, "VIM=");
1789 strcat(buf, rundir);
1790 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1791 VIM_VERSION_NODOT);
1792 putenv(strdup(buf));
1793 return;
1797 * Second case: Probably running from
1798 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1800 strcpy(buf, rundir);
1801 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1802 "/share/vim/" VIM_VERSION_NODOT "/syntax/syntax.vim");
1803 if (access(buf, R_OK) == 0)
1805 strcpy(buf, "SPRO_WSDIR=");
1806 strcat(buf, rundir);
1807 cp = strrchr(buf, '/');
1808 if (cp != NULL)
1809 strcpy(cp, "../../../../WS6U2");
1810 putenv(strdup(buf));
1812 strcpy(buf, "VIM=");
1813 strcat(buf, rundir);
1814 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1815 "/share/vim/" VIM_VERSION_NODOT);
1816 putenv(strdup(buf));
1817 return;
1822 * findYourself - Find the directory we are running from. This is used to
1823 * set $VIM. We need to set this because users can install
1824 * the package in a different directory than the compiled
1825 * directory. This is a Sun Visual WorkShop requirement!
1827 * Note: We override a user's $VIM because it won't have the
1828 * WorkShop specific files. S/he may not like this but its
1829 * better than getting the wrong files (especially as the
1830 * user is likely to have $VIM set to 5.4 or later).
1832 void
1833 findYourself(
1834 char *argv0)
1836 char *runpath = NULL;
1837 char *path;
1838 char *pathbuf;
1840 if (*argv0 == '/')
1841 runpath = strdup(argv0);
1842 else if (*argv0 == '.' || strchr(argv0, '/'))
1844 runpath = (char *) malloc(MAXPATHLEN);
1845 getcwd(runpath, MAXPATHLEN);
1846 strcat(runpath, "/");
1847 strcat(runpath, argv0);
1849 else
1851 path = getenv("PATH");
1852 if (path != NULL)
1854 runpath = (char *) malloc(MAXPATHLEN);
1855 pathbuf = strdup(path);
1856 path = strtok(pathbuf, ":");
1859 strcpy(runpath, path);
1860 strcat(runpath, "/");
1861 strcat(runpath, argv0);
1862 if (access(runpath, X_OK) == 0)
1863 break;
1864 } while ((path = strtok(NULL, ":")) != NULL);
1865 free(pathbuf);
1869 if (runpath != NULL)
1871 char runbuf[MAXPATHLEN];
1874 * We found the run directory. Now find the install dir.
1876 (void)vim_FullName((char_u *)runpath, (char_u *)runbuf, MAXPATHLEN, 1);
1877 path = strrchr(runbuf, '/');
1878 if (path != NULL)
1879 *path = NUL; /* remove the vim/gvim name */
1880 path = strrchr(runbuf, '/');
1881 if (path != NULL)
1883 if (strncmp(path, "/bin", 4) == 0)
1884 setDollarVim(runbuf);
1885 else if (strncmp(path, "/src", 4) == 0)
1887 *path = NUL; /* development tree */
1888 setDollarVim(runbuf);
1891 free(runpath);