FLTK logo

[master] 975d34d - Fix VS2017 'pclose' error, and DIR formatting

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 975d34d - Fix VS2017 'pclose' error, and DIR formatting "Greg Ercolano" Aug 30, 2021  
 
commit 975d34de4313e0cd29fc652b051c1afc1d8bf607
Author:     Greg Ercolano <erco@seriss.com>
AuthorDate: Mon Aug 30 11:56:21 2021 -0700
Commit:     Greg Ercolano <erco@seriss.com>
CommitDate: Mon Aug 30 11:56:21 2021 -0700

    Fix VS2017 'pclose' error, and DIR formatting

 examples/table-sort.cxx | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git examples/table-sort.cxx examples/table-sort.cxx
index 5193f5b..bb68982 100644
--- examples/table-sort.cxx
+++ examples/table-sort.cxx
@@ -28,6 +28,7 @@
 #include <FL/Fl_Table_Row.H>
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <string>
@@ -39,9 +40,10 @@
 #ifdef _WIN32
 // WINDOWS
 #  define DIRCMD          "dir"
-static const char *G_header[] = { "Date", "Time", "Size", "Filename", "", "", "", "", "", 0 };
+static const char *G_header[] = { "Date", "Time", "", "Size", "Filename", "", "", "", "", "", 0 };
 #  ifdef _MSC_VER
 #    define popen           _popen
+#    define pclose          _pclose
 #  endif
 #else /* _WIN32 */
 // UNIX
@@ -219,11 +221,17 @@ void MyTable::load_command(const char *cmd) {
     char s[512];
     FILE *fp = popen(cmd, "r");
     cols(0);
-    for ( int r=0; fgets(s, sizeof(s)-1, fp); r++ ) {
-        if ( r==0 && strncmp(s,"total ",6)==0) { --r; continue; }
+    for ( int line=0; fgets(s, sizeof(s)-1, fp); line++ ) {
+#ifdef _WIN32
+        // WINDOWS
+        if ( line < 5 ) continue; 	// skip DIR's 5 line header
+#else
+        // UNIX
+        if ( line==0 && strncmp(s,"total ",6)==0) continue;
+#endif
         // Add a new row
         Row newrow; rowdata_.push_back(newrow);
-        std::vector<std::string> &rc = rowdata_[r].cols;
+        std::vector<std::string> &rc = rowdata_.back().cols;
         // Break line into separate word 'columns'
         char *ss;
         const char *delim = " \t\n";
@@ -235,11 +243,18 @@ void MyTable::load_command(const char *cmd) {
             cols((int)rc.size());
         }
     }
+    pclose(fp);
+
+#ifdef _WIN32
+    // WINDOWS: Trim off DIR's 2 line footer
+    if ( rowdata_.size() > 2 )
+        { rowdata_.pop_back(); rowdata_.pop_back(); }
+#endif
+
     // How many rows we loaded
     rows((int)rowdata_.size());
     // Auto-calculate widths, with 20 pixel padding
     autowidth(20);
-    pclose(fp);
 }
 
 // Callback whenever someone clicks on different parts of the table
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.