Deleted junk files.
[MacVim/jjgod.git] / src / workshop.c
blob38d27c4d731d8554c5986ddb71b795734c1520f8
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 <fcntl.h>
17 #include <sys/types.h>
18 #include <netdb.h>
19 #include <netinet/in.h>
20 #include <errno.h>
21 #include <sys/socket.h>
22 #ifdef HAVE_LIBGEN_H
23 # include <libgen.h>
24 #endif
25 #include <unistd.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <ctype.h>
30 #include <X11/Intrinsic.h>
31 #include <Xm/Xm.h>
32 #include <Xm/PushB.h>
34 #include "integration.h" /* <EditPlugin/integration.h> */
36 #include "vim.h"
37 #include "version.h"
38 #include "gui_beval.h"
39 #include "workshop.h"
41 void workshop_hotkeys(Boolean);
43 static Boolean isShowing(int);
44 static win_T *get_window(buf_T *);
45 #if 0
46 static int get_buffer_number(buf_T *);
47 #endif
48 static void updatePriority(Boolean);
49 static char *addUniqueMnemonic(char *, char *);
50 static char *fixup(char *);
51 static char *get_selection(buf_T *);
52 static char *append_selection(int, char *, int *, int *);
53 static void load_buffer_by_name(char *, int);
54 #if 0
55 static void load_buffer_by_number(int, int);
56 #endif
57 static void load_window(char *, int lnum);
58 static void warp_to_pc(int);
59 #ifdef FEAT_BEVAL
60 void workshop_beval_cb(BalloonEval *, int);
61 #endif
62 static char *fixAccelText(char *);
63 static void addMenu(char *, char *, char *);
64 static char *lookupVerb(char *, int);
65 static int computeIndex(int, char_u *, int);
66 static void coloncmd(char *, Boolean);
68 extern Widget vimShell;
69 extern Widget textArea;
70 extern XtAppContext app_context;
72 static int tbpri; /* ToolBar priority */
73 int usingSunWorkShop = 0; /* set if -ws flag is used */
74 char curMenuName[BUFSIZ];
75 char curMenuPriority[BUFSIZ];
77 static Boolean workshopInitDone = False;
78 static Boolean workshopHotKeysEnabled = False;
81 * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it
82 * here because its C++.
84 enum
86 GPLineEval_EVALUATE, /* evaluate expression */
87 GPLineEval_INDIRECT, /* evaluate *<expression> */
88 GPLineEval_TYPE /* type of expression */
92 * Store each verb in the MenuMap. This lets us map from a verb to a menu.
93 * There may be multiple matches for a single verb in this table.
95 #define MENU_INC 50 /* menuMap incremental size increases */
96 typedef struct
98 char *name; /* name of the menu */
99 char *accel; /* optional accelerator key */
100 char *verb; /* menu verb */
101 } MenuMap;
102 static MenuMap *menuMap; /* list of verb/menu mappings */
103 static int menuMapSize; /* current size of menuMap */
104 static int menuMapMax; /* allocated size of menuMap */
105 static char *initialFileCmd; /* save command but defer doing it */
108 void
109 workshop_init()
111 char_u buf[64];
112 int is_dirty = FALSE;
113 int width, height;
114 XtInputMask mask;
117 * Turn on MenuBar, ToolBar, and Footer.
119 STRCPY(buf, p_go);
120 if (vim_strchr(p_go, GO_MENUS) == NULL)
122 STRCAT(buf, "m");
123 is_dirty = TRUE;
125 if (vim_strchr(p_go, GO_TOOLBAR) == NULL)
127 STRCAT(buf, "T");
128 is_dirty = TRUE;
130 if (vim_strchr(p_go, GO_FOOTER) == NULL)
132 STRCAT(buf, "F");
133 is_dirty = TRUE;
135 if (is_dirty)
136 set_option_value((char_u *)"go", 0L, buf, 0);
139 * Set size from workshop_get_width_height().
141 width = height = 0;
142 if (workshop_get_width_height(&width, &height))
144 XtVaSetValues(vimShell,
145 XmNwidth, width,
146 XmNheight, height,
147 NULL);
151 * Now read in the initial messages from eserve.
153 while ((mask = XtAppPending(app_context))
154 && (mask & XtIMAlternateInput) && !workshopInitDone)
155 XtAppProcessEvent(app_context, (XtInputMask)XtIMAlternateInput);
158 void
159 workshop_postinit()
161 do_cmdline_cmd((char_u *)initialFileCmd);
162 ALT_INPUT_LOCK_OFF;
163 free(initialFileCmd);
164 initialFileCmd = NULL;
167 void
168 ex_wsverb(exarg_T *eap)
170 msg_clr_cmdline();
171 workshop_perform_verb((char *) eap->arg, NULL);
175 * Editor name
176 * This string is recognized by eserve and should be all lower case.
177 * This is how the editor detects that it is talking to gvim instead
178 * of NEdit, for example, when the connection is initiated from the editor.
180 char *
181 workshop_get_editor_name()
183 return "gvim";
187 * Version number of the editor.
188 * This number is communicated along with the protocol
189 * version to the application.
191 char *
192 workshop_get_editor_version()
194 return Version;
198 * Answer functions: called by eserve
202 * Name:
203 * workshop_load_file
205 * Function:
206 * Load a given file into the WorkShop buffer.
208 /*ARGSUSED*/
209 void
210 workshop_load_file(
211 char *filename, /* the file to load */
212 int line, /* an optional line number (or 0) */
213 char *frameid) /* used for multi-frame support */
215 #ifdef WSDEBUG_TRACE
216 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
217 wstrace("workshop_load_file(%s, %d)\n", filename, line);
218 #endif
220 #ifdef FEAT_BEVAL
221 bevalServers |= BEVAL_WORKSHOP;
222 #endif
224 load_window(filename, line);
228 * Reload the WorkShop buffer
230 void
231 workshop_reload_file(
232 char *filename,
233 int line)
235 #ifdef WSDEBUG_TRACE
236 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
237 wstrace("workshop_reload_file(%s, %d)\n", filename, line);
238 #endif
239 load_window(filename, line);
242 void
243 workshop_show_file(
244 char *filename)
246 #ifdef WSDEBUG_TRACE
247 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
248 wstrace("workshop_show_file(%s)\n", filename);
249 #endif
251 load_window(filename, 0);
254 void
255 workshop_goto_line(
256 char *filename,
257 int lineno)
259 #ifdef WSDEBUG_TRACE
260 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
261 wstrace("workshop_goto_line(%s, %d)\n", filename, lineno);
262 #endif
264 load_window(filename, lineno);
267 /*ARGSUSED*/
268 void
269 workshop_front_file(
270 char *filename)
272 #ifdef WSDEBUG_TRACE
273 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
274 wstrace("workshop_front_file()\n");
275 #endif
277 * Assumption: This function will always be called after a call to
278 * workshop_show_file(), so the file is always showing.
280 if (vimShell != NULL)
281 XRaiseWindow(gui.dpy, XtWindow(vimShell));
284 void
285 workshop_save_file(
286 char *filename)
288 char cbuf[BUFSIZ]; /* build vim command here */
290 #ifdef WSDEBUG_TRACE
291 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
292 wstrace("workshop_save_file(%s)\n", filename);
293 #endif
295 /* Save the given file */
296 vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename);
297 coloncmd(cbuf, TRUE);
300 void
301 workshop_save_files()
303 /* Save the given file */
304 #ifdef WSDEBUG_TRACE
305 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
306 wstrace("workshop_save_files()\n");
307 #endif
309 add_to_input_buf((char_u *) ":wall\n", 6);
312 void
313 workshop_quit()
315 #ifdef WSDEBUG_TRACE
316 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
317 wstrace("workshop_quit()\n");
318 #endif
320 add_to_input_buf((char_u *) ":qall\n", 6);
323 void
324 workshop_minimize()
326 #ifdef WSDEBUG_TRACE
327 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
328 wstrace("workshop_minimize()\n");
329 #endif
330 workshop_minimize_shell(vimShell);
332 void
333 workshop_maximize()
335 #ifdef WSDEBUG_TRACE
336 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
337 wstrace("workshop_maximize()\n");
338 #endif
340 workshop_maximize_shell(vimShell);
343 void
344 workshop_add_mark_type(
345 int idx,
346 char *colorspec,
347 char *sign)
349 char gbuf[BUFSIZ]; /* buffer for sign name */
350 char cibuf[BUFSIZ]; /* color information */
351 char cbuf[BUFSIZ]; /* command buffer */
352 char *bp;
354 #ifdef WSDEBUG_TRACE
355 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
357 char *cp;
359 cp = strrchr(sign, '/');
360 if (cp == NULL)
361 cp = sign;
362 else
363 cp++; /* skip '/' character */
364 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx,
365 colorspec && *colorspec ? colorspec : "<None>", cp);
367 #endif
370 * Isolate the basename of sign in gbuf. We will use this for the
371 * GroupName in the highlight command sent to vim.
373 STRCPY(gbuf, gettail((char_u *)sign));
374 bp = strrchr(gbuf, '.');
375 if (bp != NULL)
376 *bp = NUL;
378 if (gbuf[0] != '-' && gbuf[1] != NUL)
380 if (colorspec != NULL && *colorspec)
382 vim_snprintf(cbuf, sizeof(cbuf),
383 "highlight WS%s guibg=%s", gbuf, colorspec);
384 coloncmd(cbuf, FALSE);
385 vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf);
387 else
388 cibuf[0] = NUL;
390 vim_snprintf(cbuf, sizeof(cbuf),
391 "sign define %d %s icon=%s", idx, cibuf, sign);
392 coloncmd(cbuf, TRUE);
396 void
397 workshop_set_mark(
398 char *filename, /* filename which gets the mark */
399 int lineno, /* line number which gets the mark */
400 int markId, /* unique mark identifier */
401 int idx) /* which mark to use */
403 char cbuf[BUFSIZ]; /* command buffer */
405 /* Set mark in a given file */
406 #ifdef WSDEBUG_TRACE
407 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
408 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n",
409 filename, lineno, markId, idx);
410 #endif
412 vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s",
413 markId, lineno, idx, filename);
414 coloncmd(cbuf, TRUE);
417 void
418 workshop_change_mark_type(
419 char *filename, /* filename which gets the mark */
420 int markId, /* unique mark identifier */
421 int idx) /* which mark to use */
423 char cbuf[BUFSIZ]; /* command buffer */
425 /* Change mark type */
426 #ifdef WSDEBUG_TRACE
427 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
428 wstrace("workshop_change_mark_type(%s, %d, %d)\n",
429 filename, markId, idx);
430 #endif
432 vim_snprintf(cbuf, sizeof(cbuf),
433 "sign place %d name=%d file=%s", markId, idx, filename);
434 coloncmd(cbuf, TRUE);
438 * Goto the given mark in a file (e.g. show it).
439 * If message is not null, display it in the footer.
441 void
442 workshop_goto_mark(
443 char *filename,
444 int markId,
445 char *message)
447 char cbuf[BUFSIZ]; /* command buffer */
449 /* Goto mark */
450 #ifdef WSDEBUG_TRACE
451 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
452 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
453 filename, markId, message && *message &&
454 !(*message == ' ' && message[1] == NULL) ?
455 message : "<None>");
456 #endif
458 vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename);
459 coloncmd(cbuf, TRUE);
460 if (message != NULL && *message != NUL)
461 gui_mch_set_footer((char_u *)message);
464 void
465 workshop_delete_mark(
466 char *filename,
467 int markId)
469 char cbuf[BUFSIZ]; /* command buffer */
471 /* Delete mark */
472 #ifdef WSDEBUG_TRACE
473 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
474 wstrace("workshop_delete_mark(%s, %d (id))\n",
475 filename, markId);
476 #endif
478 vim_snprintf(cbuf, sizeof(cbuf),
479 "sign unplace %d file=%s", markId, filename);
480 coloncmd(cbuf, TRUE);
483 #if 0 /* not used */
484 void
485 workshop_delete_all_marks(
486 void *window,
487 Boolean doRefresh)
489 #ifdef WSDEBUG_TRACE
490 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
491 wstrace("workshop_delete_all_marks(%#x, %s)\n",
492 window, doRefresh ? "True" : "False");
493 #endif
495 coloncmd("sign unplace *", TRUE);
497 #endif
500 workshop_get_mark_lineno(
501 char *filename,
502 int markId)
504 buf_T *buf; /* buffer containing filename */
505 int lineno; /* line number of filename in buf */
507 /* Get mark line number */
508 #ifdef WSDEBUG_TRACE
509 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
510 wstrace("workshop_get_mark_lineno(%s, %d)\n",
511 filename, markId);
512 #endif
514 lineno = 0;
515 buf = buflist_findname((char_u *)filename);
516 if (buf != NULL)
517 lineno = buf_findsign(buf, markId);
519 return lineno;
523 #if 0 /* not used */
524 void
525 workshop_adjust_marks(Widget *window, int pos,
526 int inserted, int deleted)
528 #ifdef WSDEBUG_TRACE
529 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
530 wstrace("XXXworkshop_adjust_marks(%s, %d, %d, %d)\n",
531 window ? XtName(window) : "<None>", pos, inserted, deleted);
532 #endif
534 #endif
537 * Are there any moved marks? If so, call workshop_move_mark on
538 * each of them now. This is how eserve can find out if for example
539 * breakpoints have moved when a program has been recompiled and
540 * reloaded into dbx.
542 /*ARGSUSED*/
543 void
544 workshop_moved_marks(char *filename)
546 #ifdef WSDEBUG_TRACE
547 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
548 wstrace("XXXworkshop_moved_marks(%s)\n", filename);
549 #endif
553 workshop_get_font_height()
555 XmFontList fontList; /* fontList made from gui.norm_font */
556 XmString str;
557 Dimension w;
558 Dimension h;
560 #ifdef WSDEBUG_TRACE
561 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
562 wstrace("workshop_get_font_height()\n");
563 #endif
565 /* Pick the proper signs for this font size */
566 fontList = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
567 h = 0;
568 if (fontList != NULL)
570 str = XmStringCreateLocalized("A");
571 XmStringExtent(fontList, str, &w, &h);
572 XmStringFree(str);
573 XmFontListFree(fontList);
576 return (int)h;
579 /*ARGSUSED*/
580 void
581 workshop_footer_message(
582 char *message,
583 int severity) /* severity is currently unused */
585 #ifdef WSDEBUG_TRACE
586 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
587 wstrace("workshop_footer_message(%s, %d)\n", message, severity);
588 #endif
590 gui_mch_set_footer((char_u *) message);
594 * workshop_menu_begin() is passed the menu name. We determine its mnemonic
595 * here and store its name and priority.
597 void
598 workshop_menu_begin(
599 char *label)
601 vimmenu_T *menu; /* pointer to last menu */
602 int menuPriority = 0; /* priority of new menu */
603 char mnembuf[64]; /* store menubar mnemonics here */
604 char *name; /* label with a mnemonic */
605 char *p; /* used to find mnemonics */
606 int idx; /* index into mnembuf */
608 #ifdef WSDEBUG_TRACE
609 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
610 wstrace("workshop_menu_begin()\n");
611 #endif
614 * Look through all existing (non-PopUp and non-Toolbar) menus
615 * and gather their mnemonics. Use this list to decide what
616 * mnemonic should be used for label.
619 idx = 0;
620 mnembuf[idx++] = 'H'; /* H is mnemonic for Help */
621 for (menu = root_menu; menu != NULL; menu = menu->next)
623 if (menu_is_menubar(menu->name))
625 p = strchr((char *)menu->name, '&');
626 if (p != NULL)
627 mnembuf[idx++] = *++p;
629 if (menu->next != NULL
630 && strcmp((char *) menu->next->dname, "Help") == 0)
632 menuPriority = menu->priority + 10;
633 break;
636 mnembuf[idx++] = NUL;
637 name = addUniqueMnemonic(mnembuf, label);
639 vim_snprintf(curMenuName, sizeof(curMenuName), "%s", name);
640 sprintf(curMenuPriority, "%d.0", menuPriority);
644 * Append the name and priority to strings to be used in vim menu commands.
646 void
647 workshop_submenu_begin(
648 char *label)
650 #ifdef WSDEBUG_TRACE
651 if (ws_debug && ws_dlevel & WS_TRACE
652 && strncmp(curMenuName, "ToolBar", 7) != 0)
653 wstrace("workshop_submenu_begin(%s)\n", label);
654 #endif
656 strcat(curMenuName, ".");
657 strcat(curMenuName, fixup(label));
659 updatePriority(True);
663 * Remove the submenu name and priority from curMenu*.
666 void
667 workshop_submenu_end()
669 char *p;
671 #ifdef WSDEBUG_TRACE
672 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)
673 && strncmp(curMenuName, "ToolBar", 7) != 0)
674 wstrace("workshop_submenu_end()\n");
675 #endif
677 p = strrchr(curMenuPriority, '.');
678 ASSERT(p != NULL);
679 *p = NUL;
681 p = strrchr(curMenuName, '.');
682 ASSERT(p != NULL);
683 *p = NUL;
687 * This is where menus are really made. Each item will generate an amenu vim
688 * command. The globals curMenuName and curMenuPriority contain the name and
689 * priority of the parent menu tree.
691 /*ARGSUSED*/
692 void
693 workshop_menu_item(
694 char *label,
695 char *verb,
696 char *accelerator,
697 char *acceleratorText,
698 char *name,
699 char *filepos,
700 char *sensitive)
702 char cbuf[BUFSIZ];
703 char namebuf[BUFSIZ];
704 char accText[BUFSIZ];
706 #ifdef WSDEBUG_TRACE
707 if (WSDLEVEL(WS_TRACE_VERBOSE)
708 && strncmp(curMenuName, "ToolBar", 7) != 0)
710 if (ws_dlevel & WS_TRACE_VERBOSE)
711 wsdebug("workshop_menu_item(\n"
712 "\tlabel = \"%s\",\n"
713 "\tverb = %s,\n"
714 "\taccelerator = %s,\n"
715 "\tacceleratorText = \"%s\",\n"
716 "\tname = %s,\n"
717 "\tfilepos = %s,\n"
718 "\tsensitive = %s)\n",
719 label && *label ? label : "<None>",
720 verb && *verb ? verb : "<None>",
721 accelerator && *accelerator ?
722 accelerator : "<None>",
723 acceleratorText && *acceleratorText ?
724 acceleratorText : "<None>",
725 name && *name ? name : "<None>",
726 filepos && *filepos ? filepos : "<None>",
727 sensitive);
728 else if (ws_dlevel & WS_TRACE)
729 wstrace("workshop_menu_item(\"%s\", %s)\n",
730 label && *label ? label : "<None>",
731 verb && *verb ? verb : "<None>", sensitive);
733 #endif
734 #ifdef WSDEBUG_SENSE
735 if (ws_debug)
736 wstrace("menu: %-21.20s%-21.20s(%s)\n", label, verb,
737 *sensitive == '1' ? "Sensitive" : "Insensitive");
738 #endif
740 if (acceleratorText != NULL)
741 vim_snprintf(accText, sizeof(accText), "<Tab>%s", acceleratorText);
742 else
743 accText[0] = NUL;
744 updatePriority(False);
745 vim_snprintf(namebuf, sizeof(namebuf), "%s.%s", curMenuName, fixup(label));
746 vim_snprintf(cbuf, sizeof(cbuf), "amenu %s %s%s\t:wsverb %s<CR>",
747 curMenuPriority, namebuf, accText, verb);
749 coloncmd(cbuf, TRUE);
750 addMenu(namebuf, fixAccelText(acceleratorText), verb);
752 if (*sensitive == '0')
754 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
755 coloncmd(cbuf, TRUE);
760 * This function is called when a complete WorkShop menu description has been
761 * sent over from eserve. We do some menu cleanup.
764 void
765 workshop_menu_end()
767 Boolean using_tearoff; /* set per current option setting */
769 #ifdef WSDEBUG_TRACE
770 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
771 wstrace("workshop_menu_end()\n");
772 #endif
774 using_tearoff = vim_strchr(p_go, GO_TEAROFF) != NULL;
775 gui_mch_toggle_tearoffs(using_tearoff);
778 void
779 workshop_toolbar_begin()
781 #ifdef WSDEBUG_TRACE
782 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
783 wstrace("workshop_toolbar_begin()\n");
784 #endif
786 coloncmd("aunmenu ToolBar", True);
787 tbpri = 10;
790 void
791 workshop_toolbar_end()
793 char_u buf[64];
795 #ifdef WSDEBUG_TRACE
796 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
798 wstrace("workshop_toolbar_end()\n");
800 #endif
803 * Turn on ToolBar.
805 STRCPY(buf, p_go);
806 if (vim_strchr(p_go, 'T') == NULL)
808 STRCAT(buf, "T");
809 set_option_value((char_u *)"go", 0L, buf, 0);
811 workshopInitDone = True;
814 /*ARGSUSED*/
815 void
816 workshop_toolbar_button(
817 char *label,
818 char *verb,
819 char *senseVerb,
820 char *filepos,
821 char *help,
822 char *sense,
823 char *file,
824 char *left)
826 char cbuf[BUFSIZ + MAXPATHLEN];
827 char namebuf[BUFSIZ];
828 static int tbid = 1;
829 char_u *p;
830 int len;
832 #ifdef WSDEBUG_TRACE
833 if (WSDLEVEL(WS_TRACE_VERBOSE))
834 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
835 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
836 label && *label ? label : "<None>",
837 verb && *verb ? verb : "<None>",
838 senseVerb && *senseVerb ? senseVerb : "<None>",
839 filepos && *filepos ? filepos : "<None>",
840 help && *help ? help : "<None>",
841 sense && *sense ? sense : "<None>",
842 file && *file ? file : "<None>",
843 left && *left ? left : "<None>");
844 else if (WSDLEVEL(WS_TRACE))
845 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
846 label && *label ? label : "<None>",
847 verb && *verb ? verb : "<None>");
848 #endif
849 #ifdef WSDEBUG_SENSE
850 if (ws_debug)
851 wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb,
852 *sense == '1' ? "Sensitive" : "Insensitive");
853 #endif
855 if (left && *left && atoi(left) > 0)
857 /* Add a separator (but pass the width passed after the ':') */
858 sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
859 tbpri - 5, tbid++, left);
861 coloncmd(cbuf, True);
864 p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. ");
865 vim_snprintf(namebuf, sizeof(namebuf), "ToolBar.%s", p);
866 vim_free(p);
867 STRCPY(cbuf, "amenu <silent> ");
868 if (file != NULL && *file != NUL)
870 p = vim_strsave_escaped((char_u *)file, (char_u *)" ");
871 len = STRLEN(cbuf);
872 vim_snprintf(cbuf + len, sizeof(cbuf) - len, "icon=%s ", p);
873 vim_free(p);
875 len = STRLEN(cbuf);
876 vim_snprintf(cbuf + len, sizeof(cbuf) - len,"1.%d %s :wsverb %s<CR>",
877 tbpri, namebuf, verb);
879 /* Define the menu item */
880 coloncmd(cbuf, True);
882 if (*sense == '0')
884 /* If menu isn't sensitive at startup... */
885 vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf);
886 coloncmd(cbuf, True);
889 if (help && *help)
891 /* Do the tooltip */
892 vim_snprintf(cbuf, sizeof(cbuf), "tmenu %s %s", namebuf, help);
893 coloncmd(cbuf, True);
896 addMenu(namebuf, NULL, verb);
897 tbpri += 10;
900 void
901 workshop_frame_sensitivities(
902 VerbSense *vs) /* list of verbs to (de)sensitize */
904 VerbSense *vp; /* iterate through vs */
905 char *menu_name; /* used in menu lookup */
906 int cnt; /* count of verbs to skip */
907 int len; /* length of nonvariant part of command */
908 char cbuf[4096];
910 #ifdef WSDEBUG_TRACE
911 if (WSDLEVEL(WS_TRACE_VERBOSE) || WSDLEVEL(4))
913 wsdebug("workshop_frame_sensitivities(\n");
914 for (vp = vs; vp->verb != NULL; vp++)
915 wsdebug("\t%-25s%d\n", vp->verb, vp->sense);
916 wsdebug(")\n");
918 else if (WSDLEVEL(WS_TRACE))
919 wstrace("workshop_frame_sensitivities()\n");
920 #endif
921 #ifdef WSDEBUG_SENSE
922 if (ws_debug)
923 for (vp = vs; vp->verb != NULL; vp++)
924 wsdebug("change: %-21.20s%-21.20s(%s)\n",
925 "", vp->verb, vp->sense == 1 ?
926 "Sensitive" : "Insensitive");
927 #endif
930 * Look for all matching menu entries for the verb. There may be more
931 * than one if the verb has both a menu and toolbar entry.
933 for (vp = vs; vp->verb != NULL; vp++)
935 cnt = 0;
936 strcpy(cbuf, "amenu");
937 strcat(cbuf, " ");
938 strcat(cbuf, vp->sense ? "enable" : "disable");
939 strcat(cbuf, " ");
940 len = strlen(cbuf);
941 while ((menu_name = lookupVerb(vp->verb, cnt++)) != NULL)
943 strcpy(&cbuf[len], menu_name);
944 coloncmd(cbuf, FALSE);
947 gui_update_menus(0);
948 gui_mch_flush();
951 void
952 workshop_set_option(
953 char *option, /* name of a supported option */
954 char *value) /* value to set option to */
956 char cbuf[BUFSIZ]; /* command buffer */
958 #ifdef WSDEBUG_TRACE
959 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
961 wstrace("workshop_set_option(%s, %s)\n", option, value);
963 #endif
965 cbuf[0] = NUL;
966 switch (*option) /* switch on 1st letter */
968 case 's':
969 if (strcmp(option, "syntax") == 0)
970 vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value);
971 else if (strcmp(option, "savefiles") == 0)
972 ; /* XXX - Not yet implemented */
973 break;
975 case 'l':
976 if (strcmp(option, "lineno") == 0)
977 sprintf(cbuf, "set %snu",
978 (strcmp(value, "on") == 0) ? "" : "no");
979 break;
981 case 'p':
982 if (strcmp(option, "parentheses") == 0)
983 sprintf(cbuf, "set %ssm",
984 (strcmp(value, "on") == 0) ? "" : "no");
985 break;
987 case 'w':
988 /* this option is set by a direct call */
989 #ifdef WSDEBUG
990 wsdebug("workshop_set_option: "
991 "Got unexpected workshopkeys option");
992 #endif
993 break;
995 case 'b': /* these options are set from direct calls */
996 if (option[7] == NUL && strcmp(option, "balloon") == 0)
998 #ifdef WSDEBUG
999 /* set by direct call to workshop_balloon_mode */
1000 wsdebug("workshop_set_option: "
1001 "Got unexpected ballooneval option");
1002 #endif
1004 else if (strcmp(option, "balloondelay") == 0)
1006 #ifdef WSDEBUG
1007 /* set by direct call to workshop_balloon_delay */
1008 wsdebug("workshop_set_option: "
1009 "Got unexpected balloondelay option");
1010 #endif
1012 break;
1014 if (cbuf[0] != NUL)
1015 coloncmd(cbuf, TRUE);
1019 void
1020 workshop_balloon_mode(
1021 Boolean on)
1023 char cbuf[BUFSIZ]; /* command buffer */
1025 #ifdef WSDEBUG_TRACE
1026 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1027 wstrace("workshop_balloon_mode(%s)\n", on ? "True" : "False");
1028 #endif
1030 sprintf(cbuf, "set %sbeval", on ? "" : "no");
1031 coloncmd(cbuf, TRUE);
1035 void
1036 workshop_balloon_delay(
1037 int delay)
1039 char cbuf[BUFSIZ]; /* command buffer */
1041 #ifdef WSDEBUG_TRACE
1042 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1043 wstrace("workshop_balloon_delay(%d)\n", delay);
1044 #endif
1046 sprintf(cbuf, "set bdlay=%d", delay);
1047 coloncmd(cbuf, TRUE);
1051 void
1052 workshop_show_balloon_tip(
1053 char *tip)
1055 #ifdef WSDEBUG_TRACE
1056 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1057 wstrace("workshop_show_balloon_tip(%s)\n", tip);
1058 #endif
1060 if (balloonEval != NULL)
1061 gui_mch_post_balloon(balloonEval, (char_u *)tip);
1065 void
1066 workshop_hotkeys(
1067 Boolean on)
1069 char cbuf[BUFSIZ]; /* command buffer */
1070 MenuMap *mp; /* iterate over menuMap entries */
1072 #ifdef WSDEBUG_TRACE
1073 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1074 wstrace("workshop_hotkeys(%s)\n", on ? "True" : "False");
1075 #endif
1077 workshopHotKeysEnabled = on;
1078 if (workshopHotKeysEnabled)
1079 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++)
1081 if (mp->accel != NULL)
1083 vim_snprintf(cbuf, sizeof(cbuf),
1084 "map %s :wsverb %s<CR>", mp->accel, mp->verb);
1085 coloncmd(cbuf, TRUE);
1088 else
1089 for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++)
1091 if (mp->accel != NULL)
1093 vim_snprintf(cbuf, sizeof(cbuf), "unmap %s", mp->accel);
1094 coloncmd(cbuf, TRUE);
1100 * A button in the toolbar has been pushed.
1102 /*ARGSUSED*/
1104 workshop_get_positions(
1105 void *clientData, /* unused */
1106 char **filename, /* output data */
1107 int *curLine, /* output data */
1108 int *curCol, /* output data */
1109 int *selStartLine, /* output data */
1110 int *selStartCol, /* output data */
1111 int *selEndLine, /* output data */
1112 int *selEndCol, /* output data */
1113 int *selLength, /* output data */
1114 char **selection) /* output data */
1116 static char ffname[MAXPATHLEN];
1118 #ifdef WSDEBUG_TRACE
1119 if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE))
1120 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1121 clientData, (curbuf && curbuf->b_sfname != NULL)
1122 ? (char *)curbuf->b_sfname : "<None>");
1123 #endif
1125 strcpy(ffname, (char *) curbuf->b_ffname);
1126 *filename = ffname; /* copy so nobody can change b_ffname */
1127 *curLine = curwin->w_cursor.lnum;
1128 *curCol = curwin->w_cursor.col;
1130 if (curbuf->b_visual.vi_mode == 'v' &&
1131 equalpos(curwin->w_cursor, curbuf->b_visual.vi_end))
1133 *selStartLine = curbuf->b_visual.vi_start.lnum;
1134 *selStartCol = curbuf->b_visual.vi_start.col;
1135 *selEndLine = curbuf->b_visual.vi_end.lnum;
1136 *selEndCol = curbuf->b_visual.vi_end.col;
1137 *selection = get_selection(curbuf);
1138 if (*selection)
1139 *selLength = strlen(*selection);
1140 else
1141 *selLength = 0;
1143 else
1145 *selStartLine = *selEndLine = -1;
1146 *selStartCol = *selEndCol = -1;
1147 *selLength = 0;
1148 *selection = "";
1151 return True;
1156 /************************************************************************
1157 * Utility functions
1158 ************************************************************************/
1160 static char *
1161 get_selection(
1162 buf_T *buf) /* buffer whose selection we want */
1164 pos_T *start; /* start of the selection */
1165 pos_T *end; /* end of the selection */
1166 char *lp; /* pointer to actual line data */
1167 int llen; /* length of actual line data */
1168 char *sp; /* pointer to selection buffer */
1169 int slen; /* string length in selection buffer */
1170 int size; /* size of selection buffer */
1171 char *new_sp; /* temp pointer to new sp */
1172 int lnum; /* line number we are appending */
1174 if (buf->b_visual.vi_mode == 'v')
1176 start = &buf->b_visual.vi_start;
1177 end = &buf->b_visual.vi_end;
1178 if (start->lnum == end->lnum)
1180 /* selection is all on one line */
1181 lp = (char *) ml_get_pos(start);
1182 llen = end->col - start->col + 1;
1183 sp = (char *) malloc(llen + 1);
1184 if (sp != NULL)
1186 strncpy(sp, lp, llen);
1187 sp[llen] = NUL;
1190 else
1192 /* multi-line selection */
1193 lp = (char *) ml_get_pos(start);
1194 llen = strlen(lp);
1195 sp = (char *) malloc(BUFSIZ + llen);
1196 if (sp != NULL)
1198 size = BUFSIZ + llen;
1199 strcpy(sp, lp);
1200 sp[llen] = '\n';
1201 slen = llen + 1;
1203 lnum = start->lnum + 1;
1204 while (lnum < end->lnum)
1205 sp = append_selection(lnum++, sp, &size, &slen);
1207 lp = (char *) ml_get(end->lnum);
1208 llen = end->col + 1;
1209 if ((slen + llen) >= size)
1211 new_sp = (char *)
1212 realloc(sp, slen + llen + 1);
1213 if (new_sp != NULL)
1215 size += llen + 1;
1216 sp = new_sp;
1219 if ((slen + llen) < size)
1221 strncpy(&sp[slen], lp, llen);
1222 sp[slen + llen] = NUL;
1228 else
1229 sp = NULL;
1231 return sp;
1234 static char *
1235 append_selection(
1236 int lnum, /* line number to append */
1237 char *sp, /* pointer to selection buffer */
1238 int *size, /* ptr to size of sp */
1239 int *slen) /* ptr to length of selection string */
1241 char *lp; /* line of data from buffer */
1242 int llen; /* strlen of lp */
1243 char *new_sp; /* temp pointer to new sp */
1245 lp = (char *)ml_get((linenr_T)lnum);
1246 llen = strlen(lp);
1248 if ((*slen + llen) <= *size)
1250 new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen);
1251 if (*new_sp != NUL)
1253 *size = BUFSIZ + *slen + llen;
1254 sp = new_sp;
1257 if ((*slen + llen) > *size)
1259 strcat(&sp[*slen], lp);
1260 *slen += llen;
1261 sp[*slen++] = '\n';
1264 return sp;
1269 static void
1270 load_buffer_by_name(
1271 char *filename, /* the file to load */
1272 int lnum) /* an optional line number (or 0) */
1274 char lnumbuf[16]; /* make line number option for :e */
1275 char cbuf[BUFSIZ]; /* command buffer */
1277 if (lnum > 0)
1278 sprintf(lnumbuf, "+%d", lnum);
1279 else
1280 lnumbuf[0] = NUL;
1282 vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename);
1283 coloncmd(cbuf, False);
1287 static void
1288 load_window(
1289 char *filename, /* filename to load */
1290 int lnum) /* linenumber to go to */
1292 buf_T *buf; /* buffer filename is stored in */
1293 win_T *win; /* window filenme is displayed in */
1296 * Make sure filename is displayed and is the current window.
1299 buf = buflist_findname((char_u *)filename);
1300 if (buf == NULL || (win = get_window(buf)) == NULL)
1302 /* No buffer or buffer is not in current window */
1303 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1304 filename, lnum); */
1305 load_buffer_by_name(filename, lnum);
1307 else
1309 /* buf is in a window */
1310 if (win != curwin)
1312 win_enter(win, False);
1313 /* wsdebug("load_window: window endter %s\n",
1314 win->w_buffer->b_sfname); */
1316 if (lnum > 0 && win->w_cursor.lnum != lnum)
1318 warp_to_pc(lnum);
1319 /* wsdebug("load_window: warp to %s[%d]\n",
1320 win->w_buffer->b_sfname, lnum); */
1323 out_flush();
1328 static void
1329 warp_to_pc(
1330 int lnum) /* line number to warp to */
1332 char lbuf[256]; /* build line command here */
1334 if (lnum > 0)
1336 if (State & INSERT)
1337 add_to_input_buf((char_u *) "\033", 1);
1338 if (isShowing(lnum))
1339 sprintf(lbuf, "%dG", lnum);
1340 else
1341 sprintf(lbuf, "%dz.", lnum);
1342 add_to_input_buf((char_u *) lbuf, strlen(lbuf));
1346 static Boolean
1347 isShowing(
1348 int lnum) /* tell if line number is showing */
1350 return lnum >= curwin->w_topline && lnum < curwin->w_botline;
1355 static win_T *
1356 get_window(
1357 buf_T *buf) /* buffer to find window for */
1359 win_T *wp = NULL; /* window filename is in */
1361 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
1362 if (buf == wp->w_buffer)
1363 break;
1364 return wp;
1368 #if 0 /* not used */
1369 static int
1370 get_buffer_number(
1371 buf_T *buf) /* buffer to get position of */
1373 buf_T *bp; /* iterate over buffer list */
1374 int pos; /* the position in the buffer list */
1376 pos = 1;
1377 for (bp = firstbuf; bp != NULL; bp = bp->b_next)
1379 if (bp == buf)
1380 return pos;
1381 pos++;
1384 return 1;
1386 #endif
1388 static void
1389 updatePriority(
1390 Boolean subMenu) /* if True then start new submenu pri */
1392 int pri; /* priority of this menu/item */
1393 char *p;
1395 p = strrchr(curMenuPriority, '.');
1396 ASSERT(p != NULL);
1397 *p++ = NUL;
1399 pri = atoi(p) + 10; /* our new priority */
1401 if (subMenu)
1402 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1403 "%s.%d.0", curMenuPriority, pri);
1404 else
1405 vim_snprintf(curMenuPriority, sizeof(curMenuPriority),
1406 "%s.%d", curMenuPriority, pri);
1409 static char *
1410 addUniqueMnemonic(
1411 char *mnemonics, /* currently used mnemonics */
1412 char *label) /* label of menu needing mnemonic */
1414 static char name[BUFSIZ]; /* buffer for the updated name */
1415 char *p; /* pointer into label */
1416 char *found; /* pointer to possible mnemonic */
1418 found = NULL;
1419 for (p = label; *p != NUL; p++)
1420 if (strchr(mnemonics, *p) == 0)
1421 if (found == NULL || (isupper((int)*p) && islower((int)*found)))
1422 found = p;
1424 if (found != NULL)
1426 strncpy(name, label, (found - label));
1427 strcat(name, "&");
1428 strcat(name, found);
1430 else
1431 strcpy(name, label);
1433 return name;
1437 * Some characters in a menu name must be escaped in vim. Since this is vim
1438 * specific, it must be done on this side.
1440 static char *
1441 fixup(
1442 char *label)
1444 static char buf[BUFSIZ];
1445 char *bp; /* pointer into buf */
1446 char *lp; /* pointer into label */
1448 lp = label;
1449 bp = buf;
1450 while (*lp != NUL)
1452 if (*lp == ' ' || *lp == '.')
1453 *bp++ = '\\';
1454 *bp++ = *lp++;
1456 *bp = NUL;
1458 return buf;
1462 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1464 /* For the NoHands test suite */
1466 char *
1467 workshop_test_getcurrentfile()
1469 char *filename, *selection;
1470 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1471 int selEndCol, selLength;
1473 if (workshop_get_positions(
1474 NULL, &filename, &curLine, &curCol, &selStartLine,
1475 &selStartCol, &selEndLine, &selEndCol, &selLength,
1476 &selection))
1477 return filename;
1478 else
1479 return NULL;
1483 workshop_test_getcursorrow()
1485 return 0;
1489 workshop_test_getcursorcol()
1491 char *filename, *selection;
1492 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1493 int selEndCol, selLength;
1495 if (workshop_get_positions(
1496 NULL, &filename, &curLine, &curCol, &selStartLine,
1497 &selStartCol, &selEndLine, &selEndCol, &selLength,
1498 &selection))
1499 return curCol;
1500 else
1501 return -1;
1504 char *
1505 workshop_test_getcursorrowtext()
1507 return NULL;
1510 char *
1511 workshop_test_getselectedtext()
1513 char *filename, *selection;
1514 int curLine, curCol, selStartLine, selStartCol, selEndLine;
1515 int selEndCol, selLength;
1517 if (workshop_get_positions(
1518 NULL, &filename, &curLine, &curCol, &selStartLine,
1519 &selStartCol, &selEndLine, &selEndCol, &selLength,
1520 &selection))
1521 return selection;
1522 else
1523 return NULL;
1526 /*ARGSUSED*/
1527 void
1528 workshop_save_sensitivity(char *filename)
1532 #endif
1534 static char *
1535 fixAccelText(
1536 char *ap) /* original acceleratorText */
1538 char buf[256]; /* build in temp buffer */
1539 char *shift; /* shift string of "" */
1541 if (ap == NULL)
1542 return NULL;
1544 /* If the accelerator is shifted use the vim form */
1545 if (strncmp("Shift+", ap, 6) == 0)
1547 shift = "S-";
1548 ap += 6;
1550 else
1551 shift = "";
1553 if (*ap == 'F' && atoi(&ap[1]) > 0)
1555 vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap);
1556 return strdup(buf);
1558 else
1559 return NULL;
1562 #ifdef FEAT_BEVAL
1563 void
1564 workshop_beval_cb(
1565 BalloonEval *beval,
1566 int state)
1568 win_T *wp;
1569 char_u *text;
1570 int type;
1571 linenr_T lnum;
1572 int col;
1573 int idx;
1574 char buf[MAXPATHLEN * 2];
1575 static int serialNo = -1;
1577 if (!p_beval)
1578 return;
1580 if (get_beval_info(beval, FALSE, &wp, &lnum, &text, &col) == OK)
1582 if (text && text[0])
1584 /* Send debugger request */
1585 if (strlen((char *) text) > (MAXPATHLEN/2))
1588 * The user has probably selected the entire
1589 * buffer or something like that - don't attempt
1590 * to evaluate it
1592 return;
1596 * WorkShop expects the col to be a character index, not
1597 * a column number. Compute the index from col. Also set
1598 * line to 0 because thats what dbx expects.
1600 idx = computeIndex(col, text, beval->ts);
1601 if (idx > 0)
1603 lnum = 0;
1606 * If successful, it will respond with a balloon cmd.
1608 if (state & ControlMask)
1609 /* Evaluate *(expression) */
1610 type = (int)GPLineEval_INDIRECT;
1611 else if (state & ShiftMask)
1612 /* Evaluate type(expression) */
1613 type = (int)GPLineEval_TYPE;
1614 else
1615 /* Evaluate value(expression) */
1616 type = (int)GPLineEval_EVALUATE;
1618 /* Send request to dbx */
1619 vim_snprintf(buf, sizeof(buf), "toolVerb debug.balloonEval "
1620 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1621 (char *)wp->w_buffer->b_ffname,
1622 (long)lnum, idx, type, serialNo++,
1623 (long)strlen((char *)text), (char *)text);
1624 balloonEval = beval;
1625 workshop_send_message(buf);
1630 #endif
1633 static int
1634 computeIndex(
1635 int wantedCol,
1636 char_u *line,
1637 int ts)
1639 int col = 0;
1640 int idx = 0;
1642 while (line[idx])
1644 if (line[idx] == '\t')
1645 col += ts - (col % ts);
1646 else
1647 col++;
1648 idx++;
1649 if (col >= wantedCol)
1650 return idx;
1653 return -1;
1656 static void
1657 addMenu(
1658 char *menu, /* menu name */
1659 char *accel, /* accelerator text (optional) */
1660 char *verb) /* WorkShop action-verb */
1662 MenuMap *newMap;
1663 char cbuf[BUFSIZ];
1665 if (menuMapSize >= menuMapMax)
1667 newMap = realloc(menuMap,
1668 sizeof(MenuMap) * (menuMapMax + MENU_INC));
1669 if (newMap != NULL)
1671 menuMap = newMap;
1672 menuMapMax += MENU_INC;
1675 if (menuMapSize < menuMapMax)
1677 menuMap[menuMapSize].name = strdup(menu);
1678 menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL;
1679 menuMap[menuMapSize++].verb = strdup(verb);
1680 if (accel && workshopHotKeysEnabled)
1682 vim_snprintf(cbuf, sizeof(cbuf),
1683 "map %s :wsverb %s<CR>", accel, verb);
1684 coloncmd(cbuf, TRUE);
1689 static char *
1690 nameStrip(
1691 char *raw) /* menu name, possibly with & chars */
1693 static char buf[BUFSIZ]; /* build stripped name here */
1694 char *bp = buf;
1696 while (*raw)
1698 if (*raw != '&')
1699 *bp++ = *raw;
1700 raw++;
1702 *bp = NUL;
1703 return buf;
1707 static char *
1708 lookupVerb(
1709 char *verb,
1710 int skip) /* number of matches to skip */
1712 int i; /* loop iterator */
1714 for (i = 0; i < menuMapSize; i++)
1715 if (strcmp(menuMap[i].verb, verb) == 0 && skip-- == 0)
1716 return nameStrip(menuMap[i].name);
1718 return NULL;
1722 static void
1723 coloncmd(
1724 char *cmd, /* the command to print */
1725 Boolean force) /* force cursor update */
1727 char_u *cpo_save = p_cpo;
1729 #ifdef WSDEBUG
1730 if (WSDLEVEL(WS_TRACE_COLONCMD))
1731 wsdebug("Cmd: %s\n", cmd);
1732 #endif
1734 p_cpo = empty_option;
1736 ALT_INPUT_LOCK_ON;
1737 do_cmdline_cmd((char_u *)cmd);
1738 ALT_INPUT_LOCK_OFF;
1740 p_cpo = cpo_save;
1742 if (force)
1743 gui_update_screen();
1747 * setDollarVim - Given the run directory, search for the vim install
1748 * directory and set $VIM.
1750 * We can be running out of SUNWspro/bin or out of
1751 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1752 * relative to both of these directories.
1754 static void
1755 setDollarVim(
1756 char *rundir)
1758 char buf[MAXPATHLEN];
1759 char *cp;
1762 * First case: Running from <install-dir>/SUNWspro/bin
1764 strcpy(buf, rundir);
1765 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1766 VIM_VERSION_NODOT "/syntax/syntax.vim");
1767 if (access(buf, R_OK) == 0)
1769 strcpy(buf, "SPRO_WSDIR=");
1770 strcat(buf, rundir);
1771 cp = strrchr(buf, '/');
1772 if (cp != NULL)
1773 strcpy(cp, "/WS6U2");
1774 putenv(strdup(buf));
1776 strcpy(buf, "VIM=");
1777 strcat(buf, rundir);
1778 strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/"
1779 VIM_VERSION_NODOT);
1780 putenv(strdup(buf));
1781 return;
1785 * Second case: Probably running from
1786 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1788 strcpy(buf, rundir);
1789 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1790 "/share/vim/" VIM_VERSION_NODOT "/syntax/syntax.vim");
1791 if (access(buf, R_OK) == 0)
1793 strcpy(buf, "SPRO_WSDIR=");
1794 strcat(buf, rundir);
1795 cp = strrchr(buf, '/');
1796 if (cp != NULL)
1797 strcpy(cp, "../../../../WS6U2");
1798 putenv(strdup(buf));
1800 strcpy(buf, "VIM=");
1801 strcat(buf, rundir);
1802 strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1803 "/share/vim/" VIM_VERSION_NODOT);
1804 putenv(strdup(buf));
1805 return;
1810 * findYourself - Find the directory we are running from. This is used to
1811 * set $VIM. We need to set this because users can install
1812 * the package in a different directory than the compiled
1813 * directory. This is a Sun Visual WorkShop requirement!
1815 * Note: We override a user's $VIM because it won't have the
1816 * WorkShop specific files. S/he may not like this but its
1817 * better than getting the wrong files (especially as the
1818 * user is likely to have $VIM set to 5.4 or later).
1820 void
1821 findYourself(
1822 char *argv0)
1824 char *runpath = NULL;
1825 char *path;
1826 char *pathbuf;
1828 if (*argv0 == '/')
1829 runpath = strdup(argv0);
1830 else if (*argv0 == '.' || strchr(argv0, '/'))
1832 runpath = (char *) malloc(MAXPATHLEN);
1833 getcwd(runpath, MAXPATHLEN);
1834 strcat(runpath, "/");
1835 strcat(runpath, argv0);
1837 else
1839 path = getenv("PATH");
1840 if (path != NULL)
1842 runpath = (char *) malloc(MAXPATHLEN);
1843 pathbuf = strdup(path);
1844 path = strtok(pathbuf, ":");
1847 strcpy(runpath, path);
1848 strcat(runpath, "/");
1849 strcat(runpath, argv0);
1850 if (access(runpath, X_OK) == 0)
1851 break;
1852 } while ((path = strtok(NULL, ":")) != NULL);
1853 free(pathbuf);
1857 if (runpath != NULL)
1859 char runbuf[MAXPATHLEN];
1862 * We found the run directory. Now find the install dir.
1864 (void)vim_FullName((char_u *)runpath, (char_u *)runbuf, MAXPATHLEN, 1);
1865 path = strrchr(runbuf, '/');
1866 if (path != NULL)
1867 *path = NUL; /* remove the vim/gvim name */
1868 path = strrchr(runbuf, '/');
1869 if (path != NULL)
1871 if (strncmp(path, "/bin", 4) == 0)
1872 setDollarVim(runbuf);
1873 else if (strncmp(path, "/src", 4) == 0)
1875 *path = NUL; /* development tree */
1876 setDollarVim(runbuf);
1879 free(runpath);