gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master d7bf627 59/62: TAB completion: support added f


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master d7bf627 59/62: TAB completion: support added for CosmicCalculator and Crop
Date: Thu, 13 May 2021 22:20:55 -0400 (EDT)

branch: master
commit d7bf62797cce7885ca996122378304bd68339d60
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    TAB completion: support added for CosmicCalculator and Crop
    
    With this commit, support for TAB completion in CosmicCalculator and Crop
    have been added. Also, to help in the readability of the "MAYBE_" variables
    related to completion in the top 'Makefile.am', their name is now in the
    format of 'MAYBE_COMPLETE_*' (until now it was 'MAYBE_*_COMPLETE').
    
    During the process, I noticed a segmentation fault in Crop (caused when a
    single image was given, but no '--width' specified) and that 'astcrop -P'
    will complain about no crop-mode being specified. Both these issues are
    also fixed in this commit.
---
 Makefile.am                                        | 35 +++++++----
 bin/arithmetic/astarithmetic-complete.bash         |  4 +-
 bin/completion.bash.in                             | 14 ++++-
 bin/convertt/astconvertt-complete.bash             |  4 +-
 bin/convolve/astconvolve-complete.bash             |  5 +-
 bin/cosmiccal/Makefile.am                          |  3 +-
 .../astcosmiccal-complete.bash}                    | 68 +++++++++-------------
 bin/crop/Makefile.am                               |  3 +-
 .../astcrop-complete.bash}                         | 60 +++++++++++--------
 bin/crop/ui.c                                      | 22 +++++--
 10 files changed, 128 insertions(+), 90 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 8139d4f..dd42042 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,25 +51,27 @@ BUILT_SOURCES = $(top_srcdir)/AUTHORS
 ## Gnulib tests have been done.
 if COND_ARITHMETIC
   MAYBE_ARITHMETIC = bin/arithmetic
-  MAYBE_ARITHMETIC_COMPLETE = bin/arithmetic/astarithmetic-complete.bash
+  MAYBE_COMPLETE_ARITHMETIC = bin/arithmetic/astarithmetic-complete.bash
 endif
 if COND_BUILDPROG
   MAYBE_BUILDPROG = bin/buildprog
-  MAYBE_BUILDPROG_COMPLETE = bin/buildprog/astbuildprog-complete.bash
+  MAYBE_COMPLETE_BUILDPROG = bin/buildprog/astbuildprog-complete.bash
 endif
 if COND_CONVERTT
   MAYBE_CONVERTT = bin/convertt
-  MAYBE_CONVERTT_COMPLETE = bin/convertt/astconvertt-complete.bash
+  MAYBE_COMPLETE_CONVERTT = bin/convertt/astconvertt-complete.bash
 endif
 if COND_CONVOLVE
   MAYBE_CONVOLVE = bin/convolve
-  MAYBE_CONVOLVE_COMPLETE = bin/convolve/astconvolve-complete.bash
+  MAYBE_COMPLETE_CONVOLVE = bin/convolve/astconvolve-complete.bash
 endif
 if COND_COSMICCAL
   MAYBE_COSMICCAL = bin/cosmiccal
+  MAYBE_COMPLETE_COSMICCAL = bin/cosmiccal/astcosmiccal-complete.bash
 endif
 if COND_CROP
   MAYBE_CROP = bin/crop
+  MAYBE_COMPLETE_CROP = bin/crop/astcrop-complete.bash
 endif
 if COND_FITS
   MAYBE_FITS = bin/fits
@@ -100,7 +102,7 @@ if COND_STATISTICS
 endif
 if COND_TABLE
   MAYBE_TABLE = bin/table
-  MAYBE_TABLE_COMPLETE = bin/table/asttable-complete.bash
+  MAYBE_COMPLETE_TABLE = bin/table/asttable-complete.bash
 endif
 #if COND_TEMPLATE
 #  MAYBE_TEMPLATE = bin/TEMPLATE
