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