Since )LIB and ]LIB will accept path names, I thought that it would be
useful for them to display directories.
Patch attached.
Notes:
1) You must specify an absolute path. This is existing behavior,
unchanged by the patch.
2) While the )LIB output is sorted, the ]LIB output is not. This is
existing behavior, unchanged by the patch.
Index: src/Command.cc
===================================================================
--- src/Command.cc (revision 346)
+++ src/Command.cc (working copy)
@@ -749,6 +749,7 @@
//
vector<UCS_string> apl_files;
vector<UCS_string> xml_files;
+vector<UCS_string> directories;
for (;;)
{
@@ -756,6 +757,16 @@
if (entry == 0) break; // directory done
UCS_string filename(entry->d_name);
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (entry->d_type == DT_DIR)
+ {
+ if (filename[0] == '.') continue;
+ filename.append_ascii("/");
+ directories.push_back(filename);
+ continue;
+ }
+#endif
+
const int dlen = strlen(entry->d_name);
if (filename[dlen - 1] != 'l') continue; // not .apl or .xml
if (filename[dlen - 4] != '.') continue; // not .apl or .xml
@@ -775,6 +786,12 @@
// 3. sort filenames alphabetically
//
+#ifdef _DIRENT_HAVE_D_TYPE
+DynArray(const UCS_string *, directory_names, directories.size());
+ loop(a, directories.size()) directory_names[a] = &directories[a];
+ UCS_string::sort_names(directory_names, directories.size());
+#endif
+
DynArray(const UCS_string *, apl_filenames, apl_files.size());
loop(a, apl_files.size()) apl_filenames[a] = &apl_files[a];
UCS_string::sort_names(apl_filenames, apl_files.size());
@@ -785,9 +802,16 @@
// 4. merge APL and XML files, adding a + if both exist
//
-DynArray(const UCS_string *, filenames, apl_files.size() + xml_files.size());
+DynArray(const UCS_string *, filenames, apl_files.size() + xml_files.size()
+#ifdef _DIRENT_HAVE_D_TYPE
+ + directories.size()
+#endif
+ );
int count = 0;
+ loop(dd, directories.size())
+ filenames[count++] = directory_names[dd];
+
for (int a = 0, x = 0;;)
{
if (a >= apl_files.size()) // end of apl_files reached
@@ -867,11 +891,23 @@
dirent * entry = readdir(dir);
if (entry == 0) break; // directory done
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (entry->d_type == DT_DIR)
+ {
+ if (entry->d_name[0] == '.') continue;
+ }
+#endif
+
+#ifdef _DIRENT_HAVE_D_TYPE
+ const int dlen = strlen(entry->d_name) + (entry->d_type == DT_DIR);
+#else
const int dlen = strlen(entry->d_name);
+#endif
#ifdef _DIRENT_HAVE_D_TYPE
if (entry->d_type != DT_REG &&
- entry->d_type != DT_LNK) continue; // not a regular file
+ entry->d_type != DT_DIR &&
+ entry->d_type != DT_LNK) continue; // not to be shown
#else
if (dlen == 1 && entry->d_name[0] == '.') continue;
if (dlen == 2 && entry->d_name[0] == '.'
@@ -890,6 +926,12 @@
do out << " "; while (++col % 9);
}
out << entry->d_name;
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (entry->d_type == DT_DIR)
+ {
+ out << "/";
+ }
+#endif
col += dlen;
}