New -find pseudo tests -use_pattern , -or_use_pattern

This commit is contained in:
Thomas Schmitt 2014-04-16 14:42:40 +00:00
parent ab534f7ae5
commit 134f8c6960
8 changed files with 177 additions and 60 deletions

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2010 Thomas Schmitt, <scdbackup@gmx.net> Copyright 2007-2014 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later. Provided under GPL version 2 or later.
@ -367,6 +367,7 @@ int Findjob_new(struct FindjoB **o, char *start_path, int flag)
m->use_shortcuts= 1; m->use_shortcuts= 1;
m->action= 0; /* print */ m->action= 0; /* print */
m->prune= 0; m->prune= 0;
m->use_pattern= 1;
m->target= NULL; /* a mere pointer, not managed memory */ m->target= NULL; /* a mere pointer, not managed memory */
m->text_2= NULL; /* a mere pointer, not managed memory */ m->text_2= NULL; /* a mere pointer, not managed memory */
m->user= 0; m->user= 0;
@ -500,6 +501,7 @@ int Findjob_new_node(struct FindjoB *job, struct ExprnodE **fnode,
/* If an operator is expected : use -and /* If an operator is expected : use -and
@param flag bit0= prepare for a pseudo-test: @param flag bit0= prepare for a pseudo-test:
if an operator is expected, do nothing and return 2 if an operator is expected, do nothing and return 2
bit1= use -or rather than -and
*/ */
int Findjob_default_and(struct FindjoB *o, int flag) int Findjob_default_and(struct FindjoB *o, int flag)
{ {
@ -508,7 +510,11 @@ int Findjob_default_and(struct FindjoB *o, int flag)
if(Findjob_cursor_complete(o, 0)) { if(Findjob_cursor_complete(o, 0)) {
if(flag & 1) if(flag & 1)
return(2); return(2);
ret= Findjob_and(o, 0); if(flag & 2) {
ret= Findjob_or(o, 0);
} else {
ret= Findjob_and(o, 0);
}
if(ret <= 0) if(ret <= 0)
return(ret); return(ret);
} }
@ -1038,18 +1044,19 @@ int Findjob_set_commit_filter_2(struct FindjoB *o, int flag)
} }
int Findjob_set_decision(struct FindjoB *o, char *decision, int flag) int Findjob_set_arg1(struct FindjoB *o, int test_type, char *arg1, int flag)
{ {
struct ExprtesT *t; struct ExprtesT *t;
int ret; int ret, hflag= 0;
ret= Findjob_default_and(o, 0); if(test_type == 23)
hflag= 2; /* prepend -or rather than -and */
ret= Findjob_default_and(o, hflag);
if(ret <= 0) if(ret <= 0)
return(ret); return(ret);
t= o->cursor->test; t= o->cursor->test;
t->test_type= 11; t->test_type= test_type;
t->arg1= strdup(decision); t->arg1= strdup(arg1);
if(t->arg1 == NULL) if(t->arg1 == NULL)
return(-1); return(-1);
return(1); return(1);

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2012 Thomas Schmitt, <scdbackup@gmx.net> Copyright 2007-2014 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later. Provided under GPL version 2 or later.
@ -50,6 +50,8 @@ struct ExprtesT {
19= -has_hfs_bless int bless_index 19= -has_hfs_bless int bless_index
20= -disk_path char *arg1 20= -disk_path char *arg1
21= -bad_outname int namespace 21= -bad_outname int namespace
22= -use_pattern char *arg1 ("on" [or "ls"], "off")
23= -or_use_pattern char *arg1 ("on" [or "ls"], "off")
*/ */
int test_type; int test_type;
@ -172,6 +174,7 @@ struct FindjoB {
*/ */
int action; int action;
int prune; int prune;
int use_pattern;
/* action specific parameters */ /* action specific parameters */
char *target; char *target;
@ -241,7 +244,7 @@ int Findjob_set_bless_filter(struct XorrisO *xorriso, struct FindjoB *o,
char *blessing, int flag); char *blessing, int flag);
int Findjob_set_decision(struct FindjoB *o, char *decision, int flag); int Findjob_set_arg1(struct FindjoB *o, int test_type, char *arg1, int flag);
int Findjob_open_bracket(struct FindjoB *job, int flag); int Findjob_open_bracket(struct FindjoB *job, int flag);

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2013 Thomas Schmitt, <scdbackup@gmx.net> Copyright 2007-2014 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later. Provided under GPL version 2 or later.
@ -2784,6 +2784,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
/* flag bit0= perform -disk_path rather than -disk_name /* flag bit0= perform -disk_path rather than -disk_name
bit0= use_pattern
*/ */
int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest, int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest,
IsoNode *node, int flag) IsoNode *node, int flag)
@ -2792,6 +2793,7 @@ int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest,
int ret; int ret;
char *disk_path= NULL, *npt; char *disk_path= NULL, *npt;
regmatch_t name_match; regmatch_t name_match;
char *arg1;
void *arg2; void *arg2;
Xorriso_alloc_meM(disk_path, char, SfileadrL); Xorriso_alloc_meM(disk_path, char, SfileadrL);
@ -2804,13 +2806,18 @@ int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest,
{ret= 1; goto ex;} {ret= 1; goto ex;}
{ret= 0; goto ex;} {ret= 0; goto ex;}
} }
arg1= (char *) ftest->arg1;
arg2= ftest->arg2; arg2= ftest->arg2;
npt= strrchr(disk_path, '/'); npt= strrchr(disk_path, '/');
if(npt != NULL) if(npt != NULL)
npt++; npt++;
else else
npt= disk_path; npt= disk_path;
ret= ! regexec(arg2, npt, 1, &name_match, 0); if(flag & 2) {
ret= ! regexec(arg2, npt, 1, &name_match, 0);
} else {
ret= (strcmp(arg1, npt) == 0);
}
ex:; ex:;
Xorriso_free_meM(disk_path); Xorriso_free_meM(disk_path);
return(ret); return(ret);
@ -2859,8 +2866,12 @@ return:
value= 0; value= 0;
break; case 1: /* -name *arg1 (regex in *arg2) */ break; case 1: /* -name *arg1 (regex in *arg2) */
ret= regexec(arg2, name, 1, &name_match, 0); if (ftest->boss->use_pattern) {
value= !ret; ret= regexec(arg2, name, 1, &name_match, 0);
value= !ret;
} else {
value= (strcmp((char *) arg1, name) == 0);
}
break; case 2: /* -type *arg1 */ break; case 2: /* -type *arg1 */
value= 1; value= 1;
@ -2997,15 +3008,20 @@ return:
ftest->boss->prune= 1; ftest->boss->prune= 1;
break; case 13: /* -wholename *arg1 (regex in *arg2) */ break; case 13: /* -wholename *arg1 (regex in *arg2) */
ret= regexec(arg2, path, 1, &name_match, 0); if (ftest->boss->use_pattern) {
value= !ret; ret= regexec(arg2, path, 1, &name_match, 0);
value= !ret;
} else {
value= (strcmp(arg1, path) == 0);
}
break; case 15: /* -has_md5 */ break; case 15: /* -has_md5 */
ret= Xorriso_get_md5(xorriso, node, path, md5, 1); ret= Xorriso_get_md5(xorriso, node, path, md5, 1);
value= (ret > 0); value= (ret > 0);
break; case 16: /* -disk_name *arg1 (regex in *arg2) */ break; case 16: /* -disk_name *arg1 (regex in *arg2) */
value= !! Exprtest_match_disk_name(xorriso, ftest, node, 0); value= !! Exprtest_match_disk_name(xorriso, ftest, node,
2 * (ftest->boss->use_pattern));
break; case 17: /* -hidden int *arg1 */ break; case 17: /* -hidden int *arg1 */
value= 1; value= 1;
@ -3045,7 +3061,8 @@ return:
} }
break; case 20: /* -disk_path */ break; case 20: /* -disk_path */
value= !! Exprtest_match_disk_name(xorriso, ftest, node, 1); value= !! Exprtest_match_disk_name(xorriso, ftest, node,
1 | 2 * (ftest->boss->use_pattern));
break; case 21: /* -bad_outname */ break; case 21: /* -bad_outname */
ret= Xorriso_test_outchar(xorriso, node, *((int *) arg1), 0); ret= Xorriso_test_outchar(xorriso, node, *((int *) arg1), 0);
@ -3055,6 +3072,14 @@ return:
} }
value= !ret; /* Xorriso_test_outchar() returns 1 for good and 0 for bad */ value= !ret; /* Xorriso_test_outchar() returns 1 for good and 0 for bad */
break; case 22: /* -use_pattern */
ftest->boss->use_pattern= (strcmp(arg1, "off") != 0);
value= 1;
break; case 23: /* -or_use_pattern */
ftest->boss->use_pattern= (strcmp(arg1, "off") != 0);
value= 0;
break; default: break; default:
/* >>> complain about unknown test type */; /* >>> complain about unknown test type */;

