mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Add a Unicode version of split_into_argv().
Created in the simplest way, by parametrising the existing code using macros. Nothing actually uses this yet. I hope to gradually switch command-line parsing from 'ANSI' to Unicode strings, but this isn't the only preparation needed, so it might yet be a while.
This commit is contained in:
parent
acaa326fa5
commit
10e1ac7752
@ -34,6 +34,7 @@ add_sources_from_current_dir(utils
|
||||
utils/security.c
|
||||
utils/shinydialogbox.c
|
||||
utils/split_into_argv.c
|
||||
utils/split_into_argv_w.c
|
||||
utils/version.c
|
||||
utils/win_strerror.c
|
||||
unicode.c)
|
||||
|
@ -161,17 +161,27 @@
|
||||
#define MOD3 0
|
||||
#endif
|
||||
|
||||
static inline bool is_word_sep(char c)
|
||||
#ifdef SPLIT_INTO_ARGV_W
|
||||
#define FUNCTION split_into_argv_w
|
||||
#define CHAR wchar_t
|
||||
#define STRLEN wcslen
|
||||
#else
|
||||
#define FUNCTION split_into_argv
|
||||
#define CHAR char
|
||||
#define STRLEN strlen
|
||||
#endif
|
||||
|
||||
static inline bool is_word_sep(CHAR c)
|
||||
{
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
||||
void split_into_argv(char *cmdline, bool includes_program_name,
|
||||
int *argc, char ***argv, char ***argstart)
|
||||
void FUNCTION(CHAR *cmdline, bool includes_program_name,
|
||||
int *argc, CHAR ***argv, CHAR ***argstart)
|
||||
{
|
||||
char *p;
|
||||
char *outputline, *q;
|
||||
char **outputargv, **outputargstart;
|
||||
CHAR *p;
|
||||
CHAR *outputline, *q;
|
||||
CHAR **outputargv, **outputargstart;
|
||||
int outputargc;
|
||||
|
||||
/*
|
||||
@ -190,9 +200,9 @@ void split_into_argv(char *cmdline, bool includes_program_name,
|
||||
* This will guaranteeably be big enough; we can realloc it
|
||||
* down later.
|
||||
*/
|
||||
outputline = snewn(1+strlen(cmdline), char);
|
||||
outputargv = snewn(strlen(cmdline)+1 / 2, char *);
|
||||
outputargstart = snewn(strlen(cmdline)+1 / 2, char *);
|
||||
outputline = snewn(1+STRLEN(cmdline), CHAR);
|
||||
outputargv = snewn(STRLEN(cmdline)+1 / 2, CHAR *);
|
||||
outputargstart = snewn(STRLEN(cmdline)+1 / 2, CHAR *);
|
||||
|
||||
p = cmdline; q = outputline; outputargc = 0;
|
||||
|
||||
@ -299,8 +309,8 @@ void split_into_argv(char *cmdline, bool includes_program_name,
|
||||
*q++ = '\0';
|
||||
}
|
||||
|
||||
outputargv = sresize(outputargv, outputargc, char *);
|
||||
outputargstart = sresize(outputargstart, outputargc, char *);
|
||||
outputargv = sresize(outputargv, outputargc, CHAR *);
|
||||
outputargstart = sresize(outputargstart, outputargc, CHAR *);
|
||||
|
||||
if (argc) *argc = outputargc;
|
||||
if (argv) *argv = outputargv; else sfree(outputargv);
|
||||
|
6
windows/utils/split_into_argv_w.c
Normal file
6
windows/utils/split_into_argv_w.c
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Unicode version of split_into_argv.
|
||||
*/
|
||||
|
||||
#define SPLIT_INTO_ARGV_W
|
||||
#include "split_into_argv.c"
|
Loading…
Reference in New Issue
Block a user