mirror of
https://github.com/bobbimanners/ProDOS-Utils.git
synced 2024-06-03 02:29:34 +00:00
Improved error handling when too many files to sort
This commit is contained in:
parent
2011ef9412
commit
3ce7f68f59
74
sortdir.c
74
sortdir.c
|
@ -3,8 +3,6 @@
|
||||||
*
|
*
|
||||||
* Bobbi January-June 2020
|
* Bobbi January-June 2020
|
||||||
*
|
*
|
||||||
* TODO: Fix bug - if too many files in a directory the blocks of the remaining
|
|
||||||
* files are not marked as used.
|
|
||||||
* TODO: Need code to write out modified freelist if there are fixes
|
* TODO: Need code to write out modified freelist if there are fixes
|
||||||
* TODO: Get both ProDOS-8 and GNO versions to build from this source
|
* TODO: Get both ProDOS-8 and GNO versions to build from this source
|
||||||
* TODO: Trimming unused directory blocks
|
* TODO: Trimming unused directory blocks
|
||||||
|
@ -38,6 +36,7 @@
|
||||||
* v0.75 Fix bug - crash when too many files to sort.
|
* v0.75 Fix bug - crash when too many files to sort.
|
||||||
* v0.76 Fix bug - checkfreeandused() not traversing all freelist.
|
* v0.76 Fix bug - checkfreeandused() not traversing all freelist.
|
||||||
* v0.77 Implemented zeroblock() for ProDOS-8.
|
* v0.77 Implemented zeroblock() for ProDOS-8.
|
||||||
|
* v0.78 Improved error handling when too many files to sort.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#pragma debug 9
|
//#pragma debug 9
|
||||||
|
@ -307,22 +306,22 @@ int subdirblocks(uchar device, uint keyblk, struct pd_dirent *ent,
|
||||||
void enqueuesubdir(uint blocknum, uint subdiridx);
|
void enqueuesubdir(uint blocknum, uint subdiridx);
|
||||||
int readdir(uint device, uint blocknum);
|
int readdir(uint device, uint blocknum);
|
||||||
#ifdef SORT
|
#ifdef SORT
|
||||||
void buildsorttable(char s, uchar callidx);
|
uchar buildsorttable(char s, uchar callidx);
|
||||||
int cmp_name_asc(const void *a, const void *b);
|
int cmp_name_asc(const void *a, const void *b);
|
||||||
int cmp_name_desc(const void *a, const void *b);
|
int cmp_name_desc(const void *a, const void *b);
|
||||||
int cmp_name_asc_ci(const void *a, const void *b);
|
int cmp_name_asc_ci(const void *a, const void *b);
|
||||||
int cmp_name_desc_ci(const void *a, const void *b);
|
int cmp_name_desc_ci(const void *a, const void *b);
|
||||||
int cmp_datetime_asc(const void *a, const void *b);
|
int cmp_datetime_asc(const void *a, const void *b);
|
||||||
int cmp_datetime_desc(const void *a, const void *b);
|
int cmp_datetime_desc(const void *a, const void *b);
|
||||||
int cmp_type_asc(const void *a, const void *b);
|
int cmp_type_asc(const void *a, const void *b);
|
||||||
int cmp_type_desc(const void *a, const void *b);
|
int cmp_type_desc(const void *a, const void *b);
|
||||||
int cmp_dir_beg(const void *a, const void *b);
|
int cmp_dir_beg(const void *a, const void *b);
|
||||||
int cmp_dir_end(const void *a, const void *b);
|
int cmp_dir_end(const void *a, const void *b);
|
||||||
int cmp_blocks_asc(const void *a, const void *b);
|
int cmp_blocks_asc(const void *a, const void *b);
|
||||||
int cmp_blocks_desc(const void *a, const void *b);
|
int cmp_blocks_desc(const void *a, const void *b);
|
||||||
int cmp_eof_asc(const void *a, const void *b);
|
int cmp_eof_asc(const void *a, const void *b);
|
||||||
int cmp_eof_desc(const void *a, const void *b);
|
int cmp_eof_desc(const void *a, const void *b);
|
||||||
void sortlist(char s);
|
void sortlist(char s);
|
||||||
#endif
|
#endif
|
||||||
void printlist(void);
|
void printlist(void);
|
||||||
uint blockidxtoblocknum(uint idx);
|
uint blockidxtoblocknum(uint idx);
|
||||||
|
@ -1214,7 +1213,7 @@ int readdir(uint device, uint blocknum) {
|
||||||
#endif
|
#endif
|
||||||
if (readdiskblock(device, blocknum, dirblkbuf) == -1) {
|
if (readdiskblock(device, blocknum, dirblkbuf) == -1) {
|
||||||
err(NONFATAL, err_rdblk1, blocknum);
|
err(NONFATAL, err_rdblk1, blocknum);
|
||||||
return 1;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr = (struct pd_dirhdr*)(dirblkbuf + PTRSZ);
|
hdr = (struct pd_dirhdr*)(dirblkbuf + PTRSZ);
|
||||||
|
@ -1234,11 +1233,11 @@ int readdir(uint device, uint blocknum) {
|
||||||
#ifdef CHECK
|
#ifdef CHECK
|
||||||
if (entsz != ENTSZ) {
|
if (entsz != ENTSZ) {
|
||||||
err(NONFATAL, err_entsz2, entsz, ENTSZ);
|
err(NONFATAL, err_entsz2, entsz, ENTSZ);
|
||||||
return 1;
|
goto done;
|
||||||
}
|
}
|
||||||
if (entperblk != ENTPERBLK) {
|
if (entperblk != ENTPERBLK) {
|
||||||
err(NONFATAL, err_entblk2, entperblk, ENTPERBLK);
|
err(NONFATAL, err_entblk2, entperblk, ENTPERBLK);
|
||||||
return 1;
|
goto done;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
idx = entsz + PTRSZ; /* Skip header */
|
idx = entsz + PTRSZ; /* Skip header */
|
||||||
|
@ -1394,10 +1393,10 @@ int readdir(uint device, uint blocknum) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
++numfiles;
|
++numfiles;
|
||||||
if (numfiles == maxfiles) {
|
// if (numfiles == maxfiles) {
|
||||||
err(NONFATAL, err_many);
|
// err(NONFATAL, err_many);
|
||||||
return 1;
|
// return 1; // TODO
|
||||||
}
|
// }
|
||||||
if (errcount == errsbeforeent) {
|
if (errcount == errsbeforeent) {
|
||||||
for (i = 0; i < 53 - strlen(namebuf); ++i)
|
for (i = 0; i < 53 - strlen(namebuf); ++i)
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
|
@ -1437,7 +1436,7 @@ int readdir(uint device, uint blocknum) {
|
||||||
#endif
|
#endif
|
||||||
if (readdiskblock(device, blocknum, dirblkbuf) == -1) {
|
if (readdiskblock(device, blocknum, dirblkbuf) == -1) {
|
||||||
err(NONFATAL, err_rdblk1, blocknum);
|
err(NONFATAL, err_rdblk1, blocknum);
|
||||||
return 1;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
blkentries = 1;
|
blkentries = 1;
|
||||||
|
@ -1460,6 +1459,7 @@ int readdir(uint device, uint blocknum) {
|
||||||
memcpy(curblk->data, dirblkbuf, BLKSZ);
|
memcpy(curblk->data, dirblkbuf, BLKSZ);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
done:
|
||||||
return errcount - errsbefore;
|
return errcount - errsbefore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1470,8 +1470,9 @@ int readdir(uint device, uint blocknum) {
|
||||||
* s - character representing the sorting mode
|
* s - character representing the sorting mode
|
||||||
* callidx - if 0, the routine populates the table, otherwise it updates
|
* callidx - if 0, the routine populates the table, otherwise it updates
|
||||||
* and existing table
|
* and existing table
|
||||||
|
* Returns 1 on error, 0 if OK.
|
||||||
*/
|
*/
|
||||||
void buildsorttable(char s, uchar callidx) {
|
uchar buildsorttable(char s, uchar callidx) {
|
||||||
static char namebuf[NMLEN+1];
|
static char namebuf[NMLEN+1];
|
||||||
uint off;
|
uint off;
|
||||||
uchar entry, i;
|
uchar entry, i;
|
||||||
|
@ -1489,6 +1490,7 @@ void buildsorttable(char s, uchar callidx) {
|
||||||
memcpy(dirblkbuf, b->data, BLKSZ);
|
memcpy(dirblkbuf, b->data, BLKSZ);
|
||||||
#endif
|
#endif
|
||||||
for (entry = firstent; entry <= ENTPERBLK; ++entry) {
|
for (entry = firstent; entry <= ENTPERBLK; ++entry) {
|
||||||
|
|
||||||
off = PTRSZ + (entry - 1) * entsz;
|
off = PTRSZ + (entry - 1) * entsz;
|
||||||
ent = (struct pd_dirent*)(dirblkbuf + off);
|
ent = (struct pd_dirent*)(dirblkbuf + off);
|
||||||
|
|
||||||
|
@ -1534,7 +1536,10 @@ void buildsorttable(char s, uchar callidx) {
|
||||||
dt.year, dt.month, dt.day, dt.hour, dt.minute);
|
dt.year, dt.month, dt.day, dt.hour, dt.minute);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++idx;
|
if (++idx == maxfiles) {
|
||||||
|
err(NONFATAL, err_many);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b = b->next;
|
b = b->next;
|
||||||
|
@ -1543,6 +1548,8 @@ void buildsorttable(char s, uchar callidx) {
|
||||||
}
|
}
|
||||||
if (callidx == 0)
|
if (callidx == 0)
|
||||||
numfiles = idx;
|
numfiles = idx;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1933,7 +1940,7 @@ void interactive(void) {
|
||||||
|
|
||||||
revers(1);
|
revers(1);
|
||||||
hlinechar(' ');
|
hlinechar(' ');
|
||||||
fputs("S O R T D I R v0.77 alpha Use ^ to return to previous question", stdout);
|
fputs("S O R T D I R v0.78 alpha Use ^ to return to previous question", stdout);
|
||||||
hlinechar(' ');
|
hlinechar(' ');
|
||||||
revers(0);
|
revers(0);
|
||||||
|
|
||||||
|
@ -2052,8 +2059,7 @@ q6:
|
||||||
void processdir(uint device, uint blocknum) {
|
void processdir(uint device, uint blocknum) {
|
||||||
uchar i, errs;
|
uchar i, errs;
|
||||||
flushall();
|
flushall();
|
||||||
errs = readdir(device, blocknum);
|
if (readdir(device, blocknum) != 0) {
|
||||||
if (errs != 0) {
|
|
||||||
err(NONFATAL, err_nosort);
|
err(NONFATAL, err_nosort);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -2065,7 +2071,11 @@ void processdir(uint device, uint blocknum) {
|
||||||
for (i = 0; i < strlen(sortopts); ++i) {
|
for (i = 0; i < strlen(sortopts); ++i) {
|
||||||
if (doverbose)
|
if (doverbose)
|
||||||
printf("[%c] ", sortopts[i]);
|
printf("[%c] ", sortopts[i]);
|
||||||
buildsorttable(sortopts[i], i);
|
if (buildsorttable(sortopts[i], i) != 0) {
|
||||||
|
err(NONFATAL, err_nosort);
|
||||||
|
putchar('\n');
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
sortlist(sortopts[i]);
|
sortlist(sortopts[i]);
|
||||||
}
|
}
|
||||||
if (doverbose)
|
if (doverbose)
|
||||||
|
|
BIN
sortdir.po
BIN
sortdir.po
Binary file not shown.
Loading…
Reference in New Issue
Block a user