--group-dir option for ls

John Love-Jensen <[email protected]> Sat, 17 May 2003 15:26:58 -0500
Newsgroups gmane.comp.gnu.fileutils.bugs
Message-ID <[email protected]>
For fileutils-4.1

Here are the changes to add in the facility to group directories 
together.

--Eljay

"Obsession - enjoy in moderation."

diff ls.c_original ls.c

271a272,273
 > static int compare_dir PARAMS ((const struct fileinfo *file1,
 >                                 const struct fileinfo *file2));
437a440,441
 > /* Group directories first. */
 > static int sort_group_dir;
666c670,671
<   TIME_OPTION
---
 >   TIME_OPTION,
 >   GROUP_DIR_OPTION
702a708
 >   {"group-dir", optional_argument, 0, GROUP_DIR_OPTION},
1315a1322,1325
 >       case GROUP_DIR_OPTION:
 >         sort_group_dir = 1;
 >         break;
 >
2134a2145,2146
 > int (*secondary_sort) ();
 >
2175a2188,2192
 >   if (sort_group_dir) {
 >     secondary_sort = func;
 >     func = compare_dir;
 >   }
 >
2176a2194,2201
 > }
 >
 > static int
 > compare_dir (const struct fileinfo *file1, const struct fileinfo 
*file2)
 > {
 >   if ((S_ISDIR(file1->stat.st_mode) != 0) == 
(S_ISDIR(file2->stat.st_mode) != 0))
 >     return secondary_sort(file1, file2);
 >   return S_ISDIR(file1->stat.st_mode) ? -1 : 1;