From 2e169770396fed12b3b9200b3354322924b36537 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Mon, 1 Dec 2025 12:39:21 -0800 Subject: Fix DIR parsing on windows for non-US locale (#1344) --- examples/table-sort.cxx | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'examples') diff --git a/examples/table-sort.cxx b/examples/table-sort.cxx index f2b4912a0..7b4a4aa0d 100644 --- a/examples/table-sort.cxx +++ b/examples/table-sort.cxx @@ -39,8 +39,11 @@ #ifdef _WIN32 // WINDOWS -# define DIRCMD "dir" -static const char *G_header[] = { "Date", "Time", "", "Size", "Filename", "", "", "", "", "", 0 }; + // DIR flags that simplify parsing: + // /-C -- disable 1000's separator in file sizes + // /A-D -- don't show directories +# define DIRCMD "dir /-C /A-D" + static std::vector G_header = { "Date", "Time", "Size", "Filename" }; # ifdef _MSC_VER # define popen _popen # define pclose _pclose @@ -48,7 +51,7 @@ static const char *G_header[] = { "Date", "Time", "", "Size", "Filename", "", "" #else /* _WIN32 */ // UNIX # define DIRCMD "ls -l" -static const char *G_header[] = { "Perms", "#L", "Own", "Group", "Size", "Date", "", "", "Filename", 0 }; + static std::vector G_header = { "Perms", "#L", "Own", "Group", "Size", "Date", "", "", "Filename" }; #endif /* _WIN32 */ // Font face/sizes for header and rows @@ -155,10 +158,10 @@ void MyTable::draw_cell(TableContext context, int R, int C, int X, int Y, int W, case CONTEXT_COL_HEADER: fl_push_clip(X,Y,W,H); { fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, FL_BACKGROUND_COLOR); - if ( C < 9 ) { + if ( C < G_header.size() ) { fl_font(HEADER_FONTFACE, HEADER_FONTSIZE); fl_color(FL_BLACK); - fl_draw(G_header[C], X+2,Y,W,H, FL_ALIGN_LEFT, 0, 0); // +2=pad left + fl_draw(G_header[C].c_str(), X+2,Y,W,H, FL_ALIGN_LEFT, 0, 0); // +2=pad left // Draw sort arrow if ( C == sort_lastcol_ ) { draw_sort_arrow(X,Y,W,H); @@ -190,8 +193,8 @@ void MyTable::autowidth(int pad) { int w, h; // Initialize all column widths to header width fl_font(HEADER_FONTFACE, HEADER_FONTSIZE); - for ( int c=0; G_header[c]; c++ ) { - w=0; fl_measure(G_header[c], w, h, 0); // pixel width of header text + for ( int c=0; c std::string } // Keep track of max # columns @@ -245,12 +255,6 @@ void MyTable::load_command(const char *cmd) { } 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 -- cgit v1.2.3