Returning true in the functor stops the file listing.

This commit is contained in:
King_DuckZ 2020-03-04 01:14:33 +01:00
parent 17f72fcbdf
commit a9798ac94e
2 changed files with 23 additions and 8 deletions

View file

@ -11,12 +11,14 @@ extern(C) {
int scan_iso (const(char)* filename, iso_listing_callback callback, void* user_data); int scan_iso (const(char)* filename, iso_listing_callback callback, void* user_data);
private int printer(void*, const(char)* path, int is_dir) { private int printer(void*, const(char)* path, int is_dir) {
writef("Entry \"%s\"", path.fromStringz); auto spath = path.fromStringz;
writef("Entry \"%s\"", spath);
if (is_dir != 0) { if (is_dir != 0) {
write(" (directory)"); write(" (directory)");
} }
write("\n"); write("\n");
return 0; return (spath == "/UMD_DATA.BIN" ? 1 : 0);
} }
} }

View file

@ -199,7 +199,7 @@ LOCAL void extract_file __PR((struct scsi_dev *dev, int f,
LOCAL void parse_cl_dir __PR((struct scsi_dev *dev, LOCAL void parse_cl_dir __PR((struct scsi_dev *dev,
struct iso_directory_record *idr, int extent)); struct iso_directory_record *idr, int extent));
LOCAL BOOL parse_de __PR((struct iso_directory_record *idr)); LOCAL BOOL parse_de __PR((struct iso_directory_record *idr));
LOCAL void parse_dir __PR((struct scsi_dev *dev, struct todo *dp, LOCAL int parse_dir __PR((struct scsi_dev *dev, struct todo *dp,
char * rootname, int extent, int len, char * rootname, int extent, int len,
iso_listing_callback callback, void* user_data)); iso_listing_callback callback, void* user_data));
LOCAL void list_locales __PR((void)); LOCAL void list_locales __PR((void));
@ -902,7 +902,7 @@ parse_de(idr)
return (TRUE); return (TRUE);
} }
LOCAL void LOCAL int
parse_dir(dev, dp, rootname, extent, len, callback, user_data) parse_dir(dev, dp, rootname, extent, len, callback, user_data)
struct scsi_dev *dev; struct scsi_dev *dev;
struct todo *dp; struct todo *dp;
@ -922,6 +922,7 @@ parse_dir(dev, dp, rootname, extent, len, callback, user_data)
int rlen; int rlen;
int blen; int blen;
int rr_flags = 0; int rr_flags = 0;
int stop_now = 0;
static char *n = 0; static char *n = 0;
static int nlen = 0; static int nlen = 0;
@ -988,7 +989,9 @@ static int nlen = 0;
int nextent; int nextent;
struct todo *tp = dp; struct todo *tp = dp;
(*callback)(user_data, n, 1); stop_now = (*callback)(user_data, n, 1);
if (stop_now)
break;
nextent = isonum_733((unsigned char *)idr->extent); nextent = isonum_733((unsigned char *)idr->extent);
while (tp) { while (tp) {
@ -1021,7 +1024,10 @@ static int nlen = 0;
(idr->name[0] != 0 || idr->name[0] != 1)) { (idr->name[0] != 0 || idr->name[0] != 1)) {
/* this is . or .. */ /* this is . or .. */
} else { } else {
callback(user_data, n, 0); stop_now = callback(user_data, n, 0);
if (stop_now)
break;
if (xtract && strcmp(xtract, n) == 0) { if (xtract && strcmp(xtract, n) == 0) {
extract_file(dev, STDOUT_FILENO, idr, "stdout"); extract_file(dev, STDOUT_FILENO, idr, "stdout");
} }
@ -1088,6 +1094,9 @@ static int nlen = 0;
i += buffer[i]; i += buffer[i];
if (i > 2048 - offsetof(struct iso_directory_record, name[0])) break; if (i > 2048 - offsetof(struct iso_directory_record, name[0])) break;
} }
if (stop_now)
break;
} }
if (Xtract) { if (Xtract) {
char *nm = strrchr(rootname, '/'); char *nm = strrchr(rootname, '/');
@ -1095,6 +1104,7 @@ static int nlen = 0;
if (nm != rootname) if (nm != rootname)
nm++; nm++;
} }
return stop_now;
} }
EXPORT int EXPORT int
@ -1175,6 +1185,7 @@ run_scanning(dev, callback, user_data)
struct iso_directory_record * idr; struct iso_directory_record * idr;
char *charset = NULL; char *charset = NULL;
int voldesc_sum = 0; int voldesc_sum = 0;
int stop_listing;
char *cp; char *cp;
#if defined(USE_NLS) #if defined(USE_NLS)
@ -1357,11 +1368,13 @@ run_scanning(dev, callback, user_data)
if (use_joliet) if (use_joliet)
idr = (struct iso_directory_record *)jpd.root_directory_record; idr = (struct iso_directory_record *)jpd.root_directory_record;
parse_dir(dev, todo_idr, "/", isonum_733((unsigned char *)idr->extent), stop_listing = parse_dir(dev, todo_idr, "/",
isonum_733((unsigned char *)idr->extent),
isonum_733((unsigned char *)idr->size), callback, user_data); isonum_733((unsigned char *)idr->size), callback, user_data);
td = todo_idr; td = todo_idr;
while (td) { while (td) {
parse_dir(dev, td, td->name, td->extent, td->length, callback, user_data); if (!stop_listing)
stop_listing = parse_dir(dev, td, td->name, td->extent, td->length, callback, user_data);
free(td->name); free(td->name);
td = td->next; td = td->next;
} }