From 70de2e9d458a3c9b601b2bb981a45abf2f28c2ba Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Mon, 12 Mar 2018 15:04:32 +0100
Subject: [PATCH] enable --select when --setcol is used

---
 modules/util/Util/Simple_CSV.pm | 8 +++++---
 modules/util/csv.pl             | 6 ++++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/modules/util/Util/Simple_CSV.pm b/modules/util/Util/Simple_CSV.pm
index f86f585..48c1dd2 100644
--- a/modules/util/Util/Simple_CSV.pm
+++ b/modules/util/Util/Simple_CSV.pm
@@ -164,10 +164,12 @@ sub load_csv_file
   my $fi_open;
   (*FI, $fi_open)= $obj->open_csv_file ($fnm);
 
-  unless ($obj->{'no_headings'})
-  {
-    $obj->load_csv_file_headings (*FI);
+  $obj->load_csv_file_headings (*FI) unless ($obj->{'no_headings'});
 
+  if (@{$obj->{columns}}  # NOTE: columns might have been defined using $obj->define_columns(...)
+      && exists ($obj->{fidef})
+     )
+  {
     my ($fidef)= map { $obj->{$_} } qw(fidef);
     if (defined ($fidef))
     {
diff --git a/modules/util/csv.pl b/modules/util/csv.pl
index 52201f2..975a698 100755
--- a/modules/util/csv.pl
+++ b/modules/util/csv.pl
@@ -112,6 +112,7 @@ while (defined (my $arg= shift (@ARGV)))
     elsif ($opt eq 'search' || $opt eq 'select')
     { # TODO: allow multiple searches!
       $search_string= $val || shift (@ARGV);
+      # print __LINE__, " search_string=[$search_string]\n";
     }
     elsif ($opt eq 'max')    { $max_items=     $val || shift (@ARGV); }
     elsif ($opt eq 'hdr')    { $view= 'header'; }
@@ -193,7 +194,7 @@ if (@set_columns)
   $csv->{'no_headings'}= 1;
 }
 
-# print "find_pattern=[$find_pattern] search_string=[$search_string]\n";
+# print __LINE__, " find_pattern=[$find_pattern] search_string=[$search_string]\n";
 
 if (defined ($find_pattern))
 {
@@ -244,14 +245,15 @@ print "procssing find_pattern=[$find_pattern]\n";
 
 if (defined ($search_string))
 {
-# print "procssing search_string=[$search_string]\n";
   my ($field_name, $field_value)= split ('=', $search_string, 2);
+# print __LINE__, " procssing search_string=[$search_string] field_name=[$field_name] field_value=[$field_value]\n";
 
   # the filter is dynamically generated since the field number is only
   # known after the column names are identified!
   sub fidef2
   {
     my $obj= shift;
+# print __LINE__, " in fidef2\n";
 
     my $cols= $obj->{'columns'};
     my $col= 0;
-- 
GitLab