New -find pseudo tests -use_pattern , -or_use_pattern

This commit is contained in:
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-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 */;