diff options
author | Greg Brockman <gdb@MIT.EDU> | 2010-08-07 07:13:39 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-08-11 18:36:23 +0200 |
commit | ad9ac6db5d58de08d0497b9184e86926377c20dd (patch) | |
tree | 02a6ec6fd2fd40799d9d1c4c1fcba657b5adbcc4 /alias.c | |
parent | Git 1.7.2 (diff) | |
download | git-ad9ac6db5d58de08d0497b9184e86926377c20dd.tar.xz git-ad9ac6db5d58de08d0497b9184e86926377c20dd.zip |
split_cmdline: Allow caller to access error string
This allows the caller to add its own error message to that returned
by split_cmdline. Thus error output following a failed split_cmdline
can be of the form
fatal: Bad alias.test string: cmdline ends with \
rather than
error: cmdline ends with \
fatal: Bad alias.test string
Signed-off-by: Greg Brockman <gdb@mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'alias.c')
-rw-r--r-- | alias.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -22,6 +22,13 @@ char *alias_lookup(const char *alias) return alias_val; } +#define SPLIT_CMDLINE_BAD_ENDING 1 +#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2 +static const char *split_cmdline_errors[] = { + "cmdline ends with \\", + "unclosed quote" +}; + int split_cmdline(char *cmdline, const char ***argv) { int src, dst, count = 0, size = 16; @@ -53,7 +60,7 @@ int split_cmdline(char *cmdline, const char ***argv) if (!c) { free(*argv); *argv = NULL; - return error("cmdline ends with \\"); + return -SPLIT_CMDLINE_BAD_ENDING; } } cmdline[dst++] = c; @@ -66,7 +73,7 @@ int split_cmdline(char *cmdline, const char ***argv) if (quoted) { free(*argv); *argv = NULL; - return error("unclosed quote"); + return -SPLIT_CMDLINE_UNCLOSED_QUOTE; } ALLOC_GROW(*argv, count+1, size); @@ -75,3 +82,6 @@ int split_cmdline(char *cmdline, const char ***argv) return count; } +const char *split_cmdline_strerror(int split_cmdline_errno) { + return split_cmdline_errors[-split_cmdline_errno-1]; +} |