comparison src/gui_w32.c @ 16111:c0961d9ac269 v8.1.1060

patch 8.1.1060: MS-Windows: get_cmd_args() is no longer needed commit https://github.com/vim/vim/commit/760285dd4f20d25e8ae3166996981b8dddba366a Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 27 21:59:45 2019 +0100 patch 8.1.1060: MS-Windows: get_cmd_args() is no longer needed Problem: MS-Windows: get_cmd_args() is no longer needed, get_cmd_argsW() is always used. Solution: Remove get_cmd_args(). (Ken Takata, closes #4171)
author Bram Moolenaar <Bram@vim.org>
date Wed, 27 Mar 2019 22:00:07 +0100
parents 728bef04b0d4
children a246b020984c
comparison
equal deleted inserted replaced
16110:16bd256c5d19 16111:c0961d9ac269
3879 dont_scroll = dont_scroll_save; 3879 dont_scroll = dont_scroll_save;
3880 3880
3881 return 0; 3881 return 0;
3882 } 3882 }
3883 3883
3884
3885 /*
3886 * Get command line arguments.
3887 * Use "prog" as the name of the program and "cmdline" as the arguments.
3888 * Copy the arguments to allocated memory.
3889 * Return the number of arguments (including program name).
3890 * Return pointers to the arguments in "argvp". Memory is allocated with
3891 * malloc(), use free() instead of vim_free().
3892 * Return pointer to buffer in "tofree".
3893 * Returns zero when out of memory.
3894 */
3895 int
3896 get_cmd_args(char *prog, char *cmdline, char ***argvp, char **tofree)
3897 {
3898 int i;
3899 char *p;
3900 char *progp;
3901 char *pnew = NULL;
3902 char *newcmdline;
3903 int inquote;
3904 int argc;
3905 char **argv = NULL;
3906 int round;
3907
3908 *tofree = NULL;
3909
3910 /* Try using the Unicode version first, it takes care of conversion when
3911 * 'encoding' is changed. */
3912 argc = get_cmd_argsW(&argv);
3913 if (argc != 0)
3914 goto done;
3915
3916 /* Handle the program name. Remove the ".exe" extension, and find the 1st
3917 * non-space. */
3918 p = strrchr(prog, '.');
3919 if (p != NULL)
3920 *p = NUL;
3921 for (progp = prog; *progp == ' '; ++progp)
3922 ;
3923
3924 /* The command line is copied to allocated memory, so that we can change
3925 * it. Add the size of the string, the separating NUL and a terminating
3926 * NUL. */
3927 newcmdline = malloc(STRLEN(cmdline) + STRLEN(progp) + 2);
3928 if (newcmdline == NULL)
3929 return 0;
3930
3931 /*
3932 * First round: count the number of arguments ("pnew" == NULL).
3933 * Second round: produce the arguments.
3934 */
3935 for (round = 1; round <= 2; ++round)
3936 {
3937 /* First argument is the program name. */
3938 if (pnew != NULL)
3939 {
3940 argv[0] = pnew;
3941 strcpy(pnew, progp);
3942 pnew += strlen(pnew);
3943 *pnew++ = NUL;
3944 }
3945
3946 /*
3947 * Isolate each argument and put it in argv[].
3948 */
3949 p = cmdline;
3950 argc = 1;
3951 while (*p != NUL)
3952 {
3953 inquote = FALSE;
3954 if (pnew != NULL)
3955 argv[argc] = pnew;
3956 ++argc;
3957 while (*p != NUL && (inquote || (*p != ' ' && *p != '\t')))
3958 {
3959 /* Backslashes are only special when followed by a double
3960 * quote. */
3961 i = (int)strspn(p, "\\");
3962 if (p[i] == '"')
3963 {
3964 /* Halve the number of backslashes. */
3965 if (i > 1 && pnew != NULL)
3966 {
3967 vim_memset(pnew, '\\', i / 2);
3968 pnew += i / 2;
3969 }
3970
3971 /* Even nr of backslashes toggles quoting, uneven copies
3972 * the double quote. */
3973 if ((i & 1) == 0)
3974 inquote = !inquote;
3975 else if (pnew != NULL)
3976 *pnew++ = '"';
3977 p += i + 1;
3978 }
3979 else if (i > 0)
3980 {
3981 /* Copy span of backslashes unmodified. */
3982 if (pnew != NULL)
3983 {
3984 vim_memset(pnew, '\\', i);
3985 pnew += i;
3986 }
3987 p += i;
3988 }
3989 else
3990 {
3991 if (pnew != NULL)
3992 *pnew++ = *p;
3993 /* Can't use mb_* functions, because 'encoding' is not
3994 * initialized yet here. */
3995 if (IsDBCSLeadByte(*p))
3996 {
3997 ++p;
3998 if (pnew != NULL)
3999 *pnew++ = *p;
4000 }
4001 ++p;
4002 }
4003 }
4004
4005 if (pnew != NULL)
4006 *pnew++ = NUL;
4007 while (*p == ' ' || *p == '\t')
4008 ++p; /* advance until a non-space */
4009 }
4010
4011 if (round == 1)
4012 {
4013 argv = (char **)malloc((argc + 1) * sizeof(char *));
4014 if (argv == NULL )
4015 {
4016 free(newcmdline);
4017 return 0; /* malloc error */
4018 }
4019 pnew = newcmdline;
4020 *tofree = newcmdline;
4021 }
4022 }
4023
4024 done:
4025 argv[argc] = NULL; /* NULL-terminated list */
4026 *argvp = argv;
4027 return argc;
4028 }
4029 3884
4030 #ifdef FEAT_XPM_W32 3885 #ifdef FEAT_XPM_W32
4031 # include "xpm_w32.h" 3886 # include "xpm_w32.h"
4032 #endif 3887 #endif
4033 3888