@@ -247,6 +249,17 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
        echo "convertt_colormaps=\"$$vals\"" >> $@.built; \
        echo "}" >> $@.built
 
+        # Extract the spectral line names for CosmicCalculator.
+       names=""
+       echo "" >> $@.built
+       for name in $$($(AWK) '/GAL_SPECLINES_NAME/{print $$NF}' \
+                             $(top_srcdir)/lib/gnuastro/speclines.h \
+                             | $(SED) -e's|"||g'); do \
+         names="$$names $$name"; \
+       done; \
+       echo "_gnuastro_autocomplete_compreply_specline_names(){" >> $@.built; \
+       echo "specline_names=\"$$names\"" >> $@.built; \
+       echo "}" >> $@.built
 
         # Copy the low-level common functions to all programs, then put the
         # arithmetic functions inside of it. We are keeping the arithmetic
@@ -256,11 +269,13 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
        cat $@.built >> $@.tmp
 
         # Copy each program's source.
-       for f in $(MAYBE_ARITHMETIC_COMPLETE) \
-                $(MAYBE_BUILDPROG_COMPLETE) \
-                $(MAYBE_CONVERTT_COMPLETE) \
-                $(MAYBE_CONVOLVE_COMPLETE) \
-                $(MAYBE_TABLE_COMPLETE); do \
+       for f in $(MAYBE_COMPLETE_ARITHMETIC) \
+                $(MAYBE_COMPLETE_BUILDPROG) \
+                $(MAYBE_COMPLETE_CONVERTT) \
+                $(MAYBE_COMPLETE_CONVOLVE) \
+                $(MAYBE_COMPLETE_COSMICCAL) \
+                $(MAYBE_COMPLETE_CROP) \
+                $(MAYBE_COMPLETE_TABLE); do \
          $(SED) -e 's|@PREFIX[@]|$(bindir)|g' $(top_srcdir)/$$f >> $@.tmp; \
        done
        chmod a-w $@.tmp
diff --git a/bin/arithmetic/astarithmetic-complete.bash 
b/bin/arithmetic/astarithmetic-complete.bash
index 71f0c8c..5a6de4c 100644
--- a/bin/arithmetic/astarithmetic-complete.bash
+++ b/bin/arithmetic/astarithmetic-complete.bash
@@ -97,11 +97,11 @@ _gnuastro_autocomplete_astarithmetic_option_value(){
             ;;
 
         --wcslinearmatrix)
-            _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
+            _gnuastro_autocomplete_compreply_wcslinearmatrix "$current"
             ;;
 
         --numthreads)
-            _gnuastro_autocomplete_compreply_numthreads
+            _gnuastro_autocomplete_compreply_numthreads "$current"
             ;;
 
     esac
