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.
Copyright 2007-2010 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2014 Thomas Schmitt, <scdbackup@gmx.net>
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->action= 0; /* print */
m->prune= 0;
m->use_pattern= 1;
m->target= NULL; /* a mere pointer, not managed memory */
m->text_2= NULL; /* a mere pointer, not managed memory */
m->user= 0;
@ -500,6 +501,7 @@ int Findjob_new_node(struct FindjoB *job, struct ExprnodE **fnode,
/* If an operator is expected : use -and
@param flag bit0= prepare for a pseudo-test:
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)
{
@ -508,7 +510,11 @@ int Findjob_default_and(struct FindjoB *o, int flag)
if(Findjob_cursor_complete(o, 0)) {
if(flag & 1)
return(2);
ret= Findjob_and(o, 0);
if(flag & 2) {
ret= Findjob_or(o, 0);
} else {
ret= Findjob_and(o, 0);
}
if(ret <= 0)
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;
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)
return(ret);
t= o->cursor->test;
t->test_type= 11;
t->arg1= strdup(decision);
t->test_type= test_type;
t->arg1= strdup(arg1);
if(t->arg1 == NULL)
return(-1);
return(1);

View File

@ -1,7 +1,7 @@
/* 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.
@ -50,6 +50,8 @@ struct ExprtesT {
19= -has_hfs_bless int bless_index
20= -disk_path char *arg1
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;
@ -172,6 +174,7 @@ struct FindjoB {
*/
int action;
int prune;
int use_pattern;
/* action specific parameters */
char *target;
@ -241,7 +244,7 @@ int Findjob_set_bless_filter(struct XorrisO *xorriso, struct FindjoB *o,
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);

View File

@ -1,7 +1,7 @@
/* 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.
@ -2784,6 +2784,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
/* flag bit0= perform -disk_path rather than -disk_name
bit0= use_pattern
*/
int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest,
IsoNode *node, int flag)
@ -2792,6 +2793,7 @@ int Exprtest_match_disk_name(struct XorrisO *xorriso, struct ExprtesT *ftest,
int ret;
char *disk_path= NULL, *npt;
regmatch_t name_match;
char *arg1;
void *arg2;
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= 0; goto ex;}
}
arg1= (char *) ftest->arg1;
arg2= ftest->arg2;
npt= strrchr(disk_path, '/');
if(npt != NULL)
npt++;
else
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:;
Xorriso_free_meM(disk_path);
return(ret);
@ -2859,8 +2866,12 @@ return:
value= 0;
break; case 1: /* -name *arg1 (regex in *arg2) */
ret= regexec(arg2, name, 1, &name_match, 0);
value= !ret;
if (ftest->boss->use_pattern) {
ret= regexec(arg2, name, 1, &name_match, 0);
value= !ret;
} else {
value= (strcmp((char *) arg1, name) == 0);
}
break; case 2: /* -type *arg1 */
value= 1;
@ -2997,15 +3008,20 @@ return:
ftest->boss->prune= 1;
break; case 13: /* -wholename *arg1 (regex in *arg2) */
ret= regexec(arg2, path, 1, &name_match, 0);
value= !ret;
if (ftest->boss->use_pattern) {
ret= regexec(arg2, path, 1, &name_match, 0);
value= !ret;
} else {
value= (strcmp(arg1, path) == 0);
}
break; case 15: /* -has_md5 */
ret= Xorriso_get_md5(xorriso, node, path, md5, 1);
value= (ret > 0);
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 */
value= 1;
@ -3045,7 +3061,8 @@ return:
}
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 */
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 */
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:
/* >>> 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))
xorriso->find_compare_result= 1;
for(i= *idx+1; i<end_idx; i++) {
ret= 1;
if(strcmp(argv[i], "-name")==0) {
if(i+1>=end_idx) {
not_enough_arguments:;
@ -863,41 +864,86 @@ not_enough_arguments:;
}
} else if(strcmp(argv[i], "-true") == 0) {
ret= Findjob_set_false(job, -1, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-false") == 0) {
ret= Findjob_set_false(job, 1, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-decision") == 0) {
if(i+1>=end_idx)
goto not_enough_arguments;
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) {
ret= Findjob_set_prune(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-sub") == 0 || strcmp(argv[i], "(") == 0) {
ret= Findjob_open_bracket(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-subend") == 0 || strcmp(argv[i], ")") == 0) {
ret= Findjob_close_bracket(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-not") == 0 || strcmp(argv[i], "!") == 0) {
ret= Findjob_not(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-and") == 0 || strcmp(argv[i], "-a") == 0) {
ret= Findjob_and(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-or") == 0 || strcmp(argv[i], "-o") == 0) {
ret= Findjob_or(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-if") == 0) {
ret= Findjob_if(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-then") == 0) {
ret= Findjob_then(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-else") == 0) {
ret= Findjob_else(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-elseif") == 0) {
ret= Findjob_elseif(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-endif") == 0) {
ret= Findjob_endif(job, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-sort_lba") == 0) {
flag|= 8;
/* If an operator is open: insert a -true test, else do nothing */
ret= Findjob_set_false(job, -1, 1);
if(ret == 2)
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) {
if(i+1>=end_idx) {
not_enough_exec_arguments:;

View File

@ -9,7 +9,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" 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.
.\"
.\" 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
dive into that directory. This test itself does always match.
.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" :
If this test is reached then the evaluation ends immediately and action
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
then -find will not dive into that directory. This test
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" :
If this test is reached then the evaluation ends immediately
and action is performed if the decision is "yes" or "true".
@ -5481,43 +5493,43 @@ Node: Insert47999
Node: SetInsert58213
Node: Manip66790
Node: CmdFind76570
Node: Filter93171
Node: Writing97727
Node: SetWrite107858
Node: Bootable128564
Node: Jigdo145931
Node: Charset150178
Node: Exception153493
Node: DialogCtl159613
Node: Inquiry162211
Node: Navigate169346
Node: Verify177644
Node: Restore186908
Node: Emulation193995
Node: Scripting204383
Node: Frontend212154
Node: Examples221761
Node: ExDevices222939
Node: ExCreate223605
Node: ExDialog224890
Node: ExGrowing226155
Node: ExModifying226960
Node: ExBootable227464
Node: ExCharset228016
Node: ExPseudo228908
Node: ExCdrecord229806
Node: ExMkisofs230123
Node: ExGrowisofs231463
Node: ExException232598
Node: ExTime233052
Node: ExIncBackup233511
Node: ExRestore237491
Node: ExRecovery238424
Node: Files238994
Node: Seealso240293
Node: Bugreport241016
Node: Legal241597
Node: CommandIdx242608
Node: ConceptIdx259343
Node: Filter93845
Node: Writing98401
Node: SetWrite108532
Node: Bootable129238
Node: Jigdo146605
Node: Charset150852
Node: Exception154167
Node: DialogCtl160287
Node: Inquiry162885
Node: Navigate170020
Node: Verify178318
Node: Restore187582
Node: Emulation194669
Node: Scripting205057
Node: Frontend212828
Node: Examples222435
Node: ExDevices223613
Node: ExCreate224279
Node: ExDialog225564
Node: ExGrowing226829
Node: ExModifying227634
Node: ExBootable228138
Node: ExCharset228690
Node: ExPseudo229582
Node: ExCdrecord230480
Node: ExMkisofs230797
Node: ExGrowisofs232137
Node: ExException233272
Node: ExTime233726
Node: ExIncBackup234185
Node: ExRestore238165
Node: ExRecovery239098
Node: Files239668
Node: Seealso240967
Node: Bugreport241690
Node: Legal242271
Node: CommandIdx243282
Node: ConceptIdx260017

End Tag Table

View File

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps
@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 .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 .\"
@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
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" :
If this test is reached then the evaluation ends immediately and action
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"