comparison src/dosinst.c @ 18777:3a68dc2a1bc1 v8.1.2378

patch 8.1.2378: using old C style comments Commit: https://github.com/vim/vim/commit/5d18efecfd6c45d69f55268948a22cd0465bb955 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 1 21:11:22 2019 +0100 patch 8.1.2378: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 Dec 2019 21:15:03 +0100
parents 1ec6539cef68
children 9800e126eaa2
comparison
equal deleted inserted replaced
18776:90a6831d6cd7 18777:3a68dc2a1bc1
21 #include <io.h> 21 #include <io.h>
22 22
23 #define GVIMEXT64_PATH "GvimExt64\\gvimext.dll" 23 #define GVIMEXT64_PATH "GvimExt64\\gvimext.dll"
24 #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll" 24 #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll"
25 25
26 /* Macro to do an error check I was typing over and over */ 26 // Macro to do an error check I was typing over and over
27 #define CHECK_REG_ERROR(code) \ 27 #define CHECK_REG_ERROR(code) \
28 do { \ 28 do { \
29 if (code != ERROR_SUCCESS) \ 29 if (code != ERROR_SUCCESS) \
30 { \ 30 { \
31 printf("%ld error number: %ld\n", (long)__LINE__, (long)code); \ 31 printf("%ld error number: %ld\n", (long)__LINE__, (long)code); \
32 return 1; \ 32 return 1; \
33 } \ 33 } \
34 } while (0) 34 } while (0)
35 35
36 int has_vim = 0; /* installable vim.exe exists */ 36 int has_vim = 0; // installable vim.exe exists
37 int has_gvim = 0; /* installable gvim.exe exists */ 37 int has_gvim = 0; // installable gvim.exe exists
38 38
39 char oldvimrc[BUFSIZE]; /* name of existing vimrc file */ 39 char oldvimrc[BUFSIZE]; // name of existing vimrc file
40 char vimrc[BUFSIZE]; /* name of vimrc file to create */ 40 char vimrc[BUFSIZE]; // name of vimrc file to create
41 41
42 char *default_bat_dir = NULL; /* when not NULL, use this as the default 42 char *default_bat_dir = NULL; // when not NULL, use this as the default
43 directory to write .bat files in */ 43 // directory to write .bat files in
44 char *default_vim_dir = NULL; /* when not NULL, use this as the default 44 char *default_vim_dir = NULL; // when not NULL, use this as the default
45 install dir for NSIS */ 45 // install dir for NSIS
46 46
47 /* 47 /*
48 * Structure used for each choice the user can make. 48 * Structure used for each choice the user can make.
49 */ 49 */
50 struct choice 50 struct choice
51 { 51 {
52 int active; /* non-zero when choice is active */ 52 int active; // non-zero when choice is active
53 char *text; /* text displayed for this choice */ 53 char *text; // text displayed for this choice
54 void (*changefunc)(int idx); /* function to change this choice */ 54 void (*changefunc)(int idx); // function to change this choice
55 int arg; /* argument for function */ 55 int arg; // argument for function
56 void (*installfunc)(int idx); /* function to install this choice */ 56 void (*installfunc)(int idx); // function to install this choice
57 }; 57 };
58 58
59 struct choice choices[30]; /* choices the user can make */ 59 struct choice choices[30]; // choices the user can make
60 int choice_count = 0; /* number of choices available */ 60 int choice_count = 0; // number of choices available
61 61
62 #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s)) 62 #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s))
63 63
64 enum 64 enum
65 { 65 {
121 "No", 121 "No",
122 "In the VIM directory", 122 "In the VIM directory",
123 "In your HOME directory", 123 "In your HOME directory",
124 }; 124 };
125 125
126 /* non-zero when selected to install the popup menu entry. */ 126 // non-zero when selected to install the popup menu entry.
127 static int install_popup = 0; 127 static int install_popup = 0;
128 128
129 /* non-zero when selected to install the "Open with" entry. */ 129 // non-zero when selected to install the "Open with" entry.
130 static int install_openwith = 0; 130 static int install_openwith = 0;
131 131
132 /* non-zero when need to add an uninstall entry in the registry */ 132 // non-zero when need to add an uninstall entry in the registry
133 static int need_uninstall_entry = 0; 133 static int need_uninstall_entry = 0;
134 134
135 /* 135 /*
136 * Definitions of the directory name (under $VIM) of the vimfiles directory 136 * Definitions of the directory name (under $VIM) of the vimfiles directory
137 * and its subdirectories: 137 * and its subdirectories:
189 { 189 {
190 char buf[BUFSIZE]; 190 char buf[BUFSIZE];
191 FILE *fd; 191 FILE *fd;
192 struct stat st; 192 struct stat st;
193 193
194 /* check for presence of the correct version number in installdir[] */ 194 // check for presence of the correct version number in installdir[]
195 runtimeidx = strlen(installdir) - strlen(VIM_VERSION_NODOT); 195 runtimeidx = strlen(installdir) - strlen(VIM_VERSION_NODOT);
196 if (runtimeidx <= 0 196 if (runtimeidx <= 0
197 || stricmp(installdir + runtimeidx, VIM_VERSION_NODOT) != 0 197 || stricmp(installdir + runtimeidx, VIM_VERSION_NODOT) != 0
198 || (installdir[runtimeidx - 1] != '/' 198 || (installdir[runtimeidx - 1] != '/'
199 && installdir[runtimeidx - 1] != '\\')) 199 && installdir[runtimeidx - 1] != '\\'))
202 VIM_VERSION_NODOT); 202 VIM_VERSION_NODOT);
203 printf("This program can only work when it is located in its original directory\n"); 203 printf("This program can only work when it is located in its original directory\n");
204 myexit(1); 204 myexit(1);
205 } 205 }
206 206
207 /* check if filetype.vim is present, which means the runtime archive has 207 // check if filetype.vim is present, which means the runtime archive has
208 * been unpacked */ 208 // been unpacked
209 sprintf(buf, "%s\\filetype.vim", installdir); 209 sprintf(buf, "%s\\filetype.vim", installdir);
210 if (stat(buf, &st) < 0) 210 if (stat(buf, &st) < 0)
211 { 211 {
212 printf("ERROR: Cannot find filetype.vim in \"%s\"\n", installdir); 212 printf("ERROR: Cannot find filetype.vim in \"%s\"\n", installdir);
213 printf("It looks like you did not unpack the runtime archive.\n"); 213 printf("It looks like you did not unpack the runtime archive.\n");
214 printf("You must unpack the runtime archive \"vim%srt.zip\" before installing.\n", 214 printf("You must unpack the runtime archive \"vim%srt.zip\" before installing.\n",
215 VIM_VERSION_NODOT + 3); 215 VIM_VERSION_NODOT + 3);
216 myexit(1); 216 myexit(1);
217 } 217 }
218 218
219 /* Check if vim.exe or gvim.exe is in the current directory. */ 219 // Check if vim.exe or gvim.exe is in the current directory.
220 if ((fd = fopen("gvim.exe", "r")) != NULL) 220 if ((fd = fopen("gvim.exe", "r")) != NULL)
221 { 221 {
222 fclose(fd); 222 fclose(fd);
223 has_gvim = 1; 223 has_gvim = 1;
224 } 224 }
249 plen = strlen(p); 249 plen = strlen(p);
250 if (qlen < 0) 250 if (qlen < 0)
251 qlen = strlen(q); 251 qlen = strlen(q);
252 for (i = 0; ; ++i) 252 for (i = 0; ; ++i)
253 { 253 {
254 /* End of "p": check if "q" also ends or just has a slash. */ 254 // End of "p": check if "q" also ends or just has a slash.
255 if (i == plen) 255 if (i == plen)
256 { 256 {
257 if (i == qlen) /* match */ 257 if (i == qlen) // match
258 return 0; 258 return 0;
259 if (i == qlen - 1 && (q[i] == '\\' || q[i] == '/')) 259 if (i == qlen - 1 && (q[i] == '\\' || q[i] == '/'))
260 return 0; /* match with trailing slash */ 260 return 0; // match with trailing slash
261 return 1; /* no match */ 261 return 1; // no match
262 } 262 }
263 263
264 /* End of "q": check if "p" also ends or just has a slash. */ 264 // End of "q": check if "p" also ends or just has a slash.
265 if (i == qlen) 265 if (i == qlen)
266 { 266 {
267 if (i == plen) /* match */ 267 if (i == plen) // match
268 return 0; 268 return 0;
269 if (i == plen - 1 && (p[i] == '\\' || p[i] == '/')) 269 if (i == plen - 1 && (p[i] == '\\' || p[i] == '/'))
270 return 0; /* match with trailing slash */ 270 return 0; // match with trailing slash
271 return 1; /* no match */ 271 return 1; // no match
272 } 272 }
273 273
274 if (!(mytoupper(p[i]) == mytoupper(q[i]) 274 if (!(mytoupper(p[i]) == mytoupper(q[i])
275 || ((p[i] == '/' || p[i] == '\\') 275 || ((p[i] == '/' || p[i] == '\\')
276 && (q[i] == '/' || q[i] == '\\')))) 276 && (q[i] == '/' || q[i] == '\\'))))
277 return 1; /* no match */ 277 return 1; // no match
278 } 278 }
279 /*NOTREACHED*/ 279 //NOTREACHED
280 } 280 }
281 281
282 /* 282 /*
283 * If the executable "**destination" is in the install directory, find another 283 * If the executable "**destination" is in the install directory, find another
284 * one in $PATH. 284 * one in $PATH.
306 || strchr(cp, '/') != NULL) 306 || strchr(cp, '/') != NULL)
307 return; 307 return;
308 308
309 tmpname = alloc(strlen(cp) + 1); 309 tmpname = alloc(strlen(cp) + 1);
310 strcpy(tmpname, cp); 310 strcpy(tmpname, cp);
311 tmpname[strlen(tmpname) - 1] = 'x'; /* .exe -> .exx */ 311 tmpname[strlen(tmpname) - 1] = 'x'; // .exe -> .exx
312 312
313 if (access(tmpname, 0) == 0) 313 if (access(tmpname, 0) == 0)
314 { 314 {
315 printf("\nERROR: %s and %s clash. Remove or rename %s.\n", 315 printf("\nERROR: %s and %s clash. Remove or rename %s.\n",
316 tmpname, cp, tmpname); 316 tmpname, cp, tmpname);
345 static void 345 static void
346 find_bat_exe(int check_bat_only) 346 find_bat_exe(int check_bat_only)
347 { 347 {
348 int i; 348 int i;
349 349
350 /* avoid looking in the "installdir" by chdir to system root */ 350 // avoid looking in the "installdir" by chdir to system root
351 mch_chdir(sysdrive); 351 mch_chdir(sysdrive);
352 mch_chdir("\\"); 352 mch_chdir("\\");
353 353
354 for (i = 1; i < TARGET_COUNT; ++i) 354 for (i = 1; i < TARGET_COUNT; ++i)
355 { 355 {
384 char *vim; 384 char *vim;
385 char buf[BUFSIZE]; 385 char buf[BUFSIZE];
386 FILE *fd; 386 FILE *fd;
387 char fname[BUFSIZE]; 387 char fname[BUFSIZE];
388 388
389 /* First get $VIMRUNTIME. If it's set, remove the tail. */ 389 // First get $VIMRUNTIME. If it's set, remove the tail.
390 vim = getenv("VIMRUNTIME"); 390 vim = getenv("VIMRUNTIME");
391 if (vim != NULL && *vim != 0 && strlen(vim) < sizeof(buf)) 391 if (vim != NULL && *vim != 0 && strlen(vim) < sizeof(buf))
392 { 392 {
393 strcpy(buf, vim); 393 strcpy(buf, vim);
394 remove_tail(buf); 394 remove_tail(buf);
397 else 397 else
398 { 398 {
399 vim = getenv("VIM"); 399 vim = getenv("VIM");
400 if (vim == NULL || *vim == 0) 400 if (vim == NULL || *vim == 0)
401 { 401 {
402 /* Use the directory from an old uninstall entry. */ 402 // Use the directory from an old uninstall entry.
403 if (default_vim_dir != NULL) 403 if (default_vim_dir != NULL)
404 vim = default_vim_dir; 404 vim = default_vim_dir;
405 else 405 else
406 /* Let NSIS know there is no default, it should use 406 // Let NSIS know there is no default, it should use
407 * $PROGRAMFILES. */ 407 // $PROGRAMFILES.
408 vim = ""; 408 vim = "";
409 } 409 }
410 } 410 }
411 411
412 /* NSIS also uses GetTempPath(), thus we should get the same directory 412 // NSIS also uses GetTempPath(), thus we should get the same directory
413 * name as where NSIS will look for vimini.ini. */ 413 // name as where NSIS will look for vimini.ini.
414 GetTempPath(sizeof(fname) - 12, fname); 414 GetTempPath(sizeof(fname) - 12, fname);
415 add_pathsep(fname); 415 add_pathsep(fname);
416 strcat(fname, "vimini.ini"); 416 strcat(fname, "vimini.ini");
417 417
418 fd = fopen(fname, "w"); 418 fd = fopen(fname, "w");
419 if (fd != NULL) 419 if (fd != NULL)
420 { 420 {
421 /* Make it look like an .ini file, so that NSIS can read it with a 421 // Make it look like an .ini file, so that NSIS can read it with a
422 * ReadINIStr command. */ 422 // ReadINIStr command.
423 fprintf(fd, "[vimini]\n"); 423 fprintf(fd, "[vimini]\n");
424 fprintf(fd, "dir=\"%s\"\n", vim); 424 fprintf(fd, "dir=\"%s\"\n", vim);
425 fclose(fd); 425 fclose(fd);
426 } 426 }
427 else 427 else
435 435
436 /* 436 /*
437 * Callback used for EnumWindows(): 437 * Callback used for EnumWindows():
438 * Count the window if the title looks like it is for the uninstaller. 438 * Count the window if the title looks like it is for the uninstaller.
439 */ 439 */
440 /*ARGSUSED*/ 440 //ARGSUSED
441 static BOOL CALLBACK 441 static BOOL CALLBACK
442 window_cb(HWND hwnd, LPARAM lparam) 442 window_cb(HWND hwnd, LPARAM lparam)
443 { 443 {
444 char title[256]; 444 char title[256];
445 445
467 remove_tail(vimrt_dir); 467 remove_tail(vimrt_dir);
468 468
469 if (!GetTempPath(sizeof(temp_dir), temp_dir)) 469 if (!GetTempPath(sizeof(temp_dir), temp_dir))
470 return FAIL; 470 return FAIL;
471 471
472 /* Copy the uninstaller to a temporary exe. */ 472 // Copy the uninstaller to a temporary exe.
473 tick = GetTickCount(); 473 tick = GetTickCount();
474 for (i = 0; ; i++) 474 for (i = 0; ; i++)
475 { 475 {
476 sprintf(temp_uninst, "%s\\vimun%04X.exe", temp_dir, 476 sprintf(temp_uninst, "%s\\vimun%04X.exe", temp_dir,
477 (unsigned int)((i + tick) & 0xFFFF)); 477 (unsigned int)((i + tick) & 0xFFFF));
481 return FAIL; 481 return FAIL;
482 if (i == 65535) 482 if (i == 65535)
483 return FAIL; 483 return FAIL;
484 } 484 }
485 485
486 /* Run the copied uninstaller silently. */ 486 // Run the copied uninstaller silently.
487 if (strchr(temp_uninst, ' ') != NULL) 487 if (strchr(temp_uninst, ' ') != NULL)
488 sprintf(buf, "\"%s\" /S _?=%s", temp_uninst, vimrt_dir); 488 sprintf(buf, "\"%s\" /S _?=%s", temp_uninst, vimrt_dir);
489 else 489 else
490 sprintf(buf, "%s /S _?=%s", temp_uninst, vimrt_dir); 490 sprintf(buf, "%s /S _?=%s", temp_uninst, vimrt_dir);
491 run_command(buf); 491 run_command(buf);
529 NULL, NULL, NULL, &temp_pfiletime) == ERROR_NO_MORE_ITEMS) 529 NULL, NULL, NULL, &temp_pfiletime) == ERROR_NO_MORE_ITEMS)
530 break; 530 break;
531 531
532 if (strncmp("Vim", subkey_name_buff, 3) == 0) 532 if (strncmp("Vim", subkey_name_buff, 3) == 0)
533 { 533 {
534 /* Open the key named Vim* */ 534 // Open the key named Vim*
535 code = RegOpenKeyEx(key_handle, subkey_name_buff, 0, 535 code = RegOpenKeyEx(key_handle, subkey_name_buff, 0,
536 KEY_WOW64_64KEY | KEY_READ, &uninstall_key_handle); 536 KEY_WOW64_64KEY | KEY_READ, &uninstall_key_handle);
537 CHECK_REG_ERROR(code); 537 CHECK_REG_ERROR(code);
538 538
539 /* get the DisplayName out of it to show the user */ 539 // get the DisplayName out of it to show the user
540 local_bufsize = sizeof(temp_string_buffer); 540 local_bufsize = sizeof(temp_string_buffer);
541 code = RegQueryValueEx(uninstall_key_handle, "displayname", 0, 541 code = RegQueryValueEx(uninstall_key_handle, "displayname", 0,
542 &value_type, (LPBYTE)temp_string_buffer, 542 &value_type, (LPBYTE)temp_string_buffer,
543 &local_bufsize); 543 &local_bufsize);
544 CHECK_REG_ERROR(code); 544 CHECK_REG_ERROR(code);
567 printf("\nRunning uninstall program for \"%s\"\n", temp_string_buffer); 567 printf("\nRunning uninstall program for \"%s\"\n", temp_string_buffer);
568 else 568 else
569 printf("\nDo you want to uninstall \"%s\" now?\n(y)es/(n)o) ", temp_string_buffer); 569 printf("\nDo you want to uninstall \"%s\" now?\n(y)es/(n)o) ", temp_string_buffer);
570 fflush(stdout); 570 fflush(stdout);
571 571
572 /* get the UninstallString */ 572 // get the UninstallString
573 local_bufsize = sizeof(temp_string_buffer); 573 local_bufsize = sizeof(temp_string_buffer);
574 code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0, 574 code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0,
575 &value_type, (LPBYTE)temp_string_buffer, &local_bufsize); 575 &value_type, (LPBYTE)temp_string_buffer, &local_bufsize);
576 CHECK_REG_ERROR(code); 576 CHECK_REG_ERROR(code);
577 577
578 /* Remember the directory, it is used as the default for NSIS. */ 578 // Remember the directory, it is used as the default for NSIS.
579 default_vim_dir = alloc(strlen(temp_string_buffer) + 1); 579 default_vim_dir = alloc(strlen(temp_string_buffer) + 1);
580 strcpy(default_vim_dir, temp_string_buffer); 580 strcpy(default_vim_dir, temp_string_buffer);
581 remove_tail(default_vim_dir); 581 remove_tail(default_vim_dir);
582 remove_tail(default_vim_dir); 582 remove_tail(default_vim_dir);
583 583
596 } 596 }
597 switch (input) 597 switch (input)
598 { 598 {
599 case 'y': 599 case 'y':
600 case 'Y': 600 case 'Y':
601 /* save the number of uninstall keys so we can know if 601 // save the number of uninstall keys so we can know if
602 * it changed */ 602 // it changed
603 RegQueryInfoKey(key_handle, NULL, NULL, NULL, 603 RegQueryInfoKey(key_handle, NULL, NULL, NULL,
604 &orig_num_keys, NULL, NULL, NULL, 604 &orig_num_keys, NULL, NULL, NULL,
605 NULL, NULL, NULL, NULL); 605 NULL, NULL, NULL, NULL);
606 606
607 /* Find existing .bat files before deleting them. */ 607 // Find existing .bat files before deleting them.
608 find_bat_exe(TRUE); 608 find_bat_exe(TRUE);
609 609
610 if (allow_silent) 610 if (allow_silent)
611 { 611 {
612 if (run_silent_uninstall(temp_string_buffer) 612 if (run_silent_uninstall(temp_string_buffer)
613 == FAIL) 613 == FAIL)
614 allow_silent = 0; /* Retry with non silent. */ 614 allow_silent = 0; // Retry with non silent.
615 } 615 }
616 if (!allow_silent) 616 if (!allow_silent)
617 { 617 {
618 /* Execute the uninstall program. Put it in double 618 // Execute the uninstall program. Put it in double
619 * quotes if there is an embedded space. */ 619 // quotes if there is an embedded space.
620 { 620 {
621 char buf[BUFSIZE]; 621 char buf[BUFSIZE];
622 622
623 if (strchr(temp_string_buffer, ' ') != NULL) 623 if (strchr(temp_string_buffer, ' ') != NULL)
624 sprintf(buf, "\"%s\"", temp_string_buffer); 624 sprintf(buf, "\"%s\"", temp_string_buffer);
625 else 625 else
626 strcpy(buf, temp_string_buffer); 626 strcpy(buf, temp_string_buffer);
627 run_command(buf); 627 run_command(buf);
628 } 628 }
629 629
630 /* Count the number of windows with a title that match 630 // Count the number of windows with a title that
631 * the installer, so that we can check when it's done. 631 // match the installer, so that we can check when
632 * The uninstaller copies itself, executes the copy 632 // it's done. The uninstaller copies itself,
633 * and exits, thus we can't wait for the process to 633 // executes the copy and exits, thus we can't wait
634 * finish. */ 634 // for the process to finish.
635 sleep(1); /* wait for uninstaller to start up */ 635 sleep(1); // wait for uninstaller to start up
636 num_windows = 0; 636 num_windows = 0;
637 EnumWindows(window_cb, 0); 637 EnumWindows(window_cb, 0);
638 if (num_windows == 0) 638 if (num_windows == 0)
639 { 639 {
640 /* Did not find the uninstaller, ask user to press 640 // Did not find the uninstaller, ask user to
641 * Enter when done. Just in case. */ 641 // press Enter when done. Just in case.
642 printf("Press Enter when the uninstaller is finished\n"); 642 printf("Press Enter when the uninstaller is finished\n");
643 rewind(stdin); 643 rewind(stdin);
644 (void)getchar(); 644 (void)getchar();
645 } 645 }
646 else 646 else
648 printf("Waiting for the uninstaller to finish (press CTRL-C to abort)."); 648 printf("Waiting for the uninstaller to finish (press CTRL-C to abort).");
649 do 649 do
650 { 650 {
651 printf("."); 651 printf(".");
652 fflush(stdout); 652 fflush(stdout);
653 sleep(1); /* wait for the uninstaller to finish */ 653 sleep(1); // wait for the uninstaller to
654 // finish
654 num_windows = 0; 655 num_windows = 0;
655 EnumWindows(window_cb, 0); 656 EnumWindows(window_cb, 0);
656 } while (num_windows > 0); 657 } while (num_windows > 0);
657 } 658 }
658 } 659 }
659 printf("\nDone!\n"); 660 printf("\nDone!\n");
660 661
661 /* Check if an uninstall reg key was deleted. 662 // Check if an uninstall reg key was deleted.
662 * if it was, we want to decrement key_index. 663 // if it was, we want to decrement key_index.
663 * if we don't do this, we will skip the key 664 // if we don't do this, we will skip the key
664 * immediately after any key that we delete. */ 665 // immediately after any key that we delete.
665 RegQueryInfoKey(key_handle, NULL, NULL, NULL, 666 RegQueryInfoKey(key_handle, NULL, NULL, NULL,
666 &new_num_keys, NULL, NULL, NULL, 667 &new_num_keys, NULL, NULL, NULL,
667 NULL, NULL, NULL, NULL); 668 NULL, NULL, NULL, NULL);
668 if (new_num_keys < orig_num_keys) 669 if (new_num_keys < orig_num_keys)
669 key_index--; 670 key_index--;
671 input = 'y'; 672 input = 'y';
672 break; 673 break;
673 674
674 case 'n': 675 case 'n':
675 case 'N': 676 case 'N':
676 /* Do not uninstall */ 677 // Do not uninstall
677 input = 'n'; 678 input = 'n';
678 break; 679 break;
679 680
680 default: /* just drop through and redo the loop */ 681 default: // just drop through and redo the loop
681 break; 682 break;
682 } 683 }
683 684
684 } while (input != 'n' && input != 'y'); 685 } while (input != 'n' && input != 'y');
685 686
703 char buf[BUFSIZE]; 704 char buf[BUFSIZE];
704 FILE *fd; 705 FILE *fd;
705 int i; 706 int i;
706 int foundone; 707 int foundone;
707 708
708 /* This may take a little while, let the user know what we're doing. */ 709 // This may take a little while, let the user know what we're doing.
709 printf("Inspecting system...\n"); 710 printf("Inspecting system...\n");
710 711
711 /* 712 /*
712 * If $VIM is set, check that it's pointing to our directory. 713 * If $VIM is set, check that it's pointing to our directory.
713 */ 714 */
783 */ 784 */
784 strcpy(oldvimrc, installdir); 785 strcpy(oldvimrc, installdir);
785 strcpy(oldvimrc + runtimeidx, "_vimrc"); 786 strcpy(oldvimrc + runtimeidx, "_vimrc");
786 if ((fd = fopen(oldvimrc, "r")) == NULL) 787 if ((fd = fopen(oldvimrc, "r")) == NULL)
787 { 788 {
788 strcpy(oldvimrc + runtimeidx, "vimrc~1"); /* short version of .vimrc */ 789 strcpy(oldvimrc + runtimeidx, "vimrc~1"); // short version of .vimrc
789 if ((fd = fopen(oldvimrc, "r")) == NULL) 790 if ((fd = fopen(oldvimrc, "r")) == NULL)
790 { 791 {
791 strcpy(oldvimrc + runtimeidx, ".vimrc"); 792 strcpy(oldvimrc + runtimeidx, ".vimrc");
792 fd = fopen(oldvimrc, "r"); 793 fd = fopen(oldvimrc, "r");
793 } 794 }
812 choices[choice_count].text = NULL; 813 choices[choice_count].text = NULL;
813 choices[choice_count].arg = 0; 814 choices[choice_count].arg = 0;
814 ++choice_count; 815 ++choice_count;
815 } 816 }
816 817
817 /*********************************************** 818 ////////////////////////////////////////////////
818 * stuff for creating the batch files. 819 // stuff for creating the batch files.
819 */
820 820
821 /* 821 /*
822 * Install the vim.bat, gvim.bat, etc. files. 822 * Install the vim.bat, gvim.bat, etc. files.
823 */ 823 */
824 static void 824 static void
842 fprintf(fd, "@echo off\n"); 842 fprintf(fd, "@echo off\n");
843 fprintf(fd, "rem -- Run Vim --\n"); 843 fprintf(fd, "rem -- Run Vim --\n");
844 fprintf(fd, "\n"); 844 fprintf(fd, "\n");
845 fprintf(fd, "setlocal\n"); 845 fprintf(fd, "setlocal\n");
846 846
847 /* Don't use double quotes for the "set" argument, also when it 847 /*
848 * Don't use double quotes for the "set" argument, also when it
848 * contains a space. The quotes would be included in the value 849 * contains a space. The quotes would be included in the value
849 * for MSDOS and NT. 850 * for MSDOS and NT.
850 * The order of preference is: 851 * The order of preference is:
851 * 1. $VIMRUNTIME/vim.exe (user preference) 852 * 1. $VIMRUNTIME/vim.exe (user preference)
852 * 2. $VIM/vim81/vim.exe (hard coded version) 853 * 2. $VIM/vim81/vim.exe (hard coded version)
856 fprintf(fd, "if exist \"%%VIM%%\\%s\\%s\" set VIM_EXE_DIR=%%VIM%%\\%s\n", 857 fprintf(fd, "if exist \"%%VIM%%\\%s\\%s\" set VIM_EXE_DIR=%%VIM%%\\%s\n",
857 VIM_VERSION_NODOT, exename, VIM_VERSION_NODOT); 858 VIM_VERSION_NODOT, exename, VIM_VERSION_NODOT);
858 fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename); 859 fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename);
859 fprintf(fd, "\n"); 860 fprintf(fd, "\n");
860 861
861 /* Give an error message when the executable could not be found. */ 862 // Give an error message when the executable could not be found.
862 fprintf(fd, "if exist \"%%VIM_EXE_DIR%%\\%s\" goto havevim\n", 863 fprintf(fd, "if exist \"%%VIM_EXE_DIR%%\\%s\" goto havevim\n",
863 exename); 864 exename);
864 fprintf(fd, "echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename); 865 fprintf(fd, "echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename);
865 fprintf(fd, "goto eof\n"); 866 fprintf(fd, "goto eof\n");
866 fprintf(fd, "\n"); 867 fprintf(fd, "\n");
888 fprintf(fd, "\n"); 889 fprintf(fd, "\n");
889 890
890 fprintf(fd, "if .%%OS%%==.Windows_NT goto ntaction\n"); 891 fprintf(fd, "if .%%OS%%==.Windows_NT goto ntaction\n");
891 fprintf(fd, "\n"); 892 fprintf(fd, "\n");
892 893
893 /* For gvim.exe use "start" to avoid that the console window stays 894 // For gvim.exe use "start" to avoid that the console window stays
894 * open. */ 895 // open.
895 if (*exename == 'g') 896 if (*exename == 'g')
896 { 897 {
897 fprintf(fd, "if .%%VIMNOFORK%%==.1 goto nofork\n"); 898 fprintf(fd, "if .%%VIMNOFORK%%==.1 goto nofork\n");
898 fprintf(fd, "start "); 899 fprintf(fd, "start ");
899 } 900 }
900 901
901 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ 902 // Always use quotes, $VIM or $VIMRUNTIME might have a space.
902 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", 903 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n",
903 exename, vimarg); 904 exename, vimarg);
904 fprintf(fd, "goto eof\n"); 905 fprintf(fd, "goto eof\n");
905 fprintf(fd, "\n"); 906 fprintf(fd, "\n");
906 907
907 if (*exename == 'g') 908 if (*exename == 'g')
908 { 909 {
909 fprintf(fd, ":nofork\n"); 910 fprintf(fd, ":nofork\n");
910 fprintf(fd, "start /w "); 911 fprintf(fd, "start /w ");
911 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ 912 // Always use quotes, $VIM or $VIMRUNTIME might have a space.
912 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", 913 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n",
913 exename, vimarg); 914 exename, vimarg);
914 fprintf(fd, "goto eof\n"); 915 fprintf(fd, "goto eof\n");
915 fprintf(fd, "\n"); 916 fprintf(fd, "\n");
916 } 917 }
917 918
918 fprintf(fd, ":ntaction\n"); 919 fprintf(fd, ":ntaction\n");
919 fprintf(fd, "rem for WinNT we can use %%*\n"); 920 fprintf(fd, "rem for WinNT we can use %%*\n");
920 921
921 /* For gvim.exe use "start /b" to avoid that the console window 922 // For gvim.exe use "start /b" to avoid that the console window
922 * stays open. */ 923 // stays open.
923 if (*exename == 'g') 924 if (*exename == 'g')
924 { 925 {
925 fprintf(fd, "if .%%VIMNOFORK%%==.1 goto noforknt\n"); 926 fprintf(fd, "if .%%VIMNOFORK%%==.1 goto noforknt\n");
926 fprintf(fd, "start \"dummy\" /b "); 927 fprintf(fd, "start \"dummy\" /b ");
927 } 928 }
928 929
929 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ 930 // Always use quotes, $VIM or $VIMRUNTIME might have a space.
930 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg); 931 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg);
931 fprintf(fd, "goto eof\n"); 932 fprintf(fd, "goto eof\n");
932 fprintf(fd, "\n"); 933 fprintf(fd, "\n");
933 934
934 if (*exename == 'g') 935 if (*exename == 'g')
935 { 936 {
936 fprintf(fd, ":noforknt\n"); 937 fprintf(fd, ":noforknt\n");
937 fprintf(fd, "start \"dummy\" /b /wait "); 938 fprintf(fd, "start \"dummy\" /b /wait ");
938 /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ 939 // Always use quotes, $VIM or $VIMRUNTIME might have a space.
939 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", 940 fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n",
940 exename, vimarg); 941 exename, vimarg);
941 } 942 }
942 943
943 fprintf(fd, "\n:eof\n"); 944 fprintf(fd, "\n:eof\n");
1062 sprintf(names[count], "Do not create a %s file.", name); 1063 sprintf(names[count], "Do not create a %s file.", name);
1063 n = get_choice(names, count + 1); 1064 n = get_choice(names, count + 1);
1064 1065
1065 if (n == count) 1066 if (n == count)
1066 { 1067 {
1067 /* Selected last item, don't create bat file. */ 1068 // Selected last item, don't create bat file.
1068 *batpath = NUL; 1069 *batpath = NUL;
1069 if (choices[idx].arg != 0) 1070 if (choices[idx].arg != 0)
1070 alloc_text(idx, " Do NOT create %s", name); 1071 alloc_text(idx, " Do NOT create %s", name);
1071 } 1072 }
1072 else 1073 else
1073 { 1074 {
1074 /* Selected one of the paths. For the first item only keep the path, 1075 // Selected one of the paths. For the first item only keep the path,
1075 * for the others append the batch file name. */ 1076 // for the others append the batch file name.
1076 strcpy(batpath, names[n]); 1077 strcpy(batpath, names[n]);
1077 add_pathsep(batpath); 1078 add_pathsep(batpath);
1078 if (choices[idx].arg != 0) 1079 if (choices[idx].arg != 0)
1079 set_bat_text(idx, batpath, name); 1080 set_bat_text(idx, batpath, name);
1080 } 1081 }
1090 static void 1091 static void
1091 change_main_bat_choice(int idx) 1092 change_main_bat_choice(int idx)
1092 { 1093 {
1093 int i; 1094 int i;
1094 1095
1095 /* let the user select a default directory or NONE */ 1096 // let the user select a default directory or NONE
1096 change_bat_choice(idx); 1097 change_bat_choice(idx);
1097 1098
1098 if (targets[0].batpath[0] != NUL) 1099 if (targets[0].batpath[0] != NUL)
1099 choices[idx].text = bat_text_yes; 1100 choices[idx].text = bat_text_yes;
1100 else 1101 else
1101 choices[idx].text = bat_text_no; 1102 choices[idx].text = bat_text_no;
1102 1103
1103 /* update the individual batch file selections */ 1104 // update the individual batch file selections
1104 for (i = 1; i < TARGET_COUNT; ++i) 1105 for (i = 1; i < TARGET_COUNT; ++i)
1105 { 1106 {
1106 /* Only make it active when the first item has a path and the vim.exe 1107 // Only make it active when the first item has a path and the vim.exe
1107 * or gvim.exe exists (there is a changefunc then). */ 1108 // or gvim.exe exists (there is a changefunc then).
1108 if (targets[0].batpath[0] != NUL 1109 if (targets[0].batpath[0] != NUL
1109 && choices[idx + i].changefunc != NULL) 1110 && choices[idx + i].changefunc != NULL)
1110 { 1111 {
1111 choices[idx + i].active = 1; 1112 choices[idx + i].active = 1;
1112 if (choices[idx + i].changefunc == change_bat_choice 1113 if (choices[idx + i].changefunc == change_bat_choice
1133 int i; 1134 int i;
1134 1135
1135 choices[choice_count].arg = target; 1136 choices[choice_count].arg = target;
1136 choices[choice_count].installfunc = install_bat_choice; 1137 choices[choice_count].installfunc = install_bat_choice;
1137 choices[choice_count].active = 1; 1138 choices[choice_count].active = 1;
1138 choices[choice_count].text = NULL; /* will be set below */ 1139 choices[choice_count].text = NULL; // will be set below
1139 if (oldbat != NULL) 1140 if (oldbat != NULL)
1140 { 1141 {
1141 /* A [g]vim.bat exists: Only choice is to overwrite it or not. */ 1142 // A [g]vim.bat exists: Only choice is to overwrite it or not.
1142 choices[choice_count].changefunc = toggle_bat_choice; 1143 choices[choice_count].changefunc = toggle_bat_choice;
1143 *batpath = NUL; 1144 *batpath = NUL;
1144 toggle_bat_choice(choice_count); 1145 toggle_bat_choice(choice_count);
1145 } 1146 }
1146 else 1147 else
1147 { 1148 {
1148 if (default_bat_dir != NULL) 1149 if (default_bat_dir != NULL)
1149 /* Prefer using the same path as an existing .bat file. */ 1150 // Prefer using the same path as an existing .bat file.
1150 strcpy(batpath, default_bat_dir); 1151 strcpy(batpath, default_bat_dir);
1151 else 1152 else
1152 { 1153 {
1153 /* No [g]vim.bat exists: Write it to a directory in $PATH. Use 1154 // No [g]vim.bat exists: Write it to a directory in $PATH. Use
1154 * $WINDIR by default, if it's empty the first item in $PATH. */ 1155 // $WINDIR by default, if it's empty the first item in $PATH.
1155 p = getenv("WINDIR"); 1156 p = getenv("WINDIR");
1156 if (p != NULL && *p != NUL) 1157 if (p != NULL && *p != NUL)
1157 strcpy(batpath, p); 1158 strcpy(batpath, p);
1158 else 1159 else
1159 { 1160 {
1160 p = getenv("PATH"); 1161 p = getenv("PATH");
1161 if (p == NULL || *p == NUL) /* "cannot happen" */ 1162 if (p == NULL || *p == NUL) // "cannot happen"
1162 strcpy(batpath, "C:/Windows"); 1163 strcpy(batpath, "C:/Windows");
1163 else 1164 else
1164 { 1165 {
1165 i = 0; 1166 i = 0;
1166 while (*p != NUL && *p != ';') 1167 while (*p != NUL && *p != ';')
1184 static void 1185 static void
1185 init_bat_choices(void) 1186 init_bat_choices(void)
1186 { 1187 {
1187 int i; 1188 int i;
1188 1189
1189 /* The first item is used to switch installing batch files on/off and 1190 // The first item is used to switch installing batch files on/off and
1190 * setting the default path. */ 1191 // setting the default path.
1191 choices[choice_count].text = bat_text_yes; 1192 choices[choice_count].text = bat_text_yes;
1192 choices[choice_count].changefunc = change_main_bat_choice; 1193 choices[choice_count].changefunc = change_main_bat_choice;
1193 choices[choice_count].installfunc = NULL; 1194 choices[choice_count].installfunc = NULL;
1194 choices[choice_count].active = 1; 1195 choices[choice_count].active = 1;
1195 choices[choice_count].arg = 0; 1196 choices[choice_count].arg = 0;
1196 ++choice_count; 1197 ++choice_count;
1197 1198
1198 /* Add items for each batch file target. Only used when not disabled by 1199 // Add items for each batch file target. Only used when not disabled by
1199 * the first item. When a .exe exists, don't offer to create a .bat. */ 1200 // the first item. When a .exe exists, don't offer to create a .bat.
1200 for (i = 1; i < TARGET_COUNT; ++i) 1201 for (i = 1; i < TARGET_COUNT; ++i)
1201 if (targets[i].oldexe == NULL 1202 if (targets[i].oldexe == NULL
1202 && (targets[i].exenamearg[0] == 'g' ? has_gvim : has_vim)) 1203 && (targets[i].exenamearg[0] == 'g' ? has_gvim : has_vim))
1203 init_bat_choice(i); 1204 init_bat_choice(i);
1204 else 1205 else
1212 install_vimrc(int idx) 1213 install_vimrc(int idx)
1213 { 1214 {
1214 FILE *fd, *tfd; 1215 FILE *fd, *tfd;
1215 char *fname; 1216 char *fname;
1216 1217
1217 /* If an old vimrc file exists, overwrite it. 1218 // If an old vimrc file exists, overwrite it.
1218 * Otherwise create a new one. */ 1219 // Otherwise create a new one.
1219 if (*oldvimrc != NUL) 1220 if (*oldvimrc != NUL)
1220 fname = oldvimrc; 1221 fname = oldvimrc;
1221 else 1222 else
1222 fname = vimrc; 1223 fname = vimrc;
1223 1224
1273 case mouse_default: 1274 case mouse_default:
1274 break; 1275 break;
1275 } 1276 }
1276 if ((tfd = fopen("diff.exe", "r")) != NULL) 1277 if ((tfd = fopen("diff.exe", "r")) != NULL)
1277 { 1278 {
1278 /* Use the diff.exe that comes with the self-extracting gvim.exe. */ 1279 // Use the diff.exe that comes with the self-extracting gvim.exe.
1279 fclose(tfd); 1280 fclose(tfd);
1280 fprintf(fd, "\n"); 1281 fprintf(fd, "\n");
1281 fprintf(fd, "\" Use the internal diff if available.\n"); 1282 fprintf(fd, "\" Use the internal diff if available.\n");
1282 fprintf(fd, "\" Otherwise use the special 'diffexpr' for Windows.\n"); 1283 fprintf(fd, "\" Otherwise use the special 'diffexpr' for Windows.\n");
1283 fprintf(fd, "if &diffopt !~# 'internal'\n"); 1284 fprintf(fd, "if &diffopt !~# 'internal'\n");
1285 fprintf(fd, "endif\n"); 1286 fprintf(fd, "endif\n");
1286 fprintf(fd, "function MyDiff()\n"); 1287 fprintf(fd, "function MyDiff()\n");
1287 fprintf(fd, " let opt = '-a --binary '\n"); 1288 fprintf(fd, " let opt = '-a --binary '\n");
1288 fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n"); 1289 fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n");
1289 fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n"); 1290 fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n");
1290 /* Use quotes only when needed, they may cause trouble. 1291 // Use quotes only when needed, they may cause trouble.
1291 * Always escape "!". */ 1292 // Always escape "!".
1292 fprintf(fd, " let arg1 = v:fname_in\n"); 1293 fprintf(fd, " let arg1 = v:fname_in\n");
1293 fprintf(fd, " if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif\n"); 1294 fprintf(fd, " if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif\n");
1294 fprintf(fd, " let arg1 = substitute(arg1, '!', '\\!', 'g')\n"); 1295 fprintf(fd, " let arg1 = substitute(arg1, '!', '\\!', 'g')\n");
1295 fprintf(fd, " let arg2 = v:fname_new\n"); 1296 fprintf(fd, " let arg2 = v:fname_new\n");
1296 fprintf(fd, " if arg2 =~ ' ' | let arg2 = '\"' . arg2 . '\"' | endif\n"); 1297 fprintf(fd, " if arg2 =~ ' ' | let arg2 = '\"' . arg2 . '\"' | endif\n");
1297 fprintf(fd, " let arg2 = substitute(arg2, '!', '\\!', 'g')\n"); 1298 fprintf(fd, " let arg2 = substitute(arg2, '!', '\\!', 'g')\n");
1298 fprintf(fd, " let arg3 = v:fname_out\n"); 1299 fprintf(fd, " let arg3 = v:fname_out\n");
1299 fprintf(fd, " if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif\n"); 1300 fprintf(fd, " if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif\n");
1300 fprintf(fd, " let arg3 = substitute(arg3, '!', '\\!', 'g')\n"); 1301 fprintf(fd, " let arg3 = substitute(arg3, '!', '\\!', 'g')\n");
1301 1302
1302 /* If the path has a space: When using cmd.exe (Win NT/2000/XP) put 1303 // If the path has a space: When using cmd.exe (Win NT/2000/XP) put
1303 * quotes around the diff command and rely on the default value of 1304 // quotes around the diff command and rely on the default value of
1304 * shellxquote to solve the quoting problem for the whole command. 1305 // shellxquote to solve the quoting problem for the whole command.
1305 * 1306 //
1306 * Otherwise put a double quote just before the space and at the 1307 // Otherwise put a double quote just before the space and at the
1307 * end of the command. Putting quotes around the whole thing 1308 // end of the command. Putting quotes around the whole thing
1308 * doesn't work on Win 95/98/ME. This is mostly guessed! */ 1309 // doesn't work on Win 95/98/ME. This is mostly guessed!
1309 fprintf(fd, " if $VIMRUNTIME =~ ' '\n"); 1310 fprintf(fd, " if $VIMRUNTIME =~ ' '\n");
1310 fprintf(fd, " if &sh =~ '\\<cmd'\n"); 1311 fprintf(fd, " if &sh =~ '\\<cmd'\n");
1311 fprintf(fd, " if empty(&shellxquote)\n"); 1312 fprintf(fd, " if empty(&shellxquote)\n");
1312 fprintf(fd, " let l:shxq_sav = ''\n"); 1313 fprintf(fd, " let l:shxq_sav = ''\n");
1313 fprintf(fd, " set shellxquote&\n"); 1314 fprintf(fd, " set shellxquote&\n");
1334 static void 1335 static void
1335 change_vimrc_choice(int idx) 1336 change_vimrc_choice(int idx)
1336 { 1337 {
1337 if (choices[idx].installfunc != NULL) 1338 if (choices[idx].installfunc != NULL)
1338 { 1339 {
1339 /* Switch to NOT change or create a vimrc file. */ 1340 // Switch to NOT change or create a vimrc file.
1340 if (*oldvimrc != NUL) 1341 if (*oldvimrc != NUL)
1341 alloc_text(idx, "Do NOT change startup file %s", oldvimrc); 1342 alloc_text(idx, "Do NOT change startup file %s", oldvimrc);
1342 else 1343 else
1343 alloc_text(idx, "Do NOT create startup file %s", vimrc); 1344 alloc_text(idx, "Do NOT create startup file %s", vimrc);
1344 choices[idx].installfunc = NULL; 1345 choices[idx].installfunc = NULL;
1346 choices[idx + 2].active = 0; 1347 choices[idx + 2].active = 0;
1347 choices[idx + 3].active = 0; 1348 choices[idx + 3].active = 0;
1348 } 1349 }
1349 else 1350 else
1350 { 1351 {
1351 /* Switch to change or create a vimrc file. */ 1352 // Switch to change or create a vimrc file.
1352 if (*oldvimrc != NUL) 1353 if (*oldvimrc != NUL)
1353 alloc_text(idx, "Overwrite startup file %s with:", oldvimrc); 1354 alloc_text(idx, "Overwrite startup file %s with:", oldvimrc);
1354 else 1355 else
1355 alloc_text(idx, "Create startup file %s with:", vimrc); 1356 alloc_text(idx, "Create startup file %s with:", vimrc);
1356 choices[idx].installfunc = install_vimrc; 1357 choices[idx].installfunc = install_vimrc;
1391 } 1392 }
1392 1393
1393 static void 1394 static void
1394 init_vimrc_choices(void) 1395 init_vimrc_choices(void)
1395 { 1396 {
1396 /* set path for a new _vimrc file (also when not used) */ 1397 // set path for a new _vimrc file (also when not used)
1397 strcpy(vimrc, installdir); 1398 strcpy(vimrc, installdir);
1398 strcpy(vimrc + runtimeidx, "_vimrc"); 1399 strcpy(vimrc + runtimeidx, "_vimrc");
1399 1400
1400 /* Set opposite value and then toggle it by calling change_vimrc_choice() */ 1401 // Set opposite value and then toggle it by calling change_vimrc_choice()
1401 if (*oldvimrc == NUL) 1402 if (*oldvimrc == NUL)
1402 choices[choice_count].installfunc = NULL; 1403 choices[choice_count].installfunc = NULL;
1403 else 1404 else
1404 choices[choice_count].installfunc = install_vimrc; 1405 choices[choice_count].installfunc = install_vimrc;
1405 choices[choice_count].text = NULL; 1406 choices[choice_count].text = NULL;
1406 change_vimrc_choice(choice_count); 1407 change_vimrc_choice(choice_count);
1407 choices[choice_count].changefunc = change_vimrc_choice; 1408 choices[choice_count].changefunc = change_vimrc_choice;
1408 choices[choice_count].active = 1; 1409 choices[choice_count].active = 1;
1409 ++choice_count; 1410 ++choice_count;
1410 1411
1411 /* default way to run Vim */ 1412 // default way to run Vim
1412 alloc_text(choice_count, compat_text, compat_choices[compat_choice]); 1413 alloc_text(choice_count, compat_text, compat_choices[compat_choice]);
1413 choices[choice_count].changefunc = change_run_choice; 1414 choices[choice_count].changefunc = change_run_choice;
1414 choices[choice_count].installfunc = NULL; 1415 choices[choice_count].installfunc = NULL;
1415 choices[choice_count].active = (*oldvimrc == NUL); 1416 choices[choice_count].active = (*oldvimrc == NUL);
1416 ++choice_count; 1417 ++choice_count;
1417 1418
1418 /* Whether to remap keys */ 1419 // Whether to remap keys
1419 alloc_text(choice_count, remap_text , remap_choices[remap_choice]); 1420 alloc_text(choice_count, remap_text , remap_choices[remap_choice]);
1420 choices[choice_count].changefunc = change_remap_choice; 1421 choices[choice_count].changefunc = change_remap_choice;
1421 choices[choice_count].installfunc = NULL; 1422 choices[choice_count].installfunc = NULL;
1422 choices[choice_count].active = (*oldvimrc == NUL); 1423 choices[choice_count].active = (*oldvimrc == NUL);
1423 ++choice_count; 1424 ++choice_count;
1424 1425
1425 /* default way to use the mouse */ 1426 // default way to use the mouse
1426 alloc_text(choice_count, mouse_text, mouse_choices[mouse_choice]); 1427 alloc_text(choice_count, mouse_text, mouse_choices[mouse_choice]);
1427 choices[choice_count].changefunc = change_mouse_choice; 1428 choices[choice_count].changefunc = change_mouse_choice;
1428 choices[choice_count].installfunc = NULL; 1429 choices[choice_count].installfunc = NULL;
1429 choices[choice_count].active = (*oldvimrc == NUL); 1430 choices[choice_count].active = (*oldvimrc == NUL);
1430 ++choice_count; 1431 ++choice_count;
1606 * Add some entries to the registry: 1607 * Add some entries to the registry:
1607 * - to add "Edit with Vim" to the context * menu 1608 * - to add "Edit with Vim" to the context * menu
1608 * - to add Vim to the "Open with..." list 1609 * - to add Vim to the "Open with..." list
1609 * - to uninstall Vim 1610 * - to uninstall Vim
1610 */ 1611 */
1611 /*ARGSUSED*/ 1612 //ARGSUSED
1612 static int 1613 static int
1613 install_registry(void) 1614 install_registry(void)
1614 { 1615 {
1615 LONG lRet = ERROR_SUCCESS; 1616 LONG lRet = ERROR_SUCCESS;
1616 const char *vim_ext_ThreadingModel = "Apartment"; 1617 const char *vim_ext_ThreadingModel = "Apartment";
1682 #elif _M_X64 1683 #elif _M_X64
1683 " (x64)" 1684 " (x64)"
1684 #endif 1685 #endif
1685 ); 1686 );
1686 1687
1687 /* For the NSIS installer use the generated uninstaller. */ 1688 // For the NSIS installer use the generated uninstaller.
1688 if (interactive) 1689 if (interactive)
1689 sprintf(uninstall_string, "%s\\uninstall.exe", installdir); 1690 sprintf(uninstall_string, "%s\\uninstall.exe", installdir);
1690 else 1691 else
1691 sprintf(uninstall_string, "%s\\uninstall-gui.exe", installdir); 1692 sprintf(uninstall_string, "%s\\uninstall-gui.exe", installdir);
1692 1693
1735 || stat(GVIMEXT64_PATH, &st) >= 0)) 1736 || stat(GVIMEXT64_PATH, &st) >= 0))
1736 { 1737 {
1737 choices[choice_count].changefunc = change_popup_choice; 1738 choices[choice_count].changefunc = change_popup_choice;
1738 choices[choice_count].installfunc = NULL; 1739 choices[choice_count].installfunc = NULL;
1739 choices[choice_count].active = 1; 1740 choices[choice_count].active = 1;
1740 change_popup_choice(choice_count); /* set the text */ 1741 change_popup_choice(choice_count); // set the text
1741 ++choice_count; 1742 ++choice_count;
1742 } 1743 }
1743 else 1744 else
1744 add_dummy_choice(); 1745 add_dummy_choice();
1745 } 1746 }
1769 if (has_gvim) 1770 if (has_gvim)
1770 { 1771 {
1771 choices[choice_count].changefunc = change_openwith_choice; 1772 choices[choice_count].changefunc = change_openwith_choice;
1772 choices[choice_count].installfunc = NULL; 1773 choices[choice_count].installfunc = NULL;
1773 choices[choice_count].active = 1; 1774 choices[choice_count].active = 1;
1774 change_openwith_choice(choice_count); /* set the text */ 1775 change_openwith_choice(choice_count); // set the text
1775 ++choice_count; 1776 ++choice_count;
1776 } 1777 }
1777 else 1778 else
1778 add_dummy_choice(); 1779 add_dummy_choice();
1779 } 1780 }
1780 1781
1781 /* create_shortcut 1782 /*
1782 *
1783 * Create a shell link. 1783 * Create a shell link.
1784 * 1784 *
1785 * returns 0 on failure, non-zero on successful completion. 1785 * returns 0 on failure, non-zero on successful completion.
1786 * 1786 *
1787 * NOTE: Currently untested with mingw. 1787 * NOTE: Currently untested with mingw.
1798 { 1798 {
1799 IShellLink *shelllink_ptr; 1799 IShellLink *shelllink_ptr;
1800 HRESULT hres; 1800 HRESULT hres;
1801 IPersistFile *persistfile_ptr; 1801 IPersistFile *persistfile_ptr;
1802 1802
1803 /* Initialize COM library */ 1803 // Initialize COM library
1804 hres = CoInitialize(NULL); 1804 hres = CoInitialize(NULL);
1805 if (!SUCCEEDED(hres)) 1805 if (!SUCCEEDED(hres))
1806 { 1806 {
1807 printf("Error: Could not open the COM library. Not creating shortcut.\n"); 1807 printf("Error: Could not open the COM library. Not creating shortcut.\n");
1808 return FAIL; 1808 return FAIL;
1809 } 1809 }
1810 1810
1811 /* Instantiate a COM object for the ShellLink, store a pointer to it 1811 // Instantiate a COM object for the ShellLink, store a pointer to it
1812 * in shelllink_ptr. */ 1812 // in shelllink_ptr.
1813 hres = CoCreateInstance(&CLSID_ShellLink, 1813 hres = CoCreateInstance(&CLSID_ShellLink,
1814 NULL, 1814 NULL,
1815 CLSCTX_INPROC_SERVER, 1815 CLSCTX_INPROC_SERVER,
1816 &IID_IShellLink, 1816 &IID_IShellLink,
1817 (void **) &shelllink_ptr); 1817 (void **) &shelllink_ptr);
1818 1818
1819 if (SUCCEEDED(hres)) /* If the instantiation was successful... */ 1819 if (SUCCEEDED(hres)) // If the instantiation was successful...
1820 { 1820 {
1821 /* ...Then build a PersistFile interface for the ShellLink so we can 1821 // ...Then build a PersistFile interface for the ShellLink so we can
1822 * save it as a file after we build it. */ 1822 // save it as a file after we build it.
1823 hres = shelllink_ptr->lpVtbl->QueryInterface(shelllink_ptr, 1823 hres = shelllink_ptr->lpVtbl->QueryInterface(shelllink_ptr,
1824 &IID_IPersistFile, (void **) &persistfile_ptr); 1824 &IID_IPersistFile, (void **) &persistfile_ptr);
1825 1825
1826 if (SUCCEEDED(hres)) 1826 if (SUCCEEDED(hres))
1827 { 1827 {
1828 wchar_t wsz[BUFSIZE]; 1828 wchar_t wsz[BUFSIZE];
1829 1829
1830 /* translate the (possibly) multibyte shortcut filename to windows 1830 // translate the (possibly) multibyte shortcut filename to windows
1831 * Unicode so it can be used as a file name. 1831 // Unicode so it can be used as a file name.
1832 */
1833 MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, sizeof(wsz)/sizeof(wsz[0])); 1832 MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, sizeof(wsz)/sizeof(wsz[0]));
1834 1833
1835 /* set the attributes */ 1834 // set the attributes
1836 shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target); 1835 shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target);
1837 shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr, 1836 shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr,
1838 workingdir); 1837 workingdir);
1839 shelllink_ptr->lpVtbl->SetIconLocation(shelllink_ptr, 1838 shelllink_ptr->lpVtbl->SetIconLocation(shelllink_ptr,
1840 iconfile_path, iconindex); 1839 iconfile_path, iconindex);
1841 shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args); 1840 shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args);
1842 1841
1843 /* save the shortcut to a file and return the PersistFile object*/ 1842 // save the shortcut to a file and return the PersistFile object
1844 persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1); 1843 persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1);
1845 persistfile_ptr->lpVtbl->Release(persistfile_ptr); 1844 persistfile_ptr->lpVtbl->Release(persistfile_ptr);
1846 } 1845 }
1847 else 1846 else
1848 { 1847 {
1849 printf("QueryInterface Error\n"); 1848 printf("QueryInterface Error\n");
1850 return FAIL; 1849 return FAIL;
1851 } 1850 }
1852 1851
1853 /* Return the ShellLink object */ 1852 // Return the ShellLink object
1854 shelllink_ptr->lpVtbl->Release(shelllink_ptr); 1853 shelllink_ptr->lpVtbl->Release(shelllink_ptr);
1855 } 1854 }
1856 else 1855 else
1857 { 1856 {
1858 printf("CoCreateInstance Error - hres = %08x\n", (int)hres); 1857 printf("CoCreateInstance Error - hres = %08x\n", (int)hres);
1880 printf("An error occurred while attempting to find the path to %s.\n", 1879 printf("An error occurred while attempting to find the path to %s.\n",
1881 shell_folder_name); 1880 shell_folder_name);
1882 return FAIL; 1881 return FAIL;
1883 } 1882 }
1884 1883
1885 /* Make sure the directory exists (create Start Menu\Programs\Vim). 1884 // Make sure the directory exists (create Start Menu\Programs\Vim).
1886 * Ignore errors if it already exists. */ 1885 // Ignore errors if it already exists.
1887 vim_mkdir(shell_folder_path, 0755); 1886 vim_mkdir(shell_folder_path, 0755);
1888 1887
1889 /* build the path to the shortcut and the path to gvim.exe */ 1888 // build the path to the shortcut and the path to gvim.exe
1890 sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name); 1889 sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name);
1891 1890
1892 return OK; 1891 return OK;
1893 } 1892 }
1894 1893
1895 static int 1894 static int
1896 build_shortcut( 1895 build_shortcut(
1897 const char *name, /* Name of the shortcut */ 1896 const char *name, // Name of the shortcut
1898 const char *exename, /* Name of the executable (e.g., vim.exe) */ 1897 const char *exename, // Name of the executable (e.g., vim.exe)
1899 const char *args, 1898 const char *args,
1900 const char *shell_folder, 1899 const char *shell_folder,
1901 const char *workingdir) 1900 const char *workingdir)
1902 { 1901 {
1903 char executable_path[BUFSIZE]; 1902 char executable_path[BUFSIZE];
1911 name, 1910 name,
1912 *shell_folder == 'd' ? "on the desktop" : "in the Start menu"); 1911 *shell_folder == 'd' ? "on the desktop" : "in the Start menu");
1913 return FAIL; 1912 return FAIL;
1914 } 1913 }
1915 1914
1916 /* Create the shortcut: */ 1915 // Create the shortcut:
1917 return create_shortcut(link_name, executable_path, 0, 1916 return create_shortcut(link_name, executable_path, 0,
1918 executable_path, args, workingdir); 1917 executable_path, args, workingdir);
1919 } 1918 }
1920 1919
1921 /* 1920 /*
1963 } 1962 }
1964 if (build_shortcut("Uninstall", 1963 if (build_shortcut("Uninstall",
1965 interactive ? "uninstall.exe" : "uninstall-gui.exe", "", 1964 interactive ? "uninstall.exe" : "uninstall-gui.exe", "",
1966 VIM_STARTMENU, installdir) == FAIL) 1965 VIM_STARTMENU, installdir) == FAIL)
1967 return; 1966 return;
1968 /* For Windows NT the working dir of the vimtutor.bat must be right, 1967 // For Windows NT the working dir of the vimtutor.bat must be right,
1969 * otherwise gvim.exe won't be found and using gvimbat doesn't work. */ 1968 // otherwise gvim.exe won't be found and using gvimbat doesn't work.
1970 if (build_shortcut("Vim tutor", "vimtutor.bat", "", 1969 if (build_shortcut("Vim tutor", "vimtutor.bat", "",
1971 VIM_STARTMENU, installdir) == FAIL) 1970 VIM_STARTMENU, installdir) == FAIL)
1972 return; 1971 return;
1973 if (build_shortcut("Help", has_gvim ? "gvim.exe" : "vim.exe", "-c h", 1972 if (build_shortcut("Help", has_gvim ? "gvim.exe" : "vim.exe", "-c h",
1974 VIM_STARTMENU, WORKDIR) == FAIL) 1973 VIM_STARTMENU, WORKDIR) == FAIL)
1975 return; 1974 return;
1976 { 1975 {
1977 char shell_folder_path[BUFSIZE]; 1976 char shell_folder_path[BUFSIZE];
1978 1977
1979 /* Creating the URL shortcut works a bit differently... */ 1978 // Creating the URL shortcut works a bit differently...
1980 if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL) 1979 if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL)
1981 { 1980 {
1982 printf("Finding the path of the Start menu failed\n"); 1981 printf("Finding the path of the Start menu failed\n");
1983 return ; 1982 return ;
1984 } 1983 }
2018 * drag and drop onto the shortcut). 2017 * drag and drop onto the shortcut).
2019 */ 2018 */
2020 void 2019 void
2021 install_shortcut_gvim(int idx) 2020 install_shortcut_gvim(int idx)
2022 { 2021 {
2023 /* Create shortcut(s) on the desktop */ 2022 // Create shortcut(s) on the desktop
2024 if (choices[idx].arg) 2023 if (choices[idx].arg)
2025 { 2024 {
2026 (void)build_shortcut(icon_names[0], "gvim.exe", 2025 (void)build_shortcut(icon_names[0], "gvim.exe",
2027 "", "desktop", WORKDIR); 2026 "", "desktop", WORKDIR);
2028 need_uninstall_entry = 1; 2027 need_uninstall_entry = 1;
2075 } 2074 }
2076 2075
2077 static void 2076 static void
2078 init_startmenu_choice(void) 2077 init_startmenu_choice(void)
2079 { 2078 {
2080 /* Start menu */ 2079 // Start menu
2081 choices[choice_count].changefunc = toggle_startmenu_choice; 2080 choices[choice_count].changefunc = toggle_startmenu_choice;
2082 choices[choice_count].installfunc = NULL; 2081 choices[choice_count].installfunc = NULL;
2083 choices[choice_count].active = 1; 2082 choices[choice_count].active = 1;
2084 toggle_startmenu_choice(choice_count); /* set the text */ 2083 toggle_startmenu_choice(choice_count); // set the text
2085 ++choice_count; 2084 ++choice_count;
2086 } 2085 }
2087 2086
2088 /* 2087 /*
2089 * Add the choice for the desktop shortcuts. 2088 * Add the choice for the desktop shortcuts.
2090 */ 2089 */
2091 static void 2090 static void
2092 init_shortcut_choices(void) 2091 init_shortcut_choices(void)
2093 { 2092 {
2094 /* Shortcut to gvim */ 2093 // Shortcut to gvim
2095 choices[choice_count].text = NULL; 2094 choices[choice_count].text = NULL;
2096 choices[choice_count].arg = 0; 2095 choices[choice_count].arg = 0;
2097 choices[choice_count].active = has_gvim; 2096 choices[choice_count].active = has_gvim;
2098 choices[choice_count].changefunc = toggle_shortcut_choice; 2097 choices[choice_count].changefunc = toggle_shortcut_choice;
2099 choices[choice_count].installfunc = install_shortcut_gvim; 2098 choices[choice_count].installfunc = install_shortcut_gvim;
2100 toggle_shortcut_choice(choice_count); 2099 toggle_shortcut_choice(choice_count);
2101 ++choice_count; 2100 ++choice_count;
2102 2101
2103 /* Shortcut to evim */ 2102 // Shortcut to evim
2104 choices[choice_count].text = NULL; 2103 choices[choice_count].text = NULL;
2105 choices[choice_count].arg = 0; 2104 choices[choice_count].arg = 0;
2106 choices[choice_count].active = has_gvim; 2105 choices[choice_count].active = has_gvim;
2107 choices[choice_count].changefunc = toggle_shortcut_choice; 2106 choices[choice_count].changefunc = toggle_shortcut_choice;
2108 choices[choice_count].installfunc = install_shortcut_evim; 2107 choices[choice_count].installfunc = install_shortcut_evim;
2109 toggle_shortcut_choice(choice_count); 2108 toggle_shortcut_choice(choice_count);
2110 ++choice_count; 2109 ++choice_count;
2111 2110
2112 /* Shortcut to gview */ 2111 // Shortcut to gview
2113 choices[choice_count].text = NULL; 2112 choices[choice_count].text = NULL;
2114 choices[choice_count].arg = 0; 2113 choices[choice_count].arg = 0;
2115 choices[choice_count].active = has_gvim; 2114 choices[choice_count].active = has_gvim;
2116 choices[choice_count].changefunc = toggle_shortcut_choice; 2115 choices[choice_count].changefunc = toggle_shortcut_choice;
2117 choices[choice_count].installfunc = install_shortcut_gview; 2116 choices[choice_count].installfunc = install_shortcut_gview;
2143 { 2142 {
2144 char c; 2143 char c;
2145 long last_char_to_copy; 2144 long last_char_to_copy;
2146 long path_length = strlen(path); 2145 long path_length = strlen(path);
2147 2146
2148 /* skip the last character just in case it is a '\\' */ 2147 // skip the last character just in case it is a '\\'
2149 last_char_to_copy = path_length - 2; 2148 last_char_to_copy = path_length - 2;
2150 c = path[last_char_to_copy]; 2149 c = path[last_char_to_copy];
2151 2150
2152 while (c != '\\') 2151 while (c != '\\')
2153 { 2152 {
2262 static void 2261 static void
2263 change_directories_choice(int idx) 2262 change_directories_choice(int idx)
2264 { 2263 {
2265 int choice_count = TABLE_SIZE(vimfiles_dir_choices); 2264 int choice_count = TABLE_SIZE(vimfiles_dir_choices);
2266 2265
2267 /* Don't offer the $HOME choice if $HOME isn't set. */ 2266 // Don't offer the $HOME choice if $HOME isn't set.
2268 if (homedir == NULL) 2267 if (homedir == NULL)
2269 --choice_count; 2268 --choice_count;
2270 choices[idx].arg = get_choice(vimfiles_dir_choices, choice_count); 2269 choices[idx].arg = get_choice(vimfiles_dir_choices, choice_count);
2271 set_directories_text(idx); 2270 set_directories_text(idx);
2272 } 2271 }
2273 2272
2274 /* 2273 /*
2275 * Create the plugin directories... 2274 * Create the plugin directories...
2276 */ 2275 */
2277 /*ARGSUSED*/ 2276 //ARGSUSED
2278 static void 2277 static void
2279 install_vimfilesdir(int idx) 2278 install_vimfilesdir(int idx)
2280 { 2279 {
2281 int i; 2280 int i;
2282 int vimfiles_dir_choice = choices[idx].arg; 2281 int vimfiles_dir_choice = choices[idx].arg;
2283 char *p; 2282 char *p;
2284 char vimdir_path[MAX_PATH]; 2283 char vimdir_path[MAX_PATH];
2285 char vimfiles_path[MAX_PATH + 9]; 2284 char vimfiles_path[MAX_PATH + 9];
2286 char tmp_dirname[BUFSIZE]; 2285 char tmp_dirname[BUFSIZE];
2287 2286
2288 /* switch on the location that the user wants the plugin directories 2287 // switch on the location that the user wants the plugin directories
2289 * built in */ 2288 // built in
2290 switch (vimfiles_dir_choice) 2289 switch (vimfiles_dir_choice)
2291 { 2290 {
2292 case vimfiles_dir_vim: 2291 case vimfiles_dir_vim:
2293 { 2292 {
2294 /* Go to the %VIM% directory - check env first, then go one dir 2293 // Go to the %VIM% directory - check env first, then go one dir
2295 * below installdir if there is no %VIM% environment variable. 2294 // below installdir if there is no %VIM% environment variable.
2296 * The accuracy of $VIM is checked in inspect_system(), so we 2295 // The accuracy of $VIM is checked in inspect_system(), so we
2297 * can be sure it is ok to use here. */ 2296 // can be sure it is ok to use here.
2298 p = getenv("VIM"); 2297 p = getenv("VIM");
2299 if (p == NULL) /* No $VIM in path */ 2298 if (p == NULL) // No $VIM in path
2300 dir_remove_last(installdir, vimdir_path); 2299 dir_remove_last(installdir, vimdir_path);
2301 else 2300 else
2302 strcpy(vimdir_path, p); 2301 strcpy(vimdir_path, p);
2303 break; 2302 break;
2304 } 2303 }
2319 // Do not create vim plugin directory. 2318 // Do not create vim plugin directory.
2320 return; 2319 return;
2321 } 2320 }
2322 } 2321 }
2323 2322
2324 /* Now, just create the directory. If it already exists, it will fail 2323 // Now, just create the directory. If it already exists, it will fail
2325 * silently. */ 2324 // silently.
2326 sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path); 2325 sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path);
2327 vim_mkdir(vimfiles_path, 0755); 2326 vim_mkdir(vimfiles_path, 0755);
2328 2327
2329 printf("Creating the following directories in \"%s\":\n", vimfiles_path); 2328 printf("Creating the following directories in \"%s\":\n", vimfiles_path);
2330 for (i = 0; i < TABLE_SIZE(vimfiles_subdirs); i++) 2329 for (i = 0; i < TABLE_SIZE(vimfiles_subdirs); i++)
2384 * Setup the choices and the default values. 2383 * Setup the choices and the default values.
2385 */ 2384 */
2386 static void 2385 static void
2387 setup_choices(void) 2386 setup_choices(void)
2388 { 2387 {
2389 /* install the batch files */ 2388 // install the batch files
2390 init_bat_choices(); 2389 init_bat_choices();
2391 2390
2392 /* (over) write _vimrc file */ 2391 // (over) write _vimrc file
2393 init_vimrc_choices(); 2392 init_vimrc_choices();
2394 2393
2395 /* Whether to add Vim to the popup menu */ 2394 // Whether to add Vim to the popup menu
2396 init_popup_choice(); 2395 init_popup_choice();
2397 2396
2398 /* Whether to add Vim to the "Open With..." menu */ 2397 // Whether to add Vim to the "Open With..." menu
2399 init_openwith_choice(); 2398 init_openwith_choice();
2400 2399
2401 /* Whether to add Vim to the Start Menu. */ 2400 // Whether to add Vim to the Start Menu.
2402 init_startmenu_choice(); 2401 init_startmenu_choice();
2403 2402
2404 /* Whether to add shortcuts to the Desktop. */ 2403 // Whether to add shortcuts to the Desktop.
2405 init_shortcut_choices(); 2404 init_shortcut_choices();
2406 2405
2407 /* Whether to create the runtime directories. */ 2406 // Whether to create the runtime directories.
2408 init_directories_choice(); 2407 init_directories_choice();
2409 } 2408 }
2410 2409
2411 static void 2410 static void
2412 print_cmd_line_help(void) 2411 print_cmd_line_help(void)
2471 break; 2470 break;
2472 } 2471 }
2473 } 2472 }
2474 else if (strcmp(argv[i], "-create-vimrc") == 0) 2473 else if (strcmp(argv[i], "-create-vimrc") == 0)
2475 { 2474 {
2476 /* Setup default vimrc choices. If there is already a _vimrc file, 2475 // Setup default vimrc choices. If there is already a _vimrc file,
2477 * it will NOT be overwritten. 2476 // it will NOT be overwritten.
2478 */
2479 init_vimrc_choices(); 2477 init_vimrc_choices();
2480 } 2478 }
2481 else if (strcmp(argv[i], "-vimrc-remap") == 0) 2479 else if (strcmp(argv[i], "-vimrc-remap") == 0)
2482 { 2480 {
2483 if (i + 1 == argc) 2481 if (i + 1 == argc)
2552 printf("Unknown argument for -create-directories: %s\n", 2550 printf("Unknown argument for -create-directories: %s\n",
2553 argv[i]); 2551 argv[i]);
2554 print_cmd_line_help(); 2552 print_cmd_line_help();
2555 } 2553 }
2556 } 2554 }
2557 else /* No choice specified, default to vim directory */ 2555 else // No choice specified, default to vim directory
2558 vimfiles_dir_choice = (int)vimfiles_dir_vim; 2556 vimfiles_dir_choice = (int)vimfiles_dir_vim;
2559 choices[choice_count - 1].arg = vimfiles_dir_choice; 2557 choices[choice_count - 1].arg = vimfiles_dir_choice;
2560 } 2558 }
2561 else if (strcmp(argv[i], "-register-OLE") == 0) 2559 else if (strcmp(argv[i], "-register-OLE") == 0)
2562 { 2560 {
2563 /* This is always done when gvim is found */ 2561 // This is always done when gvim is found
2564 } 2562 }
2565 else /* Unknown switch */ 2563 else // Unknown switch
2566 { 2564 {
2567 printf("Got unknown argument argv[%d] = %s\n", i, argv[i]); 2565 printf("Got unknown argument argv[%d] = %s\n", i, argv[i]);
2568 print_cmd_line_help(); 2566 print_cmd_line_help();
2569 } 2567 }
2570 } 2568 }
2705 static void 2703 static void
2706 install(void) 2704 install(void)
2707 { 2705 {
2708 int i; 2706 int i;
2709 2707
2710 /* Install the selected choices. */ 2708 // Install the selected choices.
2711 for (i = 0; i < choice_count; ++i) 2709 for (i = 0; i < choice_count; ++i)
2712 if (choices[i].installfunc != NULL && choices[i].active) 2710 if (choices[i].installfunc != NULL && choices[i].active)
2713 (choices[i].installfunc)(i); 2711 (choices[i].installfunc)(i);
2714 2712
2715 /* Add some entries to the registry, if needed. */ 2713 // Add some entries to the registry, if needed.
2716 if (install_popup 2714 if (install_popup
2717 || install_openwith 2715 || install_openwith
2718 || (need_uninstall_entry && interactive) 2716 || (need_uninstall_entry && interactive)
2719 || !interactive) 2717 || !interactive)
2720 install_registry(); 2718 install_registry();
2721 2719
2722 /* Register gvim with OLE. */ 2720 // Register gvim with OLE.
2723 if (has_gvim) 2721 if (has_gvim)
2724 install_OLE_register(); 2722 install_OLE_register();
2725 } 2723 }
2726 2724
2727 /* 2725 /*
2752 if (argc > 1) 2750 if (argc > 1)
2753 interactive = 0; 2751 interactive = 0;
2754 else 2752 else
2755 interactive = 1; 2753 interactive = 1;
2756 2754
2757 /* Initialize this program. */ 2755 // Initialize this program.
2758 do_inits(argv); 2756 do_inits(argv);
2759 init_homedir(); 2757 init_homedir();
2760 2758
2761 if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0) 2759 if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0)
2762 { 2760 {
2763 /* Only check for already installed Vims. Used by NSIS installer. */ 2761 // Only check for already installed Vims. Used by NSIS installer.
2764 i = uninstall_check(1); 2762 i = uninstall_check(1);
2765 2763
2766 /* Find the value of $VIM, because NSIS isn't able to do this by 2764 // Find the value of $VIM, because NSIS isn't able to do this by
2767 * itself. */ 2765 // itself.
2768 get_vim_env(); 2766 get_vim_env();
2769 2767
2770 /* When nothing found exit quietly. If something found wait for 2768 // When nothing found exit quietly. If something found wait for
2771 * a little while, so that the user can read the messages. */ 2769 // a little while, so that the user can read the messages.
2772 if (i && _isatty(1)) 2770 if (i && _isatty(1))
2773 sleep(3); 2771 sleep(3);
2774 exit(0); 2772 exit(0);
2775 } 2773 }
2776 2774
2777 printf("This program sets up the installation of Vim " 2775 printf("This program sets up the installation of Vim "
2778 VIM_VERSION_MEDIUM "\n\n"); 2776 VIM_VERSION_MEDIUM "\n\n");
2779 2777
2780 /* Check if the user unpacked the archives properly. */ 2778 // Check if the user unpacked the archives properly.
2781 check_unpack(); 2779 check_unpack();
2782 2780
2783 /* Check for already installed Vims. */ 2781 // Check for already installed Vims.
2784 if (interactive) 2782 if (interactive)
2785 uninstall_check(0); 2783 uninstall_check(0);
2786 2784
2787 /* Find out information about the system. */ 2785 // Find out information about the system.
2788 inspect_system(); 2786 inspect_system();
2789 2787
2790 if (interactive) 2788 if (interactive)
2791 { 2789 {
2792 /* Setup all the choices. */ 2790 // Setup all the choices.
2793 setup_choices(); 2791 setup_choices();
2794 2792
2795 /* Let the user change choices and finally install (or quit). */ 2793 // Let the user change choices and finally install (or quit).
2796 for (;;) 2794 for (;;)
2797 { 2795 {
2798 request_choice(); 2796 request_choice();
2799 rewind(stdin); 2797 rewind(stdin);
2800 if (scanf("%99s", buf) == 1) 2798 if (scanf("%99s", buf) == 1)
2801 { 2799 {
2802 if (isdigit(buf[0])) 2800 if (isdigit(buf[0]))
2803 { 2801 {
2804 /* Change a choice. */ 2802 // Change a choice.
2805 i = atoi(buf); 2803 i = atoi(buf);
2806 if (i > 0 && i <= choice_count && choices[i - 1].active) 2804 if (i > 0 && i <= choice_count && choices[i - 1].active)
2807 (choices[i - 1].changefunc)(i - 1); 2805 (choices[i - 1].changefunc)(i - 1);
2808 else 2806 else
2809 printf("\nIllegal choice\n"); 2807 printf("\nIllegal choice\n");
2810 } 2808 }
2811 else if (buf[0] == 'h' || buf[0] == 'H') 2809 else if (buf[0] == 'h' || buf[0] == 'H')
2812 { 2810 {
2813 /* Help */ 2811 // Help
2814 show_help(); 2812 show_help();
2815 } 2813 }
2816 else if (buf[0] == 'd' || buf[0] == 'D') 2814 else if (buf[0] == 'd' || buf[0] == 'D')
2817 { 2815 {
2818 /* Install! */ 2816 // Install!
2819 install(); 2817 install();
2820 printf("\nThat finishes the installation. Happy Vimming!\n"); 2818 printf("\nThat finishes the installation. Happy Vimming!\n");
2821 break; 2819 break;
2822 } 2820 }
2823 else if (buf[0] == 'q' || buf[0] == 'Q') 2821 else if (buf[0] == 'q' || buf[0] == 'Q')
2824 { 2822 {
2825 /* Quit */ 2823 // Quit
2826 printf("\nExiting without anything done\n"); 2824 printf("\nExiting without anything done\n");
2827 break; 2825 break;
2828 } 2826 }
2829 else 2827 else
2830 printf("\nIllegal choice\n"); 2828 printf("\nIllegal choice\n");
2839 * Run non-interactive - setup according to the command line switches 2837 * Run non-interactive - setup according to the command line switches
2840 */ 2838 */
2841 command_line_setup_choices(argc, argv); 2839 command_line_setup_choices(argc, argv);
2842 install(); 2840 install();
2843 2841
2844 /* Avoid that the user has to hit Enter, just wait a little bit to 2842 // Avoid that the user has to hit Enter, just wait a little bit to
2845 * allow reading the messages. */ 2843 // allow reading the messages.
2846 sleep(2); 2844 sleep(2);
2847 } 2845 }
2848 2846
2849 return 0; 2847 return 0;
2850 } 2848 }