Enabled use of Xorriso_parse_line() with xorriso==NULL

This commit is contained in:
Thomas Schmitt 2012-10-03 12:43:08 +00:00
parent fa9ed1d2c3
commit 7e7b575153
3 changed files with 37 additions and 14 deletions

View File

@ -1778,7 +1778,7 @@ next_command:;
ret= Xorriso_stop_msg_watcher(xorriso, 0); ret= Xorriso_stop_msg_watcher(xorriso, 0);
fprintf(stderr, "xorriso -test: Xorriso_stop_msg_watcher() = %d\n", ret); fprintf(stderr, "xorriso -test: Xorriso_stop_msg_watcher() = %d\n", ret);
} else if(strcmp(arg1, "parse") == 0) { } else if(strcmp(arg1, "parse") == 0 || strcmp(arg1, "nullparse") == 0) {
(*idx)+= 5; (*idx)+= 5;
pline= ""; pline= "";
if(*idx - 5 < argc) if(*idx - 5 < argc)
@ -1795,7 +1795,8 @@ next_command:;
pflag= 0; pflag= 0;
if(*idx - 1 < argc) if(*idx - 1 < argc)
sscanf(argv[*idx - 1], "%d", &pflag); sscanf(argv[*idx - 1], "%d", &pflag);
ret= Xorriso_parse_line(xorriso, pline, prefix, separators, max_words, ret= Xorriso_parse_line(strcmp(arg1, "nullparse") == 0 ? NULL : xorriso,
pline, prefix, separators, max_words,
&pargc, &pargv, pflag); &pargc, &pargv, pflag);
fprintf(stderr, fprintf(stderr,
"xorriso_test: Xorriso_parse_line: ret= %d , argc= %d , argv= 0x%lX\n", "xorriso_test: Xorriso_parse_line: ret= %d , argc= %d , argv= 0x%lX\n",
@ -1909,13 +1910,17 @@ int Xorriso_parse_line(struct XorrisO *xorriso, char *line,
int *argc, char ***argv, int flag) int *argc, char ***argv, int flag)
{ {
int ret, bsl_mode; int ret, bsl_mode;
char *to_parse; char *to_parse, *progname= "";
if(xorriso == NULL && (flag & (32 | 64))) {
ret= -2; goto ex;
}
*argc= 0; *argc= 0;
*argv= NULL; *argv= NULL;
to_parse= line; to_parse= line;
if(flag & 1) if((flag & 1) || xorriso == NULL)
bsl_mode= (flag >> 1) & 3; bsl_mode= (flag >> 1) & 3;
else else
bsl_mode= xorriso->bsl_interpretation & 3; bsl_mode= xorriso->bsl_interpretation & 3;
@ -1927,18 +1932,23 @@ int Xorriso_parse_line(struct XorrisO *xorriso, char *line,
} }
} }
ret= Sfile_sep_make_argv(xorriso->progname, to_parse, separators, if(xorriso != NULL)
progname= xorriso->progname;
ret= Sfile_sep_make_argv(progname, to_parse, separators,
max_words, argc, argv, max_words, argc, argv,
(!(flag & 32)) | 4 | (bsl_mode << 5)); (!(flag & 32)) | 4 | (bsl_mode << 5));
if(ret < 0) { if(ret < 0) {
Xorriso_msgs_submit(xorriso, 0, if(xorriso != NULL)
"Severe lack of resources during command line parsing", 0, "FATAL", 0); Xorriso_msgs_submit(xorriso, 0,
goto ex; "Severe lack of resources during command line parsing", 0, "FATAL", 0);
ret= -1; goto ex;
} }
if(ret == 0) { if(ret == 0) {
sprintf(xorriso->info_text, "Incomplete quotation in %s line: %s", if((flag & 64) && xorriso != NULL) {
(flag & 32) ? "command" : "parsed", to_parse); sprintf(xorriso->info_text, "Incomplete quotation in %s line: %s",
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); (flag & 32) ? "command" : "parsed", to_parse);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
}
goto ex; goto ex;
} }
ret= 1; ret= 1;

View File

@ -364,8 +364,18 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
/* Parse a text line into words. This parsing obeys the same rules as /* Parse a text line into words. This parsing obeys the same rules as
command line parsing but allows to skip a prefix, to use a user provided command line parsing but allows to skip a prefix, to use a user provided
set of separator characters, and to restrict the number of parsed words. set of separator characters, and to restrict the number of parsed words.
If parameter xorriso is NULL, then this call is safe for usage by
a concurrent thread while a xorriso API call is being executed.
@since 1.2.6 @since 1.2.6
@param xorriso The context object which provides settings for parsing @param xorriso The context object which provides settings for parsing
and output channels for error messages.
May be NULL in order to allow concurrent execution e.g.
by a callback function of Xorriso_start_msg_watcher().
If xorriso is NULL then:
flag bit1-bit4 are in effect even if bit0 is not set.
flag bit5 and bit6 may not be set.
@param line A text of one or more words according to man xorriso @param line A text of one or more words according to man xorriso
paragraph "Command processing" up to and including paragraph "Command processing" up to and including
"Backslash Interpretation". "Backslash Interpretation".
@ -391,8 +401,8 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
Do not forget to dispose the allocated memory by a Do not forget to dispose the allocated memory by a
call to Xorriso__dispose_words(). call to Xorriso__dispose_words().
@param flag Bitfield for control purposes @param flag Bitfield for control purposes
bit0= Override setting of -backslash_codes bit0= Override setting of -backslash_codes.
bit1-4= With bit1: backslash behavior bit1-4= With bit0: backslash behavior
0= off 0= off
1= in_double_quotes 1= in_double_quotes
2= in_quotes 2= in_quotes
@ -400,10 +410,13 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
bit5= Prepend the program name as (*argv)[0], so that bit5= Prepend the program name as (*argv)[0], so that
*argv is suitable for Xorriso_interpreter() *argv is suitable for Xorriso_interpreter()
and other calls which expect this. and other calls which expect this.
Not allowed if xorriso is NULL.
bit6= Issue failure message in case of return 0 bit6= Issue failure message in case of return 0
Not allowed if xorriso is NULL.
@return <=0 means error and invalidity of *argv: @return <=0 means error and invalidity of *argv:
0 = Input format error. E.g. bad quotation mark. 0 = Input format error. E.g. bad quotation mark.
-1 = Lack of resources. E.g. memory. -1 = Lack of resources. E.g. memory.
-2 = Improper combination of call parameters.
>0 means success but not necessarily a valid result: >0 means success but not necessarily a valid result:
1 = Result in argc and argv is valid (but may 1 = Result in argc and argv is valid (but may
be empty by argc == 0, argv == NULL). be empty by argc == 0, argv == NULL).

View File

@ -1 +1 @@
#define Xorriso_timestamP "2012.10.02.134601" #define Xorriso_timestamP "2012.10.03.124152"