New API calls Xorriso_parse_line() and Xorriso__dispose_words()

master
Thomas Schmitt 10 years ago
parent f34bb71269
commit fe095e322b
  1. 10
      libisoburn/libisoburn.ver
  2. 91
      xorriso/parse_exec.c
  3. 31
      xorriso/sfile.c
  4. 4
      xorriso/sfile.h
  5. 72
      xorriso/xorriso.h
  6. 2
      xorriso/xorriso_timestamp.h

@ -114,15 +114,18 @@ isoburn_toc_session_get_tracks;
isoburn_toc_track_get_emul;
isoburn_toc_track_get_entry;
isoburn_version;
Xorriso__dispose_words;
Xorriso__get_patch_level_text;
Xorriso__is_compatible;
Xorriso__version;
Xorriso__preset_signal_behavior;
Xorriso_change_is_pending;
Xorriso_destroy;
Xorriso_dialog;
Xorriso_eval_problem_status;
Xorriso_execute_option;
Xorriso__get_patch_level_text;
Xorriso_get_problem_status;
Xorriso_interpreter;
Xorriso__is_compatible;
Xorriso_lst_destroy_all;
Xorriso_lst_get_next;
Xorriso_lst_get_prev;
@ -287,8 +290,8 @@ Xorriso_option_volume_date;
Xorriso_option_write_type;
Xorriso_option_xattr;
Xorriso_option_zisofs;
Xorriso_parse_line;
Xorriso_prescan_args;
Xorriso__preset_signal_behavior;
Xorriso_process_errfile;
Xorriso_process_msg_queues;
Xorriso_program_arg_bsl;
@ -297,7 +300,6 @@ Xorriso_push_outlists;
Xorriso_read_rc;
Xorriso_set_problem_status;
Xorriso_startup_libraries;
Xorriso__version;
local: *;
};

