From e2c63be8ae8ce41574164498a95161f6fd1760d3 Mon Sep 17 00:00:00 2001 From: Bobbi Webber-Manners Date: Mon, 24 Feb 2020 22:32:18 -0500 Subject: [PATCH] Added no-op sort for use with -n filename case change option --- bobbi/sortdir.c#b00008 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bobbi/sortdir.c#b00008 b/bobbi/sortdir.c#b00008 index 93c83fd..4b4a793 100644 --- a/bobbi/sortdir.c#b00008 +++ b/bobbi/sortdir.c#b00008 @@ -2,7 +2,6 @@ * Bobbi January-February 2020 * * TODO: Fix mode - * TODO: Do-nothing sort option for use with case-change option * TODO: Case insensitive sort option * TODO: Tool for 'extending' volume dir to more than 4 blocks * TODO: Legacy/extended date format conversion @@ -195,6 +194,7 @@ int cmp_blocks_asc(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_desc(const void *a, const void *b); +int cmp_noop(const void *a, const void *b); void sortlist(char s); void printlist(void); uint blockidxtoblocknum(uint idx); @@ -1159,6 +1159,15 @@ int cmp_eof_desc(const void *a, const void *b) { return -1; } +/* + * No-op sort which just keeps items in the same order + */ +int cmp_noop(const void *a, const void *b) { + struct fileent *aa = (struct fileent*)a; + struct fileent *bb = (struct fileent*)b; + return aa->order - bb->order; +} + /* * Sort filelist[] * s defines the field to sort on @@ -1216,6 +1225,10 @@ void sortlist(char s) { qsort(filelist, numfiles, sizeof(struct fileent), cmp_eof_desc); break; + case '.': + qsort(filelist, numfiles, sizeof(struct fileent), + cmp_noop); + break; default: err(FATALBADARG, "Invalid sort option"); } @@ -1504,7 +1517,10 @@ int main(int argc, char *argv[]) { if (optind != argc - 1) usage(); - + + if ((strlen(caseopts) > 0) && (strlen(sortopts) == 0)) + strncpy(sortopts, ".", 1); + uchar dev; uint blk; if (firstblk(argv[optind], &dev, &blk) != 0) {