Snapshot 44
[MacVim.git] / src / workshop.c
blobef25b5a8742c5227a6d69b8d3a456de5c345840f
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 if (curbuf->b_ffname == NULL)
1125 ffname[0] = NUL;
1126 else
1127 /* copy so nobody can change b_ffname */
1128 strcpy(ffname, (char *) curbuf->b_ffname);
1129 *filename = ffname;
1130 *curLine = curwin->w_cursor.lnum;
1131 *curCol = curwin->w_cursor.col;
1133 if (curbuf->b_visual.vi_mode == 'v' &&
1134 equalpos(curwin->w_cursor, curbuf->b_visual.vi_end))
1136 *selStartLine = curbuf->b_visual.vi_start.lnum;
1137 *selStartCol = curbuf->b_visual.vi_start.col;
1138 *selEndLine = curbuf->b_visual.vi_end.lnum;
1139 *selEndCol = curbuf->b_visual.vi_end.col;
1140 *selection = get_selection(curbuf);
1141 if (*selection)
1142 *selLength = strlen(*selection);
1143 else
1144 *selLength = 0;
1146 else
1148 *selStartLine = *selEndLine = -1;
1149 *selStartCol = *selEndCol = -1;
1150 *selLength = 0;
1151 *selection = "";
1154 return True;
1159 /************************************************************************
1160 * Utility functions
1161 ************************************************************************/
1163 static char *
1164 get_selection(
1165 buf_T *buf) /* buffer whose selection we want */
1167 pos_T *start; /* start of the selection */
1168 pos_T *end; /* end of the selection */
1169 char *lp; /* pointer to actual line data */
1170 int llen; /* length of actual line data */
1171 char *sp; /* pointer to selection buffer */
1172 int slen; /* string length in selection buffer */
1173 int size; /* size of selection buffer */
1174 char *new_sp; /* temp pointer to new sp */
1175 int lnum; /* line number we are appending */
1177 if (buf->b_visual.vi_mode == 'v')
1179 start = &buf->b_visual.vi_start;
1180 end = &buf->b_visual.vi_end;
1181 if (start->lnum == end->lnum)
1183 /* selection is all on one line */
1184 lp = (char *) ml_get_pos(start);
1185 llen = end->col - start->col + 1;
1186 sp = (char *) malloc(llen + 1);
1187 if (sp != NULL)
1189 strncpy(sp, lp, llen);
1190 sp[llen] = NUL;
1193 else
1195 /* multi-line selection */
1196 lp = (char *) ml_get_pos(start);
1197 llen = strlen(lp);
1198 sp = (char *) malloc(BUFSIZ + llen);
1199 if (sp != NULL)
1201 size = BUFSIZ + llen;
1202 strcpy(sp, lp);
1203 sp[llen] = '\n';
1204 slen = llen + 1;
1206 lnum = start->lnum + 1;
1207 while (lnum < end->lnum)
1208 sp = append_selection(lnum++, sp, &size, &slen);
1210 lp = (char *) ml_get(end->lnum);
1211 llen = end->col + 1;
1212 if ((slen + llen) >= size)
1214 new_sp = (char *)
1215 realloc(sp, slen + llen + 1);
1216 if (new_sp != NULL)
1218 size += llen + 1;
1219 sp = new_sp;
1222 if ((slen + llen) < size)
1224 strncpy(&sp[slen], lp, llen);
1225 sp[slen + llen] = NUL;
1231 else
1232 sp = NULL;
1234 return sp;
1237 static char *
1238 append_selection(
1239 int lnum, /* line number to append */
1240 char *sp, /* pointer to selection buffer */
1241 int *size, /* ptr to size of sp */
1242 int *slen) /* ptr to length of selection string */
1244 char *lp; /* line of data from buffer */
1245 int llen; /* strlen of lp */
1246 char *new_sp; /* temp pointer to new sp */
1248 lp = (char *)ml_get((linenr_T)lnum);
1249 llen = strlen(lp);
1251 if ((*slen + llen) <= *size)
1253 new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen);
1254 if (*new_sp != NUL)
1256 *size = BUFSIZ + *slen + llen;
1257 sp = new_sp;
1260 if ((*slen + llen) > *size)
1262 strcat(&sp[*slen], lp);
1263 *slen += llen;
1264 sp[*slen++] = '\n';
1267 return sp;
1272 static void
1273 load_buffer_by_name(
1274 char *filename, /* the file to load */
1275 int lnum) /* an optional line number (or 0) */
1277 char lnumbuf[16]; /* make line number option for :e */
1278 char cbuf[BUFSIZ]; /* command buffer */
1280 if (lnum > 0)
1281 sprintf(lnumbuf, "+%d", lnum);
1282 else
1283 lnumbuf[0] = NUL;
1285 vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename);
1286 coloncmd(cbuf, False);
1290 static void
1291 load_window(
1292 char *filename, /* filename to load */
1293 int lnum) /* linenumber to go to */
1295 buf_T *buf; /* buffer filename is stored in */
1296 win_T *win; /* window filenme is displayed in */
1299 * Make sure filename is displayed and is the current window.
1302 buf = buflist_findname((char_u *)filename);
1303 if (buf == NULL || (win = get_window(buf)) == NULL)
1305 /* No buffer or buffer is not in current window */
1306 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1307 filename, lnum); */
1308 load_buffer_by_name(filename, lnum);
1310 else
1312 /* buf is in a window */
1313 if (win != curwin)
1315 win_enter(win, False);
1316 /* wsdebug("load_window: window endter %s\n",
1317 win->w_buffer->b_sfname); */
1319 if (lnum > 0 && win->w_cursor.lnum != lnum)
1321 warp_to_pc(lnum);
1322 /* wsdebug("load_window: warp to %s[%d]\n",
1323 win->w_buffer->b_sfname, lnum); */
1326 out_flush();
1331 static void
1332 warp_to_pc(
1333 int lnum) /* line number to warp to */
1335 char lbuf[256]; /* build line command here */
1337 if (lnum > 0)
1339 if (State & INSERT)
1340 add_to_input_buf((char_u *) "\033", 1);
1341 if (isShowing(lnum))
1342 sprintf(lbuf, "%dG", lnum);
1343 else
1344 sprintf(lbuf, "%dz.", lnum);
1345 add_to_input_buf((char_u *) lbuf, strlen(lbuf));
1349 static Boolean
1350 isShowing(
1351 int lnum) /* tell if line number is showing */
1353 return lnum >= curwin->w_topline && lnum < curwin->w_botline;
1358 static win_T *
1359 get_window(
1360 buf_T *buf) /* buffer to find window for */
1362 win_T *wp = NULL; /* window filename is in */
1364 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
1365 if (buf == wp->w_buffer)
1366 break;
1367 return wp;
1371 #if 0 /* not used */
1372 static int
1373 get_buffer_number(
1374 buf_T *buf) /* buffer to get position of */
1376 buf_T *bp; /* iterate over buffer list */
1377 int pos; /* the position in the buffer list */
1379 pos = 1;
1380 for (bp = firstbuf; bp != NULL; bp = bp->b_next)
1382 if (bp == buf)
1383 return pos;
1384 pos++;
1387 return 1;
1389 #endif
1391 static void
1392 updatePriority(
1393 Boolean subMenu) /* if True then start new submenu pri */
1395 int pri; /* priority of this menu/item */
1396 char *p;
1398 p = strrchr(curMenuPriority, '.');
1399 ASSERT(p != NULL);
1400 *p++ = NUL;
1402 pri = atoi(p) + 10; /* our new priority */
1404 if (subMenu)
1405 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1406 "%s.%d.0", curMenuPriority, pri);
1407 else
1408 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1409 "%s.%d", curMenuPriority, pri);
1412 static char *
1413 addUniqueMnemonic(
1414 char *mnemonics, /* currently used mnemonics */
1415 char *label) /* label of menu needing mnemonic */
1417 static char name[BUFSIZ]; /* buffer for the updated name */
1418 char *p; /* pointer into label */
1419 char *found; /* pointer to possible mnemonic */
1421 found = NULL;
1422 for (p = label; *p != NUL; p++)
1423 if (strchr(mnemonics, *p) == 0)
1424 if (found == NULL || (isupper((int)*p) && islower((int)*found)))
1425 found = p;
1427 if (found != NULL)
1429 strncpy(name, label, (found - label));
1430 strcat(name, "&");
1431 strcat(name, found);
1433 else
1434 strcpy(name, label);
1436 return name;
1440 * Some characters in a menu name must be escaped in vim. Since this is vim
1441 * specific, it must be done on this side.
1443 static char *
1444 fixup(
1445 char *label)
1447 static char buf[BUFSIZ];
1448 char *bp; /* pointer into buf */
1449 char *lp; /* pointer into label */
1451 lp = label;
1452 bp = buf;
1453 while (*lp != NUL)
1455 if (*lp == ' ' || *lp == '.')
1456 *bp++ = '\\';
1457 *bp++ = *lp++;
1459 *bp = NUL;
1461 return buf;
1465 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1467 /* For the NoHands test suite */
1469 char *
1470 workshop_test_getcurrentfile()
1472 char *filename, *selection;
1473 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1474 int selEndCol, selLength;
1476 if (workshop_get_positions(
1477 NULL, &filename, &curLine, &curCol, &selStartLine,
1478 &selStartCol, &selEndLine, &selEndCol, &selLength,
1479 &selection))
1480 return filename;
1481 else
1482 return NULL;
1486 workshop_test_getcursorrow()
1488 return 0;
1492 workshop_test_getcursorcol()
1494 char *filename, *selection;
1495 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1496 int selEndCol, selLength;
1498 if (workshop_get_positions(
1499 NULL, &filename, &curLine, &curCol, &selStartLine,
1500 &selStartCol, &selEndLine, &selEndCol, &selLength,
1501 &selection))
1502 return curCol;
1503 else
1504 return -1;
1507 char *
1508 workshop_test_getcursorrowtext()
1510 return NULL;
1513 char *
1514 workshop_test_getselectedtext()
1516 char *filename, *selection;
1517 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1518 int selEndCol, selLength;
1520 if (workshop_get_positions(
1521 NULL, &filename, &curLine, &curCol, &selStartLine,
1522 &selStartCol, &selEndLine, &selEndCol, &selLength,
1523 &selection))
1524 return selection;
1525 else
1526 return NULL;
1529 /*ARGSUSED*/
1530 void
1531 workshop_save_sensitivity(char *filename)
1535 #endif
1537 static char *
1538 fixAccelText(
1539 char *ap) /* original acceleratorText */
1541 char buf[256]; /* build in temp buffer */
1542 char *shift; /* shift string of "" */
1544 if (ap == NULL)
1545 return NULL;
1547 /* If the accelerator is shifted use the vim form */
1548 if (strncmp("Shift+", ap, 6) == 0)
1550 shift = "S-";
1551 ap += 6;
1553 else
1554 shift = "";
1556 if (*ap == 'F' && atoi(&ap[1]) > 0)
1558 vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap);
1559 return strdup(buf);
1561 else
1562 return NULL;
1565 #ifdef FEAT_BEVAL
1566 void
1567 workshop_beval_cb(
1568 BalloonEval *beval,
1569 int state)
1571 win_T *wp;
1572 char_u *text;
1573 int type;
1574 linenr_T lnum;
1575 int col;
1576 int idx;
1577 char buf[MAXPATHLEN * 2];
1578 static int serialNo = -1;
1580 if (!p_beval)
1581 return;
1583 if (get_beval_info(beval, FALSE, &wp, &lnum, &text, &col) == OK)
1585 if (text && text[0])
1587 /* Send debugger request */
1588 if (strlen((char *) text) > (MAXPATHLEN/2))
1591 * The user has probably selected the entire
1592 * buffer or something like that - don't attempt
1593 * to evaluate it
1595 return;
1599 * WorkShop expects the col to be a character index, not
1600 * a column number. Compute the index from col. Also set
1601 * line to 0 because thats what dbx expects.
1603 idx = computeIndex(col, text, beval->ts);
1604 if (idx > 0)
1606 lnum = 0;
1609 * If successful, it will respond with a balloon cmd.
1611 if (state & ControlMask)
1612 /* Evaluate *(expression) */
1613 type = (int)GPLineEval_INDIRECT;
1614 else if (state & ShiftMask)
1615 /* Evaluate type(expression) */
1616 type = (int)GPLineEval_TYPE;
1617 else
1618 /* Evaluate value(expression) */
1619 type = (int)GPLineEval_EVALUATE;
1621 /* Send request to dbx */
1622 vim_snprintf(buf, sizeof(buf), "toolVerb debug.balloonEval "
1623 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1624 (char *)wp->w_buffer->b_ffname,
1625 (long)lnum, idx, type, serialNo++,
1626 (long)strlen((char *)text), (char *)text);
1627 balloonEval = beval;
1628 workshop_send_message(buf);
1633 #endif
1636 static int
1637 computeIndex(
1638 int wantedCol,
1639 char_u *line,
1640 int ts)
1642 int col = 0;
1643 int idx = 0;
1645 while (line[idx])
1647 if (line[idx] == '\t')
1648 col += ts - (col % ts);
1649 else
1650 col++;
1651 idx++;
1652 if (col >= wantedCol)
1653 return idx;
1656 return -1;
1659 static void
1660 addMenu(
1661 char *menu, /* menu name */
1662 char *accel, /* accelerator text (optional) */
1663 char *verb) /* WorkShop action-verb */
1665 MenuMap *newMap;
1666 char cbuf[BUFSIZ];
1668 if (menuMapSize >= menuMapMax)
1670 newMap = realloc(menuMap,
1671 sizeof(MenuMap) * (menuMapMax + MENU_INC));
1672 if (newMap != NULL)
1674 menuMap = newMap;
1675 menuMapMax += MENU_INC;
1678 if (menuMapSize < menuMapMax)
1680 menuMap[menuMapSize].name = strdup(menu);
1681 menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL;
1682 menuMap[menuMapSize++].verb = strdup(verb);
1683 if (accel && workshopHotKeysEnabled)
1685 vim_snprintf(cbuf, sizeof(cbuf),
1686 "map %s :wsverb %s<CR>", accel, verb);
1687 coloncmd(cbuf, TRUE);
1692 static char *
1693 nameStrip(
1694 char *raw) /* menu name, possibly with & chars */
1696 static char buf[BUFSIZ]; /* build stripped name here */
1697 char *bp = buf;
1699 while (*raw)
1701 if (*raw != '&')
1702 *bp++ = *raw;
1703 raw++;
1705 *bp = NUL;
1706 return buf;
1710 static char *
1711 lookupVerb(
1712 char *verb,
1713 int skip) /* number of matches to skip */
1715 int i; /* loop iterator */
1717 for (i = 0; i < menuMapSize; i++)
1718 if (strcmp(menuMap[i].verb, verb) == 0 && skip-- == 0)
1719 return nameStrip(menuMap[i].name);
1721 return NULL;
1725 static void
1726 coloncmd(
1727 char *cmd, /* the command to print */
1728 Boolean force) /* force cursor update */
1730 char_u *cpo_save = p_cpo;
1732 #ifdef WSDEBUG
1733 if (WSDLEVEL(WS_TRACE_COLONCMD))
1734 wsdebug("Cmd: %s\n", cmd);
1735 #endif
1737 p_cpo = empty_option;
1739 ALT_INPUT_LOCK_ON;
1740 do_cmdline_cmd((char_u *)cmd);
1741 ALT_INPUT_LOCK_OFF;
1743 p_cpo = cpo_save;
1745 if (force)
1746 gui_update_screen();
1750 * setDollarVim - Given the run directory, search for the vim install
1751 * directory and set $VIM.
1753 * We can be running out of SUNWspro/bin or out of
1754 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1755 * relative to both of these directories.
1757 static void
1758 setDollarVim(
1759 char *rundir)
1761 char buf[MAXPATHLEN];
1762 char *cp;
1765 * First case: Running from <install-dir>/SUNWspro/bin
1767 strcpy(buf, rundir);
1768 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1769 VIM_VERSION_NODOT "/syntax/syntax.vim");
1770 if (access(buf, R_OK) == 0)
1772 strcpy(buf, "SPRO_WSDIR=");
1773 strcat(buf, rundir);
1774 cp = strrchr(buf, '/');
1775 if (cp != NULL)
1776 strcpy(cp, "/WS6U2");
1777 putenv(strdup(buf));
1779 strcpy(buf, "VIM=");
1780 strcat(buf, rundir);
1781 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1782 VIM_VERSION_NODOT);
1783 putenv(strdup(buf));
1784 return;
1788 * Second case: Probably running from
1789 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1791 strcpy(buf, rundir);
1792 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1793 "/share/vim/" VIM_VERSION_NODOT "/syntax/syntax.vim");
1794 if (access(buf, R_OK) == 0)
1796 strcpy(buf, "SPRO_WSDIR=");
1797 strcat(buf, rundir);
1798 cp = strrchr(buf, '/');
1799 if (cp != NULL)
1800 strcpy(cp, "../../../../WS6U2");
1801 putenv(strdup(buf));
1803 strcpy(buf, "VIM=");
1804 strcat(buf, rundir);
1805 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1806 "/share/vim/" VIM_VERSION_NODOT);
1807 putenv(strdup(buf));
1808 return;
1813 * findYourself - Find the directory we are running from. This is used to
1814 * set $VIM. We need to set this because users can install
1815 * the package in a different directory than the compiled
1816 * directory. This is a Sun Visual WorkShop requirement!
1818 * Note: We override a user's $VIM because it won't have the
1819 * WorkShop specific files. S/he may not like this but its
1820 * better than getting the wrong files (especially as the
1821 * user is likely to have $VIM set to 5.4 or later).
1823 void
1824 findYourself(
1825 char *argv0)
1827 char *runpath = NULL;
1828 char *path;
1829 char *pathbuf;
1831 if (*argv0 == '/')
1832 runpath = strdup(argv0);
1833 else if (*argv0 == '.' || strchr(argv0, '/'))
1835 runpath = (char *) malloc(MAXPATHLEN);
1836 getcwd(runpath, MAXPATHLEN);
1837 strcat(runpath, "/");
1838 strcat(runpath, argv0);
1840 else
1842 path = getenv("PATH");
1843 if (path != NULL)
1845 runpath = (char *) malloc(MAXPATHLEN);
1846 pathbuf = strdup(path);
1847 path = strtok(pathbuf, ":");
1850 strcpy(runpath, path);
1851 strcat(runpath, "/");
1852 strcat(runpath, argv0);
1853 if (access(runpath, X_OK) == 0)
1854 break;
1855 } while ((path = strtok(NULL, ":")) != NULL);
1856 free(pathbuf);
1860 if (runpath != NULL)
1862 char runbuf[MAXPATHLEN];
1865 * We found the run directory. Now find the install dir.
1867 (void)vim_FullName((char_u *)runpath, (char_u *)runbuf, MAXPATHLEN, 1);
1868 path = strrchr(runbuf, '/');
1869 if (path != NULL)
1870 *path = NUL; /* remove the vim/gvim name */
1871 path = strrchr(runbuf, '/');
1872 if (path != NULL)
1874 if (strncmp(path, "/bin", 4) == 0)
1875 setDollarVim(runbuf);
1876 else if (strncmp(path, "/src", 4) == 0)
1878 *path = NUL; /* development tree */
1879 setDollarVim(runbuf);
1882 free(runpath);