blob: ef41081ef950e29b77897087138dd9aaa894f04f [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * dosinst.c: Install program for Vim on MS-DOS and MS-Windows
12 *
13 * Compile with Make_mvc.mak, Make_bc3.mak, Make_bc5.mak or Make_djg.mak.
14 */
15
16/*
17 * Include common code for dosinst.c and uninstal.c.
18 */
19#define DOSINST
20#include "dosinst.h"
21
22/* Macro to do an error check I was typing over and over */
23#define CHECK_REG_ERROR(code) if (code != ERROR_SUCCESS) { printf("%ld error number: %ld\n", (long)__LINE__, (long)code); return 1; }
24
25int has_vim = 0; /* installable vim.exe exists */
26int has_gvim = 0; /* installable gvim.exe exists */
27
28char oldvimrc[BUFSIZE]; /* name of existing vimrc file */
29char vimrc[BUFSIZE]; /* name of vimrc file to create */
30
31char *default_bat_dir = NULL; /* when not NULL, use this as the default
32 directory to write .bat files in */
33char *default_vim_dir = NULL; /* when not NULL, use this as the default
34 install dir for NSIS */
35#if 0
36char homedir[BUFSIZE]; /* home directory or "" */
37#endif
38
39/*
40 * Structure used for each choice the user can make.
41 */
42struct choice
43{
44 int active; /* non-zero when choice is active */
45 char *text; /* text displayed for this choice */
46 void (*changefunc)(int idx); /* function to change this choice */
47 int arg; /* argument for function */
48 void (*installfunc)(int idx); /* function to install this choice */
49};
50
51struct choice choices[30]; /* choices the user can make */
52int choice_count = 0; /* number of choices available */
53
54#define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s))
55
56enum
57{
58 compat_vi = 1,
59 compat_some_enhancements,
60 compat_all_enhancements
61};
62char *(compat_choices[]) =
63{
64 "\nChoose the default way to run Vim:",
65 "Vi compatible",
Bram Moolenaarfff2bee2010-05-15 13:56:02 +020066 "with some Vim enhancements",
Bram Moolenaar071d4272004-06-13 20:20:40 +000067 "with syntax highlighting and other features switched on",
68};
69int compat_choice = (int)compat_all_enhancements;
70char *compat_text = "- run Vim %s";
71
72enum
73{
74 remap_no = 1,
75 remap_win
76};
77char *(remap_choices[]) =
78{
79 "\nChoose:",
80 "Do not remap keys for Windows behavior",
81 "Remap a few keys for Windows behavior (<C-V>, <C-C>, etc)",
82};
83int remap_choice = (int)remap_win;
84char *remap_text = "- %s";
85
86enum
87{
88 mouse_xterm = 1,
89 mouse_mswin
90};
91char *(mouse_choices[]) =
92{
93 "\nChoose the way how Vim uses the mouse:",
94 "right button extends selection (the Unix way)",
95 "right button has a popup menu (the Windows way)",
96};
97int mouse_choice = (int)mouse_mswin;
98char *mouse_text = "- The mouse %s";
99
100enum
101{
102 vimfiles_dir_none = 1,
103 vimfiles_dir_vim,
104 vimfiles_dir_home
105};
106static char *(vimfiles_dir_choices[]) =
107{
108 "\nCreate plugin directories:",
109 "No",
110 "In the VIM directory",
111 "In your HOME directory",
112};
113static int vimfiles_dir_choice;
114
115/* non-zero when selected to install the popup menu entry. */
116static int install_popup = 0;
117
118/* non-zero when selected to install the "Open with" entry. */
119static int install_openwith = 0;
120
121/* non-zero when need to add an uninstall entry in the registry */
122static int need_uninstall_entry = 0;
123
124/*
125 * Definitions of the directory name (under $VIM) of the vimfiles directory
126 * and its subdirectories:
127 */
128static char *(vimfiles_subdirs[]) =
129{
130 "colors",
131 "compiler",
132 "doc",
133 "ftdetect",
134 "ftplugin",
135 "indent",
136 "keymap",
137 "plugin",
138 "syntax",
139};
140
141/*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142 * Obtain a choice from a table.
143 * First entry is a question, others are choices.
144 */
145 static int
146get_choice(char **table, int entries)
147{
148 int answer;
149 int idx;
150 char dummy[100];
151
152 do
153 {
154 for (idx = 0; idx < entries; ++idx)
155 {
156 if (idx)
157 printf("%2d ", idx);
158 printf(table[idx]);
159 printf("\n");
160 }
161 printf("Choice: ");
162 if (scanf("%d", &answer) != 1)
163 {
164 scanf("%99s", dummy);
165 answer = 0;
166 }
167 }
168 while (answer < 1 || answer >= entries);
169
170 return answer;
171}
172
173/*
174 * Check if the user unpacked the archives properly.
175 * Sets "runtimeidx".
176 */
177 static void
178check_unpack(void)
179{
180 char buf[BUFSIZE];
181 FILE *fd;
182 struct stat st;
183
184 /* check for presence of the correct version number in installdir[] */
185 runtimeidx = strlen(installdir) - strlen(VIM_VERSION_NODOT);
186 if (runtimeidx <= 0
187 || stricmp(installdir + runtimeidx, VIM_VERSION_NODOT) != 0
188 || (installdir[runtimeidx - 1] != '/'
189 && installdir[runtimeidx - 1] != '\\'))
190 {
191 printf("ERROR: Install program not in directory \"%s\"\n",
192 VIM_VERSION_NODOT);
193 printf("This program can only work when it is located in its original directory\n");
194 myexit(1);
195 }
196
197 /* check if filetype.vim is present, which means the runtime archive has
198 * been unpacked */
199 sprintf(buf, "%s\\filetype.vim", installdir);
200 if (stat(buf, &st) < 0)
201 {
202 printf("ERROR: Cannot find filetype.vim in \"%s\"\n", installdir);
203 printf("It looks like you did not unpack the runtime archive.\n");
204 printf("You must unpack the runtime archive \"vim%srt.zip\" before installing.\n",
205 VIM_VERSION_NODOT + 3);
206 myexit(1);
207 }
208
209 /* Check if vim.exe or gvim.exe is in the current directory. */
210 if ((fd = fopen("gvim.exe", "r")) != NULL)
211 {
212 fclose(fd);
213 has_gvim = 1;
214 }
215 if ((fd = fopen("vim.exe", "r")) != NULL)
216 {
217 fclose(fd);
218 has_vim = 1;
219 }
220 if (!has_gvim && !has_vim)
221 {
222 printf("ERROR: Cannot find any Vim executables in \"%s\"\n\n",
223 installdir);
224 myexit(1);
225 }
226}
227
228/*
229 * Compare paths "p[plen]" to "q[qlen]". Return 0 if they match.
230 * Ignores case and differences between '/' and '\'.
231 * "plen" and "qlen" can be negative, strlen() is used then.
232 */
233 static int
234pathcmp(char *p, int plen, char *q, int qlen)
235{
236 int i;
237
238 if (plen < 0)
239 plen = strlen(p);
240 if (qlen < 0)
241 qlen = strlen(q);
242 for (i = 0; ; ++i)
243 {
244 /* End of "p": check if "q" also ends or just has a slash. */
245 if (i == plen)
246 {
247 if (i == qlen) /* match */
248 return 0;
249 if (i == qlen - 1 && (q[i] == '\\' || q[i] == '/'))
250 return 0; /* match with trailing slash */
251 return 1; /* no match */
252 }
253
254 /* End of "q": check if "p" also ends or just has a slash. */
255 if (i == qlen)
256 {
257 if (i == plen) /* match */
258 return 0;
259 if (i == plen - 1 && (p[i] == '\\' || p[i] == '/'))
260 return 0; /* match with trailing slash */
261 return 1; /* no match */
262 }
263
264 if (!(mytoupper(p[i]) == mytoupper(q[i])
265 || ((p[i] == '/' || p[i] == '\\')
266 && (q[i] == '/' || q[i] == '\\'))))
267 return 1; /* no match */
268 }
269 /*NOTREACHED*/
270}
271
272/*
273 * If the executable "**destination" is in the install directory, find another
274 * one in $PATH.
275 * On input "**destination" is the path of an executable in allocated memory
276 * (or NULL).
277 * "*destination" is set to NULL or the location of the file.
278 */
279 static void
280findoldfile(char **destination)
281{
282 char *bp = *destination;
283 size_t indir_l = strlen(installdir);
284 char *cp = bp + indir_l;
285 char *tmpname;
286 char *farname;
287
288 /*
289 * No action needed if exe not found or not in this directory.
290 */
291 if (bp == NULL
292 || strnicmp(bp, installdir, indir_l) != 0
293 || strchr("/\\", *cp++) == NULL
294 || strchr(cp, '\\') != NULL
295 || strchr(cp, '/') != NULL)
296 return;
297
298 tmpname = alloc((int)strlen(cp) + 1);
299 strcpy(tmpname, cp);
300 tmpname[strlen(tmpname) - 1] = 'x'; /* .exe -> .exx */
301
302 if (access(tmpname, 0) == 0)
303 {
304 printf("\nERROR: %s and %s clash. Remove or rename %s.\n",
305 tmpname, cp, tmpname);
306 myexit(1);
307 }
308
309 if (rename(cp, tmpname) != 0)
310 {
311 printf("\nERROR: failed to rename %s to %s: %s\n",
312 cp, tmpname, strerror(0));
313 myexit(1);
314 }
315
316 farname = searchpath_save(cp);
317
318 if (rename(tmpname, cp) != 0)
319 {
320 printf("\nERROR: failed to rename %s back to %s: %s\n",
321 tmpname, cp, strerror(0));
322 myexit(1);
323 }
324
325 free(*destination);
326 free(tmpname);
327 *destination = farname;
328}
329
330/*
331 * Check if there is a vim.[exe|bat|, gvim.[exe|bat|, etc. in the path.
332 * When "check_bat_only" is TRUE, only find "default_bat_dir".
333 */
334 static void
335find_bat_exe(int check_bat_only)
336{
337 int i;
338
Bram Moolenaar42bbef42006-03-25 22:02:07 +0000339 /* avoid looking in the "installdir" by chdir to system root */
340 mch_chdir(sysdrive);
341 mch_chdir("\\");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000342
343 for (i = 1; i < TARGET_COUNT; ++i)
344 {
345 targets[i].oldbat = searchpath_save(targets[i].batname);
346 if (!check_bat_only)
347 targets[i].oldexe = searchpath_save(targets[i].exename);
348
349 if (default_bat_dir == NULL && targets[i].oldbat != NULL)
350 {
351 default_bat_dir = alloc(strlen(targets[i].oldbat) + 1);
352 strcpy(default_bat_dir, targets[i].oldbat);
353 remove_tail(default_bat_dir);
354 }
355 if (check_bat_only && targets[i].oldbat != NULL)
Bram Moolenaar42bbef42006-03-25 22:02:07 +0000356 {
Bram Moolenaar071d4272004-06-13 20:20:40 +0000357 free(targets[i].oldbat);
Bram Moolenaar42bbef42006-03-25 22:02:07 +0000358 targets[i].oldbat = NULL;
359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360 }
361
362 mch_chdir(installdir);
363}
364
365#ifdef WIN3264
366/*
367 * Get the value of $VIMRUNTIME or $VIM and write it in $TEMP/vimini.ini, so
368 * that NSIS can read it.
369 * When not set, use the directory of a previously installed Vim.
370 */
371 static void
372get_vim_env(void)
373{
374 char *vim;
375 char buf[BUFSIZE];
376 FILE *fd;
377 char fname[BUFSIZE];
378
379 /* First get $VIMRUNTIME. If it's set, remove the tail. */
380 vim = getenv("VIMRUNTIME");
381 if (vim != NULL && *vim != 0)
382 {
383 strcpy(buf, vim);
384 remove_tail(buf);
385 vim = buf;
386 }
387 else
388 {
389 vim = getenv("VIM");
390 if (vim == NULL || *vim == 0)
391 {
392 /* Use the directory from an old uninstall entry. */
393 if (default_vim_dir != NULL)
394 vim = default_vim_dir;
395 else
396 /* Let NSIS know there is no default, it should use
Bram Moolenaarb8017e72007-05-10 18:59:07 +0000397 * $PROGRAMFILES. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398 vim = "";
399 }
400 }
401
402 /* NSIS also uses GetTempPath(), thus we should get the same directory
403 * name as where NSIS will look for vimini.ini. */
404 GetTempPath(BUFSIZE, fname);
405 add_pathsep(fname);
406 strcat(fname, "vimini.ini");
407
408 fd = fopen(fname, "w");
409 if (fd != NULL)
410 {
411 /* Make it look like an .ini file, so that NSIS can read it with a
412 * ReadINIStr command. */
413 fprintf(fd, "[vimini]\n");
414 fprintf(fd, "dir=\"%s\"\n", vim);
415 fclose(fd);
416 }
417 else
418 {
419 printf("Failed to open %s\n", fname);
Bram Moolenaarab8205e2010-07-07 15:14:03 +0200420 sleep(2);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000421 }
422}
423
Bram Moolenaarb230bd52010-05-25 21:02:00 +0200424static int num_windows;
425
426/*
427 * Callback used for EnumWindows():
428 * Count the window if the title looks like it is for the uninstaller.
429 */
430/*ARGSUSED*/
431 static BOOL CALLBACK
432window_cb(HWND hwnd, LPARAM lparam)
433{
434 char title[256];
435
436 title[0] = 0;
437 GetWindowText(hwnd, title, 256);
438 if (strstr(title, "Vim ") != NULL && strstr(title, "Uninstall:") != NULL)
439 ++num_windows;
440 return TRUE;
441}
442
Bram Moolenaar071d4272004-06-13 20:20:40 +0000443/*
444 * Check for already installed Vims.
445 * Return non-zero when found one.
446 */
447 static int
Bram Moolenaar442b4222010-05-24 21:34:22 +0200448uninstall_check(int skip_question)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449{
450 HKEY key_handle;
451 HKEY uninstall_key_handle;
452 char *uninstall_key = "software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
453 char subkey_name_buff[BUFSIZE];
454 char temp_string_buffer[BUFSIZE];
455 DWORD local_bufsize = BUFSIZE;
456 FILETIME temp_pfiletime;
457 DWORD key_index;
458 char input;
459 long code;
460 DWORD value_type;
461 DWORD orig_num_keys;
462 DWORD new_num_keys;
463 int foundone = 0;
464
465 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, uninstall_key, 0, KEY_READ,
466 &key_handle);
467 CHECK_REG_ERROR(code);
468
469 for (key_index = 0;
470 RegEnumKeyEx(key_handle, key_index, subkey_name_buff, &local_bufsize,
471 NULL, NULL, NULL, &temp_pfiletime) != ERROR_NO_MORE_ITEMS;
472 key_index++)
473 {
474 local_bufsize = BUFSIZE;
475 if (strncmp("Vim", subkey_name_buff, 3) == 0)
476 {
477 /* Open the key named Vim* */
478 code = RegOpenKeyEx(key_handle, subkey_name_buff, 0, KEY_READ,
479 &uninstall_key_handle);
480 CHECK_REG_ERROR(code);
481
482 /* get the DisplayName out of it to show the user */
483 code = RegQueryValueEx(uninstall_key_handle, "displayname", 0,
484 &value_type, (LPBYTE)temp_string_buffer,
485 &local_bufsize);
486 local_bufsize = BUFSIZE;
487 CHECK_REG_ERROR(code);
488
489 foundone = 1;
490 printf("\n*********************************************************\n");
491 printf("Vim Install found what looks like an existing Vim version.\n");
492 printf("The name of the entry is:\n");
493 printf("\n \"%s\"\n\n", temp_string_buffer);
494
495 printf("Installing the new version will disable part of the existing version.\n");
496 printf("(The batch files used in a console and the \"Edit with Vim\" entry in\n");
497 printf("the popup menu will use the new version)\n");
498
Bram Moolenaar442b4222010-05-24 21:34:22 +0200499 if (skip_question)
500 printf("\nRunning uninstall program for \"%s\"\n", temp_string_buffer);
501 else
502 printf("\nDo you want to uninstall \"%s\" now?\n(y)es/(n)o) ", temp_string_buffer);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 fflush(stdout);
504
505 /* get the UninstallString */
506 code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0,
507 &value_type, (LPBYTE)temp_string_buffer, &local_bufsize);
508 local_bufsize = BUFSIZE;
509 CHECK_REG_ERROR(code);
510
511 /* Remember the directory, it is used as the default for NSIS. */
512 default_vim_dir = alloc(strlen(temp_string_buffer) + 1);
513 strcpy(default_vim_dir, temp_string_buffer);
514 remove_tail(default_vim_dir);
515 remove_tail(default_vim_dir);
516
517 input = 'n';
518 do
519 {
520 if (input != 'n')
521 printf("%c is an invalid reply. Please enter either 'y' or 'n'\n", input);
522
Bram Moolenaar442b4222010-05-24 21:34:22 +0200523 if (skip_question)
524 input = 'y';
525 else
526 {
527 rewind(stdin);
528 scanf("%c", &input);
529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530 switch (input)
531 {
532 case 'y':
533 case 'Y':
534 /* save the number of uninstall keys so we can know if
535 * it changed */
536 RegQueryInfoKey(key_handle, NULL, NULL, NULL,
537 &orig_num_keys, NULL, NULL, NULL,
538 NULL, NULL, NULL, NULL);
539
Bram Moolenaar442b4222010-05-24 21:34:22 +0200540 /* Find existing .bat files before deleting them. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541 find_bat_exe(TRUE);
542
543 /* Execute the uninstall program. Put it in double
544 * quotes if there is an embedded space. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {
546 char buf[BUFSIZE];
547
Bram Moolenaarb230bd52010-05-25 21:02:00 +0200548 if (strchr(temp_string_buffer, ' ') != NULL)
549 sprintf(buf, "\"%s\"", temp_string_buffer);
550 else
551 strcpy(buf, temp_string_buffer);
552 run_command(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 }
Bram Moolenaarb230bd52010-05-25 21:02:00 +0200554
555 /* Count the number of windows with a title that match
556 * the installer, so that we can check when it's done.
557 * The uninstaller copies itself, executes the copy
558 * and exits, thus we can't wait for the process to
559 * finish. */
Bram Moolenaarab8205e2010-07-07 15:14:03 +0200560 sleep(1); /* wait for uninstaller to start up */
Bram Moolenaarb230bd52010-05-25 21:02:00 +0200561 num_windows = 0;
562 EnumWindows(window_cb, 0);
Bram Moolenaarab8205e2010-07-07 15:14:03 +0200563 sleep(1); /* wait for windows to be counted */
Bram Moolenaarb230bd52010-05-25 21:02:00 +0200564 if (num_windows == 0)
565 {
566 /* Did not find the uninstaller, ask user to press
567 * Enter when done. Just in case. */
568 printf("Press Enter when the uninstaller is finished\n");
569 rewind(stdin);
570 (void)getchar();
571 }
572 else
573 {
574 printf("Waiting for the uninstaller to finish (press CTRL-C to abort).");
575 do
576 {
577 printf(".");
578 fflush(stdout);
579 num_windows = 0;
580 EnumWindows(window_cb, 0);
Bram Moolenaarab8205e2010-07-07 15:14:03 +0200581 sleep(1); /* wait for windows to be counted */
Bram Moolenaarb230bd52010-05-25 21:02:00 +0200582 } while (num_windows > 0);
583 }
584 printf("\nDone!\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585
Bram Moolenaarfff2bee2010-05-15 13:56:02 +0200586 /* Check if an uninstall reg key was deleted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 * if it was, we want to decrement key_index.
588 * if we don't do this, we will skip the key
589 * immediately after any key that we delete. */
590 RegQueryInfoKey(key_handle, NULL, NULL, NULL,
591 &new_num_keys, NULL, NULL, NULL,
592 NULL, NULL, NULL, NULL);
593 if (new_num_keys < orig_num_keys)
594 key_index--;
595
596 input = 'y';
597 break;
598
599 case 'n':
600 case 'N':
601 /* Do not uninstall */
602 input = 'n';
603 break;
604
605 default: /* just drop through and redo the loop */
606 break;
607 }
608
609 } while (input != 'n' && input != 'y');
610
611 RegCloseKey(uninstall_key_handle);
612 }
613 }
614 RegCloseKey(key_handle);
615
616 return foundone;
617}
618#endif
619
620/*
621 * Find out information about the system.
622 */
623 static void
624inspect_system(void)
625{
626 char *p;
627 char buf[BUFSIZE];
628 FILE *fd;
629 int i;
630 int foundone;
631
632 /* This may take a little while, let the user know what we're doing. */
633 printf("Inspecting system...\n");
634
635 /*
636 * If $VIM is set, check that it's pointing to our directory.
637 */
638 p = getenv("VIM");
639 if (p != NULL && pathcmp(p, -1, installdir, runtimeidx - 1) != 0)
640 {
641 printf("------------------------------------------------------\n");
642 printf("$VIM is set to \"%s\".\n", p);
643 printf("This is different from where this version of Vim is:\n");
644 strcpy(buf, installdir);
645 *(buf + runtimeidx - 1) = NUL;
646 printf("\"%s\"\n", buf);
647 printf("You must adjust or remove the setting of $VIM,\n");
648 if (interactive)
649 {
650 printf("to be able to use this install program.\n");
651 myexit(1);
652 }
653 printf("otherwise Vim WILL NOT WORK properly!\n");
654 printf("------------------------------------------------------\n");
655 }
656
657 /*
658 * If $VIMRUNTIME is set, check that it's pointing to our runtime directory.
659 */
660 p = getenv("VIMRUNTIME");
661 if (p != NULL && pathcmp(p, -1, installdir, -1) != 0)
662 {
663 printf("------------------------------------------------------\n");
664 printf("$VIMRUNTIME is set to \"%s\".\n", p);
665 printf("This is different from where this version of Vim is:\n");
666 printf("\"%s\"\n", installdir);
667 printf("You must adjust or remove the setting of $VIMRUNTIME,\n");
668 if (interactive)
669 {
670 printf("to be able to use this install program.\n");
671 myexit(1);
672 }
673 printf("otherwise Vim WILL NOT WORK properly!\n");
674 printf("------------------------------------------------------\n");
675 }
676
677 /*
678 * Check if there is a vim.[exe|bat|, gvim.[exe|bat|, etc. in the path.
679 */
680 find_bat_exe(FALSE);
681
682 /*
683 * A .exe in the install directory may be found anyway on Windows 2000.
684 * Check for this situation and find another executable if necessary.
685 * w.briscoe@ponl.com 2001-01-20
686 */
687 foundone = 0;
688 for (i = 1; i < TARGET_COUNT; ++i)
689 {
690 findoldfile(&(targets[i].oldexe));
691 if (targets[i].oldexe != NULL)
692 foundone = 1;
693 }
694
695 if (foundone)
696 {
697 printf("Warning: Found Vim executable(s) in your $PATH:\n");
698 for (i = 1; i < TARGET_COUNT; ++i)
699 if (targets[i].oldexe != NULL)
700 printf("%s\n", targets[i].oldexe);
701 printf("It will be used instead of the version you are installing.\n");
702 printf("Please delete or rename it, or adjust your $PATH setting.\n");
703 }
704
705 /*
706 * Check if there is an existing ../_vimrc or ../.vimrc file.
707 */
708 strcpy(oldvimrc, installdir);
709 strcpy(oldvimrc + runtimeidx, "_vimrc");
710 if ((fd = fopen(oldvimrc, "r")) == NULL)
711 {
712 strcpy(oldvimrc + runtimeidx, "vimrc~1"); /* short version of .vimrc */
713 if ((fd = fopen(oldvimrc, "r")) == NULL)
714 {
715 strcpy(oldvimrc + runtimeidx, ".vimrc");
716 fd = fopen(oldvimrc, "r");
717 }
718 }
719 if (fd != NULL)
720 fclose(fd);
721 else
722 *oldvimrc = NUL;
723
724#if 0 /* currently not used */
725 /*
726 * Get default home directory.
727 * Prefer $HOME if it's set. For Win NT use $HOMEDRIVE and $HOMEPATH.
728 * Otherwise, if there is a "c:" drive use that.
729 */
730 p = getenv("HOME");
731 if (p != NULL && *p != NUL && strlen(p) < BUFSIZE)
732 strcpy(homedir, p);
733 else
734 {
735 p = getenv("HOMEDRIVE");
736 if (p != NULL && *p != NUL && strlen(p) + 2 < BUFSIZE)
737 {
738 strcpy(homedir, p);
739 p = getenv("HOMEPATH");
740 if (p != NULL && *p != NUL && strlen(homedir) + strlen(p) < BUFSIZE)
741 strcat(homedir, p);
742 else
743 strcat(homedir, "\\");
744 }
745 else
746 {
747 struct stat st;
748
749 if (stat("c:\\", &st) == 0)
750 strcpy(homedir, "c:\\");
751 else
752 *homedir = NUL;
753 }
754 }
755#endif
756}
757
758/*
759 * Add a dummy choice to avoid that the numbering changes depending on items
760 * in the environment. The user may type a number he remembered without
761 * looking.
762 */
763 static void
764add_dummy_choice(void)
765{
766 choices[choice_count].installfunc = NULL;
767 choices[choice_count].active = 0;
768 choices[choice_count].changefunc = NULL;
769 choices[choice_count].installfunc = NULL;
770 ++choice_count;
771}
772
773/***********************************************
774 * stuff for creating the batch files.
775 */
776
777/*
778 * Install the vim.bat, gvim.bat, etc. files.
779 */
780 static void
781install_bat_choice(int idx)
782{
783 char *batpath = targets[choices[idx].arg].batpath;
784 char *oldname = targets[choices[idx].arg].oldbat;
785 char *exename = targets[choices[idx].arg].exenamearg;
786 char *vimarg = targets[choices[idx].arg].exearg;
787 FILE *fd;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788
789 if (*batpath != NUL)
790 {
791 fd = fopen(batpath, "w");
792 if (fd == NULL)
793 printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath);
794 else
795 {
796 need_uninstall_entry = 1;
797
798 fprintf(fd, "@echo off\n");
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000799 fprintf(fd, "rem -- Run Vim --\n");
800 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000802 /* Don't use double quotes for the "set" argument, also when it
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803 * contains a space. The quotes would be included in the value
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000804 * for MSDOS and NT.
805 * The order of preference is:
806 * 1. $VIMRUNTIME/vim.exe (user preference)
807 * 2. $VIM/vim70/vim.exe (hard coded version)
808 * 3. installdir/vim.exe (hard coded install directory)
809 */
810 fprintf(fd, "set VIM_EXE_DIR=%s\n", installdir);
811 fprintf(fd, "if exist \"%%VIM%%\\%s\\%s\" set VIM_EXE_DIR=%%VIM%%\\%s\n",
812 VIM_VERSION_NODOT, exename, VIM_VERSION_NODOT);
813 fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename);
814 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000815
816 /* Give an error message when the executable could not be found. */
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000817 fprintf(fd, "if exist \"%%VIM_EXE_DIR%%\\%s\" goto havevim\n",
818 exename);
819 fprintf(fd, "echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename);
820 fprintf(fd, "goto eof\n");
821 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 fprintf(fd, ":havevim\n");
823
824 fprintf(fd, "rem collect the arguments in VIMARGS for Win95\n");
825 fprintf(fd, "set VIMARGS=\n");
826 if (*exename == 'g')
827 fprintf(fd, "set VIMNOFORK=\n");
828 fprintf(fd, ":loopstart\n");
829 fprintf(fd, "if .%%1==. goto loopend\n");
830 if (*exename == 'g')
831 {
832 fprintf(fd, "if NOT .%%1==.-f goto noforkarg\n");
833 fprintf(fd, "set VIMNOFORK=1\n");
834 fprintf(fd, ":noforkarg\n");
835 }
836 fprintf(fd, "set VIMARGS=%%VIMARGS%% %%1\n");
837 fprintf(fd, "shift\n");
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000838 fprintf(fd, "goto loopstart\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 fprintf(fd, ":loopend\n");
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000840 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000842 fprintf(fd, "if .%%OS%%==.Windows_NT goto ntaction\n");
843 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844
845 /* For gvim.exe use "start" to avoid that the console window stays
846 * open. */
847 if (*exename == 'g')
848 {
849 fprintf(fd, "if .%%VIMNOFORK%%==.1 goto nofork\n");
850 fprintf(fd, "start ");
851 }
852
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000853 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
854 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n",
855 exename, vimarg);
856 fprintf(fd, "goto eof\n");
857 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858
859 if (*exename == 'g')
860 {
861 fprintf(fd, ":nofork\n");
862 fprintf(fd, "start /w ");
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000863 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
864 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n",
865 exename, vimarg);
866 fprintf(fd, "goto eof\n");
867 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868 }
869
870 fprintf(fd, ":ntaction\n");
871 fprintf(fd, "rem for WinNT we can use %%*\n");
872
873 /* For gvim.exe use "start /b" to avoid that the console window
874 * stays open. */
875 if (*exename == 'g')
876 {
877 fprintf(fd, "if .%%VIMNOFORK%%==.1 goto noforknt\n");
878 fprintf(fd, "start \"dummy\" /b ");
879 }
880
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000881 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
882 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg);
883 fprintf(fd, "goto eof\n");
884 fprintf(fd, "\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000885
886 if (*exename == 'g')
887 {
888 fprintf(fd, ":noforknt\n");
889 fprintf(fd, "start \"dummy\" /b /wait ");
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000890 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */
891 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
892 exename, vimarg);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 }
894
895 fprintf(fd, "\n:eof\n");
896 fprintf(fd, "set VIMARGS=\n");
897 if (*exename == 'g')
898 fprintf(fd, "set VIMNOFORK=\n");
899
900 fclose(fd);
901 printf("%s has been %s\n", batpath,
902 oldname == NULL ? "created" : "overwritten");
903 }
904 }
905}
906
907/*
908 * Make the text string for choice "idx".
909 * The format "fmt" is must have one %s item, which "arg" is used for.
910 */
911 static void
912alloc_text(int idx, char *fmt, char *arg)
913{
914 if (choices[idx].text != NULL)
915 free(choices[idx].text);
916
917 choices[idx].text = alloc((int)(strlen(fmt) + strlen(arg)) - 1);
918 sprintf(choices[idx].text, fmt, arg);
919}
920
921/*
922 * Toggle the "Overwrite .../vim.bat" to "Don't overwrite".
923 */
924 static void
925toggle_bat_choice(int idx)
926{
927 char *batname = targets[choices[idx].arg].batpath;
928 char *oldname = targets[choices[idx].arg].oldbat;
929
930 if (*batname == NUL)
931 {
932 alloc_text(idx, " Overwrite %s", oldname);
933 strcpy(batname, oldname);
934 }
935 else
936 {
937 alloc_text(idx, " Do NOT overwrite %s", oldname);
938 *batname = NUL;
939 }
940}
941
942/*
943 * Do some work for a batch file entry: Append the batch file name to the path
944 * and set the text for the choice.
945 */
946 static void
947set_bat_text(int idx, char *batpath, char *name)
948{
949 strcat(batpath, name);
950
951 alloc_text(idx, " Create %s", batpath);
952}
953
954/*
955 * Select a directory to write the batch file line.
956 */
957 static void
958change_bat_choice(int idx)
959{
960 char *path;
961 char *batpath;
962 char *name;
963 int n;
964 char *s;
965 char *p;
966 int count;
967 char **names = NULL;
968 int i;
969 int target = choices[idx].arg;
970
971 name = targets[target].batname;
972 batpath = targets[target].batpath;
973
974 path = getenv("PATH");
975 if (path == NULL)
976 {
977 printf("\nERROR: The variable $PATH is not set\n");
978 return;
979 }
980
981 /*
982 * first round: count number of names in path;
983 * second round: save names to names[].
984 */
985 for (;;)
986 {
987 count = 1;
988 for (p = path; *p; )
989 {
990 s = strchr(p, ';');
991 if (s == NULL)
992 s = p + strlen(p);
993 if (names != NULL)
994 {
995 names[count] = alloc((int)(s - p) + 1);
996 strncpy(names[count], p, s - p);
997 names[count][s - p] = NUL;
998 }
999 ++count;
1000 p = s;
1001 if (*p != NUL)
1002 ++p;
1003 }
1004 if (names != NULL)
1005 break;
1006 names = alloc((int)(count + 1) * sizeof(char *));
1007 }
1008 names[0] = alloc(50);
1009 sprintf(names[0], "Select directory to create %s in:", name);
1010 names[count] = alloc(50);
1011 if (choices[idx].arg == 0)
1012 sprintf(names[count], "Do not create any .bat file.");
1013 else
1014 sprintf(names[count], "Do not create a %s file.", name);
1015 n = get_choice(names, count + 1);
1016
1017 if (n == count)
1018 {
1019 /* Selected last item, don't create bat file. */
1020 *batpath = NUL;
1021 if (choices[idx].arg != 0)
1022 alloc_text(idx, " Do NOT create %s", name);
1023 }
1024 else
1025 {
1026 /* Selected one of the paths. For the first item only keep the path,
1027 * for the others append the batch file name. */
1028 strcpy(batpath, names[n]);
1029 add_pathsep(batpath);
1030 if (choices[idx].arg != 0)
1031 set_bat_text(idx, batpath, name);
1032 }
1033
1034 for (i = 0; i <= count; ++i)
1035 free(names[i]);
1036 free(names);
1037}
1038
1039char *bat_text_yes = "Install .bat files to use Vim at the command line:";
1040char *bat_text_no = "do NOT install .bat files to use Vim at the command line";
1041
1042 static void
1043change_main_bat_choice(int idx)
1044{
1045 int i;
1046
1047 /* let the user select a default directory or NONE */
1048 change_bat_choice(idx);
1049
1050 if (targets[0].batpath[0] != NUL)
1051 choices[idx].text = bat_text_yes;
1052 else
1053 choices[idx].text = bat_text_no;
1054
1055 /* update the individual batch file selections */
1056 for (i = 1; i < TARGET_COUNT; ++i)
1057 {
1058 /* Only make it active when the first item has a path and the vim.exe
1059 * or gvim.exe exists (there is a changefunc then). */
1060 if (targets[0].batpath[0] != NUL
1061 && choices[idx + i].changefunc != NULL)
1062 {
1063 choices[idx + i].active = 1;
1064 if (choices[idx + i].changefunc == change_bat_choice
1065 && targets[i].batpath[0] != NUL)
1066 {
1067 strcpy(targets[i].batpath, targets[0].batpath);
1068 set_bat_text(idx + i, targets[i].batpath, targets[i].batname);
1069 }
1070 }
1071 else
1072 choices[idx + i].active = 0;
1073 }
1074}
1075
1076/*
1077 * Initialize a choice for creating a batch file.
1078 */
1079 static void
1080init_bat_choice(int target)
1081{
1082 char *batpath = targets[target].batpath;
1083 char *oldbat = targets[target].oldbat;
1084 char *p;
1085 int i;
1086
1087 choices[choice_count].arg = target;
1088 choices[choice_count].installfunc = install_bat_choice;
1089 choices[choice_count].active = 1;
1090 choices[choice_count].text = NULL; /* will be set below */
1091 if (oldbat != NULL)
1092 {
1093 /* A [g]vim.bat exists: Only choice is to overwrite it or not. */
1094 choices[choice_count].changefunc = toggle_bat_choice;
1095 *batpath = NUL;
1096 toggle_bat_choice(choice_count);
1097 }
1098 else
1099 {
1100 if (default_bat_dir != NULL)
1101 /* Prefer using the same path as an existing .bat file. */
1102 strcpy(batpath, default_bat_dir);
1103 else
1104 {
1105 /* No [g]vim.bat exists: Write it to a directory in $PATH. Use
1106 * $WINDIR by default, if it's empty the first item in $PATH. */
1107 p = getenv("WINDIR");
1108 if (p != NULL && *p != NUL)
1109 strcpy(batpath, p);
1110 else
1111 {
1112 p = getenv("PATH");
1113 if (p == NULL || *p == NUL) /* "cannot happen" */
1114 strcpy(batpath, "C:/Windows");
1115 else
1116 {
1117 i = 0;
1118 while (*p != NUL && *p != ';')
1119 batpath[i++] = *p++;
1120 batpath[i] = NUL;
1121 }
1122 }
1123 }
1124 add_pathsep(batpath);
1125 set_bat_text(choice_count, batpath, targets[target].batname);
1126
1127 choices[choice_count].changefunc = change_bat_choice;
1128 }
1129 ++choice_count;
1130}
1131
1132/*
1133 * Set up the choices for installing .bat files.
1134 * For these items "arg" is the index in targets[].
1135 */
1136 static void
1137init_bat_choices(void)
1138{
1139 int i;
1140
1141 /* The first item is used to switch installing batch files on/off and
1142 * setting the default path. */
1143 choices[choice_count].text = bat_text_yes;
1144 choices[choice_count].changefunc = change_main_bat_choice;
1145 choices[choice_count].installfunc = NULL;
1146 choices[choice_count].active = 1;
1147 choices[choice_count].arg = 0;
1148 ++choice_count;
1149
1150 /* Add items for each batch file target. Only used when not disabled by
1151 * the first item. When a .exe exists, don't offer to create a .bat. */
1152 for (i = 1; i < TARGET_COUNT; ++i)
1153 if (targets[i].oldexe == NULL
1154 && (targets[i].exenamearg[0] == 'g' ? has_gvim : has_vim))
1155 init_bat_choice(i);
1156 else
1157 add_dummy_choice();
1158}
1159
1160/*
1161 * Install the vimrc file.
1162 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001163 static void
1164install_vimrc(int idx)
1165{
1166 FILE *fd, *tfd;
1167 char *fname;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168
1169 /* If an old vimrc file exists, overwrite it.
1170 * Otherwise create a new one. */
1171 if (*oldvimrc != NUL)
1172 fname = oldvimrc;
1173 else
1174 fname = vimrc;
1175
1176 fd = fopen(fname, "w");
1177 if (fd == NULL)
1178 {
1179 printf("\nERROR: Cannot open \"%s\" for writing.\n", fname);
1180 return;
1181 }
1182 switch (compat_choice)
1183 {
1184 case compat_vi:
1185 fprintf(fd, "set compatible\n");
1186 break;
1187 case compat_some_enhancements:
1188 fprintf(fd, "set nocompatible\n");
1189 break;
1190 case compat_all_enhancements:
1191 fprintf(fd, "set nocompatible\n");
1192 fprintf(fd, "source $VIMRUNTIME/vimrc_example.vim\n");
1193 break;
1194 }
1195 switch (remap_choice)
1196 {
1197 case remap_no:
1198 break;
1199 case remap_win:
1200 fprintf(fd, "source $VIMRUNTIME/mswin.vim\n");
1201 break;
1202 }
1203 switch (mouse_choice)
1204 {
1205 case mouse_xterm:
1206 fprintf(fd, "behave xterm\n");
1207 break;
1208 case mouse_mswin:
1209 fprintf(fd, "behave mswin\n");
1210 break;
1211 }
1212 if ((tfd = fopen("diff.exe", "r")) != NULL)
1213 {
1214 /* Use the diff.exe that comes with the self-extracting gvim.exe. */
1215 fclose(tfd);
1216 fprintf(fd, "\n");
1217 fprintf(fd, "set diffexpr=MyDiff()\n");
1218 fprintf(fd, "function MyDiff()\n");
1219 fprintf(fd, " let opt = '-a --binary '\n");
1220 fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n");
1221 fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n");
1222 /* Use quotes only when needed, they may cause trouble. */
1223 fprintf(fd, " let arg1 = v:fname_in\n");
1224 fprintf(fd, " if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif\n");
1225 fprintf(fd, " let arg2 = v:fname_new\n");
1226 fprintf(fd, " if arg2 =~ ' ' | let arg2 = '\"' . arg2 . '\"' | endif\n");
1227 fprintf(fd, " let arg3 = v:fname_out\n");
1228 fprintf(fd, " if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif\n");
Bram Moolenaar33aec762006-01-22 23:30:12 +00001229
1230 /* If the path has a space: When using cmd.exe (Win NT/2000/XP) put
1231 * quotes around the whole command and around the diff command.
1232 * Otherwise put a double quote just before the space and at the
1233 * end of the command. Putting quotes around the whole thing
1234 * doesn't work on Win 95/98/ME. This is mostly guessed! */
1235 fprintf(fd, " let eq = ''\n");
1236 fprintf(fd, " if $VIMRUNTIME =~ ' '\n");
1237 fprintf(fd, " if &sh =~ '\\<cmd'\n");
1238 fprintf(fd, " let cmd = '\"\"' . $VIMRUNTIME . '\\diff\"'\n");
1239 fprintf(fd, " let eq = '\"'\n");
1240 fprintf(fd, " else\n");
1241 fprintf(fd, " let cmd = substitute($VIMRUNTIME, ' ', '\" ', '') . '\\diff\"'\n");
1242 fprintf(fd, " endif\n");
1243 fprintf(fd, " else\n");
1244 fprintf(fd, " let cmd = $VIMRUNTIME . '\\diff'\n");
1245 fprintf(fd, " endif\n");
1246 fprintf(fd, " silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq\n");
1247
Bram Moolenaar071d4272004-06-13 20:20:40 +00001248 fprintf(fd, "endfunction\n");
1249 fprintf(fd, "\n");
1250 }
1251 fclose(fd);
1252 printf("%s has been written\n", fname);
1253}
1254
1255 static void
1256change_vimrc_choice(int idx)
1257{
1258 if (choices[idx].installfunc != NULL)
1259 {
1260 /* Switch to NOT change or create a vimrc file. */
1261 if (*oldvimrc != NUL)
1262 alloc_text(idx, "Do NOT change startup file %s", oldvimrc);
1263 else
1264 alloc_text(idx, "Do NOT create startup file %s", vimrc);
1265 choices[idx].installfunc = NULL;
1266 choices[idx + 1].active = 0;
1267 choices[idx + 2].active = 0;
1268 choices[idx + 3].active = 0;
1269 }
1270 else
1271 {
1272 /* Switch to change or create a vimrc file. */
1273 if (*oldvimrc != NUL)
1274 alloc_text(idx, "Overwrite startup file %s with:", oldvimrc);
1275 else
1276 alloc_text(idx, "Create startup file %s with:", vimrc);
1277 choices[idx].installfunc = install_vimrc;
1278 choices[idx + 1].active = 1;
1279 choices[idx + 2].active = 1;
1280 choices[idx + 3].active = 1;
1281 }
1282}
1283
1284/*
1285 * Change the choice how to run Vim.
1286 */
1287 static void
1288change_run_choice(int idx)
1289{
1290 compat_choice = get_choice(compat_choices, TABLE_SIZE(compat_choices));
1291 alloc_text(idx, compat_text, compat_choices[compat_choice]);
1292}
1293
1294/*
1295 * Change the choice if keys are to be remapped.
1296 */
1297 static void
1298change_remap_choice(int idx)
1299{
1300 remap_choice = get_choice(remap_choices, TABLE_SIZE(remap_choices));
1301 alloc_text(idx, remap_text, remap_choices[remap_choice]);
1302}
1303
1304/*
1305 * Change the choice how to select text.
1306 */
1307 static void
1308change_mouse_choice(int idx)
1309{
1310 mouse_choice = get_choice(mouse_choices, TABLE_SIZE(mouse_choices));
1311 alloc_text(idx, mouse_text, mouse_choices[mouse_choice]);
1312}
1313
1314 static void
1315init_vimrc_choices(void)
1316{
1317 /* set path for a new _vimrc file (also when not used) */
1318 strcpy(vimrc, installdir);
1319 strcpy(vimrc + runtimeidx, "_vimrc");
1320
1321 /* Set opposite value and then toggle it by calling change_vimrc_choice() */
1322 if (*oldvimrc == NUL)
1323 choices[choice_count].installfunc = NULL;
1324 else
1325 choices[choice_count].installfunc = install_vimrc;
1326 choices[choice_count].text = NULL;
1327 change_vimrc_choice(choice_count);
1328 choices[choice_count].changefunc = change_vimrc_choice;
1329 choices[choice_count].active = 1;
1330 ++choice_count;
1331
1332 /* default way to run Vim */
1333 alloc_text(choice_count, compat_text, compat_choices[compat_choice]);
1334 choices[choice_count].changefunc = change_run_choice;
1335 choices[choice_count].installfunc = NULL;
1336 choices[choice_count].active = (*oldvimrc == NUL);
1337 ++choice_count;
1338
1339 /* Whether to remap keys */
1340 alloc_text(choice_count, remap_text , remap_choices[remap_choice]);
1341 choices[choice_count].changefunc = change_remap_choice;
1342 choices[choice_count].installfunc = NULL;;
1343 choices[choice_count].active = (*oldvimrc == NUL);
1344 ++choice_count;
1345
1346 /* default way to use the mouse */
1347 alloc_text(choice_count, mouse_text, mouse_choices[mouse_choice]);
1348 choices[choice_count].changefunc = change_mouse_choice;
1349 choices[choice_count].installfunc = NULL;;
1350 choices[choice_count].active = (*oldvimrc == NUL);
1351 ++choice_count;
1352}
1353
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001354#if defined(WIN3264)
1355/*
1356 * Modern way of creating registry entries, also works on 64 bit windows when
1357 * compiled as a 32 bit program.
1358 */
1359# ifndef KEY_WOW64_64KEY
1360# define KEY_WOW64_64KEY 0x0100
1361# endif
1362
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001363 static LONG
1364reg_create_key(
1365 HKEY root,
1366 const char *subkey,
1367 PHKEY phKey)
1368{
1369 DWORD disp;
1370
1371 *phKey = NULL;
1372 return RegCreateKeyEx(
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001373 root, subkey,
1374 0, NULL, REG_OPTION_NON_VOLATILE,
1375 KEY_WOW64_64KEY | KEY_WRITE,
1376 NULL, phKey, &disp);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001377}
1378
1379 static LONG
1380reg_set_string_value(
1381 HKEY hKey,
1382 const char *value_name,
1383 const char *data)
1384{
1385 return RegSetValueEx(hKey, value_name, 0, REG_SZ,
1386 (LPBYTE)data, (DWORD)(1 + strlen(data)));
1387}
1388
1389 static LONG
1390reg_create_key_and_value(
1391 HKEY hRootKey,
1392 const char *subkey,
1393 const char *value_name,
1394 const char *data)
1395{
1396 HKEY hKey;
1397 LONG lRet = reg_create_key(hRootKey, subkey, &hKey);
1398
1399 if (ERROR_SUCCESS == lRet)
1400 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001401 lRet = reg_set_string_value(hKey, value_name, data);
1402 RegCloseKey(hKey);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001403 }
1404 return lRet;
1405}
1406
1407 static LONG
1408register_inproc_server(
1409 HKEY hRootKey,
1410 const char *clsid,
1411 const char *extname,
1412 const char *module,
1413 const char *threading_model)
1414{
1415 CHAR subkey[BUFSIZE];
1416 LONG lRet;
1417
1418 sprintf(subkey, "CLSID\\%s", clsid);
1419 lRet = reg_create_key_and_value(hRootKey, subkey, NULL, extname);
1420 if (ERROR_SUCCESS == lRet)
1421 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001422 sprintf(subkey, "CLSID\\%s\\InProcServer32", clsid);
1423 lRet = reg_create_key_and_value(hRootKey, subkey, NULL, module);
1424 if (ERROR_SUCCESS == lRet)
1425 {
1426 lRet = reg_create_key_and_value(hRootKey, subkey,
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001427 "ThreadingModel", threading_model);
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001428 }
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001429 }
1430 return lRet;
1431}
1432
1433 static LONG
1434register_shellex(
1435 HKEY hRootKey,
1436 const char *clsid,
1437 const char *name,
1438 const char *exe_path)
1439{
1440 LONG lRet = reg_create_key_and_value(
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001441 hRootKey,
1442 "*\\shellex\\ContextMenuHandlers\\gvim",
1443 NULL,
1444 clsid);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001445
1446 if (ERROR_SUCCESS == lRet)
1447 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001448 lRet = reg_create_key_and_value(
1449 HKEY_LOCAL_MACHINE,
1450 "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved",
1451 clsid,
1452 name);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001453
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001454 if (ERROR_SUCCESS == lRet)
1455 {
1456 lRet = reg_create_key_and_value(
1457 HKEY_LOCAL_MACHINE,
1458 "Software\\Vim\\Gvim",
1459 "path",
1460 exe_path);
1461 }
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001462 }
1463 return lRet;
1464}
1465
1466 static LONG
1467register_openwith(
1468 HKEY hRootKey,
1469 const char *exe_path)
1470{
1471 LONG lRet = reg_create_key_and_value(
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001472 hRootKey,
1473 "Applications\\gvim.exe\\shell\\edit\\command",
1474 NULL,
1475 exe_path);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001476
1477 if (ERROR_SUCCESS == lRet)
1478 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001479 int i;
1480 static const char *openwith[] = {
1481 ".htm\\OpenWithList\\gvim.exe",
1482 ".vim\\OpenWithList\\gvim.exe",
1483 "*\\OpenWithList\\gvim.exe",
1484 };
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001485
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001486 for (i = 0; ERROR_SUCCESS == lRet
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001487 && i < sizeof(openwith) / sizeof(openwith[0]); i++)
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001488 {
1489 lRet = reg_create_key_and_value(hRootKey, openwith[i], NULL, "");
1490 }
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001491 }
1492
1493 return lRet;
1494}
1495
1496 static LONG
1497register_uninstall(
1498 HKEY hRootKey,
1499 const char *appname,
1500 const char *display_name,
1501 const char *uninstall_string)
1502{
1503 LONG lRet = reg_create_key_and_value(hRootKey, appname,
1504 "DisplayName", display_name);
1505
1506 if (ERROR_SUCCESS == lRet)
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001507 lRet = reg_create_key_and_value(hRootKey, appname,
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001508 "UninstallString", uninstall_string);
1509 return lRet;
1510}
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001511#endif /* WIN3264 */
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001512
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513/*
1514 * Add some entries to the registry:
1515 * - to add "Edit with Vim" to the context * menu
1516 * - to add Vim to the "Open with..." list
1517 * - to uninstall Vim
1518 */
1519/*ARGSUSED*/
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001520 static int
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521install_registry(void)
1522{
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001523#ifdef WIN3264
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001524 LONG lRet = ERROR_SUCCESS;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 const char *vim_ext_ThreadingModel = "Apartment";
1526 const char *vim_ext_name = "Vim Shell Extension";
1527 const char *vim_ext_clsid = "{51EEE242-AD87-11d3-9C1E-0090278BBD99}";
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001528 char vim_exe_path[BUFSIZE];
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001529 char display_name[BUFSIZE];
1530 char uninstall_string[BUFSIZE];
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001532 sprintf(vim_exe_path, "%s\\gvim.exe", installdir);
1533
1534 if (install_popup)
1535 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001536 char bufg[BUFSIZE];
1537 struct stat st;
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001538
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001539 if (stat("gvimext.dll", &st) >= 0)
1540 sprintf(bufg, "%s\\gvimext.dll", installdir);
1541 else
1542 /* gvimext.dll is in gvimext subdir */
1543 sprintf(bufg, "%s\\gvimext\\gvimext.dll", installdir);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001544
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001545 printf("Creating \"Edit with Vim\" popup menu entry\n");
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001546
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001547 lRet = register_inproc_server(
1548 HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name,
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001549 bufg, vim_ext_ThreadingModel);
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001550 if (ERROR_SUCCESS != lRet)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001551 return FAIL;
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001552 lRet = register_shellex(
1553 HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name, vim_exe_path);
1554 if (ERROR_SUCCESS != lRet)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001555 return FAIL;
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001556 }
1557
1558 if (install_openwith)
1559 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001560 printf("Creating \"Open with ...\" list entry\n");
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001561
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001562 lRet = register_openwith(HKEY_CLASSES_ROOT, vim_exe_path);
1563 if (ERROR_SUCCESS != lRet)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001564 return FAIL;
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001565 }
1566
1567 printf("Creating an uninstall entry\n");
1568
1569 /* For the NSIS installer use the generated uninstaller. */
1570 if (interactive)
1571 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001572 sprintf(display_name, "Vim " VIM_VERSION_SHORT);
Bram Moolenaar16d79a32010-07-18 22:33:56 +02001573 sprintf(uninstall_string, "%s\\uninstal.exe", installdir);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575 else
1576 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001577 sprintf(display_name, "Vim " VIM_VERSION_SHORT " (self-installing)");
Bram Moolenaar16d79a32010-07-18 22:33:56 +02001578 sprintf(uninstall_string, "%s\\uninstall-gui.exe", installdir);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 }
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001580
1581 lRet = register_uninstall(
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001582 HKEY_LOCAL_MACHINE,
1583 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT,
1584 display_name,
1585 uninstall_string);
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001586 if (ERROR_SUCCESS != lRet)
1587 return FAIL;
1588#endif /* WIN3264 */
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001589
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001590 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591}
1592
1593 static void
1594change_popup_choice(int idx)
1595{
1596 if (install_popup == 0)
1597 {
1598 choices[idx].text = "Install an entry for Vim in the popup menu for the right\n mouse button so that you can edit any file with Vim";
1599 install_popup = 1;
1600 }
1601 else
1602 {
1603 choices[idx].text = "Do NOT install an entry for Vim in the popup menu for the\n right mouse button to edit any file with Vim";
1604 install_popup = 0;
1605 }
1606}
1607
1608/*
1609 * Only add the choice for the popup menu entry when gvim.exe was found and
1610 * both gvimext.dll and regedit.exe exist.
1611 */
1612 static void
1613init_popup_choice(void)
1614{
1615 struct stat st;
1616
1617 if (has_gvim
1618 && (stat("gvimext.dll", &st) >= 0
1619 || stat("gvimext/gvimext.dll", &st) >= 0)
1620#ifndef WIN3264
1621 && searchpath("regedit.exe") != NULL
1622#endif
1623 )
1624 {
1625 choices[choice_count].changefunc = change_popup_choice;
1626 choices[choice_count].installfunc = NULL;
1627 choices[choice_count].active = 1;
1628 change_popup_choice(choice_count); /* set the text */
1629 ++choice_count;
1630 }
1631 else
1632 add_dummy_choice();
1633}
1634
1635 static void
1636change_openwith_choice(int idx)
1637{
1638 if (install_openwith == 0)
1639 {
1640 choices[idx].text = "Add Vim to the \"Open With...\" list in the popup menu for the right\n mouse button so that you can edit any file with Vim";
1641 install_openwith = 1;
1642 }
1643 else
1644 {
1645 choices[idx].text = "Do NOT add Vim to the \"Open With...\" list in the popup menu for the\n right mouse button to edit any file with Vim";
1646 install_openwith = 0;
1647 }
1648}
1649
1650/*
1651 * Only add the choice for the open-with menu entry when gvim.exe was found
1652 * and and regedit.exe exist.
1653 */
1654 static void
1655init_openwith_choice(void)
1656{
1657 if (has_gvim
1658#ifndef WIN3264
1659 && searchpath("regedit.exe") != NULL
1660#endif
1661 )
1662 {
1663 choices[choice_count].changefunc = change_openwith_choice;
1664 choices[choice_count].installfunc = NULL;
1665 choices[choice_count].active = 1;
1666 change_openwith_choice(choice_count); /* set the text */
1667 ++choice_count;
1668 }
1669 else
1670 add_dummy_choice();
1671}
1672
1673#ifdef WIN3264
1674/* create_shortcut
1675 *
1676 * Create a shell link.
1677 *
1678 * returns 0 on failure, non-zero on successful completion.
1679 *
1680 * NOTE: Currently untested with mingw.
1681 */
1682 int
1683create_shortcut(
1684 const char *shortcut_name,
1685 const char *iconfile_path,
1686 int iconindex,
1687 const char *shortcut_target,
1688 const char *shortcut_args,
1689 const char *workingdir
1690 )
1691{
1692 IShellLink *shelllink_ptr;
1693 HRESULT hres;
1694 IPersistFile *persistfile_ptr;
1695
1696 /* Initialize COM library */
1697 hres = CoInitialize(NULL);
1698 if (!SUCCEEDED(hres))
1699 {
1700 printf("Error: Could not open the COM library. Not creating shortcut.\n");
1701 return FAIL;
1702 }
1703
1704 /* Instantiate a COM object for the ShellLink, store a pointer to it
1705 * in shelllink_ptr. */
1706 hres = CoCreateInstance(&CLSID_ShellLink,
1707 NULL,
1708 CLSCTX_INPROC_SERVER,
1709 &IID_IShellLink,
1710 (void **) &shelllink_ptr);
1711
1712 if (SUCCEEDED(hres)) /* If the instantiation was successful... */
1713 {
1714 /* ...Then build a PersistFile interface for the ShellLink so we can
1715 * save it as a file after we build it. */
1716 hres = shelllink_ptr->lpVtbl->QueryInterface(shelllink_ptr,
1717 &IID_IPersistFile, (void **) &persistfile_ptr);
1718
1719 if (SUCCEEDED(hres))
1720 {
1721 wchar_t wsz[BUFSIZE];
1722
1723 /* translate the (possibly) multibyte shortcut filename to windows
1724 * Unicode so it can be used as a file name.
1725 */
1726 MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, BUFSIZE);
1727
1728 /* set the attributes */
1729 shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target);
1730 shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr,
1731 workingdir);
1732 shelllink_ptr->lpVtbl->SetIconLocation(shelllink_ptr,
1733 iconfile_path, iconindex);
1734 shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args);
1735
1736 /* save the shortcut to a file and return the PersistFile object*/
1737 persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1);
1738 persistfile_ptr->lpVtbl->Release(persistfile_ptr);
1739 }
1740 else
1741 {
1742 printf("QueryInterface Error\n");
1743 return FAIL;
1744 }
1745
1746 /* Return the ShellLink object */
1747 shelllink_ptr->lpVtbl->Release(shelllink_ptr);
1748 }
1749 else
1750 {
1751 printf("CoCreateInstance Error - hres = %08x\n", (int)hres);
1752 return FAIL;
1753 }
1754
1755 return OK;
1756}
1757
1758/*
1759 * Build a path to where we will put a specified link.
1760 *
1761 * Return 0 on error, non-zero on success
1762 */
1763 int
1764build_link_name(
1765 char *link_path,
1766 const char *link_name,
1767 const char *shell_folder_name)
1768{
1769 char shell_folder_path[BUFSIZE];
1770
1771 if (get_shell_folder_path(shell_folder_path, shell_folder_name) == FAIL)
1772 {
1773 printf("An error occurred while attempting to find the path to %s.\n",
1774 shell_folder_name);
1775 return FAIL;
1776 }
1777
1778 /* Make sure the directory exists (create Start Menu\Programs\Vim).
1779 * Ignore errors if it already exists. */
1780 vim_mkdir(shell_folder_path, 0755);
1781
1782 /* build the path to the shortcut and the path to gvim.exe */
1783 sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name);
1784
1785 return OK;
1786}
1787
1788 static int
1789build_shortcut(
1790 const char *name, /* Name of the shortcut */
1791 const char *exename, /* Name of the executable (e.g., vim.exe) */
1792 const char *args,
1793 const char *shell_folder,
1794 const char *workingdir)
1795{
1796 char executable_path[BUFSIZE];
1797 char link_name[BUFSIZE];
1798
1799 sprintf(executable_path, "%s\\%s", installdir, exename);
1800
1801 if (build_link_name(link_name, name, shell_folder) == FAIL)
1802 {
1803 printf("An error has occurred. A shortcut to %s will not be created %s.\n",
1804 name,
1805 *shell_folder == 'd' ? "on the desktop" : "in the Start menu");
1806 return FAIL;
1807 }
1808
1809 /* Create the shortcut: */
1810 return create_shortcut(link_name, executable_path, 0,
1811 executable_path, args, workingdir);
1812}
1813
1814/*
1815 * We used to use "homedir" as the working directory, but that is a bad choice
1816 * on multi-user systems. Not specifying a directory appears to work best.
1817 */
1818#define WORKDIR ""
1819
1820/*
1821 * Create shortcut(s) in the Start Menu\Programs\Vim folder.
1822 */
1823 static void
1824install_start_menu(int idx)
1825{
1826 need_uninstall_entry = 1;
1827 printf("Creating start menu\n");
1828 if (has_vim)
1829 {
1830 if (build_shortcut("Vim", "vim.exe", "",
1831 VIM_STARTMENU, WORKDIR) == FAIL)
1832 return;
1833 if (build_shortcut("Vim Read-only", "vim.exe", "-R",
1834 VIM_STARTMENU, WORKDIR) == FAIL)
1835 return;
1836 if (build_shortcut("Vim Diff", "vim.exe", "-d",
1837 VIM_STARTMENU, WORKDIR) == FAIL)
1838 return;
1839 }
1840 if (has_gvim)
1841 {
1842 if (build_shortcut("gVim", "gvim.exe", "",
1843 VIM_STARTMENU, WORKDIR) == FAIL)
1844 return;
1845 if (build_shortcut("gVim Easy", "gvim.exe", "-y",
1846 VIM_STARTMENU, WORKDIR) == FAIL)
1847 return;
1848 if (build_shortcut("gVim Read-only", "gvim.exe", "-R",
1849 VIM_STARTMENU, WORKDIR) == FAIL)
1850 return;
1851 if (build_shortcut("gVim Diff", "gvim.exe", "-d",
1852 VIM_STARTMENU, WORKDIR) == FAIL)
1853 return;
1854 }
1855 if (build_shortcut("Uninstall",
1856 interactive ? "uninstal.exe" : "uninstall-gui.exe", "",
1857 VIM_STARTMENU, installdir) == FAIL)
1858 return;
1859 /* For Windows NT the working dir of the vimtutor.bat must be right,
1860 * otherwise gvim.exe won't be found and using gvimbat doesn't work. */
1861 if (build_shortcut("Vim tutor", "vimtutor.bat", "",
1862 VIM_STARTMENU, installdir) == FAIL)
1863 return;
1864 if (build_shortcut("Help", has_gvim ? "gvim.exe" : "vim.exe", "-c h",
1865 VIM_STARTMENU, WORKDIR) == FAIL)
1866 return;
1867 {
1868 char shell_folder_path[BUFSIZE];
1869
1870 /* Creating the URL shortcut works a bit differently... */
1871 if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL)
1872 {
1873 printf("Finding the path of the Start menu failed\n");
1874 return ;
1875 }
1876 add_pathsep(shell_folder_path);
1877 strcat(shell_folder_path, "Vim Online.url");
1878 if (!WritePrivateProfileString("InternetShortcut", "URL",
1879 "http://vim.sf.net/", shell_folder_path))
1880 {
1881 printf("Creating the Vim online URL failed\n");
1882 return;
1883 }
1884 }
1885}
1886
1887 static void
1888toggle_startmenu_choice(int idx)
1889{
1890 if (choices[idx].installfunc == NULL)
1891 {
1892 choices[idx].installfunc = install_start_menu;
1893 choices[idx].text = "Add Vim to the Start menu";
1894 }
1895 else
1896 {
1897 choices[idx].installfunc = NULL;
1898 choices[idx].text = "Do NOT add Vim to the Start menu";
1899 }
1900}
1901
1902/*
1903 * Function to actually create the shortcuts
1904 *
1905 * Currently I am supplying no working directory to the shortcut. This
1906 * means that the initial working dir will be:
1907 * - the location of the shortcut if no file is supplied
1908 * - the location of the file being edited if a file is supplied (ie via
1909 * drag and drop onto the shortcut).
1910 */
1911 void
1912install_shortcut_gvim(int idx)
1913{
1914 /* Create shortcut(s) on the desktop */
1915 if (choices[idx].arg)
1916 {
1917 (void)build_shortcut(icon_names[0], "gvim.exe",
1918 "", "desktop", WORKDIR);
1919 need_uninstall_entry = 1;
1920 }
1921}
1922
1923 void
1924install_shortcut_evim(int idx)
1925{
1926 if (choices[idx].arg)
1927 {
1928 (void)build_shortcut(icon_names[1], "gvim.exe",
1929 "-y", "desktop", WORKDIR);
1930 need_uninstall_entry = 1;
1931 }
1932}
1933
1934 void
1935install_shortcut_gview(int idx)
1936{
1937 if (choices[idx].arg)
1938 {
1939 (void)build_shortcut(icon_names[2], "gvim.exe",
1940 "-R", "desktop", WORKDIR);
1941 need_uninstall_entry = 1;
1942 }
1943}
1944
1945 void
1946toggle_shortcut_choice(int idx)
1947{
1948 char *arg;
1949
1950 if (choices[idx].installfunc == install_shortcut_gvim)
1951 arg = "gVim";
1952 else if (choices[idx].installfunc == install_shortcut_evim)
1953 arg = "gVim Easy";
1954 else
1955 arg = "gVim Read-only";
1956 if (choices[idx].arg)
1957 {
1958 choices[idx].arg = 0;
1959 alloc_text(idx, "Do NOT create a desktop icon for %s", arg);
1960 }
1961 else
1962 {
1963 choices[idx].arg = 1;
1964 alloc_text(idx, "Create a desktop icon for %s", arg);
1965 }
1966}
1967#endif /* WIN3264 */
1968
1969 static void
1970init_startmenu_choice(void)
1971{
1972#ifdef WIN3264
1973 /* Start menu */
1974 choices[choice_count].changefunc = toggle_startmenu_choice;
1975 choices[choice_count].installfunc = NULL;
1976 choices[choice_count].active = 1;
1977 toggle_startmenu_choice(choice_count); /* set the text */
1978 ++choice_count;
1979#else
1980 add_dummy_choice();
1981#endif
1982}
1983
1984/*
1985 * Add the choice for the desktop shortcuts.
1986 */
1987 static void
1988init_shortcut_choices(void)
1989{
1990#ifdef WIN3264
1991 /* Shortcut to gvim */
1992 choices[choice_count].text = NULL;
1993 choices[choice_count].arg = 0;
1994 choices[choice_count].active = has_gvim;
1995 choices[choice_count].changefunc = toggle_shortcut_choice;
1996 choices[choice_count].installfunc = install_shortcut_gvim;
1997 toggle_shortcut_choice(choice_count);
1998 ++choice_count;
1999
2000 /* Shortcut to evim */
2001 choices[choice_count].text = NULL;
2002 choices[choice_count].arg = 0;
2003 choices[choice_count].active = has_gvim;
2004 choices[choice_count].changefunc = toggle_shortcut_choice;
2005 choices[choice_count].installfunc = install_shortcut_evim;
2006 toggle_shortcut_choice(choice_count);
2007 ++choice_count;
2008
2009 /* Shortcut to gview */
2010 choices[choice_count].text = NULL;
2011 choices[choice_count].arg = 0;
2012 choices[choice_count].active = has_gvim;
2013 choices[choice_count].changefunc = toggle_shortcut_choice;
2014 choices[choice_count].installfunc = install_shortcut_gview;
2015 toggle_shortcut_choice(choice_count);
2016 ++choice_count;
2017#else
2018 add_dummy_choice();
2019 add_dummy_choice();
2020 add_dummy_choice();
2021#endif
2022}
2023
2024#ifdef WIN3264
2025/*
2026 * Attempt to register OLE for Vim.
2027 */
2028 static void
2029install_OLE_register(void)
2030{
2031 char register_command_string[BUFSIZE + 30];
2032
2033 printf("\n--- Attempting to register Vim with OLE ---\n");
2034 printf("(There is no message whether this works or not.)\n");
2035
2036#ifndef __CYGWIN__
2037 sprintf(register_command_string, "\"%s\\gvim.exe\" -silent -register", installdir);
2038#else
2039 /* handle this differently for Cygwin which sometimes has trouble with
2040 * Windows-style pathnames here. */
2041 sprintf(register_command_string, "./gvim.exe -silent -register");
2042#endif
2043 system(register_command_string);
2044}
2045#endif /* WIN3264 */
2046
2047/*
2048 * Remove the last part of directory "path[]" to get its parent, and put the
2049 * result in "to[]".
2050 */
2051 static void
2052dir_remove_last(const char *path, char to[BUFSIZE])
2053{
2054 char c;
2055 long last_char_to_copy;
2056 long path_length = strlen(path);
2057
2058 /* skip the last character just in case it is a '\\' */
2059 last_char_to_copy = path_length - 2;
2060 c = path[last_char_to_copy];
2061
2062 while (c != '\\')
2063 {
2064 last_char_to_copy--;
2065 c = path[last_char_to_copy];
2066 }
2067
2068 strncpy(to, path, (size_t)last_char_to_copy);
2069 to[last_char_to_copy] = NUL;
2070}
2071
2072 static void
2073set_directories_text(int idx)
2074{
2075 if (vimfiles_dir_choice == (int)vimfiles_dir_none)
2076 alloc_text(idx, "Do NOT create plugin directories%s", "");
2077 else
2078 alloc_text(idx, "Create plugin directories: %s",
2079 vimfiles_dir_choices[vimfiles_dir_choice]);
2080}
2081
2082/*
2083 * Change the directory that the vim plugin directories will be created in:
2084 * $HOME, $VIM or nowhere.
2085 */
2086 static void
2087change_directories_choice(int idx)
2088{
2089 int choice_count = TABLE_SIZE(vimfiles_dir_choices);
2090
2091 /* Don't offer the $HOME choice if $HOME isn't set. */
2092 if (getenv("HOME") == NULL)
2093 --choice_count;
2094 vimfiles_dir_choice = get_choice(vimfiles_dir_choices, choice_count);
2095 set_directories_text(idx);
2096}
2097
2098/*
2099 * Create the plugin directories...
2100 */
2101/*ARGSUSED*/
2102 static void
2103install_vimfilesdir(int idx)
2104{
2105 int i;
2106 char *p;
2107 char vimdir_path[BUFSIZE];
2108 char vimfiles_path[BUFSIZE];
2109 char tmp_dirname[BUFSIZE];
2110
2111 /* switch on the location that the user wants the plugin directories
2112 * built in */
2113 switch (vimfiles_dir_choice)
2114 {
2115 case vimfiles_dir_vim:
2116 {
2117 /* Go to the %VIM% directory - check env first, then go one dir
2118 * below installdir if there is no %VIM% environment variable.
2119 * The accuracy of $VIM is checked in inspect_system(), so we
2120 * can be sure it is ok to use here. */
2121 p = getenv("VIM");
2122 if (p == NULL) /* No $VIM in path */
2123 dir_remove_last(installdir, vimdir_path);
2124 else
2125 strcpy(vimdir_path, p);
2126 break;
2127 }
2128 case vimfiles_dir_home:
2129 {
2130 /* Find the $HOME directory. Its existence was already checked. */
2131 p = getenv("HOME");
2132 if (p == NULL)
2133 {
2134 printf("Internal error: $HOME is NULL\n");
2135 p = "c:\\";
2136 }
2137 strcpy(vimdir_path, p);
2138 break;
2139 }
2140 case vimfiles_dir_none:
2141 {
2142 /* Do not create vim plugin directory */
2143 return;
2144 }
2145 }
2146
2147 /* Now, just create the directory. If it already exists, it will fail
2148 * silently. */
2149 sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path);
2150 vim_mkdir(vimfiles_path, 0755);
2151
2152 printf("Creating the following directories in \"%s\":\n", vimfiles_path);
2153 for (i = 0; i < TABLE_SIZE(vimfiles_subdirs); i++)
2154 {
2155 sprintf(tmp_dirname, "%s\\%s", vimfiles_path, vimfiles_subdirs[i]);
2156 printf(" %s", vimfiles_subdirs[i]);
2157 vim_mkdir(tmp_dirname, 0755);
2158 }
2159 printf("\n");
2160}
2161
2162/*
2163 * Add the creation of runtime files to the setup sequence.
2164 */
2165 static void
2166init_directories_choice(void)
2167{
2168 struct stat st;
2169 char tmp_dirname[BUFSIZE];
2170 char *p;
2171
2172 choices[choice_count].text = alloc(150);
2173 choices[choice_count].changefunc = change_directories_choice;
2174 choices[choice_count].installfunc = install_vimfilesdir;
2175 choices[choice_count].active = 1;
2176
2177 /* Check if the "compiler" directory already exists. That's a good
2178 * indication that the plugin directories were already created. */
2179 if (getenv("HOME") != NULL)
2180 {
2181 vimfiles_dir_choice = (int)vimfiles_dir_home;
2182 sprintf(tmp_dirname, "%s\\vimfiles\\compiler", getenv("HOME"));
2183 if (stat(tmp_dirname, &st) == 0)
2184 vimfiles_dir_choice = (int)vimfiles_dir_none;
2185 }
2186 else
2187 {
2188 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2189 p = getenv("VIM");
2190 if (p == NULL) /* No $VIM in path, use the install dir */
2191 dir_remove_last(installdir, tmp_dirname);
2192 else
2193 strcpy(tmp_dirname, p);
2194 strcat(tmp_dirname, "\\vimfiles\\compiler");
2195 if (stat(tmp_dirname, &st) == 0)
2196 vimfiles_dir_choice = (int)vimfiles_dir_none;
2197 }
2198
2199 set_directories_text(choice_count);
2200 ++choice_count;
2201}
2202
2203/*
2204 * Setup the choices and the default values.
2205 */
2206 static void
2207setup_choices(void)
2208{
2209 /* install the batch files */
2210 init_bat_choices();
2211
2212 /* (over) write _vimrc file */
2213 init_vimrc_choices();
2214
2215 /* Whether to add Vim to the popup menu */
2216 init_popup_choice();
2217
2218 /* Whether to add Vim to the "Open With..." menu */
2219 init_openwith_choice();
2220
2221 /* Whether to add Vim to the Start Menu. */
2222 init_startmenu_choice();
2223
2224 /* Whether to add shortcuts to the Desktop. */
2225 init_shortcut_choices();
2226
2227 /* Whether to create the runtime directories. */
2228 init_directories_choice();
2229}
2230
2231 static void
2232print_cmd_line_help(void)
2233{
2234 printf("Vim installer non-interactive command line arguments:\n");
2235 printf("\n");
2236 printf("-create-batfiles [vim gvim evim view gview vimdiff gvimdiff]\n");
2237 printf(" Create .bat files for Vim variants in the Windows directory.\n");
2238 printf("-create-vimrc\n");
2239 printf(" Create a default _vimrc file if one does not already exist.\n");
2240 printf("-install-popup\n");
2241 printf(" Install the Edit-with-Vim context menu entry\n");
2242 printf("-install-openwith\n");
2243 printf(" Add Vim to the \"Open With...\" context menu list\n");
2244#ifdef WIN3264
2245 printf("-add-start-menu");
2246 printf(" Add Vim to the start menu\n");
2247 printf("-install-icons");
2248 printf(" Create icons for gVim executables on the desktop\n");
2249#endif
2250 printf("-create-directories [vim|home]\n");
2251 printf(" Create runtime directories to drop plugins into; in the $VIM\n");
2252 printf(" or $HOME directory\n");
2253#ifdef WIN3264
2254 printf("-register-OLE");
Bram Moolenaarce0842a2005-07-18 21:58:11 +00002255 printf(" Ignored\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256#endif
2257 printf("\n");
2258}
2259
2260/*
2261 * Setup installation choices based on command line switches
2262 */
2263 static void
2264command_line_setup_choices(int argc, char **argv)
2265{
2266 int i, j;
2267
2268 for (i = 1; i < argc; i++)
2269 {
2270 if (strcmp(argv[i], "-create-batfiles") == 0)
2271 {
2272 if (i + 1 == argc)
2273 continue;
2274 while (argv[i + 1][0] != '-' && i < argc)
2275 {
2276 i++;
2277 for (j = 1; j < TARGET_COUNT; ++j)
2278 if ((targets[j].exenamearg[0] == 'g' ? has_gvim : has_vim)
2279 && strcmp(argv[i], targets[j].name) == 0)
2280 {
2281 init_bat_choice(j);
2282 break;
2283 }
2284 if (j == TARGET_COUNT)
2285 printf("%s is not a valid choice for -create-batfiles\n",
2286 argv[i]);
2287
2288 if (i + 1 == argc)
2289 break;
2290 }
2291 }
2292 else if (strcmp(argv[i], "-create-vimrc") == 0)
2293 {
2294 /* Setup default vimrc choices. If there is already a _vimrc file,
2295 * it will NOT be overwritten.
2296 */
2297 init_vimrc_choices();
2298 }
2299 else if (strcmp(argv[i], "-install-popup") == 0)
2300 {
2301 init_popup_choice();
2302 }
2303 else if (strcmp(argv[i], "-install-openwith") == 0)
2304 {
2305 init_openwith_choice();
2306 }
2307 else if (strcmp(argv[i], "-add-start-menu") == 0)
2308 {
2309 init_startmenu_choice();
2310 }
2311 else if (strcmp(argv[i], "-install-icons") == 0)
2312 {
2313 init_shortcut_choices();
2314 }
2315 else if (strcmp(argv[i], "-create-directories") == 0)
2316 {
2317 init_directories_choice();
2318 if (argv[i + 1][0] != '-')
2319 {
2320 i++;
2321 if (strcmp(argv[i], "vim") == 0)
2322 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2323 else if (strcmp(argv[i], "home") == 0)
2324 {
2325 if (getenv("HOME") == NULL) /* No $HOME in environment */
2326 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2327 else
2328 vimfiles_dir_choice = (int)vimfiles_dir_home;
2329 }
2330 else
2331 {
2332 printf("Unknown argument for -create-directories: %s\n",
2333 argv[i]);
2334 print_cmd_line_help();
2335 }
2336 }
2337 else /* No choice specified, default to vim directory */
2338 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2339 }
2340#ifdef WIN3264
2341 else if (strcmp(argv[i], "-register-OLE") == 0)
2342 {
2343 /* This is always done when gvim is found */
2344 }
2345#endif
2346 else /* Unknown switch */
2347 {
2348 printf("Got unknown argument argv[%d] = %s\n", i, argv[i]);
2349 print_cmd_line_help();
2350 }
2351 }
2352}
2353
2354
2355/*
2356 * Show a few screens full of helpful information.
2357 */
2358 static void
2359show_help(void)
2360{
2361 static char *(items[]) =
2362 {
2363"Installing .bat files\n"
2364"---------------------\n"
2365"The vim.bat file is written in one of the directories in $PATH.\n"
2366"This makes it possible to start Vim from the command line.\n"
2367"If vim.exe can be found in $PATH, the choice for vim.bat will not be\n"
2368"present. It is assumed you will use the existing vim.exe.\n"
2369"If vim.bat can already be found in $PATH this is probably for an old\n"
2370"version of Vim (but this is not checked!). You can overwrite it.\n"
2371"If no vim.bat already exists, you can select one of the directories in\n"
2372"$PATH for creating the batch file, or disable creating a vim.bat file.\n"
2373"\n"
2374"If you choose not to create the vim.bat file, Vim can still be executed\n"
2375"in other ways, but not from the command line.\n"
2376"\n"
2377"The same applies to choices for gvim, evim, (g)view, and (g)vimdiff.\n"
2378"The first item can be used to change the path for all of them.\n"
2379,
2380"Creating a _vimrc file\n"
2381"----------------------\n"
2382"The _vimrc file is used to set options for how Vim behaves.\n"
2383"The install program can create a _vimrc file with a few basic choices.\n"
2384"You can edit this file later to tune your preferences.\n"
2385"If you already have a _vimrc or .vimrc file it can be overwritten.\n"
2386"Don't do that if you have made changes to it.\n"
2387,
2388"Vim features\n"
2389"------------\n"
2390"(this choice is only available when creating a _vimrc file)\n"
2391"1. Vim can run in Vi-compatible mode. Many nice Vim features are then\n"
2392" disabled. In the not-Vi-compatible mode Vim is still mostly Vi\n"
2393" compatible, but adds nice features like multi-level undo. Only\n"
2394" choose Vi-compatible if you really need full Vi compatibility.\n"
2395"2. Running Vim with some enhancements is useful when you want some of\n"
2396" the nice Vim features, but have a slow computer and want to keep it\n"
2397" really fast.\n"
2398"3. Syntax highlighting shows many files in color. Not only does this look\n"
2399" nice, it also makes it easier to spot errors and you can work faster.\n"
2400" The other features include editing compressed files.\n"
2401,
2402"Windows key mapping\n"
2403"-------------------\n"
2404"(this choice is only available when creating a _vimrc file)\n"
2405"Under MS-Windows the CTRL-C key copies text to the clipboard and CTRL-V\n"
2406"pastes text from the clipboard. There are a few more keys like these.\n"
2407"Unfortunately, in Vim these keys normally have another meaning.\n"
2408"1. Choose to have the keys like they normally are in Vim (useful if you\n"
2409" also use Vim on other systems).\n"
2410"2. Choose to have the keys work like they are used on MS-Windows (useful\n"
2411" if you mostly work on MS-Windows).\n"
2412,
2413"Mouse use\n"
2414"---------\n"
2415"(this choice is only available when creating a _vimrc file)\n"
2416"The right mouse button can be used in two ways:\n"
2417"1. The Unix way is to extend an existing selection. The popup menu is\n"
2418" not available.\n"
2419"2. The MS-Windows way is to show a popup menu, which allows you to\n"
2420" copy/paste text, undo/redo, etc. Extending the selection can still be\n"
2421" done by keeping SHIFT pressed while using the left mouse button\n"
2422,
2423"Edit-with-Vim context menu entry\n"
2424"--------------------------------\n"
2425"(this choice is only available when gvim.exe and gvimext.dll are present)\n"
2426"You can associate different file types with Vim, so that you can (double)\n"
2427"click on a file to edit it with Vim. This means you have to individually\n"
2428"select each file type.\n"
2429"An alternative is the option offered here: Install an \"Edit with Vim\"\n"
2430"entry in the popup menu for the right mouse button. This means you can\n"
2431"edit any file with Vim.\n"
2432,
2433"\"Open With...\" context menu entry\n"
2434"--------------------------------\n"
2435"(this choice is only available when gvim.exe is present)\n"
2436"This option adds Vim to the \"Open With...\" entry in the popup menu for\n"
2437"the right mouse button. This also makes it possible to edit HTML files\n"
2438"directly from Internet Explorer.\n"
2439,
2440"Add Vim to the Start menu\n"
2441"-------------------------\n"
2442"In Windows 95 and later, Vim can be added to the Start menu. This will\n"
2443"create a submenu with an entry for vim, gvim, evim, vimdiff, etc..\n"
2444,
2445"Icons on the desktop\n"
2446"--------------------\n"
2447"(these choices are only available when installing gvim)\n"
2448"In Windows 95 and later, shortcuts (icons) can be created on the Desktop.\n"
2449,
2450"Create plugin directories\n"
2451"-------------------------\n"
2452"Plugin directories allow extending Vim by dropping a file into a directory.\n"
2453"This choice allows creating them in $HOME (if you have a home directory) or\n"
2454"$VIM (used for everybody on the system).\n"
2455,
2456NULL
2457 };
2458 int i;
2459 int c;
2460
2461 rewind(stdin);
2462 printf("\n");
2463 for (i = 0; items[i] != NULL; ++i)
2464 {
2465 printf(items[i]);
2466 printf("\n");
2467 printf("Hit Enter to continue, b (back) or q (quit help): ");
2468 c = getchar();
2469 rewind(stdin);
2470 if (c == 'b' || c == 'B')
2471 {
2472 if (i == 0)
2473 --i;
2474 else
2475 i -= 2;
2476 }
2477 if (c == 'q' || c == 'Q')
2478 break;
2479 printf("\n");
2480 }
2481}
2482
2483/*
2484 * Install the choices.
2485 */
2486 static void
2487install(void)
2488{
2489 int i;
2490
2491 /* Install the selected choices. */
2492 for (i = 0; i < choice_count; ++i)
2493 if (choices[i].installfunc != NULL && choices[i].active)
2494 (choices[i].installfunc)(i);
2495
2496 /* Add some entries to the registry, if needed. */
2497 if (install_popup
2498 || install_openwith
2499 || (need_uninstall_entry && interactive)
2500 || !interactive)
2501 install_registry();
2502
2503#ifdef WIN3264
2504 /* Register gvim with OLE. */
2505 if (has_gvim)
2506 install_OLE_register();
2507#endif
2508}
2509
2510/*
2511 * request_choice
2512 */
2513 static void
2514request_choice(void)
2515{
2516 int i;
2517
2518 printf("\n\nInstall will do for you:\n");
2519 for (i = 0; i < choice_count; ++i)
2520 if (choices[i].active)
2521 printf("%2d %s\n", i + 1, choices[i].text);
2522 printf("To change an item, enter its number\n\n");
2523 printf("Enter item number, h (help), d (do it) or q (quit): ");
2524}
2525
2526 int
2527main(int argc, char **argv)
2528{
2529 int i;
2530 char buf[BUFSIZE];
2531
2532 /*
2533 * Run interactively if there are no command line arguments.
2534 */
2535 if (argc > 1)
2536 interactive = 0;
2537 else
2538 interactive = 1;
2539
2540 /* Initialize this program. */
2541 do_inits(argv);
2542
2543#ifdef WIN3264
2544 if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0)
2545 {
2546 /* Only check for already installed Vims. Used by NSIS installer. */
Bram Moolenaar442b4222010-05-24 21:34:22 +02002547 i = uninstall_check(1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548
2549 /* Find the value of $VIM, because NSIS isn't able to do this by
2550 * itself. */
2551 get_vim_env();
2552
2553 /* When nothing found exit quietly. If something found wait for
Bram Moolenaarb230bd52010-05-25 21:02:00 +02002554 * a little while, so that the user can read the messages. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 if (i)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02002556 sleep(3);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 exit(0);
2558 }
2559#endif
2560
2561 printf("This program sets up the installation of Vim "
2562 VIM_VERSION_MEDIUM "\n\n");
2563
2564 /* Check if the user unpacked the archives properly. */
2565 check_unpack();
2566
2567#ifdef WIN3264
2568 /* Check for already installed Vims. */
2569 if (interactive)
Bram Moolenaar442b4222010-05-24 21:34:22 +02002570 uninstall_check(0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571#endif
2572
2573 /* Find out information about the system. */
2574 inspect_system();
2575
2576 if (interactive)
2577 {
2578 /* Setup all the choices. */
2579 setup_choices();
2580
2581 /* Let the user change choices and finally install (or quit). */
2582 for (;;)
2583 {
2584 request_choice();
2585 rewind(stdin);
2586 if (scanf("%99s", buf) == 1)
2587 {
2588 if (isdigit(buf[0]))
2589 {
2590 /* Change a choice. */
2591 i = atoi(buf);
2592 if (i > 0 && i <= choice_count && choices[i - 1].active)
2593 (choices[i - 1].changefunc)(i - 1);
2594 else
2595 printf("\nIllegal choice\n");
2596 }
2597 else if (buf[0] == 'h' || buf[0] == 'H')
2598 {
2599 /* Help */
2600 show_help();
2601 }
2602 else if (buf[0] == 'd' || buf[0] == 'D')
2603 {
2604 /* Install! */
2605 install();
2606 printf("\nThat finishes the installation. Happy Vimming!\n");
2607 break;
2608 }
2609 else if (buf[0] == 'q' || buf[0] == 'Q')
2610 {
2611 /* Quit */
2612 printf("\nExiting without anything done\n");
2613 break;
2614 }
2615 else
2616 printf("\nIllegal choice\n");
2617 }
2618 }
2619 printf("\n");
Bram Moolenaar442b4222010-05-24 21:34:22 +02002620 myexit(0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 }
2622 else
2623 {
2624 /*
2625 * Run non-interactive - setup according to the command line switches
2626 */
2627 command_line_setup_choices(argc, argv);
2628 install();
Bram Moolenaar442b4222010-05-24 21:34:22 +02002629
2630 /* Avoid that the user has to hit Enter, just wait a little bit to
2631 * allow reading the messages. */
Bram Moolenaarab8205e2010-07-07 15:14:03 +02002632 sleep(2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 }
2634
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 return 0;
2636}