From: Junio C Hamano Date: Wed, 11 Aug 2010 18:31:45 GMT Subject: Re: [PATCH/RFC] split_cmdline: Allow caller to access error string Message-ID: <7vhbj1yp9q.fsf@alter.siamese.dyndns.org> In-Reply-To: <1281158019-25995-1-git-send-email-gdb@mit.edu> Greg Brockman writes: > 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 > --- > diff --git a/alias.c b/alias.c > index 372b7d8..6f771cb 100644 > --- a/alias.c > +++ b/alias.c > @@ -1,7 +1,9 @@ > ... > +#define SPLIT_CMDLINE_BAD_ENDING 1 > +#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2 > +static const char *split_cmdline_errors = { "cmdline ends with \\", "unclosed quote" }; > ... > @@ -53,7 +55,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; >... > @@ -75,3 +77,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]; > +} Looks like a reasonable way to go. Thanks.