View File

@ -720,6 +720,7 @@ int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
if(!(flag&2)) if(!(flag&2))
xorriso->find_compare_result= 1; xorriso->find_compare_result= 1;
for(i= *idx+1; i<end_idx; i++) { for(i= *idx+1; i<end_idx; i++) {
ret= 1;
if(strcmp(argv[i], "-name")==0) { if(strcmp(argv[i], "-name")==0) {
if(i+1>=end_idx) { if(i+1>=end_idx) {
not_enough_arguments:; not_enough_arguments:;
@ -863,41 +864,86 @@ not_enough_arguments:;
} }
} else if(strcmp(argv[i], "-true") == 0) { } else if(strcmp(argv[i], "-true") == 0) {
ret= Findjob_set_false(job, -1, 0); ret= Findjob_set_false(job, -1, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-false") == 0) { } else if(strcmp(argv[i], "-false") == 0) {
ret= Findjob_set_false(job, 1, 0); ret= Findjob_set_false(job, 1, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-decision") == 0) { } else if(strcmp(argv[i], "-decision") == 0) {
if(i+1>=end_idx) if(i+1>=end_idx)
goto not_enough_arguments; goto not_enough_arguments;
i++; i++;
ret= Findjob_set_decision(job, argv[i], 0); ret= Findjob_set_arg1(job, 11, argv[i], 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-prune") == 0) { } else if(strcmp(argv[i], "-prune") == 0) {
ret= Findjob_set_prune(job, 0); ret= Findjob_set_prune(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-sub") == 0 || strcmp(argv[i], "(") == 0) { } else if(strcmp(argv[i], "-sub") == 0 || strcmp(argv[i], "(") == 0) {
ret= Findjob_open_bracket(job, 0); ret= Findjob_open_bracket(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-subend") == 0 || strcmp(argv[i], ")") == 0) { } else if(strcmp(argv[i], "-subend") == 0 || strcmp(argv[i], ")") == 0) {
ret= Findjob_close_bracket(job, 0); ret= Findjob_close_bracket(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-not") == 0 || strcmp(argv[i], "!") == 0) { } else if(strcmp(argv[i], "-not") == 0 || strcmp(argv[i], "!") == 0) {
ret= Findjob_not(job, 0); ret= Findjob_not(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-and") == 0 || strcmp(argv[i], "-a") == 0) { } else if(strcmp(argv[i], "-and") == 0 || strcmp(argv[i], "-a") == 0) {
ret= Findjob_and(job, 0); ret= Findjob_and(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-or") == 0 || strcmp(argv[i], "-o") == 0) { } else if(strcmp(argv[i], "-or") == 0 || strcmp(argv[i], "-o") == 0) {
ret= Findjob_or(job, 0); ret= Findjob_or(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-if") == 0) { } else if(strcmp(argv[i], "-if") == 0) {
ret= Findjob_if(job, 0); ret= Findjob_if(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-then") == 0) { } else if(strcmp(argv[i], "-then") == 0) {
ret= Findjob_then(job, 0); ret= Findjob_then(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-else") == 0) { } else if(strcmp(argv[i], "-else") == 0) {
ret= Findjob_else(job, 0); ret= Findjob_else(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-elseif") == 0) { } else if(strcmp(argv[i], "-elseif") == 0) {
ret= Findjob_elseif(job, 0); ret= Findjob_elseif(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-endif") == 0) { } else if(strcmp(argv[i], "-endif") == 0) {
ret= Findjob_endif(job, 0); ret= Findjob_endif(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-sort_lba") == 0) { } else if(strcmp(argv[i], "-sort_lba") == 0) {
flag|= 8; flag|= 8;
/* If an operator is open: insert a -true test, else do nothing */ /* If an operator is open: insert a -true test, else do nothing */
ret= Findjob_set_false(job, -1, 1); ret= Findjob_set_false(job, -1, 1);
if(ret == 2) if(ret == 2)
ret= 1; ret= 1;
} else if(strcmp(argv[i], "-use_pattern") == 0 ||
strcmp(argv[i], "-or_use_pattern") == 0) {
if(i + 1 >= end_idx)
goto not_enough_arguments;
i++;
ret= Findjob_set_arg1(job,
22 + (strcmp(argv[i], "-or_use_pattern") == 0),
argv[i], 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-or_use_pattern") == 0) {
if(i + 1 >= end_idx)
goto not_enough_arguments;
i++;
ret= Findjob_set_arg1(job, 23, argv[i], 1);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-exec")==0) { } else if(strcmp(argv[i], "-exec")==0) {
if(i+1>=end_idx) { if(i+1>=end_idx) {
not_enough_exec_arguments:; not_enough_exec_arguments:;

View File

@ -9,7 +9,7 @@
.\" First parameter, NAME, should be all caps .\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1) .\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "Version 1.3.7, Apr 12, 2014" .TH XORRISO 1 "Version 1.3.7, Apr 16, 2014"
.\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.\" Some roff macros, for reference: .\" Some roff macros, for reference:
@ -1817,6 +1817,18 @@ to name length, permissible characters, and mandatory name components.
If this test is reached and the tested file is a directory then \-find will not If this test is reached and the tested file is a directory then \-find will not
dive into that directory. This test itself does always match. dive into that directory. This test itself does always match.
.br .br
\fB\-use_pattern\fR "on"|"off" :
This pseudo test controls the interpretation of wildcards with tests
\-name, \-wholename, and \-disk_name. Default is "on". If interpretation
is disabled by "off", then the parameters of \-name, \-wholename, and \-disk_name
have to match literally rather than as regular expression.
This test itself does always match.
.br
\fB\-or_use_pattern\fR "on"|"off" :
Like \-use_pattern, but automatically appending the test by \-or rather
than by \-and. Further the test itself does never match. So a subsequent
test \-or will cause its other operand to be performed.
.br
\fB\-decision\fR "yes"|"no" : \fB\-decision\fR "yes"|"no" :
If this test is reached then the evaluation ends immediately and action If this test is reached then the evaluation ends immediately and action
is performed if the decision is "yes" or "true". See operator \-if. is performed if the decision is "yes" or "true". See operator \-if.

View File

@ -1629,6 +1629,18 @@ File: xorriso.info, Node: CmdFind, Next: Filter, Prev: Manip, Up: Commands
If this test is reached and the tested file is a directory If this test is reached and the tested file is a directory
then -find will not dive into that directory. This test then -find will not dive into that directory. This test
itself does always match. itself does always match.
-use_pattern "on"|"off" :
This pseudo test controls the interpretation of wildcards
with tests -name, -wholename, and -disk_name. Default is
"on". If interpretation is disabled by "off", then the
parameters of -name, -wholename, and -disk_name have to match
literally rather than as regular expression. This test
itself does always match.
-or_use_pattern "on"|"off" :
Like -use_pattern, but automatically appending the test by
-or rather than by -and. Further the test itself does never
match. So a subsequent test -or will cause its other operand
to be performed.
-decision "yes"|"no" : -decision "yes"|"no" :
If this test is reached then the evaluation ends immediately If this test is reached then the evaluation ends immediately
and action is performed if the decision is "yes" or "true". and action is performed if the decision is "yes" or "true".
@ -5481,43 +5493,43 @@ Node: Insert47999
Node: SetInsert58213 Node: SetInsert58213
Node: Manip66790 Node: Manip66790
Node: CmdFind76570 Node: CmdFind76570
Node: Filter93171 Node: Filter93845
Node: Writing97727 Node: Writing98401
Node: SetWrite107858 Node: SetWrite108532
Node: Bootable128564 Node: Bootable129238
Node: Jigdo145931 Node: Jigdo146605
Node: Charset150178 Node: Charset150852
Node: Exception153493 Node: Exception154167
Node: DialogCtl159613 Node: DialogCtl160287
Node: Inquiry162211 Node: Inquiry162885
Node: Navigate169346 Node: Navigate170020
Node: Verify177644 Node: Verify178318
Node: Restore186908 Node: Restore187582
Node: Emulation193995 Node: Emulation194669
Node: Scripting204383 Node: Scripting205057
Node: Frontend212154 Node: Frontend212828
Node: Examples221761 Node: Examples222435
Node: ExDevices222939 Node: ExDevices223613
Node: ExCreate223605 Node: ExCreate224279
Node: ExDialog224890 Node: ExDialog225564
Node: ExGrowing226155 Node: ExGrowing226829
Node: ExModifying226960 Node: ExModifying227634
Node: ExBootable227464 Node: ExBootable228138
Node: ExCharset228016 Node: ExCharset228690
Node: ExPseudo228908 Node: ExPseudo229582
Node: ExCdrecord229806 Node: ExCdrecord230480
Node: ExMkisofs230123 Node: ExMkisofs230797
Node: ExGrowisofs231463 Node: ExGrowisofs232137
Node: ExException232598 Node: ExException233272
Node: ExTime233052 Node: ExTime233726
Node: ExIncBackup233511 Node: ExIncBackup234185
Node: ExRestore237491 Node: ExRestore238165
Node: ExRecovery238424 Node: ExRecovery239098
Node: Files238994 Node: Files239668
Node: Seealso240293 Node: Seealso240967
Node: Bugreport241016 Node: Bugreport241690
Node: Legal241597 Node: Legal242271
Node: CommandIdx242608 Node: CommandIdx243282
Node: ConceptIdx259343 Node: ConceptIdx260017
 
End Tag Table End Tag Table

View File

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps @c man .\" First parameter, NAME, should be all caps
@c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection @c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
@c man .\" other parameters are allowed: see man(7), man(1) @c man .\" other parameters are allowed: see man(7), man(1)
@c man .TH XORRISO 1 "Version 1.3.7, Apr 12, 2014" @c man .TH XORRISO 1 "Version 1.3.7, Apr 16, 2014"
@c man .\" Please adjust this date whenever revising the manpage. @c man .\" Please adjust this date whenever revising the manpage.
@c man .\" @c man .\"
@c man .\" Some roff macros, for reference: @c man .\" Some roff macros, for reference:
@ -2198,6 +2198,18 @@ to name length, permissible characters, and mandatory name components.
If this test is reached and the tested file is a directory then -find will not If this test is reached and the tested file is a directory then -find will not
dive into that directory. This test itself does always match. dive into that directory. This test itself does always match.
@* @*
@item -use_pattern "on"|"off" :
This pseudo test controls the interpretation of wildcards with tests
-name, -wholename, and -disk_name. Default is "on". If interpretation
is disabled by "off", then the parameters of -name, -wholename, and -disk_name
have to match literally rather than as regular expression.
This test itself does always match.
@*
@item -or_use_pattern "on"|"off" :
Like -use_pattern, but automatically appending the test by -or rather
than by -and. Further the test itself does never match. So a subsequent
test -or will cause its other operand to be performed.
@*
@item -decision "yes"|"no" : @item -decision "yes"|"no" :
If this test is reached then the evaluation ends immediately and action If this test is reached then the evaluation ends immediately and action
is performed if the decision is "yes" or "true". See operator -if. is performed if the decision is "yes" or "true". See operator -if.

View File

@ -1 +1 @@
#define Xorriso_timestamP "2014.04.14.190506" #define Xorriso_timestamP "2014.04.16.144146"