diff --git a/bin/completion.bash.in b/bin/completion.bash.in
index 66cb168..7d5a66a 100644
--- a/bin/completion.bash.in
+++ b/bin/completion.bash.in
@@ -655,7 +655,9 @@ _gnuastro_autocomplete_compreply_tableformat(){
 # Add completion replies for the values to '--numthreads'.
 _gnuastro_autocomplete_compreply_numthreads(){
     if nproc &> /dev/null; then
-        for v in $(seq $(nproc)); do COMPREPLY+=("$v"); done
+        local numthreads="$(seq $(nproc))"
+        _gnuastro_autocomplete_compreply_from_string \
+            "$numthreads" "$1"
     fi
 }
 
@@ -684,6 +686,16 @@ _gnuastro_autocomplete_compreply_numbertype(){
 
 
 
+# Values to the common '--wcslinearmatrix' option.
+_gnuastro_autocomplete_compreply_wcslinearmatrix(){
+    _gnuastro_autocomplete_compreply_from_string \
+        "cd pc" "$1"
+}
+
+
+
+
+
 # Add matching options to the completion replies.
 _gnuastro_autocomplete_compreply_options_all(){
 
diff --git a/bin/convertt/astconvertt-complete.bash 
b/bin/convertt/astconvertt-complete.bash
index 613065d..f314794 100644
--- a/bin/convertt/astconvertt-complete.bash
+++ b/bin/convertt/astconvertt-complete.bash
@@ -81,11 +81,11 @@ _gnuastro_autocomplete_astconvertt_option_value(){
             ;;
 
         --wcslinearmatrix)
-            _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
+            _gnuastro_autocomplete_compreply_wcslinearmatrix "$current"
             ;;
 
         --numthreads)
-            _gnuastro_autocomplete_compreply_numthreads
+            _gnuastro_autocomplete_compreply_numthreads "$current"
             ;;
 
 
diff --git a/bin/convolve/astconvolve-complete.bash 
b/bin/convolve/astconvolve-complete.bash
index 8d89913..992335c 100644
--- a/bin/convolve/astconvolve-complete.bash
+++ b/bin/convolve/astconvolve-complete.bash
@@ -62,7 +62,6 @@ _gnuastro_autocomplete_astconvolve_option_value(){
     local fits_file=""
     local given_hdu=""
     local given_file=""
-    local convertt_colormaps=""
 
     # Keep this in the same order as the output of '--help', for options
     # with similar operations, keep the order within the '|'s.
@@ -117,7 +116,7 @@ _gnuastro_autocomplete_astconvolve_option_value(){
             ;;
 
         --wcslinearmatrix)
-            _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
+            _gnuastro_autocomplete_compreply_wcslinearmatrix "$current"
             ;;
 
         -d|--domain)
@@ -126,7 +125,7 @@ _gnuastro_autocomplete_astconvolve_option_value(){
             ;;
 
         --numthreads)
-            _gnuastro_autocomplete_compreply_numthreads
+            _gnuastro_autocomplete_compreply_numthreads "$current"
             ;;
 
 
diff --git a/bin/cosmiccal/Makefile.am b/bin/cosmiccal/Makefile.am
index 9ad628c..d67988e 100644
--- a/bin/cosmiccal/Makefile.am
+++ b/bin/cosmiccal/Makefile.am
@@ -36,7 +36,8 @@ astcosmiccal_LDADD = 
$(top_builddir)/bootstrapped/lib/libgnu.la \
 
 astcosmiccal_SOURCES = main.c ui.c cosmiccal.c
 
-EXTRA_DIST = main.h authors-cite.h args.h ui.h cosmiccal.h
+EXTRA_DIST = main.h authors-cite.h args.h ui.h cosmiccal.h \
+             astcosmiccal-complete.bash
 
 
 
diff --git a/bin/convertt/astconvertt-complete.bash 
b/bin/cosmiccal/astcosmiccal-complete.bash
similarity index 68%
copy from bin/convertt/astconvertt-complete.bash
copy to bin/cosmiccal/astcosmiccal-complete.bash
index 613065d..a861db7 100644
--- a/bin/convertt/astconvertt-complete.bash
+++ b/bin/cosmiccal/astcosmiccal-complete.bash
@@ -1,5 +1,5 @@
-# Bash autocompletion to Gnuastro's ConvertType. See the comments above
-# 'bin/completion.bash.in' for more.
+# Bash autocompletion to Gnuastro's CosmicCalculator program. See the
+# comments above 'bin/completion.bash.in' for more.
 #
 # Original author:
 #     Mohammad Akhlaghi <mohammad@akhlaghi.org>
@@ -34,16 +34,13 @@
 
 
 #######################################################################
-############      Only for ConvertType (this program)      ############
+############    Only for CosmicCalculator (this program)   ############
 #######################################################################
 
-# Dealing with arguments: ConvertType can take multiple images as arguments
-# (so unlike other programs, there is no option to print options). One way
-# would be to calculate how many color channels there are in each input and
-# look at the desired output format and its necessary color channels. But
-# that is too complicated for now.
-_gnuastro_autocomplete_astconvertt_arguments(){
-    _gnuastro_autocomplete_compreply_images_all "$argument"
+# Dealing with arguments: CosmicCalculator doesn't take any arguments, so
+# show the use the list of options immediately.
+_gnuastro_autocomplete_astcosmiccal_arguments(){
+    _gnuastro_autocomplete_compreply_options_all ""
 }
 
 
@@ -51,44 +48,37 @@ _gnuastro_autocomplete_astconvertt_arguments(){
 
 
 # Fill option value (depends on option).
-_gnuastro_autocomplete_astconvertt_option_value(){
+_gnuastro_autocomplete_astcosmiccal_option_value(){
 
     # Internal variables.
-    local fits_file=""
-    local given_hdu=""
-    local given_file=""
-    local convertt_colormaps=""
+    local specline_names=""
 
     # Keep this in the same order as the output of '--help', for options
     # with similar operations, keep the order within the '|'s.
     case "$option_name" in
 
-        -h|--hdu|-g|--globalhdu)
-            _gnuastro_autocomplete_given_file image ""
-            _gnuastro_autocomplete_compreply_hdus \
-                image "$given_file" "$current"
-            ;;
+        --obsline)
+            # Put the list of spectral lines in 'specline_names'.
+            _gnuastro_autocomplete_compreply_specline_names
 
-        --colormap)
-            _gnuastro_autocomplete_compreply_convertt_colormap
+            # Add them to the replies.
             _gnuastro_autocomplete_compreply_from_string \
-                "$convertt_colormaps" "$current"
+                "$specline_names" "$current"
+
+            # If this is the only suggestion, then add a ',' (to let the
+            # user easily type-in their observed value at this line.
+            if [        x"${COMPREPLY[0]}" != x ] \
+                   && [ x"${COMPREPLY[1]}"  = x ]; then
+                COMPREPLY[0]="${COMPREPLY[0]},";
+                compopt -o nospace
+            fi
             ;;
 
-        -u|--quality)
+        --lineatz)
+            _gnuastro_autocomplete_compreply_specline_names
             _gnuastro_autocomplete_compreply_from_string \
-                "$(seq 100)" "$current"
-            ;;
-
-        --wcslinearmatrix)
-            _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
+                "$specline_names" "$current"
             ;;
