Remove unnecessary spell files
[MacVim.git] / src / workshop.c
blob66a60d3ba8b2f21e0039a8cb0df6b5f380f54a8d
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 #endif
61 static char *fixAccelText(char *);
62 static void addMenu(char *, char *, char *);
63 static char *lookupVerb(char *, int);
64 static int computeIndex(int, char_u *, 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 /*ARGSUSED*/
208 void
209 workshop_load_file(
210 char *filename, /* the file to load */
211 int line, /* an optional line number (or 0) */
212 char *frameid) /* used for multi-frame support */
214 #ifdef WSDEBUG_TRACE
215 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
216 wstrace("workshop_load_file(%s, %d)\n", filename, line);
217 #endif
219 #ifdef FEAT_BEVAL
220 bevalServers |= BEVAL_WORKSHOP;
221 #endif
223 load_window(filename, line);
227 * Reload the WorkShop buffer
229 void
230 workshop_reload_file(
231 char *filename,
232 int line)
234 #ifdef WSDEBUG_TRACE
235 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
236 wstrace("workshop_reload_file(%s, %d)\n", filename, line);
237 #endif
238 load_window(filename, line);
241 void
242 workshop_show_file(
243 char *filename)
245 #ifdef WSDEBUG_TRACE
246 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
247 wstrace("workshop_show_file(%s)\n", filename);
248 #endif
250 load_window(filename, 0);
253 void
254 workshop_goto_line(
255 char *filename,
256 int lineno)
258 #ifdef WSDEBUG_TRACE
259 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
260 wstrace("workshop_goto_line(%s, %d)\n", filename, lineno);
261 #endif
263 load_window(filename, lineno);
266 /*ARGSUSED*/
267 void
268 workshop_front_file(
269 char *filename)
271 #ifdef WSDEBUG_TRACE
272 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
273 wstrace("workshop_front_file()\n");
274 #endif
276 * Assumption: This function will always be called after a call to
277 * workshop_show_file(), so the file is always showing.
279 if (vimShell != NULL)
280 XRaiseWindow(gui.dpy, XtWindow(vimShell));
283 void
284 workshop_save_file(
285 char *filename)
287 char cbuf[BUFSIZ]; /* build vim command here */
289 #ifdef WSDEBUG_TRACE
290 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
291 wstrace("workshop_save_file(%s)\n", filename);
292 #endif
294 /* Save the given file */
295 vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename);
296 coloncmd(cbuf, TRUE);
299 void
300 workshop_save_files()
302 /* Save the given file */
303 #ifdef WSDEBUG_TRACE
304 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
305 wstrace("workshop_save_files()\n");
306 #endif
308 add_to_input_buf((char_u *) ":wall\n", 6);
311 void
312 workshop_quit()
314 #ifdef WSDEBUG_TRACE
315 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
316 wstrace("workshop_quit()\n");
317 #endif
319 add_to_input_buf((char_u *) ":qall\n", 6);
322 void
323 workshop_minimize()
325 #ifdef WSDEBUG_TRACE
326 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
327 wstrace("workshop_minimize()\n");
328 #endif
329 workshop_minimize_shell(vimShell);
331 void
332 workshop_maximize()
334 #ifdef WSDEBUG_TRACE
335 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
336 wstrace("workshop_maximize()\n");
337 #endif
339 workshop_maximize_shell(vimShell);
342 void
343 workshop_add_mark_type(
344 int idx,
345 char *colorspec,
346 char *sign)
348 char gbuf[BUFSIZ]; /* buffer for sign name */
349 char cibuf[BUFSIZ]; /* color information */
350 char cbuf[BUFSIZ]; /* command buffer */
351 char *bp;
353 #ifdef WSDEBUG_TRACE
354 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
356 char *cp;
358 cp = strrchr(sign, '/');
359 if (cp == NULL)
360 cp = sign;
361 else
362 cp++; /* skip '/' character */
363 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx,
364 colorspec && *colorspec ? colorspec : "<None>", cp);
366 #endif
369 * Isolate the basename of sign in gbuf. We will use this for the
370 * GroupName in the highlight command sent to vim.
372 STRCPY(gbuf, gettail((char_u *)sign));
373 bp = strrchr(gbuf, '.');
374 if (bp != NULL)
375 *bp = NUL;
377 if (gbuf[0] != '-' && gbuf[1] != NUL)
379 if (colorspec != NULL && *colorspec)
381 vim_snprintf(cbuf, sizeof(cbuf),
382 "highlight WS%s guibg=%s", gbuf, colorspec);
383 coloncmd(cbuf, FALSE);
384 vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf);
386 else
387 cibuf[0] = NUL;
389 vim_snprintf(cbuf, sizeof(cbuf),
390 "sign define %d %s icon=%s", idx, cibuf, sign);
391 coloncmd(cbuf, TRUE);
395 void
396 workshop_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 */
402 char cbuf[BUFSIZ]; /* command buffer */
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
411 vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s",
412 markId, lineno, idx, filename);
413 coloncmd(cbuf, TRUE);
416 void
417 workshop_change_mark_type(
418 char *filename, /* filename which gets the mark */
419 int markId, /* unique mark identifier */
420 int idx) /* which mark to use */
422 char cbuf[BUFSIZ]; /* command buffer */
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
431 vim_snprintf(cbuf, sizeof(cbuf),
432 "sign place %d name=%d file=%s", markId, idx, filename);
433 coloncmd(cbuf, TRUE);
437 * Goto the given mark in a file (e.g. show it).
438 * If message is not null, display it in the footer.
440 void
441 workshop_goto_mark(
442 char *filename,
443 int markId,
444 char *message)
446 char cbuf[BUFSIZ]; /* command buffer */
448 /* Goto mark */
449 #ifdef WSDEBUG_TRACE
450 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
451 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
452 filename, markId, message && *message &&
453 !(*message == ' ' && message[1] == NULL) ?
454 message : "<None>");
455 #endif
457 vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename);
458 coloncmd(cbuf, TRUE);
459 if (message != NULL && *message != NUL)
460 gui_mch_set_footer((char_u *)message);
463 void
464 workshop_delete_mark(
465 char *filename,
466 int markId)
468 char cbuf[BUFSIZ]; /* command buffer */
470 /* Delete mark */
471 #ifdef WSDEBUG_TRACE
472 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
473 wstrace("workshop_delete_mark(%s, %d (id))\n",
474 filename, markId);
475 #endif
477 vim_snprintf(cbuf, sizeof(cbuf),
478 "sign unplace %d file=%s", markId, filename);
479 coloncmd(cbuf, TRUE);
482 #if 0 /* not used */
483 void
484 workshop_delete_all_marks(
485 void *window,
486 Boolean doRefresh)
488 #ifdef WSDEBUG_TRACE
489 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
490 wstrace("workshop_delete_all_marks(%#x, %s)\n",
491 window, doRefresh ? "True" : "False");
492 #endif
494 coloncmd("sign unplace *", TRUE);
496 #endif
499 workshop_get_mark_lineno(
500 char *filename,
501 int markId)
503 buf_T *buf; /* buffer containing filename */
504 int lineno; /* line number of filename in buf */
506 /* Get mark line number */
507 #ifdef WSDEBUG_TRACE
508 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
509 wstrace("workshop_get_mark_lineno(%s, %d)\n",
510 filename, markId);
511 #endif
513 lineno = 0;
514 buf = buflist_findname((char_u *)filename);
515 if (buf != NULL)
516 lineno = buf_findsign(buf, markId);
518 return lineno;
522 #if 0 /* not used */
523 void
524 workshop_adjust_marks(Widget *window, int pos,
525 int inserted, int deleted)
527 #ifdef WSDEBUG_TRACE
528 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
529 wstrace("XXXworkshop_adjust_marks(%s, %d, %d, %d)\n",
530 window ? XtName(window) : "<None>", pos, inserted, deleted);
531 #endif
533 #endif
536 * Are there any moved marks? If so, call workshop_move_mark on
537 * each of them now. This is how eserve can find out if for example
538 * breakpoints have moved when a program has been recompiled and
539 * reloaded into dbx.
541 /*ARGSUSED*/
542 void
543 workshop_moved_marks(char *filename)
545 #ifdef WSDEBUG_TRACE
546 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
547 wstrace("XXXworkshop_moved_marks(%s)\n", filename);
548 #endif
552 workshop_get_font_height()
554 XmFontList fontList; /* fontList made from gui.norm_font */
555 XmString str;
556 Dimension w;
557 Dimension h;
559 #ifdef WSDEBUG_TRACE
560 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
561 wstrace("workshop_get_font_height()\n");
562 #endif
564 /* Pick the proper signs for this font size */
565 fontList = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
566 h = 0;
567 if (fontList != NULL)
569 str = XmStringCreateLocalized("A");
570 XmStringExtent(fontList, str, &w, &h);
571 XmStringFree(str);
572 XmFontListFree(fontList);
575 return (int)h;
578 /*ARGSUSED*/
579 void
580 workshop_footer_message(
581 char *message,
582 int severity) /* 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 /*ARGSUSED*/
691 void
692 workshop_menu_item(
693 char *label,
694 char *verb,
695 char *accelerator,
696 char *acceleratorText,
697 char *name,
698 char *filepos,
699 char *sensitive)
701 char cbuf[BUFSIZ];
702 char namebuf[BUFSIZ];
703 char accText[BUFSIZ];
705 #ifdef WSDEBUG_TRACE
706 if (WSDLEVEL(WS_TRACE_VERBOSE)
707 && strncmp(curMenuName, "ToolBar", 7) != 0)
709 if (ws_dlevel & WS_TRACE_VERBOSE)
710 wsdebug("workshop_menu_item(\n"
711 "\tlabel = \"%s\",\n"
712 "\tverb = %s,\n"
713 "\taccelerator = %s,\n"
714 "\tacceleratorText = \"%s\",\n"
715 "\tname = %s,\n"
716 "\tfilepos = %s,\n"
717 "\tsensitive = %s)\n",
718 label && *label ? label : "<None>",
719 verb && *verb ? verb : "<None>",
720 accelerator && *accelerator ?
721 accelerator : "<None>",
722 acceleratorText && *acceleratorText ?
723 acceleratorText : "<None>",
724 name && *name ? name : "<None>",
725 filepos && *filepos ? filepos : "<None>",
726 sensitive);
727 else if (ws_dlevel & WS_TRACE)
728 wstrace("workshop_menu_item(\"%s\", %s)\n",
729 label && *label ? label : "<None>",
730 verb && *verb ? verb : "<None>", sensitive);
732 #endif
733 #ifdef WSDEBUG_SENSE
734 if (ws_debug)
735 wstrace("menu: %-21.20s%-21.20s(%s)\n", label, verb,
736 *sensitive == '1' ? "Sensitive" : "Insensitive");
737 #endif
739 if (acceleratorText != NULL)
740 vim_snprintf(accText, sizeof(accText), "<Tab>%s", acceleratorText);
741 else
742 accText[0] = NUL;
743 updatePriority(False);
744 vim_snprintf(namebuf, sizeof(namebuf), "%s.%s", curMenuName, fixup(label));
745 vim_snprintf(cbuf, sizeof(cbuf), "amenu %s %s%s\t:wsverb %s<CR>",
746 curMenuPriority, namebuf, accText, verb);
748 coloncmd(cbuf, TRUE);
749 addMenu(namebuf, fixAccelText(acceleratorText), verb);
751 if (*sensitive == '0')
753 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
754 coloncmd(cbuf, TRUE);
759 * This function is called when a complete WorkShop menu description has been
760 * sent over from eserve. We do some menu cleanup.
763 void
764 workshop_menu_end()
766 Boolean using_tearoff; /* set per current option setting */
768 #ifdef WSDEBUG_TRACE
769 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
770 wstrace("workshop_menu_end()\n");
771 #endif
773 using_tearoff = vim_strchr(p_go, GO_TEAROFF) != NULL;
774 gui_mch_toggle_tearoffs(using_tearoff);
777 void
778 workshop_toolbar_begin()
780 #ifdef WSDEBUG_TRACE
781 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
782 wstrace("workshop_toolbar_begin()\n");
783 #endif
785 coloncmd("aunmenu ToolBar", True);
786 tbpri = 10;
789 void
790 workshop_toolbar_end()
792 char_u buf[64];
794 #ifdef WSDEBUG_TRACE
795 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
797 wstrace("workshop_toolbar_end()\n");
799 #endif
802 * Turn on ToolBar.
804 STRCPY(buf, p_go);
805 if (vim_strchr(p_go, 'T') == NULL)
807 STRCAT(buf, "T");
808 set_option_value((char_u *)"go", 0L, buf, 0);
810 workshopInitDone = True;
813 /*ARGSUSED*/
814 void
815 workshop_toolbar_button(
816 char *label,
817 char *verb,
818 char *senseVerb,
819 char *filepos,
820 char *help,
821 char *sense,
822 char *file,
823 char *left)
825 char cbuf[BUFSIZ + MAXPATHLEN];
826 char namebuf[BUFSIZ];
827 static int tbid = 1;
828 char_u *p;
829 int len;
831 #ifdef WSDEBUG_TRACE
832 if (WSDLEVEL(WS_TRACE_VERBOSE))
833 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
834 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
835 label && *label ? label : "<None>",
836 verb && *verb ? verb : "<None>",
837 senseVerb && *senseVerb ? senseVerb : "<None>",
838 filepos && *filepos ? filepos : "<None>",
839 help && *help ? help : "<None>",
840 sense && *sense ? sense : "<None>",
841 file && *file ? file : "<None>",
842 left && *left ? left : "<None>");
843 else if (WSDLEVEL(WS_TRACE))
844 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
845 label && *label ? label : "<None>",
846 verb && *verb ? verb : "<None>");
847 #endif
848 #ifdef WSDEBUG_SENSE
849 if (ws_debug)
850 wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb,
851 *sense == '1' ? "Sensitive" : "Insensitive");
852 #endif
854 if (left && *left && atoi(left) > 0)
856 /* Add a separator (but pass the width passed after the ':') */
857 sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
858 tbpri - 5, tbid++, left);
860 coloncmd(cbuf, True);
863 p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. ");
864 vim_snprintf(namebuf, sizeof(namebuf), "ToolBar.%s", p);
865 vim_free(p);
866 STRCPY(cbuf, "amenu <silent> ");
867 if (file != NULL && *file != NUL)
869 p = vim_strsave_escaped((char_u *)file, (char_u *)" ");
870 len = STRLEN(cbuf);
871 vim_snprintf(cbuf + len, sizeof(cbuf) - len, "icon=%s ", p);
872 vim_free(p);
874 len = STRLEN(cbuf);
875 vim_snprintf(cbuf + len, sizeof(cbuf) - len,"1.%d %s :wsverb %s<CR>",
876 tbpri, namebuf, verb);
878 /* Define the menu item */
879 coloncmd(cbuf, True);
881 if (*sense == '0')
883 /* If menu isn't sensitive at startup... */
884 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
885 coloncmd(cbuf, True);
888 if (help && *help)
890 /* Do the tooltip */
891 vim_snprintf(cbuf, sizeof(cbuf), "tmenu %s %s", namebuf, help);
892 coloncmd(cbuf, True);
895 addMenu(namebuf, NULL, verb);
896 tbpri += 10;
899 void
900 workshop_frame_sensitivities(
901 VerbSense *vs) /* list of verbs to (de)sensitize */
903 VerbSense *vp; /* iterate through vs */
904 char *menu_name; /* used in menu lookup */
905 int cnt; /* count of verbs to skip */
906 int len; /* length of nonvariant part of command */
907 char cbuf[4096];
909 #ifdef WSDEBUG_TRACE
910 if (WSDLEVEL(WS_TRACE_VERBOSE) || WSDLEVEL(4))
912 wsdebug("workshop_frame_sensitivities(\n");
913 for (vp = vs; vp->verb != NULL; vp++)
914 wsdebug("\t%-25s%d\n", vp->verb, vp->sense);
915 wsdebug(")\n");
917 else if (WSDLEVEL(WS_TRACE))
918 wstrace("workshop_frame_sensitivities()\n");
919 #endif
920 #ifdef WSDEBUG_SENSE
921 if (ws_debug)
922 for (vp = vs; vp->verb != NULL; vp++)
923 wsdebug("change: %-21.20s%-21.20s(%s)\n",
924 "", vp->verb, vp->sense == 1 ?
925 "Sensitive" : "Insensitive");
926 #endif
929 * Look for all matching menu entries for the verb. There may be more
930 * than one if the verb has both a menu and toolbar entry.
932 for (vp = vs; vp->verb != NULL; vp++)
934 cnt = 0;
935 strcpy(cbuf, "amenu");
936 strcat(cbuf, " ");
937 strcat(cbuf, vp->sense ? "enable" : "disable");
938 strcat(cbuf, " ");
939 len = strlen(cbuf);
940 while ((menu_name = lookupVerb(vp->verb, cnt++)) != NULL)
942 strcpy(&cbuf[len], menu_name);
943 coloncmd(cbuf, FALSE);
946 gui_update_menus(0);
947 gui_mch_flush();
950 void
951 workshop_set_option(
952 char *option, /* name of a supported option */
953 char *value) /* value to set option to */
955 char cbuf[BUFSIZ]; /* command buffer */
957 #ifdef WSDEBUG_TRACE
958 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
960 wstrace("workshop_set_option(%s, %s)\n", option, value);
962 #endif
964 cbuf[0] = NUL;
965 switch (*option) /* switch on 1st letter */
967 case 's':
968 if (strcmp(option, "syntax") == 0)
969 vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value);
970 else if (strcmp(option, "savefiles") == 0)
971 ; /* 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.
1101 /*ARGSUSED*/
1103 workshop_get_positions(
1104 void *clientData, /* unused */
1105 char **filename, /* output data */
1106 int *curLine, /* output data */
1107 int *curCol, /* output data */
1108 int *selStartLine, /* output data */
1109 int *selStartCol, /* output data */
1110 int *selEndLine, /* output data */
1111 int *selEndCol, /* output data */
1112 int *selLength, /* output data */
1113 char **selection) /* output data */
1115 static char ffname[MAXPATHLEN];
1117 #ifdef WSDEBUG_TRACE
1118 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1119 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1120 clientData, (curbuf && curbuf->b_sfname != NULL)
1121 ? (char *)curbuf->b_sfname : "<None>");
1122 #endif
1124 strcpy(ffname, (char *) curbuf->b_ffname);
1125 *filename = ffname; /* copy so nobody can change b_ffname */
1126 *curLine = curwin->w_cursor.lnum;
1127 *curCol = curwin->w_cursor.col;
1129 if (curbuf->b_visual.vi_mode == 'v' &&
1130 equalpos(curwin->w_cursor, curbuf->b_visual.vi_end))
1132 *selStartLine = curbuf->b_visual.vi_start.lnum;
1133 *selStartCol = curbuf->b_visual.vi_start.col;
1134 *selEndLine = curbuf->b_visual.vi_end.lnum;
1135 *selEndCol = curbuf->b_visual.vi_end.col;
1136 *selection = get_selection(curbuf);
1137 if (*selection)
1138 *selLength = strlen(*selection);
1139 else
1140 *selLength = 0;
1142 else
1144 *selStartLine = *selEndLine = -1;
1145 *selStartCol = *selEndCol = -1;
1146 *selLength = 0;
1147 *selection = "";
1150 return True;
1155 /************************************************************************
1156 * Utility functions
1157 ************************************************************************/
1159 static char *
1160 get_selection(
1161 buf_T *buf) /* buffer whose selection we want */
1163 pos_T *start; /* start of the selection */
1164 pos_T *end; /* end of the selection */
1165 char *lp; /* pointer to actual line data */
1166 int llen; /* length of actual line data */
1167 char *sp; /* pointer to selection buffer */
1168 int slen; /* string length in selection buffer */
1169 int size; /* size of selection buffer */
1170 char *new_sp; /* temp pointer to new sp */
1171 int lnum; /* line number we are appending */
1173 if (buf->b_visual.vi_mode == 'v')
1175 start = &buf->b_visual.vi_start;
1176 end = &buf->b_visual.vi_end;
1177 if (start->lnum == end->lnum)
1179 /* selection is all on one line */
1180 lp = (char *) ml_get_pos(start);
1181 llen = end->col - start->col + 1;
1182 sp = (char *) malloc(llen + 1);
1183 if (sp != NULL)
1185 strncpy(sp, lp, llen);
1186 sp[llen] = NUL;
1189 else
1191 /* multi-line selection */
1192 lp = (char *) ml_get_pos(start);
1193 llen = strlen(lp);
1194 sp = (char *) malloc(BUFSIZ + llen);
1195 if (sp != NULL)
1197 size = BUFSIZ + llen;
1198 strcpy(sp, lp);
1199 sp[llen] = '\n';
1200 slen = llen + 1;
1202 lnum = start->lnum + 1;
1203 while (lnum < end->lnum)
1204 sp = append_selection(lnum++, sp, &size, &slen);
1206 lp = (char *) ml_get(end->lnum);
1207 llen = end->col + 1;
1208 if ((slen + llen) >= size)
1210 new_sp = (char *)
1211 realloc(sp, slen + llen + 1);
1212 if (new_sp != NULL)
1214 size += llen + 1;
1215 sp = new_sp;
1218 if ((slen + llen) < size)
1220 strncpy(&sp[slen], lp, llen);
1221 sp[slen + llen] = NUL;
1227 else
1228 sp = NULL;
1230 return sp;
1233 static char *
1234 append_selection(
1235 int lnum, /* line number to append */
1236 char *sp, /* pointer to selection buffer */
1237 int *size, /* ptr to size of sp */
1238 int *slen) /* ptr to length of selection string */
1240 char *lp; /* line of data from buffer */
1241 int llen; /* strlen of lp */
1242 char *new_sp; /* temp pointer to new sp */
1244 lp = (char *)ml_get((linenr_T)lnum);
1245 llen = strlen(lp);
1247 if ((*slen + llen) <= *size)
1249 new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen);
1250 if (*new_sp != NUL)
1252 *size = BUFSIZ + *slen + llen;
1253 sp = new_sp;
1256 if ((*slen + llen) > *size)
1258 strcat(&sp[*slen], lp);
1259 *slen += llen;
1260 sp[*slen++] = '\n';
1263 return sp;
1268 static void
1269 load_buffer_by_name(
1270 char *filename, /* the file to load */
1271 int lnum) /* an optional line number (or 0) */
1273 char lnumbuf[16]; /* make line number option for :e */
1274 char cbuf[BUFSIZ]; /* command buffer */
1276 if (lnum > 0)
1277 sprintf(lnumbuf, "+%d", lnum);
1278 else
1279 lnumbuf[0] = NUL;
1281 vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename);
1282 coloncmd(cbuf, False);
1286 static void
1287 load_window(
1288 char *filename, /* filename to load */
1289 int lnum) /* linenumber to go to */
1291 buf_T *buf; /* buffer filename is stored in */
1292 win_T *win; /* window filenme is displayed in */
1295 * Make sure filename is displayed and is the current window.
1298 buf = buflist_findname((char_u *)filename);
1299 if (buf == NULL || (win = get_window(buf)) == NULL)
1301 /* No buffer or buffer is not in current window */
1302 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1303 filename, lnum); */
1304 load_buffer_by_name(filename, lnum);
1306 else
1308 /* buf is in a window */
1309 if (win != curwin)
1311 win_enter(win, False);
1312 /* wsdebug("load_window: window endter %s\n",
1313 win->w_buffer->b_sfname); */
1315 if (lnum > 0 && win->w_cursor.lnum != lnum)
1317 warp_to_pc(lnum);
1318 /* wsdebug("load_window: warp to %s[%d]\n",
1319 win->w_buffer->b_sfname, lnum); */
1322 out_flush();
1327 static void
1328 warp_to_pc(
1329 int lnum) /* line number to warp to */
1331 char lbuf[256]; /* build line command here */
1333 if (lnum > 0)
1335 if (State & INSERT)
1336 add_to_input_buf((char_u *) "\033", 1);
1337 if (isShowing(lnum))
1338 sprintf(lbuf, "%dG", lnum);
1339 else
1340 sprintf(lbuf, "%dz.", lnum);
1341 add_to_input_buf((char_u *) lbuf, strlen(lbuf));
1345 static Boolean
1346 isShowing(
1347 int lnum) /* tell if line number is showing */
1349 return lnum >= curwin->w_topline && lnum < curwin->w_botline;
1354 static win_T *
1355 get_window(
1356 buf_T *buf) /* buffer to find window for */
1358 win_T *wp = NULL; /* window filename is in */
1360 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
1361 if (buf == wp->w_buffer)
1362 break;
1363 return wp;
1367 #if 0 /* not used */
1368 static int
1369 get_buffer_number(
1370 buf_T *buf) /* buffer to get position of */
1372 buf_T *bp; /* iterate over buffer list */
1373 int pos; /* the position in the buffer list */
1375 pos = 1;
1376 for (bp = firstbuf; bp != NULL; bp = bp->b_next)
1378 if (bp == buf)
1379 return pos;
1380 pos++;
1383 return 1;
1385 #endif
1387 static void
1388 updatePriority(
1389 Boolean subMenu) /* if True then start new submenu pri */
1391 int pri; /* priority of this menu/item */
1392 char *p;
1394 p = strrchr(curMenuPriority, '.');
1395 ASSERT(p != NULL);
1396 *p++ = NUL;
1398 pri = atoi(p) + 10; /* our new priority */
1400 if (subMenu)
1401 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1402 "%s.%d.0", curMenuPriority, pri);
1403 else
1404 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1405 "%s.%d", curMenuPriority, pri);
1408 static char *
1409 addUniqueMnemonic(
1410 char *mnemonics, /* currently used mnemonics */
1411 char *label) /* label of menu needing mnemonic */
1413 static char name[BUFSIZ]; /* buffer for the updated name */
1414 char *p; /* pointer into label */
1415 char *found; /* pointer to possible mnemonic */
1417 found = NULL;
1418 for (p = label; *p != NUL; p++)
1419 if (strchr(mnemonics, *p) == 0)
1420 if (found == NULL || (isupper((int)*p) && islower((int)*found)))
1421 found = p;
1423 if (found != NULL)
1425 strncpy(name, label, (found - label));
1426 strcat(name, "&");
1427 strcat(name, found);
1429 else
1430 strcpy(name, label);
1432 return name;
1436 * Some characters in a menu name must be escaped in vim. Since this is vim
1437 * specific, it must be done on this side.
1439 static char *
1440 fixup(
1441 char *label)
1443 static char buf[BUFSIZ];
1444 char *bp; /* pointer into buf */
1445 char *lp; /* pointer into label */
1447 lp = label;
1448 bp = buf;
1449 while (*lp != NUL)
1451 if (*lp == ' ' || *lp == '.')
1452 *bp++ = '\\';
1453 *bp++ = *lp++;
1455 *bp = NUL;
1457 return buf;
1461 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1463 /* For the NoHands test suite */
1465 char *
1466 workshop_test_getcurrentfile()
1468 char *filename, *selection;
1469 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1470 int selEndCol, selLength;
1472 if (workshop_get_positions(
1473 NULL, &filename, &curLine, &curCol, &selStartLine,
1474 &selStartCol, &selEndLine, &selEndCol, &selLength,
1475 &selection))
1476 return filename;
1477 else
1478 return NULL;
1482 workshop_test_getcursorrow()
1484 return 0;
1488 workshop_test_getcursorcol()
1490 char *filename, *selection;
1491 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1492 int selEndCol, selLength;
1494 if (workshop_get_positions(
1495 NULL, &filename, &curLine, &curCol, &selStartLine,
1496 &selStartCol, &selEndLine, &selEndCol, &selLength,
1497 &selection))
1498 return curCol;
1499 else
1500 return -1;
1503 char *
1504 workshop_test_getcursorrowtext()
1506 return NULL;
1509 char *
1510 workshop_test_getselectedtext()
1512 char *filename, *selection;
1513 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1514 int selEndCol, selLength;
1516 if (workshop_get_positions(
1517 NULL, &filename, &curLine, &curCol, &selStartLine,
1518 &selStartCol, &selEndLine, &selEndCol, &selLength,
1519 &selection))
1520 return selection;
1521 else
1522 return NULL;
1525 /*ARGSUSED*/
1526 void
1527 workshop_save_sensitivity(char *filename)
1531 #endif
1533 static char *
1534 fixAccelText(
1535 char *ap) /* original acceleratorText */
1537 char buf[256]; /* build in temp buffer */
1538 char *shift; /* shift string of "" */
1540 if (ap == NULL)
1541 return NULL;
1543 /* If the accelerator is shifted use the vim form */
1544 if (strncmp("Shift+", ap, 6) == 0)
1546 shift = "S-";
1547 ap += 6;
1549 else
1550 shift = "";
1552 if (*ap == 'F' && atoi(&ap[1]) > 0)
1554 vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap);
1555 return strdup(buf);
1557 else
1558 return NULL;
1561 #ifdef FEAT_BEVAL
1562 void
1563 workshop_beval_cb(
1564 BalloonEval *beval,
1565 int state)
1567 win_T *wp;
1568 char_u *text;
1569 int type;
1570 linenr_T lnum;
1571 int col;
1572 int idx;
1573 char buf[MAXPATHLEN * 2];
1574 static int serialNo = -1;
1576 if (!p_beval)
1577 return;
1579 if (get_beval_info(beval, FALSE, &wp, &lnum, &text, &col) == OK)
1581 if (text && text[0])
1583 /* Send debugger request */
1584 if (strlen((char *) text) > (MAXPATHLEN/2))
1587 * The user has probably selected the entire
1588 * buffer or something like that - don't attempt
1589 * to evaluate it
1591 return;
1595 * WorkShop expects the col to be a character index, not
1596 * a column number. Compute the index from col. Also set
1597 * line to 0 because thats what dbx expects.
1599 idx = computeIndex(col, text, beval->ts);
1600 if (idx > 0)
1602 lnum = 0;
1605 * If successful, it will respond with a balloon cmd.
1607 if (state & ControlMask)
1608 /* Evaluate *(expression) */
1609 type = (int)GPLineEval_INDIRECT;
1610 else if (state & ShiftMask)
1611 /* Evaluate type(expression) */
1612 type = (int)GPLineEval_TYPE;
1613 else
1614 /* Evaluate value(expression) */
1615 type = (int)GPLineEval_EVALUATE;
1617 /* Send request to dbx */
1618 vim_snprintf(buf, sizeof(buf), "toolVerb debug.balloonEval "
1619 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1620 (char *)wp->w_buffer->b_ffname,
1621 (long)lnum, idx, type, serialNo++,
1622 (long)strlen((char *)text), (char *)text);
1623 balloonEval = beval;
1624 workshop_send_message(buf);
1629 #endif
1632 static int
1633 computeIndex(
1634 int wantedCol,
1635 char_u *line,
1636 int ts)
1638 int col = 0;
1639 int idx = 0;
1641 while (line[idx])
1643 if (line[idx] == '\t')
1644 col += ts - (col % ts);
1645 else
1646 col++;
1647 idx++;
1648 if (col >= wantedCol)
1649 return idx;
1652 return -1;
1655 static void
1656 addMenu(
1657 char *menu, /* menu name */
1658 char *accel, /* accelerator text (optional) */
1659 char *verb) /* WorkShop action-verb */
1661 MenuMap *newMap;
1662 char cbuf[BUFSIZ];
1664 if (menuMapSize >= menuMapMax)
1666 newMap = realloc(menuMap,
1667 sizeof(MenuMap) * (menuMapMax + MENU_INC));
1668 if (newMap != NULL)
1670 menuMap = newMap;
1671 menuMapMax += MENU_INC;
1674 if (menuMapSize < menuMapMax)
1676 menuMap[menuMapSize].name = strdup(menu);
1677 menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL;
1678 menuMap[menuMapSize++].verb = strdup(verb);
1679 if (accel && workshopHotKeysEnabled)
1681 vim_snprintf(cbuf, sizeof(cbuf),
1682 "map %s :wsverb %s<CR>", accel, verb);
1683 coloncmd(cbuf, TRUE);
1688 static char *
1689 nameStrip(
1690 char *raw) /* menu name, possibly with & chars */
1692 static char buf[BUFSIZ]; /* build stripped name here */
1693 char *bp = buf;
1695 while (*raw)
1697 if (*raw != '&')
1698 *bp++ = *raw;
1699 raw++;
1701 *bp = NUL;
1702 return buf;
1706 static char *
1707 lookupVerb(
1708 char *verb,
1709 int skip) /* number of matches to skip */
1711 int i; /* loop iterator */
1713 for (i = 0; i < menuMapSize; i++)
1714 if (strcmp(menuMap[i].verb, verb) == 0 && skip-- == 0)
1715 return nameStrip(menuMap[i].name);
1717 return NULL;
1721 static void
1722 coloncmd(
1723 char *cmd, /* the command to print */
1724 Boolean force) /* force cursor update */
1726 char_u *cpo_save = p_cpo;
1728 #ifdef WSDEBUG
1729 if (WSDLEVEL(WS_TRACE_COLONCMD))
1730 wsdebug("Cmd: %s\n", cmd);
1731 #endif
1733 p_cpo = empty_option;
1735 ALT_INPUT_LOCK_ON;
1736 do_cmdline_cmd((char_u *)cmd);
1737 ALT_INPUT_LOCK_OFF;
1739 p_cpo = cpo_save;
1741 if (force)
1742 gui_update_screen();
1746 * setDollarVim - Given the run directory, search for the vim install
1747 * directory and set $VIM.
1749 * We can be running out of SUNWspro/bin or out of
1750 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1751 * relative to both of these directories.
1753 static void
1754 setDollarVim(
1755 char *rundir)
1757 char buf[MAXPATHLEN];
1758 char *cp;
1761 * First case: Running from <install-dir>/SUNWspro/bin
1763 strcpy(buf, rundir);
1764 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1765 VIM_VERSION_NODOT "/syntax/syntax.vim");
1766 if (access(buf, R_OK) == 0)
1768 strcpy(buf, "SPRO_WSDIR=");
1769 strcat(buf, rundir);
1770 cp = strrchr(buf, '/');
1771 if (cp != NULL)
1772 strcpy(cp, "/WS6U2");
1773 putenv(strdup(buf));
1775 strcpy(buf, "VIM=");
1776 strcat(buf, rundir);
1777 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1778 VIM_VERSION_NODOT);
1779 putenv(strdup(buf));
1780 return;
1784 * Second case: Probably running from
1785 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1787 strcpy(buf, rundir);
1788 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1789 "/share/vim/" VIM_VERSION_NODOT "/syntax/syntax.vim");
1790 if (access(buf, R_OK) == 0)
1792 strcpy(buf, "SPRO_WSDIR=");
1793 strcat(buf, rundir);
1794 cp = strrchr(buf, '/');
1795 if (cp != NULL)
1796 strcpy(cp, "../../../../WS6U2");
1797 putenv(strdup(buf));
1799 strcpy(buf, "VIM=");
1800 strcat(buf, rundir);
1801 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1802 "/share/vim/" VIM_VERSION_NODOT);
1803 putenv(strdup(buf));
1804 return;
1809 * findYourself - Find the directory we are running from. This is used to
1810 * set $VIM. We need to set this because users can install
1811 * the package in a different directory than the compiled
1812 * directory. This is a Sun Visual WorkShop requirement!
1814 * Note: We override a user's $VIM because it won't have the
1815 * WorkShop specific files. S/he may not like this but its
1816 * better than getting the wrong files (especially as the
1817 * user is likely to have $VIM set to 5.4 or later).
1819 void
1820 findYourself(
1821 char *argv0)
1823 char *runpath = NULL;
1824 char *path;
1825 char *pathbuf;
1827 if (*argv0 == '/')
1828 runpath = strdup(argv0);
1829 else if (*argv0 == '.' || strchr(argv0, '/'))
1831 runpath = (char *) malloc(MAXPATHLEN);
1832 getcwd(runpath, MAXPATHLEN);
1833 strcat(runpath, "/");
1834 strcat(runpath, argv0);
1836 else
1838 path = getenv("PATH");
1839 if (path != NULL)
1841 runpath = (char *) malloc(MAXPATHLEN);
1842 pathbuf = strdup(path);
1843 path = strtok(pathbuf, ":");
1846 strcpy(runpath, path);
1847 strcat(runpath, "/");
1848 strcat(runpath, argv0);
1849 if (access(runpath, X_OK) == 0)
1850 break;
1851 } while ((path = strtok(NULL, ":")) != NULL);
1852 free(pathbuf);
1856 if (runpath != NULL)
1858 char runbuf[MAXPATHLEN];
1861 * We found the run directory. Now find the install dir.
1863 (void)vim_FullName((char_u *)runpath, (char_u *)runbuf, MAXPATHLEN, 1);
1864 path = strrchr(runbuf, '/');
1865 if (path != NULL)
1866 *path = NUL; /* remove the vim/gvim name */
1867 path = strrchr(runbuf, '/');
1868 if (path != NULL)
1870 if (strncmp(path, "/bin", 4) == 0)
1871 setDollarVim(runbuf);
1872 else if (strncmp(path, "/src", 4) == 0)
1874 *path = NUL; /* development tree */
1875 setDollarVim(runbuf);
1878 free(runpath);