@ -1682,6 +1682,32 @@ next_command:;
} else if(strcmp(cmd,"test")==0) { /* This option does not exist. */
/* install temporary test code here */;
{
int pargc, pflag, max_words;
char **pargv= NULL, *pline, *prefix, *separators;
(*idx)+= 5;
pline= arg1;
prefix= arg2;
if(*idx - 3 < argc)
separators= argv[*idx - 3];
max_words= 0;
if(*idx - 2 < argc)
sscanf(argv[*idx - 2], "%d", &max_words);
pflag= 0;
if(*idx - 1 < argc)
sscanf(argv[*idx - 1], "%d", &pflag);
ret= Xorriso_parse_line(xorriso, pline, prefix, separators, max_words,
&pargc, &pargv, pflag);
fprintf(stderr,
"xorriso_test: Xorriso_parse_line: ret= %d , argc= %d , argv= 0x%lX\n",
ret, pargc, (unsigned long) pargv);
if(ret == 1)
for(i= 0; i < pargc; i++)
fprintf(stderr, "xorriso_test: argv[%d]= '%s'\n", i, pargv[i]);
Xorriso__dispose_words(&pargc, &pargv);
}
} else if(strcmp(cmd,"toc")==0) {
Xorriso_option_toc(xorriso, 0);
@ -1776,6 +1802,53 @@ ex:;
}
int Xorriso_parse_line(struct XorrisO *xorriso, char *line,
char *prefix, char *separators, int max_words,
int *argc, char ***argv, int flag)
{
int ret;
char *to_parse;
*argc= 0;
*argv= NULL;
to_parse= line;
if(prefix[0]) {
if(strncmp(line, prefix, strlen(prefix)) == 0) {
to_parse= line + strlen(prefix);
} else {
ret= 2; goto ex;
}
}
ret= Sfile_sep_make_argv(xorriso->progname, to_parse, separators,
max_words, argc, argv,
(!(flag & 32)) | 4 | ((xorriso->bsl_interpretation & 3) << 5));
if(ret < 0) {
Xorriso_msgs_submit(xorriso, 0,
"Severe lack of resources during command line parsing", 0, "FATAL", 0);
goto ex;
}
if(ret == 0) {
sprintf(xorriso->info_text, "Incomplete quotation in %s line: %s",
(flag & 32) ? "command" : "parsed", to_parse);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto ex;
}
ret= 1;
ex:;
if(ret <= 0)
Sfile_sep_make_argv("", "", "", 0, argc, argv, 2); /* release memory */
return(ret);
}
void Xorriso__dispose_words(int *argc, char ***argv)
{
Sfile_make_argv("", "", argc, argv, 2); /* release memory */
}
int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag)
/*
bit0-bit15 are forwarded to Xorriso_interpreter
@ -1795,20 +1868,10 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag)
xorriso->idle_time= 0.0;
tdiff= tv.tv_sec+(1.e-6*(double) tv.tv_usec);
/* parse line into args */
ret= Sfile_make_argv(xorriso->progname, line, &argc, &argv,
4 | ((xorriso->bsl_interpretation & 3) << 5));
if(ret < 0) {
Xorriso_msgs_submit(xorriso, 0,
"Severe lack of resources during command line parsing", 0, "FATAL", 0);
goto ex;
}
if(ret == 0) {
sprintf(xorriso->info_text, "Incomplete quotation in command line: %s",
line);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= Xorriso_parse_line(xorriso, line, "", "", 0, &argc, &argv, 32 | 64);
if(ret <= 0)
goto ex;
}
if(argc<2)
{ret= 1; goto ex;}
if(argv[1][0]=='#')
@ -1931,7 +1994,7 @@ int Xorriso_prescan_args(struct XorrisO *xorriso, int argc, char **argv,
arg1= argv[i+1];
arg2= "";
if(i+2<argc)
arg2= argv[2+1];
arg2= argv[i+2];
if(i>1)
xorriso->did_something_useful= 1;
if(i==1 && argc==2) {

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2010 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2012 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -638,8 +638,8 @@ int Sfile_destroy_argv(int *argc, char ***argv, int flag)
}
int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv,
int flag)
int Sfile_sep_make_argv(char *progname, char *line, char *separators,
int max_words, int *argc, char ***argv, int flag)
/*
bit0= read progname as first argument from line
bit1= just release argument list argv and return
@ -682,12 +682,26 @@ int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv,
if(pass==0) maxl= 0;
}
while(*(++cpt)!=0){
if(isspace(*cpt)) continue;
if(*separators) {
if(strchr(separators, *cpt) != NULL)
continue;
} else if(isspace(*cpt))
continue;
start= cpt;
buf[0]= 0;
cpt--;
if(max_words > 0 && argzaehl >= max_words && *cpt != 0) {
/* take uninterpreted up to the end */
cpt+= strlen(cpt) - 1;
}
while(*(++cpt)!=0) {
if(isspace(*cpt)) break;
if(*separators) {
if(strchr(separators, *cpt) != NULL)
break;
} else if(isspace(*cpt))
break;
if(*cpt=='"'){
l= cpt-start; bufl= strlen(buf);
if(l>0) {
@ -794,6 +808,13 @@ ex:
}
int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv,
int flag)
{
return Sfile_sep_make_argv(progname, line, "", 0, argc, argv, flag);
}
/* @param flag bit0= append */
int Sfile_str(char target[SfileadrL], char *source, int flag)
{

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2010 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2012 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -93,6 +93,8 @@ int Sfile_argv_bsl(int argc, char ***argv, int flag);
*/
int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv,
int flag);
int Sfile_sep_make_argv(char *progname, char *line, char *separators,
int max_argc, int *argc, char ***argv, int flag);
/* YYMMDD[.hhmm[ss]] */
int Sfile_decode_datestr(struct tm *reply, char *text, int flag);

@ -287,10 +287,7 @@ int Xorriso_read_rc(struct XorrisO *xorriso, int flag);
(*argv)[1] to (*argv)[argc-1] contain commands and parameters
If argv after the call differs from argv before the call,
then one should dispose it later by:
for(i= 0; i < argc; i++)
if(argv[i] != NULL)
free(argv[i]);
free(argv);
Xorriso__dispose_words(argc, argv);
@param flag unused yet, submit 0
@return <= 0 error , > 0 success
*/
@ -305,7 +302,7 @@ int Xorriso_program_arg_bsl(struct XorrisO *xorriso, int argc, char ***argv,
parameters. All parameters must be given in the same call as their command.
@since 1.2.2:
Commands may get arranged in a sequence that is most likely to make sense.
E.g. image loading settings before drive aquiration, then commands fori
E.g. image loading settings before drive aquiration, then commands for
adding files, then settings for writing, then writing.
This feature may be enabled by command "-x" in Xorriso_prescan_args()
or by parameter flag of this call.
@ -357,6 +354,71 @@ int Xorriso_interpreter(struct XorrisO *xorriso,
int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
/* 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
set of separator characters, and to restrict the number of parsed words.
@since 1.2.6
@param xorriso The context object which provides settings for parsing
@param line A text of one or more words according to man xorriso
paragraph "Command processing" up to and including
"Backslash Interpretation".
@param prefix If not empty then the line will only be parsed if it
begins by the prefix text. Parsing will then begin after
the end of the prefix.
If the prefix does not match, then 0 will be returned
in *argc, argv will be NULL, and the return value will
be 2.
@param separators If not empty this overrides the default list of word
separating characters. Default set is the one of
isspace(3).
@param max_words If not 0: Maximum number of words to parse. If there
remains line text after the last parsed word and its
following separators, then this remainder is copied
unparsed into a final result word. In this case *argc
will be larger than max_words by one. Note that trailing
separators are considered to be followed by an empty
word.
@param argc Will return the number of allocated and filled word
strings.
@param argv Will return the array of word strings.
Do not forget to dispose the allocated memory by a
call to Xorriso__dispose_words().
@param flag Bitfield for control purposes
bit0= Override setting of -backslash_codes
bit1-4= With bit1: backslash behavior
0= off
1= in_double_quotes
2= in_quotes
3= with_quoted_input resp. on
bit5= Prepend the program name as (*argv)[0], so that
*argv is suitable for Xorriso_interpreter()
and other calls which expect this.
bit6= Issue failure message in case of return 0
@return <=0 means error and invalidity of *argv:
0 = Input format error. E.g. bad quotation mark.
-1 = Lack of resources. E.g. memory.
>0 means success but not necessarily a valid result:
1 = Result in argc and argv is valid (but may
be empty by argc == 0, argv == NULL).
2 = Line did not match prefix. Result is invalid
and empty.
*/
int Xorriso_parse_line(struct XorrisO *xorriso, char *line,
char *prefix, char *separators, int max_words,
int *argc, char ***argv, int flag);
/* Dispose a list of strings as allocated by Xorriso_parse_line() or
Xorriso_program_arg_bsl().
@since 1.2.6
@param argc A pointer to the number of allocated and filled word
strings. *argc will be set to 0 by this call.
@param argv A pointer to the array of word strings.
*argv will be set to NULL by this call.
*/
void Xorriso__dispose_words(int *argc, char ***argv);
/* Enter xorriso command line dialog mode, using libreadline if configured
at build time and not disabled at run time.
This call returns immediately if not option -dialog "on" was performed

@ -1 +1 @@
#define Xorriso_timestamP "2012.09.08.082759"
#define Xorriso_timestamP "2012.09.08.173754"

Loading…
Cancel
Save