]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
hfaxd: sorting fixups
authorAidan Van Dyk <aidan@ifax.com>
Thu, 8 May 2008 17:33:32 +0000 (17:33 +0000)
committerAidan Van Dyk <aidan@ifax.com>
Thu, 8 May 2008 17:33:32 +0000 (17:33 +0000)
I forgot the FILESORTFORMAT sorting last time.

And I don't know how I slipped mssing the Jprintf in Jobs.c++

hfaxd/FileSystem.c++
hfaxd/HylaFAXServer.h
hfaxd/Jobs.c++

index 2a4fe03b4e60d7107e9d20f0834047188846fe38..275386d44820f6a4d225cd931c7e55e0727c233d 100644 (file)
@@ -482,6 +482,7 @@ HylaFAXServer::listCmd(const char* pathname)
 void
 HylaFAXServer::listDirectory(FILE* fd, const SpoolDir& sd, DIR* dir)
 {
+    KeyStringArray listing;
     /*
      * Use an absolute pathname when doing file
      * lookups to improve cache locality.
@@ -496,10 +497,32 @@ HylaFAXServer::listDirectory(FILE* fd, const SpoolDir& sd, DIR* dir)
        if (!FileCache::update(path | dp->d_name, sb))
            continue;
        if ((this->*sd.isVisibleFile)(dp->d_name, sb)) {
-           (this->*sd.listFile)(fd, sd, dp->d_name, sb);
-           fputs("\r\n", fd);
+           if (fileSortFormat.length() == 0) {
+               Fprintf(fd, fileFormat, dp->d_name, sb);
+               fputs("\r\n", fd);
+           } else
+           {
+               fxStackBuffer buf;
+               Fprintf(buf, fileFormat, dp->d_name, sb);
+               fxStr content(buf, buf.getLength());
+               buf.reset();
+               Fprintf(buf, fileSortFormat, dp->d_name, sb);
+               fxStr key(buf, buf.getLength());
+               listing.append(KeyString(key, content));
+           }
        }
     }
+
+    if (listing.length() > 1)
+       listing.qsort();
+
+    for (int i = 0; i < listing.length(); i++)
+    {
+       fwrite(listing[i], listing[i].length(), 1, fd);
+       fputs("\r\n", fd);
+    }
+
+
 }
 
 void
@@ -545,7 +568,7 @@ static const char fformat[] = {
  * in preferred formats.
  */
 void
-HylaFAXServer::Fprintf(FILE* fd, const char* fmt,
+HylaFAXServer::Fprintf(fxStackBuffer& buf, const char* fmt,
     const char* filename, const struct stat& sb)
 {
     for (const char* cp = fmt; *cp; cp++) {
@@ -569,62 +592,70 @@ HylaFAXServer::Fprintf(FILE* fd, const char* fmt,
            }
            if (!islower(c)) {
                if (c == '%')           // %% -> %
-                   putc(c, fd);
+                   buf.put(c);
                else
-                   fprintf(fd, "%.*s%c", fp-fspec, fspec, c);
+                   buf.fput("%.*s%c", fp-fspec, fspec, c);
                continue;
            }
            fp[0] = fformat[c-'a'];     // printf format string
            fp[1] = '\0';
            switch (c) {
            case 'a':
-               fprintf(fd, fspec, asctime(cvtTime(sb.st_atime))+4);
+               buf.fput(fspec, asctime(cvtTime(sb.st_atime))+4);
                break;
            case 'c':
-               fprintf(fd, fspec, asctime(cvtTime(sb.st_ctime))+4);
+               buf.fput(fspec, asctime(cvtTime(sb.st_ctime))+4);
                break;
            case 'd':
-               fprintf(fd, fspec, (u_int) sb.st_dev);
+               buf.fput(fspec, (u_int) sb.st_dev);
                break;
            case 'f':
-               fprintf(fd, fspec, filename);
+               buf.fput(fspec, filename);
                break;
            case 'g':
-               fprintf(fd, fspec, (u_int) sb.st_gid);
+               buf.fput(fspec, (u_int) sb.st_gid);
                break;
            case 'i':
-               fprintf(fd, fspec, (u_int) sb.st_ino);          // XXX
+               buf.fput(fspec, (u_int) sb.st_ino);             // XXX
                break;
            case 'l':
-               fprintf(fd, fspec, (u_int) sb.st_nlink);
+               buf.fput(fspec, (u_int) sb.st_nlink);
                break;
            case 'm':
-               fprintf(fd, fspec, asctime(cvtTime(sb.st_mtime))+4);
+               buf.fput(fspec, asctime(cvtTime(sb.st_mtime))+4);
                break;
            case 'o':
-               fprintf(fd, fspec, userName((u_int) sb.st_gid));
+               buf.fput(fspec, userName((u_int) sb.st_gid));
                break;
            case 'p':
            case 'q':
                { char prot[10];                                // XXX HP C++
                  makeProt(sb, c == 'q', prot);
-                 fprintf(fd, fspec, prot);
+                 buf.fput(fspec, prot);
                }
                break;
            case 'r':
-               fprintf(fd, fspec, (u_int) sb.st_rdev);
+               buf.fput(fspec, (u_int) sb.st_rdev);
                break;
            case 's':
-               fprintf(fd, fspec, (u_int) sb.st_size);         // XXX
+               buf.fput(fspec, (u_int) sb.st_size);            // XXX
                break;
            case 'u':
-               fprintf(fd, fspec, (u_int) sb.st_uid);
+               buf.fput(fspec, (u_int) sb.st_uid);
                break;
            }
        } else
-           putc(*cp, fd);
+           buf.put(*cp);
     }
 }
+void
+HylaFAXServer::Fprintf(FILE* fd, const char* fmt,
+    const char* filename, const struct stat& sb)
+{
+    fxStackBuffer buf;
+    Fprintf(buf, fmt, filename, sb);
+    fwrite((const char*)buf, buf.getLength(), 1, fd);
+}
 
 void
 HylaFAXServer::makeProt(const struct stat& sb, bool withGrp, char prot[10])
index 2e20deb342132a9efde2aa6d63f440ab964cda66..ecb55c0ab8059b573e894149a2df1023d4271d0e 100644 (file)
@@ -440,6 +440,7 @@ protected:
     void listUnixFile(FILE*, const SpoolDir&, const char*, const struct stat&);
     void makeProt(const struct stat& sb, bool withGrp, char prot[10]);
     void Fprintf(FILE*, const char* fmt, const char*, const struct stat&);
+    void Fprintf(fxStackBuffer&, const char* fmt, const char*, const struct stat&);
 
     void nlstDirectory(FILE* fd, const SpoolDir& sd, DIR* dir);
     void nlstUnixFile(FILE*, const SpoolDir&, const char*, const struct stat&);
index 77249b6729659e6c2b62efe6b7ce0d7844a9d44a..3db4c131e9b9dd6a26c317e1dccdb3c0504cb40d 100644 (file)
@@ -1979,6 +1979,7 @@ void
 HylaFAXServer::Jprintf(FILE* fd, const char* fmt, const Job& job)
 {
     fxStackBuffer buf;
+    Jprintf(buf, fmt, job);
     fwrite((const char*)buf, buf.getLength(), 1, fd);
 }