-
-        --numthreads)
-            _gnuastro_autocomplete_compreply_numthreads
-            ;;
-
-
     esac
 }
 
@@ -96,7 +86,7 @@ _gnuastro_autocomplete_astconvertt_option_value(){
 
 
 
-_gnuastro_autocomplete_astconvertt(){
+_gnuastro_autocomplete_astcosmiccal(){
 
     # The installation directory of Gnuastro. The '@PREFIX@' part will be
     # replaced automatically during 'make install', with the user's given
@@ -139,7 +129,7 @@ _gnuastro_autocomplete_astconvertt(){
     # If 'option_name_complete==1', then we are busy filling in the option
     # value.
     if [ $option_name_complete = 1 ]; then
-        _gnuastro_autocomplete_astconvertt_option_value
+        _gnuastro_autocomplete_astcosmiccal_option_value
 
     # When 'option_name' is not empty (and not yet complete), we are busy
     # filling in the option name.
@@ -148,7 +138,7 @@ _gnuastro_autocomplete_astconvertt(){
 
     # In the case of "none-of-the-above", it is an argument.
     else
-        _gnuastro_autocomplete_astconvertt_arguments
+        _gnuastro_autocomplete_astcosmiccal_arguments
     fi
 }
 
@@ -159,4 +149,4 @@ _gnuastro_autocomplete_astconvertt(){
 # Define the completion specification, or COMPSPEC: -o bashdefault: Use
 # Bash default completions if nothing is found.  -F function: Use this
 # 'function' to generate the given program's completion.
-complete -o bashdefault -F _gnuastro_autocomplete_astconvertt astconvertt
+complete -o bashdefault -F _gnuastro_autocomplete_astcosmiccal astcosmiccal
diff --git a/bin/crop/Makefile.am b/bin/crop/Makefile.am
index c4a5450..4ad999a 100644
--- a/bin/crop/Makefile.am
+++ b/bin/crop/Makefile.am
@@ -36,7 +36,8 @@ astcrop_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la \
 
 astcrop_SOURCES = main.c ui.c crop.c wcsmode.c onecrop.c
 
-EXTRA_DIST = main.h authors-cite.h args.h ui.h crop.h wcsmode.h onecrop.h
+EXTRA_DIST = main.h authors-cite.h args.h ui.h crop.h wcsmode.h onecrop.h \
+             astcrop-complete.bash
 
 
 
diff --git a/bin/convertt/astconvertt-complete.bash 
b/bin/crop/astcrop-complete.bash
similarity index 72%
copy from bin/convertt/astconvertt-complete.bash
copy to bin/crop/astcrop-complete.bash
index 613065d..a14eaab 100644
--- a/bin/convertt/astconvertt-complete.bash
+++ b/bin/crop/astcrop-complete.bash
@@ -1,4 +1,4 @@
-# Bash autocompletion to Gnuastro's ConvertType. See the comments above
+# Bash autocompletion to Gnuastro's Crop program. See the comments above
 # 'bin/completion.bash.in' for more.
 #
 # Original author:
@@ -34,16 +34,13 @@
 
 
 #######################################################################
-############      Only for ConvertType (this program)      ############
+############          Only for Crop (this program)         ############
 #######################################################################
 
-# Dealing with arguments: ConvertType can take multiple images as arguments
-# (so unlike other programs, there is no option to print options). One way
-# would be to calculate how many color channels there are in each input and
-# look at the desired output format and its necessary color channels. But
-# that is too complicated for now.
-_gnuastro_autocomplete_astconvertt_arguments(){
-    _gnuastro_autocomplete_compreply_images_all "$argument"
+# Dealing with arguments: Crop can take any number of images, so don't
+# suggest options
+_gnuastro_autocomplete_astcrop_arguments(){
+    _gnuastro_autocomplete_compreply_files_certain image "$argument"
 }
 
 
@@ -51,43 +48,56 @@ _gnuastro_autocomplete_astconvertt_arguments(){
 
 
 # Fill option value (depends on option).
-_gnuastro_autocomplete_astconvertt_option_value(){
+_gnuastro_autocomplete_astcrop_option_value(){
 
     # Internal variables.
     local fits_file=""
     local given_hdu=""
     local given_file=""
-    local convertt_colormaps=""
 
     # Keep this in the same order as the output of '--help', for options
     # with similar operations, keep the order within the '|'s.
     case "$option_name" in
 
-        -h|--hdu|-g|--globalhdu)
+        -h|--hdu)
             _gnuastro_autocomplete_given_file image ""
             _gnuastro_autocomplete_compreply_hdus \
                 image "$given_file" "$current"
             ;;
 
-        --colormap)
-            _gnuastro_autocomplete_compreply_convertt_colormap
+        -O|--mode)
             _gnuastro_autocomplete_compreply_from_string \
-                "$convertt_colormaps" "$current"
+                "img wcs" "$current"
             ;;
 
-        -u|--quality)
-            _gnuastro_autocomplete_compreply_from_string \
-                "$(seq 100)" "$current"
+        -T|--type)
+            _gnuastro_autocomplete_compreply_numbertype "$current"
             ;;
 
         --wcslinearmatrix)
-            _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
+            _gnuastro_autocomplete_compreply_wcslinearmatrix "$current"
             ;;
 
-        --numthreads)
-            _gnuastro_autocomplete_compreply_numthreads
+        --cathdu)
+            _gnuastro_autocomplete_given_file table "--catalog"
+            _gnuastro_autocomplete_compreply_hdus \
+                table "$given_file" "$current"
+            ;;
+
+        --catalog)
+            _gnuastro_autocomplete_compreply_files_certain table "$current"
             ;;
 
