blob: 6dcb5e30dba143c3d996011098f1af9d938ad6ed [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{
Bram Moolenaar78050042010-07-31 20:53:54 +02001471 char exe_cmd[BUFSIZE];
1472 LONG lRet;
1473
1474 sprintf(exe_cmd, "%s \"%%1\"", exe_path);
1475 lRet = reg_create_key_and_value(
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001476 hRootKey,
1477 "Applications\\gvim.exe\\shell\\edit\\command",
1478 NULL,
Bram Moolenaar78050042010-07-31 20:53:54 +02001479 exe_cmd);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001480
1481 if (ERROR_SUCCESS == lRet)
1482 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001483 int i;
1484 static const char *openwith[] = {
1485 ".htm\\OpenWithList\\gvim.exe",
1486 ".vim\\OpenWithList\\gvim.exe",
1487 "*\\OpenWithList\\gvim.exe",
1488 };
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001489
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001490 for (i = 0; ERROR_SUCCESS == lRet
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001491 && i < sizeof(openwith) / sizeof(openwith[0]); i++)
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001492 {
1493 lRet = reg_create_key_and_value(hRootKey, openwith[i], NULL, "");
1494 }
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001495 }
1496
1497 return lRet;
1498}
1499
1500 static LONG
1501register_uninstall(
1502 HKEY hRootKey,
1503 const char *appname,
1504 const char *display_name,
1505 const char *uninstall_string)
1506{
1507 LONG lRet = reg_create_key_and_value(hRootKey, appname,
1508 "DisplayName", display_name);
1509
1510 if (ERROR_SUCCESS == lRet)
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001511 lRet = reg_create_key_and_value(hRootKey, appname,
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001512 "UninstallString", uninstall_string);
1513 return lRet;
1514}
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001515#endif /* WIN3264 */
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001516
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517/*
1518 * Add some entries to the registry:
1519 * - to add "Edit with Vim" to the context * menu
1520 * - to add Vim to the "Open with..." list
1521 * - to uninstall Vim
1522 */
1523/*ARGSUSED*/
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001524 static int
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525install_registry(void)
1526{
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001527#ifdef WIN3264
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001528 LONG lRet = ERROR_SUCCESS;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 const char *vim_ext_ThreadingModel = "Apartment";
1530 const char *vim_ext_name = "Vim Shell Extension";
1531 const char *vim_ext_clsid = "{51EEE242-AD87-11d3-9C1E-0090278BBD99}";
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001532 char vim_exe_path[BUFSIZE];
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001533 char display_name[BUFSIZE];
1534 char uninstall_string[BUFSIZE];
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001536 sprintf(vim_exe_path, "%s\\gvim.exe", installdir);
1537
1538 if (install_popup)
1539 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001540 char bufg[BUFSIZE];
1541 struct stat st;
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001542
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001543 if (stat("gvimext.dll", &st) >= 0)
1544 sprintf(bufg, "%s\\gvimext.dll", installdir);
1545 else
1546 /* gvimext.dll is in gvimext subdir */
1547 sprintf(bufg, "%s\\gvimext\\gvimext.dll", installdir);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001548
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001549 printf("Creating \"Edit with Vim\" popup menu entry\n");
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001550
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001551 lRet = register_inproc_server(
1552 HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name,
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001553 bufg, vim_ext_ThreadingModel);
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001554 if (ERROR_SUCCESS != lRet)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001555 return FAIL;
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001556 lRet = register_shellex(
1557 HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name, vim_exe_path);
1558 if (ERROR_SUCCESS != lRet)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001559 return FAIL;
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001560 }
1561
1562 if (install_openwith)
1563 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001564 printf("Creating \"Open with ...\" list entry\n");
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001565
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001566 lRet = register_openwith(HKEY_CLASSES_ROOT, vim_exe_path);
1567 if (ERROR_SUCCESS != lRet)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001568 return FAIL;
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001569 }
1570
1571 printf("Creating an uninstall entry\n");
1572
1573 /* For the NSIS installer use the generated uninstaller. */
1574 if (interactive)
1575 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001576 sprintf(display_name, "Vim " VIM_VERSION_SHORT);
Bram Moolenaar16d79a32010-07-18 22:33:56 +02001577 sprintf(uninstall_string, "%s\\uninstal.exe", installdir);
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001578 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 else
1580 {
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001581 sprintf(display_name, "Vim " VIM_VERSION_SHORT " (self-installing)");
Bram Moolenaar16d79a32010-07-18 22:33:56 +02001582 sprintf(uninstall_string, "%s\\uninstall-gui.exe", installdir);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001583 }
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001584
1585 lRet = register_uninstall(
Bram Moolenaarcc448b32010-07-14 16:52:17 +02001586 HKEY_LOCAL_MACHINE,
1587 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT,
1588 display_name,
1589 uninstall_string);
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001590 if (ERROR_SUCCESS != lRet)
1591 return FAIL;
1592#endif /* WIN3264 */
Bram Moolenaarccd9ccf2010-07-07 13:19:55 +02001593
Bram Moolenaarab8205e2010-07-07 15:14:03 +02001594 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595}
1596
1597 static void
1598change_popup_choice(int idx)
1599{
1600 if (install_popup == 0)
1601 {
1602 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";
1603 install_popup = 1;
1604 }
1605 else
1606 {
1607 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";
1608 install_popup = 0;
1609 }
1610}
1611
1612/*
1613 * Only add the choice for the popup menu entry when gvim.exe was found and
1614 * both gvimext.dll and regedit.exe exist.
1615 */
1616 static void
1617init_popup_choice(void)
1618{
1619 struct stat st;
1620
1621 if (has_gvim
1622 && (stat("gvimext.dll", &st) >= 0
1623 || stat("gvimext/gvimext.dll", &st) >= 0)
1624#ifndef WIN3264
1625 && searchpath("regedit.exe") != NULL
1626#endif
1627 )
1628 {
1629 choices[choice_count].changefunc = change_popup_choice;
1630 choices[choice_count].installfunc = NULL;
1631 choices[choice_count].active = 1;
1632 change_popup_choice(choice_count); /* set the text */
1633 ++choice_count;
1634 }
1635 else
1636 add_dummy_choice();
1637}
1638
1639 static void
1640change_openwith_choice(int idx)
1641{
1642 if (install_openwith == 0)
1643 {
1644 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";
1645 install_openwith = 1;
1646 }
1647 else
1648 {
1649 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";
1650 install_openwith = 0;
1651 }
1652}
1653
1654/*
1655 * Only add the choice for the open-with menu entry when gvim.exe was found
1656 * and and regedit.exe exist.
1657 */
1658 static void
1659init_openwith_choice(void)
1660{
1661 if (has_gvim
1662#ifndef WIN3264
1663 && searchpath("regedit.exe") != NULL
1664#endif
1665 )
1666 {
1667 choices[choice_count].changefunc = change_openwith_choice;
1668 choices[choice_count].installfunc = NULL;
1669 choices[choice_count].active = 1;
1670 change_openwith_choice(choice_count); /* set the text */
1671 ++choice_count;
1672 }
1673 else
1674 add_dummy_choice();
1675}
1676
1677#ifdef WIN3264
1678/* create_shortcut
1679 *
1680 * Create a shell link.
1681 *
1682 * returns 0 on failure, non-zero on successful completion.
1683 *
1684 * NOTE: Currently untested with mingw.
1685 */
1686 int
1687create_shortcut(
1688 const char *shortcut_name,
1689 const char *iconfile_path,
1690 int iconindex,
1691 const char *shortcut_target,
1692 const char *shortcut_args,
1693 const char *workingdir
1694 )
1695{
1696 IShellLink *shelllink_ptr;
1697 HRESULT hres;
1698 IPersistFile *persistfile_ptr;
1699
1700 /* Initialize COM library */
1701 hres = CoInitialize(NULL);
1702 if (!SUCCEEDED(hres))
1703 {
1704 printf("Error: Could not open the COM library. Not creating shortcut.\n");
1705 return FAIL;
1706 }
1707
1708 /* Instantiate a COM object for the ShellLink, store a pointer to it
1709 * in shelllink_ptr. */
1710 hres = CoCreateInstance(&CLSID_ShellLink,
1711 NULL,
1712 CLSCTX_INPROC_SERVER,
1713 &IID_IShellLink,
1714 (void **) &shelllink_ptr);
1715
1716 if (SUCCEEDED(hres)) /* If the instantiation was successful... */
1717 {
1718 /* ...Then build a PersistFile interface for the ShellLink so we can
1719 * save it as a file after we build it. */
1720 hres = shelllink_ptr->lpVtbl->QueryInterface(shelllink_ptr,
1721 &IID_IPersistFile, (void **) &persistfile_ptr);
1722
1723 if (SUCCEEDED(hres))
1724 {
1725 wchar_t wsz[BUFSIZE];
1726
1727 /* translate the (possibly) multibyte shortcut filename to windows
1728 * Unicode so it can be used as a file name.
1729 */
1730 MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, BUFSIZE);
1731
1732 /* set the attributes */
1733 shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target);
1734 shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr,
1735 workingdir);
1736 shelllink_ptr->lpVtbl->SetIconLocation(shelllink_ptr,
1737 iconfile_path, iconindex);
1738 shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args);
1739
1740 /* save the shortcut to a file and return the PersistFile object*/
1741 persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1);
1742 persistfile_ptr->lpVtbl->Release(persistfile_ptr);
1743 }
1744 else
1745 {
1746 printf("QueryInterface Error\n");
1747 return FAIL;
1748 }
1749
1750 /* Return the ShellLink object */
1751 shelllink_ptr->lpVtbl->Release(shelllink_ptr);
1752 }
1753 else
1754 {
1755 printf("CoCreateInstance Error - hres = %08x\n", (int)hres);
1756 return FAIL;
1757 }
1758
1759 return OK;
1760}
1761
1762/*
1763 * Build a path to where we will put a specified link.
1764 *
1765 * Return 0 on error, non-zero on success
1766 */
1767 int
1768build_link_name(
1769 char *link_path,
1770 const char *link_name,
1771 const char *shell_folder_name)
1772{
1773 char shell_folder_path[BUFSIZE];
1774
1775 if (get_shell_folder_path(shell_folder_path, shell_folder_name) == FAIL)
1776 {
1777 printf("An error occurred while attempting to find the path to %s.\n",
1778 shell_folder_name);
1779 return FAIL;
1780 }
1781
1782 /* Make sure the directory exists (create Start Menu\Programs\Vim).
1783 * Ignore errors if it already exists. */
1784 vim_mkdir(shell_folder_path, 0755);
1785
1786 /* build the path to the shortcut and the path to gvim.exe */
1787 sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name);
1788
1789 return OK;
1790}
1791
1792 static int
1793build_shortcut(
1794 const char *name, /* Name of the shortcut */
1795 const char *exename, /* Name of the executable (e.g., vim.exe) */
1796 const char *args,
1797 const char *shell_folder,
1798 const char *workingdir)
1799{
1800 char executable_path[BUFSIZE];
1801 char link_name[BUFSIZE];
1802
1803 sprintf(executable_path, "%s\\%s", installdir, exename);
1804
1805 if (build_link_name(link_name, name, shell_folder) == FAIL)
1806 {
1807 printf("An error has occurred. A shortcut to %s will not be created %s.\n",
1808 name,
1809 *shell_folder == 'd' ? "on the desktop" : "in the Start menu");
1810 return FAIL;
1811 }
1812
1813 /* Create the shortcut: */
1814 return create_shortcut(link_name, executable_path, 0,
1815 executable_path, args, workingdir);
1816}
1817
1818/*
1819 * We used to use "homedir" as the working directory, but that is a bad choice
1820 * on multi-user systems. Not specifying a directory appears to work best.
1821 */
1822#define WORKDIR ""
1823
1824/*
1825 * Create shortcut(s) in the Start Menu\Programs\Vim folder.
1826 */
1827 static void
1828install_start_menu(int idx)
1829{
1830 need_uninstall_entry = 1;
1831 printf("Creating start menu\n");
1832 if (has_vim)
1833 {
1834 if (build_shortcut("Vim", "vim.exe", "",
1835 VIM_STARTMENU, WORKDIR) == FAIL)
1836 return;
1837 if (build_shortcut("Vim Read-only", "vim.exe", "-R",
1838 VIM_STARTMENU, WORKDIR) == FAIL)
1839 return;
1840 if (build_shortcut("Vim Diff", "vim.exe", "-d",
1841 VIM_STARTMENU, WORKDIR) == FAIL)
1842 return;
1843 }
1844 if (has_gvim)
1845 {
1846 if (build_shortcut("gVim", "gvim.exe", "",
1847 VIM_STARTMENU, WORKDIR) == FAIL)
1848 return;
1849 if (build_shortcut("gVim Easy", "gvim.exe", "-y",
1850 VIM_STARTMENU, WORKDIR) == FAIL)
1851 return;
1852 if (build_shortcut("gVim Read-only", "gvim.exe", "-R",
1853 VIM_STARTMENU, WORKDIR) == FAIL)
1854 return;
1855 if (build_shortcut("gVim Diff", "gvim.exe", "-d",
1856 VIM_STARTMENU, WORKDIR) == FAIL)
1857 return;
1858 }
1859 if (build_shortcut("Uninstall",
1860 interactive ? "uninstal.exe" : "uninstall-gui.exe", "",
1861 VIM_STARTMENU, installdir) == FAIL)
1862 return;
1863 /* For Windows NT the working dir of the vimtutor.bat must be right,
1864 * otherwise gvim.exe won't be found and using gvimbat doesn't work. */
1865 if (build_shortcut("Vim tutor", "vimtutor.bat", "",
1866 VIM_STARTMENU, installdir) == FAIL)
1867 return;
1868 if (build_shortcut("Help", has_gvim ? "gvim.exe" : "vim.exe", "-c h",
1869 VIM_STARTMENU, WORKDIR) == FAIL)
1870 return;
1871 {
1872 char shell_folder_path[BUFSIZE];
1873
1874 /* Creating the URL shortcut works a bit differently... */
1875 if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL)
1876 {
1877 printf("Finding the path of the Start menu failed\n");
1878 return ;
1879 }
1880 add_pathsep(shell_folder_path);
1881 strcat(shell_folder_path, "Vim Online.url");
1882 if (!WritePrivateProfileString("InternetShortcut", "URL",
1883 "http://vim.sf.net/", shell_folder_path))
1884 {
1885 printf("Creating the Vim online URL failed\n");
1886 return;
1887 }
1888 }
1889}
1890
1891 static void
1892toggle_startmenu_choice(int idx)
1893{
1894 if (choices[idx].installfunc == NULL)
1895 {
1896 choices[idx].installfunc = install_start_menu;
1897 choices[idx].text = "Add Vim to the Start menu";
1898 }
1899 else
1900 {
1901 choices[idx].installfunc = NULL;
1902 choices[idx].text = "Do NOT add Vim to the Start menu";
1903 }
1904}
1905
1906/*
1907 * Function to actually create the shortcuts
1908 *
1909 * Currently I am supplying no working directory to the shortcut. This
1910 * means that the initial working dir will be:
1911 * - the location of the shortcut if no file is supplied
1912 * - the location of the file being edited if a file is supplied (ie via
1913 * drag and drop onto the shortcut).
1914 */
1915 void
1916install_shortcut_gvim(int idx)
1917{
1918 /* Create shortcut(s) on the desktop */
1919 if (choices[idx].arg)
1920 {
1921 (void)build_shortcut(icon_names[0], "gvim.exe",
1922 "", "desktop", WORKDIR);
1923 need_uninstall_entry = 1;
1924 }
1925}
1926
1927 void
1928install_shortcut_evim(int idx)
1929{
1930 if (choices[idx].arg)
1931 {
1932 (void)build_shortcut(icon_names[1], "gvim.exe",
1933 "-y", "desktop", WORKDIR);
1934 need_uninstall_entry = 1;
1935 }
1936}
1937
1938 void
1939install_shortcut_gview(int idx)
1940{
1941 if (choices[idx].arg)
1942 {
1943 (void)build_shortcut(icon_names[2], "gvim.exe",
1944 "-R", "desktop", WORKDIR);
1945 need_uninstall_entry = 1;
1946 }
1947}
1948
1949 void
1950toggle_shortcut_choice(int idx)
1951{
1952 char *arg;
1953
1954 if (choices[idx].installfunc == install_shortcut_gvim)
1955 arg = "gVim";
1956 else if (choices[idx].installfunc == install_shortcut_evim)
1957 arg = "gVim Easy";
1958 else
1959 arg = "gVim Read-only";
1960 if (choices[idx].arg)
1961 {
1962 choices[idx].arg = 0;
1963 alloc_text(idx, "Do NOT create a desktop icon for %s", arg);
1964 }
1965 else
1966 {
1967 choices[idx].arg = 1;
1968 alloc_text(idx, "Create a desktop icon for %s", arg);
1969 }
1970}
1971#endif /* WIN3264 */
1972
1973 static void
1974init_startmenu_choice(void)
1975{
1976#ifdef WIN3264
1977 /* Start menu */
1978 choices[choice_count].changefunc = toggle_startmenu_choice;
1979 choices[choice_count].installfunc = NULL;
1980 choices[choice_count].active = 1;
1981 toggle_startmenu_choice(choice_count); /* set the text */
1982 ++choice_count;
1983#else
1984 add_dummy_choice();
1985#endif
1986}
1987
1988/*
1989 * Add the choice for the desktop shortcuts.
1990 */
1991 static void
1992init_shortcut_choices(void)
1993{
1994#ifdef WIN3264
1995 /* Shortcut to gvim */
1996 choices[choice_count].text = NULL;
1997 choices[choice_count].arg = 0;
1998 choices[choice_count].active = has_gvim;
1999 choices[choice_count].changefunc = toggle_shortcut_choice;
2000 choices[choice_count].installfunc = install_shortcut_gvim;
2001 toggle_shortcut_choice(choice_count);
2002 ++choice_count;
2003
2004 /* Shortcut to evim */
2005 choices[choice_count].text = NULL;
2006 choices[choice_count].arg = 0;
2007 choices[choice_count].active = has_gvim;
2008 choices[choice_count].changefunc = toggle_shortcut_choice;
2009 choices[choice_count].installfunc = install_shortcut_evim;
2010 toggle_shortcut_choice(choice_count);
2011 ++choice_count;
2012
2013 /* Shortcut to gview */
2014 choices[choice_count].text = NULL;
2015 choices[choice_count].arg = 0;
2016 choices[choice_count].active = has_gvim;
2017 choices[choice_count].changefunc = toggle_shortcut_choice;
2018 choices[choice_count].installfunc = install_shortcut_gview;
2019 toggle_shortcut_choice(choice_count);
2020 ++choice_count;
2021#else
2022 add_dummy_choice();
2023 add_dummy_choice();
2024 add_dummy_choice();
2025#endif
2026}
2027
2028#ifdef WIN3264
2029/*
2030 * Attempt to register OLE for Vim.
2031 */
2032 static void
2033install_OLE_register(void)
2034{
2035 char register_command_string[BUFSIZE + 30];
2036
2037 printf("\n--- Attempting to register Vim with OLE ---\n");
2038 printf("(There is no message whether this works or not.)\n");
2039
2040#ifndef __CYGWIN__
2041 sprintf(register_command_string, "\"%s\\gvim.exe\" -silent -register", installdir);
2042#else
2043 /* handle this differently for Cygwin which sometimes has trouble with
2044 * Windows-style pathnames here. */
2045 sprintf(register_command_string, "./gvim.exe -silent -register");
2046#endif
2047 system(register_command_string);
2048}
2049#endif /* WIN3264 */
2050
2051/*
2052 * Remove the last part of directory "path[]" to get its parent, and put the
2053 * result in "to[]".
2054 */
2055 static void
2056dir_remove_last(const char *path, char to[BUFSIZE])
2057{
2058 char c;
2059 long last_char_to_copy;
2060 long path_length = strlen(path);
2061
2062 /* skip the last character just in case it is a '\\' */
2063 last_char_to_copy = path_length - 2;
2064 c = path[last_char_to_copy];
2065
2066 while (c != '\\')
2067 {
2068 last_char_to_copy--;
2069 c = path[last_char_to_copy];
2070 }
2071
2072 strncpy(to, path, (size_t)last_char_to_copy);
2073 to[last_char_to_copy] = NUL;
2074}
2075
2076 static void
2077set_directories_text(int idx)
2078{
2079 if (vimfiles_dir_choice == (int)vimfiles_dir_none)
2080 alloc_text(idx, "Do NOT create plugin directories%s", "");
2081 else
2082 alloc_text(idx, "Create plugin directories: %s",
2083 vimfiles_dir_choices[vimfiles_dir_choice]);
2084}
2085
2086/*
2087 * Change the directory that the vim plugin directories will be created in:
2088 * $HOME, $VIM or nowhere.
2089 */
2090 static void
2091change_directories_choice(int idx)
2092{
2093 int choice_count = TABLE_SIZE(vimfiles_dir_choices);
2094
2095 /* Don't offer the $HOME choice if $HOME isn't set. */
2096 if (getenv("HOME") == NULL)
2097 --choice_count;
2098 vimfiles_dir_choice = get_choice(vimfiles_dir_choices, choice_count);
2099 set_directories_text(idx);
2100}
2101
2102/*
2103 * Create the plugin directories...
2104 */
2105/*ARGSUSED*/
2106 static void
2107install_vimfilesdir(int idx)
2108{
2109 int i;
2110 char *p;
2111 char vimdir_path[BUFSIZE];
2112 char vimfiles_path[BUFSIZE];
2113 char tmp_dirname[BUFSIZE];
2114
2115 /* switch on the location that the user wants the plugin directories
2116 * built in */
2117 switch (vimfiles_dir_choice)
2118 {
2119 case vimfiles_dir_vim:
2120 {
2121 /* Go to the %VIM% directory - check env first, then go one dir
2122 * below installdir if there is no %VIM% environment variable.
2123 * The accuracy of $VIM is checked in inspect_system(), so we
2124 * can be sure it is ok to use here. */
2125 p = getenv("VIM");
2126 if (p == NULL) /* No $VIM in path */
2127 dir_remove_last(installdir, vimdir_path);
2128 else
2129 strcpy(vimdir_path, p);
2130 break;
2131 }
2132 case vimfiles_dir_home:
2133 {
2134 /* Find the $HOME directory. Its existence was already checked. */
2135 p = getenv("HOME");
2136 if (p == NULL)
2137 {
2138 printf("Internal error: $HOME is NULL\n");
2139 p = "c:\\";
2140 }
2141 strcpy(vimdir_path, p);
2142 break;
2143 }
2144 case vimfiles_dir_none:
2145 {
2146 /* Do not create vim plugin directory */
2147 return;
2148 }
2149 }
2150
2151 /* Now, just create the directory. If it already exists, it will fail
2152 * silently. */
2153 sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path);
2154 vim_mkdir(vimfiles_path, 0755);
2155
2156 printf("Creating the following directories in \"%s\":\n", vimfiles_path);
2157 for (i = 0; i < TABLE_SIZE(vimfiles_subdirs); i++)
2158 {
2159 sprintf(tmp_dirname, "%s\\%s", vimfiles_path, vimfiles_subdirs[i]);
2160 printf(" %s", vimfiles_subdirs[i]);
2161 vim_mkdir(tmp_dirname, 0755);
2162 }
2163 printf("\n");
2164}
2165
2166/*
2167 * Add the creation of runtime files to the setup sequence.
2168 */
2169 static void
2170init_directories_choice(void)
2171{
2172 struct stat st;
2173 char tmp_dirname[BUFSIZE];
2174 char *p;
2175
2176 choices[choice_count].text = alloc(150);
2177 choices[choice_count].changefunc = change_directories_choice;
2178 choices[choice_count].installfunc = install_vimfilesdir;
2179 choices[choice_count].active = 1;
2180
2181 /* Check if the "compiler" directory already exists. That's a good
2182 * indication that the plugin directories were already created. */
2183 if (getenv("HOME") != NULL)
2184 {
2185 vimfiles_dir_choice = (int)vimfiles_dir_home;
2186 sprintf(tmp_dirname, "%s\\vimfiles\\compiler", getenv("HOME"));
2187 if (stat(tmp_dirname, &st) == 0)
2188 vimfiles_dir_choice = (int)vimfiles_dir_none;
2189 }
2190 else
2191 {
2192 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2193 p = getenv("VIM");
2194 if (p == NULL) /* No $VIM in path, use the install dir */
2195 dir_remove_last(installdir, tmp_dirname);
2196 else
2197 strcpy(tmp_dirname, p);
2198 strcat(tmp_dirname, "\\vimfiles\\compiler");
2199 if (stat(tmp_dirname, &st) == 0)
2200 vimfiles_dir_choice = (int)vimfiles_dir_none;
2201 }
2202
2203 set_directories_text(choice_count);
2204 ++choice_count;
2205}
2206
2207/*
2208 * Setup the choices and the default values.
2209 */
2210 static void
2211setup_choices(void)
2212{
2213 /* install the batch files */
2214 init_bat_choices();
2215
2216 /* (over) write _vimrc file */
2217 init_vimrc_choices();
2218
2219 /* Whether to add Vim to the popup menu */
2220 init_popup_choice();
2221
2222 /* Whether to add Vim to the "Open With..." menu */
2223 init_openwith_choice();
2224
2225 /* Whether to add Vim to the Start Menu. */
2226 init_startmenu_choice();
2227
2228 /* Whether to add shortcuts to the Desktop. */
2229 init_shortcut_choices();
2230
2231 /* Whether to create the runtime directories. */
2232 init_directories_choice();
2233}
2234
2235 static void
2236print_cmd_line_help(void)
2237{
2238 printf("Vim installer non-interactive command line arguments:\n");
2239 printf("\n");
2240 printf("-create-batfiles [vim gvim evim view gview vimdiff gvimdiff]\n");
2241 printf(" Create .bat files for Vim variants in the Windows directory.\n");
2242 printf("-create-vimrc\n");
2243 printf(" Create a default _vimrc file if one does not already exist.\n");
2244 printf("-install-popup\n");
2245 printf(" Install the Edit-with-Vim context menu entry\n");
2246 printf("-install-openwith\n");
2247 printf(" Add Vim to the \"Open With...\" context menu list\n");
2248#ifdef WIN3264
2249 printf("-add-start-menu");
2250 printf(" Add Vim to the start menu\n");
2251 printf("-install-icons");
2252 printf(" Create icons for gVim executables on the desktop\n");
2253#endif
2254 printf("-create-directories [vim|home]\n");
2255 printf(" Create runtime directories to drop plugins into; in the $VIM\n");
2256 printf(" or $HOME directory\n");
2257#ifdef WIN3264
2258 printf("-register-OLE");
Bram Moolenaarce0842a2005-07-18 21:58:11 +00002259 printf(" Ignored\n");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260#endif
2261 printf("\n");
2262}
2263
2264/*
2265 * Setup installation choices based on command line switches
2266 */
2267 static void
2268command_line_setup_choices(int argc, char **argv)
2269{
2270 int i, j;
2271
2272 for (i = 1; i < argc; i++)
2273 {
2274 if (strcmp(argv[i], "-create-batfiles") == 0)
2275 {
2276 if (i + 1 == argc)
2277 continue;
2278 while (argv[i + 1][0] != '-' && i < argc)
2279 {
2280 i++;
2281 for (j = 1; j < TARGET_COUNT; ++j)
2282 if ((targets[j].exenamearg[0] == 'g' ? has_gvim : has_vim)
2283 && strcmp(argv[i], targets[j].name) == 0)
2284 {
2285 init_bat_choice(j);
2286 break;
2287 }
2288 if (j == TARGET_COUNT)
2289 printf("%s is not a valid choice for -create-batfiles\n",
2290 argv[i]);
2291
2292 if (i + 1 == argc)
2293 break;
2294 }
2295 }
2296 else if (strcmp(argv[i], "-create-vimrc") == 0)
2297 {
2298 /* Setup default vimrc choices. If there is already a _vimrc file,
2299 * it will NOT be overwritten.
2300 */
2301 init_vimrc_choices();
2302 }
2303 else if (strcmp(argv[i], "-install-popup") == 0)
2304 {
2305 init_popup_choice();
2306 }
2307 else if (strcmp(argv[i], "-install-openwith") == 0)
2308 {
2309 init_openwith_choice();
2310 }
2311 else if (strcmp(argv[i], "-add-start-menu") == 0)
2312 {
2313 init_startmenu_choice();
2314 }
2315 else if (strcmp(argv[i], "-install-icons") == 0)
2316 {
2317 init_shortcut_choices();
2318 }
2319 else if (strcmp(argv[i], "-create-directories") == 0)
2320 {
2321 init_directories_choice();
2322 if (argv[i + 1][0] != '-')
2323 {
2324 i++;
2325 if (strcmp(argv[i], "vim") == 0)
2326 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2327 else if (strcmp(argv[i], "home") == 0)
2328 {
2329 if (getenv("HOME") == NULL) /* No $HOME in environment */
2330 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2331 else
2332 vimfiles_dir_choice = (int)vimfiles_dir_home;
2333 }
2334 else
2335 {
2336 printf("Unknown argument for -create-directories: %s\n",
2337 argv[i]);
2338 print_cmd_line_help();
2339 }
2340 }
2341 else /* No choice specified, default to vim directory */
2342 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2343 }
2344#ifdef WIN3264
2345 else if (strcmp(argv[i], "-register-OLE") == 0)
2346 {
2347 /* This is always done when gvim is found */
2348 }
2349#endif
2350 else /* Unknown switch */
2351 {
2352 printf("Got unknown argument argv[%d] = %s\n", i, argv[i]);
2353 print_cmd_line_help();
2354 }
2355 }
2356}
2357
2358
2359/*
2360 * Show a few screens full of helpful information.
2361 */
2362 static void
2363show_help(void)
2364{
2365 static char *(items[]) =
2366 {
2367"Installing .bat files\n"
2368"---------------------\n"
2369"The vim.bat file is written in one of the directories in $PATH.\n"
2370"This makes it possible to start Vim from the command line.\n"
2371"If vim.exe can be found in $PATH, the choice for vim.bat will not be\n"
2372"present. It is assumed you will use the existing vim.exe.\n"
2373"If vim.bat can already be found in $PATH this is probably for an old\n"
2374"version of Vim (but this is not checked!). You can overwrite it.\n"
2375"If no vim.bat already exists, you can select one of the directories in\n"
2376"$PATH for creating the batch file, or disable creating a vim.bat file.\n"
2377"\n"
2378"If you choose not to create the vim.bat file, Vim can still be executed\n"
2379"in other ways, but not from the command line.\n"
2380"\n"
2381"The same applies to choices for gvim, evim, (g)view, and (g)vimdiff.\n"
2382"The first item can be used to change the path for all of them.\n"
2383,
2384"Creating a _vimrc file\n"
2385"----------------------\n"
2386"The _vimrc file is used to set options for how Vim behaves.\n"
2387"The install program can create a _vimrc file with a few basic choices.\n"
2388"You can edit this file later to tune your preferences.\n"
2389"If you already have a _vimrc or .vimrc file it can be overwritten.\n"
2390"Don't do that if you have made changes to it.\n"
2391,
2392"Vim features\n"
2393"------------\n"
2394"(this choice is only available when creating a _vimrc file)\n"
2395"1. Vim can run in Vi-compatible mode. Many nice Vim features are then\n"
2396" disabled. In the not-Vi-compatible mode Vim is still mostly Vi\n"
2397" compatible, but adds nice features like multi-level undo. Only\n"
2398" choose Vi-compatible if you really need full Vi compatibility.\n"
2399"2. Running Vim with some enhancements is useful when you want some of\n"
2400" the nice Vim features, but have a slow computer and want to keep it\n"
2401" really fast.\n"
2402"3. Syntax highlighting shows many files in color. Not only does this look\n"
2403" nice, it also makes it easier to spot errors and you can work faster.\n"
2404" The other features include editing compressed files.\n"
2405,
2406"Windows key mapping\n"
2407"-------------------\n"
2408"(this choice is only available when creating a _vimrc file)\n"
2409"Under MS-Windows the CTRL-C key copies text to the clipboard and CTRL-V\n"
2410"pastes text from the clipboard. There are a few more keys like these.\n"
2411"Unfortunately, in Vim these keys normally have another meaning.\n"
2412"1. Choose to have the keys like they normally are in Vim (useful if you\n"
2413" also use Vim on other systems).\n"
2414"2. Choose to have the keys work like they are used on MS-Windows (useful\n"
2415" if you mostly work on MS-Windows).\n"
2416,
2417"Mouse use\n"
2418"---------\n"
2419"(this choice is only available when creating a _vimrc file)\n"
2420"The right mouse button can be used in two ways:\n"
2421"1. The Unix way is to extend an existing selection. The popup menu is\n"
2422" not available.\n"
2423"2. The MS-Windows way is to show a popup menu, which allows you to\n"
2424" copy/paste text, undo/redo, etc. Extending the selection can still be\n"
2425" done by keeping SHIFT pressed while using the left mouse button\n"
2426,
2427"Edit-with-Vim context menu entry\n"
2428"--------------------------------\n"
2429"(this choice is only available when gvim.exe and gvimext.dll are present)\n"
2430"You can associate different file types with Vim, so that you can (double)\n"
2431"click on a file to edit it with Vim. This means you have to individually\n"
2432"select each file type.\n"
2433"An alternative is the option offered here: Install an \"Edit with Vim\"\n"
2434"entry in the popup menu for the right mouse button. This means you can\n"
2435"edit any file with Vim.\n"
2436,
2437"\"Open With...\" context menu entry\n"
2438"--------------------------------\n"
2439"(this choice is only available when gvim.exe is present)\n"
2440"This option adds Vim to the \"Open With...\" entry in the popup menu for\n"
2441"the right mouse button. This also makes it possible to edit HTML files\n"
2442"directly from Internet Explorer.\n"
2443,
2444"Add Vim to the Start menu\n"
2445"-------------------------\n"
2446"In Windows 95 and later, Vim can be added to the Start menu. This will\n"
2447"create a submenu with an entry for vim, gvim, evim, vimdiff, etc..\n"
2448,
2449"Icons on the desktop\n"
2450"--------------------\n"
2451"(these choices are only available when installing gvim)\n"
2452"In Windows 95 and later, shortcuts (icons) can be created on the Desktop.\n"
2453,
2454"Create plugin directories\n"
2455"-------------------------\n"
2456"Plugin directories allow extending Vim by dropping a file into a directory.\n"
2457"This choice allows creating them in $HOME (if you have a home directory) or\n"
2458"$VIM (used for everybody on the system).\n"
2459,
2460NULL
2461 };
2462 int i;
2463 int c;
2464
2465 rewind(stdin);
2466 printf("\n");
2467 for (i = 0; items[i] != NULL; ++i)
2468 {
2469 printf(items[i]);
2470 printf("\n");
2471 printf("Hit Enter to continue, b (back) or q (quit help): ");
2472 c = getchar();
2473 rewind(stdin);
2474 if (c == 'b' || c == 'B')
2475 {
2476 if (i == 0)
2477 --i;
2478 else
2479 i -= 2;
2480 }
2481 if (c == 'q' || c == 'Q')
2482 break;
2483 printf("\n");
2484 }
2485}
2486
2487/*
2488 * Install the choices.
2489 */
2490 static void
2491install(void)
2492{
2493 int i;
2494
2495 /* Install the selected choices. */
2496 for (i = 0; i < choice_count; ++i)
2497 if (choices[i].installfunc != NULL && choices[i].active)
2498 (choices[i].installfunc)(i);
2499
2500 /* Add some entries to the registry, if needed. */
2501 if (install_popup
2502 || install_openwith
2503 || (need_uninstall_entry && interactive)
2504 || !interactive)
2505 install_registry();
2506
2507#ifdef WIN3264
2508 /* Register gvim with OLE. */
2509 if (has_gvim)
2510 install_OLE_register();
2511#endif
2512}
2513
2514/*
2515 * request_choice
2516 */
2517 static void
2518request_choice(void)
2519{
2520 int i;
2521
2522 printf("\n\nInstall will do for you:\n");
2523 for (i = 0; i < choice_count; ++i)
2524 if (choices[i].active)
2525 printf("%2d %s\n", i + 1, choices[i].text);
2526 printf("To change an item, enter its number\n\n");
2527 printf("Enter item number, h (help), d (do it) or q (quit): ");
2528}
2529
2530 int
2531main(int argc, char **argv)
2532{
2533 int i;
2534 char buf[BUFSIZE];
2535
2536 /*
2537 * Run interactively if there are no command line arguments.
2538 */
2539 if (argc > 1)
2540 interactive = 0;
2541 else
2542 interactive = 1;
2543
2544 /* Initialize this program. */
2545 do_inits(argv);
2546
2547#ifdef WIN3264
2548 if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0)
2549 {
2550 /* Only check for already installed Vims. Used by NSIS installer. */
Bram Moolenaar442b4222010-05-24 21:34:22 +02002551 i = uninstall_check(1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552
2553 /* Find the value of $VIM, because NSIS isn't able to do this by
2554 * itself. */
2555 get_vim_env();
2556
2557 /* When nothing found exit quietly. If something found wait for
Bram Moolenaarb230bd52010-05-25 21:02:00 +02002558 * a little while, so that the user can read the messages. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 if (i)
Bram Moolenaarab8205e2010-07-07 15:14:03 +02002560 sleep(3);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 exit(0);
2562 }
2563#endif
2564
2565 printf("This program sets up the installation of Vim "
2566 VIM_VERSION_MEDIUM "\n\n");
2567
2568 /* Check if the user unpacked the archives properly. */
2569 check_unpack();
2570
2571#ifdef WIN3264
2572 /* Check for already installed Vims. */
2573 if (interactive)
Bram Moolenaar442b4222010-05-24 21:34:22 +02002574 uninstall_check(0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575#endif
2576
2577 /* Find out information about the system. */
2578 inspect_system();
2579
2580 if (interactive)
2581 {
2582 /* Setup all the choices. */
2583 setup_choices();
2584
2585 /* Let the user change choices and finally install (or quit). */
2586 for (;;)
2587 {
2588 request_choice();
2589 rewind(stdin);
2590 if (scanf("%99s", buf) == 1)
2591 {
2592 if (isdigit(buf[0]))
2593 {
2594 /* Change a choice. */
2595 i = atoi(buf);
2596 if (i > 0 && i <= choice_count && choices[i - 1].active)
2597 (choices[i - 1].changefunc)(i - 1);
2598 else
2599 printf("\nIllegal choice\n");
2600 }
2601 else if (buf[0] == 'h' || buf[0] == 'H')
2602 {
2603 /* Help */
2604 show_help();
2605 }
2606 else if (buf[0] == 'd' || buf[0] == 'D')
2607 {
2608 /* Install! */
2609 install();
2610 printf("\nThat finishes the installation. Happy Vimming!\n");
2611 break;
2612 }
2613 else if (buf[0] == 'q' || buf[0] == 'Q')
2614 {
2615 /* Quit */
2616 printf("\nExiting without anything done\n");
2617 break;
2618 }
2619 else
2620 printf("\nIllegal choice\n");
2621 }
2622 }
2623 printf("\n");
Bram Moolenaar442b4222010-05-24 21:34:22 +02002624 myexit(0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 }
2626 else
2627 {
2628 /*
2629 * Run non-interactive - setup according to the command line switches
2630 */
2631 command_line_setup_choices(argc, argv);
2632 install();
Bram Moolenaar442b4222010-05-24 21:34:22 +02002633
2634 /* Avoid that the user has to hit Enter, just wait a little bit to
2635 * allow reading the messages. */
Bram Moolenaarab8205e2010-07-07 15:14:03 +02002636 sleep(2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 }
2638
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 return 0;
2640}