Merge branch 'vim-with-runtime' into feat/rel-line-numbers
[vim_extended.git] / src / workshop.c
blob7d4e891f3612ca1bd4def04ea855392a828c5f30
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 static int computeIndex(int, char_u *, int);
61 #endif
62 static char *fixAccelText(char *);
63 static void addMenu(char *, char *, char *);
64 static char *lookupVerb(char *, int);
65 static void coloncmd(char *, Boolean);
67 extern Widget vimShell;
68 extern Widget textArea;
69 extern XtAppContext app_context;
71 static int tbpri; /* ToolBar priority */
72 int usingSunWorkShop = 0; /* set if -ws flag is used */
73 char curMenuName[BUFSIZ];
74 char curMenuPriority[BUFSIZ];
76 static Boolean workshopInitDone = False;
77 static Boolean workshopHotKeysEnabled = False;
80 * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it
81 * here because its C++.
83 enum
85 GPLineEval_EVALUATE, /* evaluate expression */
86 GPLineEval_INDIRECT, /* evaluate *<expression> */
87 GPLineEval_TYPE /* type of expression */
91 * Store each verb in the MenuMap. This lets us map from a verb to a menu.
92 * There may be multiple matches for a single verb in this table.
94 #define MENU_INC 50 /* menuMap incremental size increases */
95 typedef struct
97 char *name; /* name of the menu */
98 char *accel; /* optional accelerator key */
99 char *verb; /* menu verb */
100 } MenuMap;
101 static MenuMap *menuMap; /* list of verb/menu mappings */
102 static int menuMapSize; /* current size of menuMap */
103 static int menuMapMax; /* allocated size of menuMap */
104 static char *initialFileCmd; /* save command but defer doing it */
107 void
108 workshop_init()
110 char_u buf[64];
111 int is_dirty = FALSE;
112 int width, height;
113 XtInputMask mask;
116 * Turn on MenuBar, ToolBar, and Footer.
118 STRCPY(buf, p_go);
119 if (vim_strchr(p_go, GO_MENUS) == NULL)
121 STRCAT(buf, "m");
122 is_dirty = TRUE;
124 if (vim_strchr(p_go, GO_TOOLBAR) == NULL)
126 STRCAT(buf, "T");
127 is_dirty = TRUE;
129 if (vim_strchr(p_go, GO_FOOTER) == NULL)
131 STRCAT(buf, "F");
132 is_dirty = TRUE;
134 if (is_dirty)
135 set_option_value((char_u *)"go", 0L, buf, 0);
138 * Set size from workshop_get_width_height().
140 width = height = 0;
141 if (workshop_get_width_height(&width, &height))
143 XtVaSetValues(vimShell,
144 XmNwidth, width,
145 XmNheight, height,
146 NULL);
150 * Now read in the initial messages from eserve.
152 while ((mask = XtAppPending(app_context))
153 && (mask & XtIMAlternateInput) && !workshopInitDone)
154 XtAppProcessEvent(app_context, (XtInputMask)XtIMAlternateInput);
157 void
158 workshop_postinit()
160 do_cmdline_cmd((char_u *)initialFileCmd);
161 ALT_INPUT_LOCK_OFF;
162 free(initialFileCmd);
163 initialFileCmd = NULL;
166 void
167 ex_wsverb(exarg_T *eap)
169 msg_clr_cmdline();
170 workshop_perform_verb((char *) eap->arg, NULL);
174 * Editor name
175 * This string is recognized by eserve and should be all lower case.
176 * This is how the editor detects that it is talking to gvim instead
177 * of NEdit, for example, when the connection is initiated from the editor.
179 char *
180 workshop_get_editor_name()
182 return "gvim";
186 * Version number of the editor.
187 * This number is communicated along with the protocol
188 * version to the application.
190 char *
191 workshop_get_editor_version()
193 return Version;
197 * Answer functions: called by eserve
201 * Name:
202 * workshop_load_file
204 * Function:
205 * Load a given file into the WorkShop buffer.
207 void
208 workshop_load_file(
209 char *filename, /* the file to load */
210 int line, /* an optional line number (or 0) */
211 char *frameid UNUSED) /* used for multi-frame support */
213 #ifdef WSDEBUG_TRACE
214 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
215 wstrace("workshop_load_file(%s, %d)\n", filename, line);
216 #endif
218 #ifdef FEAT_BEVAL
219 bevalServers |= BEVAL_WORKSHOP;
220 #endif
222 load_window(filename, line);
226 * Reload the WorkShop buffer
228 void
229 workshop_reload_file(
230 char *filename,
231 int line)
233 #ifdef WSDEBUG_TRACE
234 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
235 wstrace("workshop_reload_file(%s, %d)\n", filename, line);
236 #endif
237 load_window(filename, line);
240 void
241 workshop_show_file(
242 char *filename)
244 #ifdef WSDEBUG_TRACE
245 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
246 wstrace("workshop_show_file(%s)\n", filename);
247 #endif
249 load_window(filename, 0);
252 void
253 workshop_goto_line(
254 char *filename,
255 int lineno)
257 #ifdef WSDEBUG_TRACE
258 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
259 wstrace("workshop_goto_line(%s, %d)\n", filename, lineno);
260 #endif
262 load_window(filename, lineno);
265 void
266 workshop_front_file(
267 char *filename UNUSED)
269 #ifdef WSDEBUG_TRACE
270 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
271 wstrace("workshop_front_file()\n");
272 #endif
274 * Assumption: This function will always be called after a call to
275 * workshop_show_file(), so the file is always showing.
277 if (vimShell != NULL)
278 XRaiseWindow(gui.dpy, XtWindow(vimShell));
281 void
282 workshop_save_file(
283 char *filename)
285 char cbuf[BUFSIZ]; /* build vim command here */
287 #ifdef WSDEBUG_TRACE
288 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
289 wstrace("workshop_save_file(%s)\n", filename);
290 #endif
292 /* Save the given file */
293 vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename);
294 coloncmd(cbuf, TRUE);
297 void
298 workshop_save_files()
300 /* Save the given file */
301 #ifdef WSDEBUG_TRACE
302 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
303 wstrace("workshop_save_files()\n");
304 #endif
306 add_to_input_buf((char_u *) ":wall\n", 6);
309 void
310 workshop_quit()
312 #ifdef WSDEBUG_TRACE
313 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
314 wstrace("workshop_quit()\n");
315 #endif
317 add_to_input_buf((char_u *) ":qall\n", 6);
320 void
321 workshop_minimize()
323 #ifdef WSDEBUG_TRACE
324 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
325 wstrace("workshop_minimize()\n");
326 #endif
327 workshop_minimize_shell(vimShell);
329 void
330 workshop_maximize()
332 #ifdef WSDEBUG_TRACE
333 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
334 wstrace("workshop_maximize()\n");
335 #endif
337 workshop_maximize_shell(vimShell);
340 void
341 workshop_add_mark_type(
342 int idx,
343 char *colorspec,
344 char *sign)
346 char gbuf[BUFSIZ]; /* buffer for sign name */
347 char cibuf[BUFSIZ]; /* color information */
348 char cbuf[BUFSIZ]; /* command buffer */
349 char *bp;
351 #ifdef WSDEBUG_TRACE
352 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
354 char *cp;
356 cp = strrchr(sign, '/');
357 if (cp == NULL)
358 cp = sign;
359 else
360 cp++; /* skip '/' character */
361 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx,
362 colorspec && *colorspec ? colorspec : "<None>", cp);
364 #endif
367 * Isolate the basename of sign in gbuf. We will use this for the
368 * GroupName in the highlight command sent to vim.
370 STRCPY(gbuf, gettail((char_u *)sign));
371 bp = strrchr(gbuf, '.');
372 if (bp != NULL)
373 *bp = NUL;
375 if (gbuf[0] != '-' && gbuf[1] != NUL)
377 if (colorspec != NULL && *colorspec)
379 vim_snprintf(cbuf, sizeof(cbuf),
380 "highlight WS%s guibg=%s", gbuf, colorspec);
381 coloncmd(cbuf, FALSE);
382 vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf);
384 else
385 cibuf[0] = NUL;
387 vim_snprintf(cbuf, sizeof(cbuf),
388 "sign define %d %s icon=%s", idx, cibuf, sign);
389 coloncmd(cbuf, TRUE);
393 void
394 workshop_set_mark(
395 char *filename, /* filename which gets the mark */
396 int lineno, /* line number which gets the mark */
397 int markId, /* unique mark identifier */
398 int idx) /* which mark to use */
400 char cbuf[BUFSIZ]; /* command buffer */
402 /* Set mark in a given file */
403 #ifdef WSDEBUG_TRACE
404 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
405 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n",
406 filename, lineno, markId, idx);
407 #endif
409 vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s",
410 markId, lineno, idx, filename);
411 coloncmd(cbuf, TRUE);
414 void
415 workshop_change_mark_type(
416 char *filename, /* filename which gets the mark */
417 int markId, /* unique mark identifier */
418 int idx) /* which mark to use */
420 char cbuf[BUFSIZ]; /* command buffer */
422 /* Change mark type */
423 #ifdef WSDEBUG_TRACE
424 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
425 wstrace("workshop_change_mark_type(%s, %d, %d)\n",
426 filename, markId, idx);
427 #endif
429 vim_snprintf(cbuf, sizeof(cbuf),
430 "sign place %d name=%d file=%s", markId, idx, filename);
431 coloncmd(cbuf, TRUE);
435 * Goto the given mark in a file (e.g. show it).
436 * If message is not null, display it in the footer.
438 void
439 workshop_goto_mark(
440 char *filename,
441 int markId,
442 char *message)
444 char cbuf[BUFSIZ]; /* command buffer */
446 /* Goto mark */
447 #ifdef WSDEBUG_TRACE
448 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
449 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
450 filename, markId, message && *message &&
451 !(*message == ' ' && message[1] == NULL) ?
452 message : "<None>");
453 #endif
455 vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename);
456 coloncmd(cbuf, TRUE);
457 if (message != NULL && *message != NUL)
458 gui_mch_set_footer((char_u *)message);
461 void
462 workshop_delete_mark(
463 char *filename,
464 int markId)
466 char cbuf[BUFSIZ]; /* command buffer */
468 /* Delete mark */
469 #ifdef WSDEBUG_TRACE
470 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
471 wstrace("workshop_delete_mark(%s, %d (id))\n",
472 filename, markId);
473 #endif
475 vim_snprintf(cbuf, sizeof(cbuf),
476 "sign unplace %d file=%s", markId, filename);
477 coloncmd(cbuf, TRUE);
480 #if 0 /* not used */
481 void
482 workshop_delete_all_marks(
483 void *window,
484 Boolean doRefresh)
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
492 coloncmd("sign unplace *", TRUE);
494 #endif
497 workshop_get_mark_lineno(
498 char *filename,
499 int markId)
501 buf_T *buf; /* buffer containing filename */
502 int lineno; /* line number of filename in buf */
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
511 lineno = 0;
512 buf = buflist_findname((char_u *)filename);
513 if (buf != NULL)
514 lineno = buf_findsign(buf, markId);
516 return lineno;
520 #if 0 /* not used */
521 void
522 workshop_adjust_marks(Widget *window, int pos,
523 int inserted, int deleted)
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
531 #endif
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.
539 void
540 workshop_moved_marks(char *filename UNUSED)
542 #ifdef WSDEBUG_TRACE
543 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
544 wstrace("XXXworkshop_moved_marks(%s)\n", filename);
545 #endif
549 workshop_get_font_height()
551 XmFontList fontList; /* fontList made from gui.norm_font */
552 XmString str;
553 Dimension w;
554 Dimension h;
556 #ifdef WSDEBUG_TRACE
557 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
558 wstrace("workshop_get_font_height()\n");
559 #endif
561 /* Pick the proper signs for this font size */
562 fontList = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
563 h = 0;
564 if (fontList != NULL)
566 str = XmStringCreateLocalized("A");
567 XmStringExtent(fontList, str, &w, &h);
568 XmStringFree(str);
569 XmFontListFree(fontList);
572 return (int)h;
575 void
576 workshop_footer_message(
577 char *message,
578 int severity UNUSED) /* severity is currently unused */
580 #ifdef WSDEBUG_TRACE
581 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
582 wstrace("workshop_footer_message(%s, %d)\n", message, severity);
583 #endif
585 gui_mch_set_footer((char_u *) message);
589 * workshop_menu_begin() is passed the menu name. We determine its mnemonic
590 * here and store its name and priority.
592 void
593 workshop_menu_begin(
594 char *label)
596 vimmenu_T *menu; /* pointer to last menu */
597 int menuPriority = 0; /* priority of new menu */
598 char mnembuf[64]; /* store menubar mnemonics here */
599 char *name; /* label with a mnemonic */
600 char *p; /* used to find mnemonics */
601 int idx; /* index into mnembuf */
603 #ifdef WSDEBUG_TRACE
604 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
605 wstrace("workshop_menu_begin()\n");
606 #endif
609 * Look through all existing (non-PopUp and non-Toolbar) menus
610 * and gather their mnemonics. Use this list to decide what
611 * mnemonic should be used for label.
614 idx = 0;
615 mnembuf[idx++] = 'H'; /* H is mnemonic for Help */
616 for (menu = root_menu; menu != NULL; menu = menu->next)
618 if (menu_is_menubar(menu->name))
620 p = strchr((char *)menu->name, '&');
621 if (p != NULL)
622 mnembuf[idx++] = *++p;
624 if (menu->next != NULL
625 && strcmp((char *) menu->next->dname, "Help") == 0)
627 menuPriority = menu->priority + 10;
628 break;
631 mnembuf[idx++] = NUL;
632 name = addUniqueMnemonic(mnembuf, label);
634 vim_snprintf(curMenuName, sizeof(curMenuName), "%s", name);
635 sprintf(curMenuPriority, "%d.0", menuPriority);
639 * Append the name and priority to strings to be used in vim menu commands.
641 void
642 workshop_submenu_begin(
643 char *label)
645 #ifdef WSDEBUG_TRACE
646 if (ws_debug && ws_dlevel & WS_TRACE
647 && strncmp(curMenuName, "ToolBar", 7) != 0)
648 wstrace("workshop_submenu_begin(%s)\n", label);
649 #endif
651 strcat(curMenuName, ".");
652 strcat(curMenuName, fixup(label));
654 updatePriority(True);
658 * Remove the submenu name and priority from curMenu*.
661 void
662 workshop_submenu_end()
664 char *p;
666 #ifdef WSDEBUG_TRACE
667 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)
668 && strncmp(curMenuName, "ToolBar", 7) != 0)
669 wstrace("workshop_submenu_end()\n");
670 #endif
672 p = strrchr(curMenuPriority, '.');
673 ASSERT(p != NULL);
674 *p = NUL;
676 p = strrchr(curMenuName, '.');
677 ASSERT(p != NULL);
678 *p = NUL;
682 * This is where menus are really made. Each item will generate an amenu vim
683 * command. The globals curMenuName and curMenuPriority contain the name and
684 * priority of the parent menu tree.
686 void
687 workshop_menu_item(
688 char *label,
689 char *verb,
690 char *accelerator UNUSED,
691 char *acceleratorText,
692 char *name UNUSED,
693 char *filepos UNUSED,
694 char *sensitive)
696 char cbuf[BUFSIZ];
697 char namebuf[BUFSIZ];
698 char accText[BUFSIZ];
700 #ifdef WSDEBUG_TRACE
701 if (WSDLEVEL(WS_TRACE_VERBOSE)
702 && strncmp(curMenuName, "ToolBar", 7) != 0)
704 if (ws_dlevel & WS_TRACE_VERBOSE)
705 wsdebug("workshop_menu_item(\n"
706 "\tlabel = \"%s\",\n"
707 "\tverb = %s,\n"
708 "\taccelerator = %s,\n"
709 "\tacceleratorText = \"%s\",\n"
710 "\tname = %s,\n"
711 "\tfilepos = %s,\n"
712 "\tsensitive = %s)\n",
713 label && *label ? label : "<None>",
714 verb && *verb ? verb : "<None>",
715 accelerator && *accelerator ?
716 accelerator : "<None>",
717 acceleratorText && *acceleratorText ?
718 acceleratorText : "<None>",
719 name && *name ? name : "<None>",
720 filepos && *filepos ? filepos : "<None>",
721 sensitive);
722 else if (ws_dlevel & WS_TRACE)
723 wstrace("workshop_menu_item(\"%s\", %s)\n",
724 label && *label ? label : "<None>",
725 verb && *verb ? verb : "<None>", sensitive);
727 #endif
728 #ifdef WSDEBUG_SENSE
729 if (ws_debug)
730 wstrace("menu: %-21.20s%-21.20s(%s)\n", label, verb,
731 *sensitive == '1' ? "Sensitive" : "Insensitive");
732 #endif
734 if (acceleratorText != NULL)
735 vim_snprintf(accText, sizeof(accText), "<Tab>%s", acceleratorText);
736 else
737 accText[0] = NUL;
738 updatePriority(False);
739 vim_snprintf(namebuf, sizeof(namebuf), "%s.%s", curMenuName, fixup(label));
740 vim_snprintf(cbuf, sizeof(cbuf), "amenu %s %s%s\t:wsverb %s<CR>",
741 curMenuPriority, namebuf, accText, verb);
743 coloncmd(cbuf, TRUE);
744 addMenu(namebuf, fixAccelText(acceleratorText), verb);
746 if (*sensitive == '0')
748 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
749 coloncmd(cbuf, TRUE);
754 * This function is called when a complete WorkShop menu description has been
755 * sent over from eserve. We do some menu cleanup.
758 void
759 workshop_menu_end()
761 Boolean using_tearoff; /* set per current option setting */
763 #ifdef WSDEBUG_TRACE
764 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
765 wstrace("workshop_menu_end()\n");
766 #endif
768 using_tearoff = vim_strchr(p_go, GO_TEAROFF) != NULL;
769 gui_mch_toggle_tearoffs(using_tearoff);
772 void
773 workshop_toolbar_begin()
775 #ifdef WSDEBUG_TRACE
776 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
777 wstrace("workshop_toolbar_begin()\n");
778 #endif
780 coloncmd("aunmenu ToolBar", True);
781 tbpri = 10;
784 void
785 workshop_toolbar_end()
787 char_u buf[64];
789 #ifdef WSDEBUG_TRACE
790 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
792 wstrace("workshop_toolbar_end()\n");
794 #endif
797 * Turn on ToolBar.
799 STRCPY(buf, p_go);
800 if (vim_strchr(p_go, 'T') == NULL)
802 STRCAT(buf, "T");
803 set_option_value((char_u *)"go", 0L, buf, 0);
805 workshopInitDone = True;
808 void
809 workshop_toolbar_button(
810 char *label,
811 char *verb,
812 char *senseVerb UNUSED,
813 char *filepos UNUSED,
814 char *help,
815 char *sense,
816 char *file,
817 char *left)
819 char cbuf[BUFSIZ + MAXPATHLEN];
820 char namebuf[BUFSIZ];
821 static int tbid = 1;
822 char_u *p;
823 int len;
825 #ifdef WSDEBUG_TRACE
826 if (WSDLEVEL(WS_TRACE_VERBOSE))
827 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
828 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
829 label && *label ? label : "<None>",
830 verb && *verb ? verb : "<None>",
831 senseVerb && *senseVerb ? senseVerb : "<None>",
832 filepos && *filepos ? filepos : "<None>",
833 help && *help ? help : "<None>",
834 sense && *sense ? sense : "<None>",
835 file && *file ? file : "<None>",
836 left && *left ? left : "<None>");
837 else if (WSDLEVEL(WS_TRACE))
838 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
839 label && *label ? label : "<None>",
840 verb && *verb ? verb : "<None>");
841 #endif
842 #ifdef WSDEBUG_SENSE
843 if (ws_debug)
844 wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb,
845 *sense == '1' ? "Sensitive" : "Insensitive");
846 #endif
848 if (left && *left && atoi(left) > 0)
850 /* Add a separator (but pass the width passed after the ':') */
851 sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
852 tbpri - 5, tbid++, left);
854 coloncmd(cbuf, True);
857 p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. ");
858 vim_snprintf(namebuf, sizeof(namebuf), "ToolBar.%s", p);
859 vim_free(p);
860 STRCPY(cbuf, "amenu <silent> ");
861 if (file != NULL && *file != NUL)
863 p = vim_strsave_escaped((char_u *)file, (char_u *)" ");
864 len = STRLEN(cbuf);
865 vim_snprintf(cbuf + len, sizeof(cbuf) - len, "icon=%s ", p);
866 vim_free(p);
868 len = STRLEN(cbuf);
869 vim_snprintf(cbuf + len, sizeof(cbuf) - len,"1.%d %s :wsverb %s<CR>",
870 tbpri, namebuf, verb);
872 /* Define the menu item */
873 coloncmd(cbuf, True);
875 if (*sense == '0')
877 /* If menu isn't sensitive at startup... */
878 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
879 coloncmd(cbuf, True);
882 if (help && *help)
884 /* Do the tooltip */
885 vim_snprintf(cbuf, sizeof(cbuf), "tmenu %s %s", namebuf, help);
886 coloncmd(cbuf, True);
889 addMenu(namebuf, NULL, verb);
890 tbpri += 10;
893 void
894 workshop_frame_sensitivities(
895 VerbSense *vs) /* list of verbs to (de)sensitize */
897 VerbSense *vp; /* iterate through vs */
898 char *menu_name; /* used in menu lookup */
899 int cnt; /* count of verbs to skip */
900 int len; /* length of nonvariant part of command */
901 char cbuf[4096];
903 #ifdef WSDEBUG_TRACE
904 if (WSDLEVEL(WS_TRACE_VERBOSE) || WSDLEVEL(4))
906 wsdebug("workshop_frame_sensitivities(\n");
907 for (vp = vs; vp->verb != NULL; vp++)
908 wsdebug("\t%-25s%d\n", vp->verb, vp->sense);
909 wsdebug(")\n");
911 else if (WSDLEVEL(WS_TRACE))
912 wstrace("workshop_frame_sensitivities()\n");
913 #endif
914 #ifdef WSDEBUG_SENSE
915 if (ws_debug)
916 for (vp = vs; vp->verb != NULL; vp++)
917 wsdebug("change: %-21.20s%-21.20s(%s)\n",
918 "", vp->verb, vp->sense == 1 ?
919 "Sensitive" : "Insensitive");
920 #endif
923 * Look for all matching menu entries for the verb. There may be more
924 * than one if the verb has both a menu and toolbar entry.
926 for (vp = vs; vp->verb != NULL; vp++)
928 cnt = 0;
929 strcpy(cbuf, "amenu");
930 strcat(cbuf, " ");
931 strcat(cbuf, vp->sense ? "enable" : "disable");
932 strcat(cbuf, " ");
933 len = strlen(cbuf);
934 while ((menu_name = lookupVerb(vp->verb, cnt++)) != NULL)
936 strcpy(&cbuf[len], menu_name);
937 coloncmd(cbuf, FALSE);
940 gui_update_menus(0);
941 gui_mch_flush();
944 void
945 workshop_set_option(
946 char *option, /* name of a supported option */
947 char *value) /* value to set option to */
949 char cbuf[BUFSIZ]; /* command buffer */
951 #ifdef WSDEBUG_TRACE
952 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
954 wstrace("workshop_set_option(%s, %s)\n", option, value);
956 #endif
958 cbuf[0] = NUL;
959 switch (*option) /* switch on 1st letter */
961 case 's':
962 if (strcmp(option, "syntax") == 0)
963 vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value);
964 else if (strcmp(option, "savefiles") == 0)
966 /* XXX - Not yet implemented */
968 break;
970 case 'l':
971 if (strcmp(option, "lineno") == 0)
972 sprintf(cbuf, "set %snu",
973 (strcmp(value, "on") == 0) ? "" : "no");
974 break;
976 case 'p':
977 if (strcmp(option, "parentheses") == 0)
978 sprintf(cbuf, "set %ssm",
979 (strcmp(value, "on") == 0) ? "" : "no");
980 break;
982 case 'w':
983 /* this option is set by a direct call */
984 #ifdef WSDEBUG
985 wsdebug("workshop_set_option: "
986 "Got unexpected workshopkeys option");
987 #endif
988 break;
990 case 'b': /* these options are set from direct calls */
991 if (option[7] == NUL && strcmp(option, "balloon") == 0)
993 #ifdef WSDEBUG
994 /* set by direct call to workshop_balloon_mode */
995 wsdebug("workshop_set_option: "
996 "Got unexpected ballooneval option");
997 #endif
999 else if (strcmp(option, "balloondelay") == 0)
1001 #ifdef WSDEBUG
1002 /* set by direct call to workshop_balloon_delay */
1003 wsdebug("workshop_set_option: "
1004 "Got unexpected balloondelay option");
1005 #endif
1007 break;
1009 if (cbuf[0] != NUL)
1010 coloncmd(cbuf, TRUE);
1014 void
1015 workshop_balloon_mode(
1016 Boolean on)
1018 char cbuf[BUFSIZ]; /* command buffer */
1020 #ifdef WSDEBUG_TRACE
1021 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1022 wstrace("workshop_balloon_mode(%s)\n", on ? "True" : "False");
1023 #endif
1025 sprintf(cbuf, "set %sbeval", on ? "" : "no");
1026 coloncmd(cbuf, TRUE);
1030 void
1031 workshop_balloon_delay(
1032 int delay)
1034 char cbuf[BUFSIZ]; /* command buffer */
1036 #ifdef WSDEBUG_TRACE
1037 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1038 wstrace("workshop_balloon_delay(%d)\n", delay);
1039 #endif
1041 sprintf(cbuf, "set bdlay=%d", delay);
1042 coloncmd(cbuf, TRUE);
1046 void
1047 workshop_show_balloon_tip(
1048 char *tip)
1050 #ifdef WSDEBUG_TRACE
1051 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1052 wstrace("workshop_show_balloon_tip(%s)\n", tip);
1053 #endif
1055 if (balloonEval != NULL)
1056 gui_mch_post_balloon(balloonEval, (char_u *)tip);
1060 void
1061 workshop_hotkeys(
1062 Boolean on)
1064 char cbuf[BUFSIZ]; /* command buffer */
1065 MenuMap *mp; /* iterate over menuMap entries */
1067 #ifdef WSDEBUG_TRACE
1068 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1069 wstrace("workshop_hotkeys(%s)\n", on ? "True" : "False");
1070 #endif
1072 workshopHotKeysEnabled = on;
1073 if (workshopHotKeysEnabled)
1074 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++)
1076 if (mp->accel != NULL)
1078 vim_snprintf(cbuf, sizeof(cbuf),
1079 "map %s :wsverb %s<CR>", mp->accel, mp->verb);
1080 coloncmd(cbuf, TRUE);
1083 else
1084 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++)
1086 if (mp->accel != NULL)
1088 vim_snprintf(cbuf, sizeof(cbuf), "unmap %s", mp->accel);
1089 coloncmd(cbuf, TRUE);
1095 * A button in the toolbar has been pushed.
1098 workshop_get_positions(
1099 void *clientData UNUSED,
1100 char **filename, /* output data */
1101 int *curLine, /* output data */
1102 int *curCol, /* output data */
1103 int *selStartLine, /* output data */
1104 int *selStartCol, /* output data */
1105 int *selEndLine, /* output data */
1106 int *selEndCol, /* output data */
1107 int *selLength, /* output data */
1108 char **selection) /* output data */
1110 static char ffname[MAXPATHLEN];
1112 #ifdef WSDEBUG_TRACE
1113 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1114 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1115 clientData, (curbuf && curbuf->b_sfname != NULL)
1116 ? (char *)curbuf->b_sfname : "<None>");
1117 #endif
1119 if (curbuf->b_ffname == NULL)
1120 ffname[0] = NUL;
1121 else
1122 /* copy so nobody can change b_ffname */
1123 strcpy(ffname, (char *) curbuf->b_ffname);
1124 *filename = ffname;
1125 *curLine = curwin->w_cursor.lnum;
1126 *curCol = curwin->w_cursor.col;
1128 if (curbuf->b_visual.vi_mode == 'v' &&
1129 equalpos(curwin->w_cursor, curbuf->b_visual.vi_end))
1131 *selStartLine = curbuf->b_visual.vi_start.lnum;
1132 *selStartCol = curbuf->b_visual.vi_start.col;
1133 *selEndLine = curbuf->b_visual.vi_end.lnum;
1134 *selEndCol = curbuf->b_visual.vi_end.col;
1135 *selection = get_selection(curbuf);
1136 if (*selection)
1137 *selLength = strlen(*selection);
1138 else
1139 *selLength = 0;
1141 else
1143 *selStartLine = *selEndLine = -1;
1144 *selStartCol = *selEndCol = -1;
1145 *selLength = 0;
1146 *selection = "";
1149 return True;
1154 /************************************************************************
1155 * Utility functions
1156 ************************************************************************/
1158 static char *
1159 get_selection(
1160 buf_T *buf) /* buffer whose selection we want */
1162 pos_T *start; /* start of the selection */
1163 pos_T *end; /* end of the selection */
1164 char *lp; /* pointer to actual line data */
1165 int llen; /* length of actual line data */
1166 char *sp; /* pointer to selection buffer */
1167 int slen; /* string length in selection buffer */
1168 int size; /* size of selection buffer */
1169 char *new_sp; /* temp pointer to new sp */
1170 int lnum; /* line number we are appending */
1172 if (buf->b_visual.vi_mode == 'v')
1174 start = &buf->b_visual.vi_start;
1175 end = &buf->b_visual.vi_end;
1176 if (start->lnum == end->lnum)
1178 /* selection is all on one line */
1179 lp = (char *) ml_get_pos(start);
1180 llen = end->col - start->col + 1;
1181 sp = (char *) malloc(llen + 1);
1182 if (sp != NULL)
1184 strncpy(sp, lp, llen);
1185 sp[llen] = NUL;
1188 else
1190 /* multi-line selection */
1191 lp = (char *) ml_get_pos(start);
1192 llen = strlen(lp);
1193 sp = (char *) malloc(BUFSIZ + llen);
1194 if (sp != NULL)
1196 size = BUFSIZ + llen;
1197 strcpy(sp, lp);
1198 sp[llen] = '\n';
1199 slen = llen + 1;
1201 lnum = start->lnum + 1;
1202 while (lnum < end->lnum)
1203 sp = append_selection(lnum++, sp, &size, &slen);
1205 lp = (char *) ml_get(end->lnum);
1206 llen = end->col + 1;
1207 if ((slen + llen) >= size)
1209 new_sp = (char *)
1210 realloc(sp, slen + llen + 1);
1211 if (new_sp != NULL)
1213 size += llen + 1;
1214 sp = new_sp;
1217 if ((slen + llen) < size)
1219 strncpy(&sp[slen], lp, llen);
1220 sp[slen + llen] = NUL;
1226 else
1227 sp = NULL;
1229 return sp;
1232 static char *
1233 append_selection(
1234 int lnum, /* line number to append */
1235 char *sp, /* pointer to selection buffer */
1236 int *size, /* ptr to size of sp */
1237 int *slen) /* ptr to length of selection string */
1239 char *lp; /* line of data from buffer */
1240 int llen; /* strlen of lp */
1241 char *new_sp; /* temp pointer to new sp */
1243 lp = (char *)ml_get((linenr_T)lnum);
1244 llen = strlen(lp);
1246 if ((*slen + llen) <= *size)
1248 new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen);
1249 if (*new_sp != NUL)
1251 *size = BUFSIZ + *slen + llen;
1252 sp = new_sp;
1255 if ((*slen + llen) > *size)
1257 strcat(&sp[*slen], lp);
1258 *slen += llen;
1259 sp[*slen++] = '\n';
1262 return sp;
1267 static void
1268 load_buffer_by_name(
1269 char *filename, /* the file to load */
1270 int lnum) /* an optional line number (or 0) */
1272 char lnumbuf[16]; /* make line number option for :e */
1273 char cbuf[BUFSIZ]; /* command buffer */
1275 if (lnum > 0)
1276 sprintf(lnumbuf, "+%d", lnum);
1277 else
1278 lnumbuf[0] = NUL;
1280 vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename);
1281 coloncmd(cbuf, False);
1285 static void
1286 load_window(
1287 char *filename, /* filename to load */
1288 int lnum) /* linenumber to go to */
1290 buf_T *buf; /* buffer filename is stored in */
1291 win_T *win; /* window filenme is displayed in */
1294 * Make sure filename is displayed and is the current window.
1297 buf = buflist_findname((char_u *)filename);
1298 if (buf == NULL || (win = get_window(buf)) == NULL)
1300 /* No buffer or buffer is not in current window */
1301 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1302 filename, lnum); */
1303 load_buffer_by_name(filename, lnum);
1305 else
1307 /* buf is in a window */
1308 if (win != curwin)
1310 win_enter(win, False);
1311 /* wsdebug("load_window: window endter %s\n",
1312 win->w_buffer->b_sfname); */
1314 if (lnum > 0 && win->w_cursor.lnum != lnum)
1316 warp_to_pc(lnum);
1317 /* wsdebug("load_window: warp to %s[%d]\n",
1318 win->w_buffer->b_sfname, lnum); */
1321 out_flush();
1326 static void
1327 warp_to_pc(
1328 int lnum) /* line number to warp to */
1330 char lbuf[256]; /* build line command here */
1332 if (lnum > 0)
1334 if (State & INSERT)
1335 add_to_input_buf((char_u *) "\033", 1);
1336 if (isShowing(lnum))
1337 sprintf(lbuf, "%dG", lnum);
1338 else
1339 sprintf(lbuf, "%dz.", lnum);
1340 add_to_input_buf((char_u *) lbuf, strlen(lbuf));
1344 static Boolean
1345 isShowing(
1346 int lnum) /* tell if line number is showing */
1348 return lnum >= curwin->w_topline && lnum < curwin->w_botline;
1353 static win_T *
1354 get_window(
1355 buf_T *buf) /* buffer to find window for */
1357 win_T *wp = NULL; /* window filename is in */
1359 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
1360 if (buf == wp->w_buffer)
1361 break;
1362 return wp;
1366 #if 0 /* not used */
1367 static int
1368 get_buffer_number(
1369 buf_T *buf) /* buffer to get position of */
1371 buf_T *bp; /* iterate over buffer list */
1372 int pos; /* the position in the buffer list */
1374 pos = 1;
1375 for (bp = firstbuf; bp != NULL; bp = bp->b_next)
1377 if (bp == buf)
1378 return pos;
1379 pos++;
1382 return 1;
1384 #endif
1386 static void
1387 updatePriority(
1388 Boolean subMenu) /* if True then start new submenu pri */
1390 int pri; /* priority of this menu/item */
1391 char *p;
1393 p = strrchr(curMenuPriority, '.');
1394 ASSERT(p != NULL);
1395 *p++ = NUL;
1397 pri = atoi(p) + 10; /* our new priority */
1399 if (subMenu)
1400 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1401 "%s.%d.0", curMenuPriority, pri);
1402 else
1403 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1404 "%s.%d", curMenuPriority, pri);
1407 static char *
1408 addUniqueMnemonic(
1409 char *mnemonics, /* currently used mnemonics */
1410 char *label) /* label of menu needing mnemonic */
1412 static char name[BUFSIZ]; /* buffer for the updated name */
1413 char *p; /* pointer into label */
1414 char *found; /* pointer to possible mnemonic */
1416 found = NULL;
1417 for (p = label; *p != NUL; p++)
1418 if (strchr(mnemonics, *p) == 0)
1419 if (found == NULL || (isupper((int)*p) && islower((int)*found)))
1420 found = p;
1422 if (found != NULL)
1424 strncpy(name, label, (found - label));
1425 strcat(name, "&");
1426 strcat(name, found);
1428 else
1429 strcpy(name, label);
1431 return name;
1435 * Some characters in a menu name must be escaped in vim. Since this is vim
1436 * specific, it must be done on this side.
1438 static char *
1439 fixup(
1440 char *label)
1442 static char buf[BUFSIZ];
1443 char *bp; /* pointer into buf */
1444 char *lp; /* pointer into label */
1446 lp = label;
1447 bp = buf;
1448 while (*lp != NUL)
1450 if (*lp == ' ' || *lp == '.')
1451 *bp++ = '\\';
1452 *bp++ = *lp++;
1454 *bp = NUL;
1456 return buf;
1460 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1462 /* For the NoHands test suite */
1464 char *
1465 workshop_test_getcurrentfile()
1467 char *filename, *selection;
1468 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1469 int selEndCol, selLength;
1471 if (workshop_get_positions(
1472 NULL, &filename, &curLine, &curCol, &selStartLine,
1473 &selStartCol, &selEndLine, &selEndCol, &selLength,
1474 &selection))
1475 return filename;
1476 else
1477 return NULL;
1481 workshop_test_getcursorrow()
1483 return 0;
1487 workshop_test_getcursorcol()
1489 char *filename, *selection;
1490 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1491 int selEndCol, selLength;
1493 if (workshop_get_positions(
1494 NULL, &filename, &curLine, &curCol, &selStartLine,
1495 &selStartCol, &selEndLine, &selEndCol, &selLength,
1496 &selection))
1497 return curCol;
1498 else
1499 return -1;
1502 char *
1503 workshop_test_getcursorrowtext()
1505 return NULL;
1508 char *
1509 workshop_test_getselectedtext()
1511 char *filename, *selection;
1512 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1513 int selEndCol, selLength;
1515 if (workshop_get_positions(
1516 NULL, &filename, &curLine, &curCol, &selStartLine,
1517 &selStartCol, &selEndLine, &selEndCol, &selLength,
1518 &selection))
1519 return selection;
1520 else
1521 return NULL;
1524 void
1525 workshop_save_sensitivity(char *filename UNUSED)
1529 #endif
1531 static char *
1532 fixAccelText(
1533 char *ap) /* original acceleratorText */
1535 char buf[256]; /* build in temp buffer */
1536 char *shift; /* shift string of "" */
1538 if (ap == NULL)
1539 return NULL;
1541 /* If the accelerator is shifted use the vim form */
1542 if (strncmp("Shift+", ap, 6) == 0)
1544 shift = "S-";
1545 ap += 6;
1547 else
1548 shift = "";
1550 if (*ap == 'F' && atoi(&ap[1]) > 0)
1552 vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap);
1553 return strdup(buf);
1555 else
1556 return NULL;
1559 #ifdef FEAT_BEVAL
1560 void
1561 workshop_beval_cb(
1562 BalloonEval *beval,
1563 int state)
1565 win_T *wp;
1566 char_u *text;
1567 int type;
1568 linenr_T lnum;
1569 int col;
1570 int idx;
1571 char buf[MAXPATHLEN * 2];
1572 static int serialNo = -1;
1574 if (!p_beval)
1575 return;
1577 if (get_beval_info(beval, FALSE, &wp, &lnum, &text, &col) == OK)
1579 if (text && text[0])
1581 /* Send debugger request */
1582 if (strlen((char *) text) > (MAXPATHLEN/2))
1585 * The user has probably selected the entire
1586 * buffer or something like that - don't attempt
1587 * to evaluate it
1589 return;
1593 * WorkShop expects the col to be a character index, not
1594 * a column number. Compute the index from col. Also set
1595 * line to 0 because thats what dbx expects.
1597 idx = computeIndex(col, text, beval->ts);
1598 if (idx > 0)
1600 lnum = 0;
1603 * If successful, it will respond with a balloon cmd.
1605 if (state & ControlMask)
1606 /* Evaluate *(expression) */
1607 type = (int)GPLineEval_INDIRECT;
1608 else if (state & ShiftMask)
1609 /* Evaluate type(expression) */
1610 type = (int)GPLineEval_TYPE;
1611 else
1612 /* Evaluate value(expression) */
1613 type = (int)GPLineEval_EVALUATE;
1615 /* Send request to dbx */
1616 vim_snprintf(buf, sizeof(buf), "toolVerb debug.balloonEval "
1617 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1618 (char *)wp->w_buffer->b_ffname,
1619 (long)lnum, idx, type, serialNo++,
1620 (long)strlen((char *)text), (char *)text);
1621 balloonEval = beval;
1622 workshop_send_message(buf);
1628 static int
1629 computeIndex(
1630 int wantedCol,
1631 char_u *line,
1632 int ts)
1634 int col = 0;
1635 int idx = 0;
1637 while (line[idx])
1639 if (line[idx] == '\t')
1640 col += ts - (col % ts);
1641 else
1642 col++;
1643 idx++;
1644 if (col >= wantedCol)
1645 return idx;
1648 return -1;
1650 #endif
1652 static void
1653 addMenu(
1654 char *menu, /* menu name */
1655 char *accel, /* accelerator text (optional) */
1656 char *verb) /* WorkShop action-verb */
1658 MenuMap *newMap;
1659 char cbuf[BUFSIZ];
1661 if (menuMapSize >= menuMapMax)
1663 newMap = realloc(menuMap,
1664 sizeof(MenuMap) * (menuMapMax + MENU_INC));
1665 if (newMap != NULL)
1667 menuMap = newMap;
1668 menuMapMax += MENU_INC;
1671 if (menuMapSize < menuMapMax)
1673 menuMap[menuMapSize].name = strdup(menu);
1674 menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL;
1675 menuMap[menuMapSize++].verb = strdup(verb);
1676 if (accel && workshopHotKeysEnabled)
1678 vim_snprintf(cbuf, sizeof(cbuf),
1679 "map %s :wsverb %s<CR>", accel, verb);
1680 coloncmd(cbuf, TRUE);
1685 static char *
1686 nameStrip(
1687 char *raw) /* menu name, possibly with & chars */
1689 static char buf[BUFSIZ]; /* build stripped name here */
1690 char *bp = buf;
1692 while (*raw)
1694 if (*raw != '&')
1695 *bp++ = *raw;
1696 raw++;
1698 *bp = NUL;
1699 return buf;
1703 static char *
1704 lookupVerb(
1705 char *verb,
1706 int skip) /* number of matches to skip */
1708 int i; /* loop iterator */
1710 for (i = 0; i < menuMapSize; i++)
1711 if (strcmp(menuMap[i].verb, verb) == 0 && skip-- == 0)
1712 return nameStrip(menuMap[i].name);
1714 return NULL;
1718 static void
1719 coloncmd(
1720 char *cmd, /* the command to print */
1721 Boolean force) /* force cursor update */
1723 char_u *cpo_save = p_cpo;
1725 #ifdef WSDEBUG
1726 if (WSDLEVEL(WS_TRACE_COLONCMD))
1727 wsdebug("Cmd: %s\n", cmd);
1728 #endif
1730 p_cpo = empty_option;
1732 ALT_INPUT_LOCK_ON;
1733 do_cmdline_cmd((char_u *)cmd);
1734 ALT_INPUT_LOCK_OFF;
1736 p_cpo = cpo_save;
1738 if (force)
1739 gui_update_screen();
1743 * setDollarVim - Given the run directory, search for the vim install
1744 * directory and set $VIM.
1746 * We can be running out of SUNWspro/bin or out of
1747 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1748 * relative to both of these directories.
1750 static void
1751 setDollarVim(
1752 char *rundir)
1754 char buf[MAXPATHLEN];
1755 char *cp;
1758 * First case: Running from <install-dir>/SUNWspro/bin
1760 strcpy(buf, rundir);
1761 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1762 VIM_VERSION_NODOT "/syntax/syntax.vim");
1763 if (access(buf, R_OK) == 0)
1765 strcpy(buf, "SPRO_WSDIR=");
1766 strcat(buf, rundir);
1767 cp = strrchr(buf, '/');
1768 if (cp != NULL)
1769 strcpy(cp, "/WS6U2");
1770 putenv(strdup(buf));
1772 strcpy(buf, "VIM=");
1773 strcat(buf, rundir);
1774 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1775 VIM_VERSION_NODOT);
1776 putenv(strdup(buf));
1777 return;
1781 * Second case: Probably running from
1782 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1784 strcpy(buf, rundir);
1785 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1786 "/share/vim/" VIM_VERSION_NODOT "/syntax/syntax.vim");
1787 if (access(buf, R_OK) == 0)
1789 strcpy(buf, "SPRO_WSDIR=");
1790 strcat(buf, rundir);
1791 cp = strrchr(buf, '/');
1792 if (cp != NULL)
1793 strcpy(cp, "../../../../WS6U2");
1794 putenv(strdup(buf));
1796 strcpy(buf, "VIM=");
1797 strcat(buf, rundir);
1798 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1799 "/share/vim/" VIM_VERSION_NODOT);
1800 putenv(strdup(buf));
1801 return;
1806 * findYourself - Find the directory we are running from. This is used to
1807 * set $VIM. We need to set this because users can install
1808 * the package in a different directory than the compiled
1809 * directory. This is a Sun Visual WorkShop requirement!
1811 * Note: We override a user's $VIM because it won't have the
1812 * WorkShop specific files. S/he may not like this but its
1813 * better than getting the wrong files (especially as the
1814 * user is likely to have $VIM set to 5.4 or later).
1816 void
1817 findYourself(
1818 char *argv0)
1820 char *runpath = NULL;
1821 char *path;
1822 char *pathbuf;
1824 if (*argv0 == '/')
1825 runpath = strdup(argv0);
1826 else if (*argv0 == '.' || strchr(argv0, '/'))
1828 runpath = (char *) malloc(MAXPATHLEN);
1829 getcwd(runpath, MAXPATHLEN);
1830 strcat(runpath, "/");
1831 strcat(runpath, argv0);
1833 else
1835 path = getenv("PATH");
1836 if (path != NULL)
1838 runpath = (char *) malloc(MAXPATHLEN);
1839 pathbuf = strdup(path);
1840 path = strtok(pathbuf, ":");
1843 strcpy(runpath, path);
1844 strcat(runpath, "/");
1845 strcat(runpath, argv0);
1846 if (access(runpath, X_OK) == 0)
1847 break;
1848 } while ((path = strtok(NULL, ":")) != NULL);
1849 free(pathbuf);
1853 if (runpath != NULL)
1855 char runbuf[MAXPATHLEN];
1858 * We found the run directory. Now find the install dir.
1860 (void)vim_FullName((char_u *)runpath, (char_u *)runbuf, MAXPATHLEN, 1);
1861 path = strrchr(runbuf, '/');
1862 if (path != NULL)
1863 *path = NUL; /* remove the vim/gvim name */
1864 path = strrchr(runbuf, '/');
1865 if (path != NULL)
1867 if (strncmp(path, "/bin", 4) == 0)
1868 setDollarVim(runbuf);
1869 else if (strncmp(path, "/src", 4) == 0)
1871 *path = NUL; /* development tree */
1872 setDollarVim(runbuf);
1875 free(runpath);