+        --namecol|--coordcol)
+            _gnuastro_autocomplete_given_file_and_hdu \
+                table "--catalog" "--hdu"
+            _gnuastro_autocomplete_compreply_table_columns \
+                "$given_file" "$given_hdu" "$current"
+            ;;
+
+        --numthreads)
+            _gnuastro_autocomplete_compreply_numthreads "$current"
+            ;;
 
     esac
 }
@@ -96,7 +106,7 @@ _gnuastro_autocomplete_astconvertt_option_value(){
 
 
 
-_gnuastro_autocomplete_astconvertt(){
+_gnuastro_autocomplete_astcrop(){
 
     # The installation directory of Gnuastro. The '@PREFIX@' part will be
     # replaced automatically during 'make install', with the user's given
@@ -139,7 +149,7 @@ _gnuastro_autocomplete_astconvertt(){
     # If 'option_name_complete==1', then we are busy filling in the option
     # value.
     if [ $option_name_complete = 1 ]; then
-        _gnuastro_autocomplete_astconvertt_option_value
+        _gnuastro_autocomplete_astcrop_option_value
 
     # When 'option_name' is not empty (and not yet complete), we are busy
     # filling in the option name.
@@ -148,7 +158,7 @@ _gnuastro_autocomplete_astconvertt(){
 
     # In the case of "none-of-the-above", it is an argument.
     else
-        _gnuastro_autocomplete_astconvertt_arguments
+        _gnuastro_autocomplete_astcrop_arguments
     fi
 }
 
@@ -159,4 +169,4 @@ _gnuastro_autocomplete_astconvertt(){
 # Define the completion specification, or COMPSPEC: -o bashdefault: Use
 # Bash default completions if nothing is found.  -F function: Use this
 # 'function' to generate the given program's completion.
-complete -o bashdefault -F _gnuastro_autocomplete_astconvertt astconvertt
+complete -o bashdefault -F _gnuastro_autocomplete_astcrop astcrop
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index b95d51f..c4142ea 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -280,11 +280,12 @@ ui_read_check_only_options(struct cropparams *p)
   switch(checksum)
     {
     case 0:
-      error(EXIT_FAILURE, 0, "no crop definition. You can use any of the "
-            "following options to define the crop(s): '--center', "
-            "'--catalog', '--section', or '--polygon'. Please run this "
-            "command for more information:\n\n"
-            "    $ info gnuastro \"Crop modes\"\n");
+      if(p->cp.printparams==0)
+        error(EXIT_FAILURE, 0, "no crop definition. You can use any of "
+              "the following options to define the crop(s): '--center', "
+              "'--catalog', '--section', or '--polygon'. Please run this "
+              "command for more information:\n\n"
+              "    $ info gnuastro \"Crop modes\"\n");
     case 1:
       /* Everything is ok, just ignore the switch structure. */
       break;
@@ -875,9 +876,17 @@ ui_preparations_to_img_mode(struct cropparams *p)
           "will get wrong results. You can suppress this warning "
           "with '--quiet'", p->inputs->v, p->cp.hdu);
 
-  /* Convert the given coordinates. */
+  /* Convert the given width into pixels. */
   if(p->center || p->catname)
     {
+      /* This function may be called before the formal sanity checks are
+         complete. So we need to check for the presence of '--width' again
+         here. */
+      if(p->width==NULL)
+        error(EXIT_FAILURE, 0, "no crop width specified. When crops are "
+              "defined by their center (with '--center' or '--catalog') a "
+              "width is necessary (using the '--width' option)");
+
       /* Check the requested width and convert it to pixels. */
       darr=p->width->array;
       if(wcs->naxis<p->width->size)
@@ -988,6 +997,7 @@ ui_preparations(struct cropparams *p)
       ui_preparations_to_img_mode(p);
     }
 
+
   /* For polygon and section, there should be no center checking. */
   if(p->polygon || p->section)
     p->checkcenter=0;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]