[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master acf58c1 58/62: TAB completion: now supported i
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master acf58c1 58/62: TAB completion: now supported in ConvertType and Convolve |
Date: |
Thu, 13 May 2021 22:20:55 -0400 (EDT) |
branch: master
commit acf58c135f7400755f8dc6109044dde78814c777
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
TAB completion: now supported in ConvertType and Convolve
With this commit, TAB completion has been added for ConvertType and
Convolve. Also, some general fixes and generalizations have been done in
the general TAB completion infrastructure:
- Table's TAB completion now supports suggesting multiple columns with one
'--column'. Until now, asking for multiple columns with TAB completion
required multiple calls to '--column'.
- The 'bin/completion.bash' is now a prerequisite of 'all-local', so the
creation of the final TAB completion file is done before the final
announcement.
- The new '_gnuastro_autocomplete_compreply_from_string' function has been
added to easily suggest a match for multiple strings.
- The new '_gnuastro_autocomplete_compreply_images_all' function will
search for all acceptable image formats (including JPEG and TIFF).
- To make the automatic parsing for TAB completion easy, some minor
cleaning of the spaces were preformed in the 'ui_colormap_sanity_check'
function of 'bin/convertt/ui.c', 'gal_jpeg_name_is_jpeg' of 'lib/jpeg.c'
and 'gal_tiff_name_is_tiff' of 'lib/tiff.c'.
- '_gnuastro_autocomplete_compreply_hdus' didn't support automatically
limiting the suggestions and would always print all the HDUs. This has
been fixed with this commit.
- '_gnuastro_autocomplete_given_file' wasn't checking that the specified
file is actually an image or a table when it was a value of an option.
- I noticed that in the output of '--help' for the '--interpmetric'
option, we were mistakenly suggesting a value of type 'INT' instead of
'STR'.
---
Makefile.am | 48 ++++-
bin/arithmetic/astarithmetic-complete.bash | 32 ++--
bin/buildprog/astbuildprog-complete.bash | 2 +-
bin/completion.bash.in | 200 +++++++++++++++++++--
bin/convertt/Makefile.am | 3 +-
.../astconvertt-complete.bash} | 74 ++++----
bin/convertt/ui.c | 17 +-
.../astconvolve-complete.bash} | 106 +++++------
bin/table/asttable-complete.bash | 48 ++---
lib/gnuastro-internal/commonopts.h | 2 +-
lib/jpeg.c | 10 +-
lib/tiff.c | 2 +-
12 files changed, 376 insertions(+), 168 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 0760a73..8139d4f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -55,12 +55,15 @@ if COND_ARITHMETIC
endif
if COND_BUILDPROG
MAYBE_BUILDPROG = bin/buildprog
+ MAYBE_BUILDPROG_COMPLETE = bin/buildprog/astbuildprog-complete.bash
endif
if COND_CONVERTT
MAYBE_CONVERTT = bin/convertt
+ MAYBE_CONVERTT_COMPLETE = bin/convertt/astconvertt-complete.bash
endif
if COND_CONVOLVE
MAYBE_CONVOLVE = bin/convolve
+ MAYBE_CONVOLVE_COMPLETE = bin/convolve/astconvolve-complete.bash
endif
if COND_COSMICCAL
MAYBE_COSMICCAL = bin/cosmiccal
@@ -186,7 +189,7 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
rm -f $@ $@.built $@.tmp
# Extract the arithmetic library operators into a '.built' file.
- echo "" > $@.built
+ echo "" >> $@.built
for op in $$($(AWK) '/^gal_arithmetic_operator_string/{parse=1} \
/^\}/{parse=0} \
parse==1 && /GAL_ARITHMETIC_OP/{print $$NF}' \
@@ -211,6 +214,40 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
echo "arithmetic_prog_operators=\"$$ops\"" >> $@.built; \
echo "}" >> $@.built
+ # Extract recognized file-format suffixes.
+ for form in jpeg tiff; do \
+ sufs=""; \
+ echo "" >> $@.built; \
+ for suf in $$($(AWK) '/^gal_'$$form'_name_is_'$$form'/{parse=1} \
+ /^\}/{parse=0} \
+ parse==1 && /strcmp\(&name/{ \
+ for(i=1;i<=NF;++i) if($$i ~ /^"/) print $$i;
\
+ }' $(top_srcdir)/lib/$$form.c \
+ | $(SED) -e's|"||g' -e's|)||g'); do \
+ sufs="$$sufs $$suf"; \
+ done; \
+ echo "_gnuastro_autocomplete_compreply_suffixes_$$form(){" >>
$@.built; \
+ echo "suffixes_$$form=\"$$sufs\"" >> $@.built; \
+ echo "}" >> $@.built; \
+ done
+
+ # Extract color-map values for ConvertType.
+ vals=""
+ echo "" >> $@.built
+ for val in $$($(AWK) '/^ui_colormap_sanity_check/{parse=1} \
+ /^\}/{parse=0} \
+ parse==1 && /strcmp\(strarr/{ \
+ for(i=1;i<=NF;++i) if($$i ~ /^"/) { \
+ print $$i; break} \
+ }' $(top_srcdir)/bin/convertt/ui.c \
+ | $(SED) -e's|"||g' -e's|)\+||'); do \
+ vals="$$vals $$val"; \
+ done; \
+ echo "_gnuastro_autocomplete_compreply_convertt_colormap(){" >>
$@.built; \
+ echo "convertt_colormaps=\"$$vals\"" >> $@.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
# operators separate to help in debugging when necessary (they can
@@ -220,6 +257,9 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
# Copy each program's source.
for f in $(MAYBE_ARITHMETIC_COMPLETE) \
+ $(MAYBE_BUILDPROG_COMPLETE) \
+ $(MAYBE_CONVERTT_COMPLETE) \
+ $(MAYBE_CONVOLVE_COMPLETE) \
$(MAYBE_TABLE_COMPLETE); do \
$(SED) -e 's|@PREFIX[@]|$(bindir)|g' $(top_srcdir)/$$f >> $@.tmp; \
done
@@ -245,7 +285,11 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
## only print its message when 'make' was called with no options. Make will
## set MAKECMDGOALS to blank if there are no arguments, however, the way
## Automake works, its value is set to "all-am".
-all-local:
+##
+## 'bin/completion.bash' has been set as a pre-requisite of this because if
+## we don't do this, the completion script will be created after printing
+## the message (making the message hard to notice for a user).
+all-local: bin/completion.bash
# If we are in static linking mode, correct the 'lib_dependencies'
# variable of 'libgnuastro.la'. Because by default it will not
diff --git a/bin/arithmetic/astarithmetic-complete.bash
b/bin/arithmetic/astarithmetic-complete.bash
index bbaff18..71f0c8c 100644
--- a/bin/arithmetic/astarithmetic-complete.bash
+++ b/bin/arithmetic/astarithmetic-complete.bash
@@ -47,31 +47,18 @@ _gnuastro_autocomplete_astarithmetic_arguments(){
# Print all accessible images.
_gnuastro_autocomplete_compreply_files_certain image "$argument"
- # If atleast one image has already been given, an then print the
+ # If atleast one image has already been given, also print the
# arithmetic operators with the file names.
if _gnuastro_autocomplete_first_in_arguments image; then
- # Get the list of operators as variables.
+ # Fill the variables.
_gnuastro_autocomplete_compreply_arithmetic_lib
_gnuastro_autocomplete_compreply_arithmetic_prog
- # Limit the operators to those that start with the already given
- # portion.
- if [ x"$argument" = x ]; then
- for f in $arithmetic_lib_operators $arithmetic_prog_operators; do
- COMPREPLY+=("$f");
- done
- else
- # We aren't using 'grep' because it can confuse the '--XXX' with
- # its own options on some systems (and placing a '--' before the
- # search string may not be portable).
- for f in $(echo $arithmetic_lib_operators
$arithmetic_prog_operators \
- | awk '{for(i=1;i<=NF;++i) \
- if($i ~ /^'$argument'/) print $i}'); do
- COMPREPLY+=("$f");
- done
- fi
-
+ # Add them to COMPREPLY
+ _gnuastro_autocomplete_compreply_from_string \
+ "$arithmetic_lib_operators $arithmetic_prog_operators" \
+ "$argument"
fi
}
@@ -93,7 +80,8 @@ _gnuastro_autocomplete_astarithmetic_option_value(){
-h|--hdu|-g|--globalhdu|-w|--wcshdu)
_gnuastro_autocomplete_given_file image ""
- _gnuastro_autocomplete_compreply_hdus image "$given_file"
+ _gnuastro_autocomplete_compreply_hdus \
+ image "$given_file" "$current"
;;
-w|--wcsfile)
@@ -109,7 +97,7 @@ _gnuastro_autocomplete_astarithmetic_option_value(){
;;
--wcslinearmatrix)
- for v in cd pc; do COMPREPLY+=("$v"); done
+ _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
;;
--numthreads)
@@ -130,7 +118,7 @@ _gnuastro_autocomplete_astarithmetic(){
# requested installation directory. Ff you are debugging, please
# correct it yourself (usually to '/usr/local/bin', but don't commit
# this particular change).
- local gnuastro_prefix="@PREFIX@";
+ local gnuastro_prefix="@PREFIX@"
# Basic initialization. The variables we want to remain inside this
# function are given a 'local' here and set inside the 'initialize'
diff --git a/bin/buildprog/astbuildprog-complete.bash
b/bin/buildprog/astbuildprog-complete.bash
index ef82c4d..25960ec 100644
--- a/bin/buildprog/astbuildprog-complete.bash
+++ b/bin/buildprog/astbuildprog-complete.bash
@@ -113,7 +113,7 @@ _gnuastro_autocomplete_astbuildprog(){
# requested installation directory. Ff you are debugging, please
# correct it yourself (usually to '/usr/local/bin', but don't commit
# this particular change).
- local gnuastro_prefix="@PREFIX@";
+ local gnuastro_prefix="@PREFIX@"
# Basic initialization. The variables we want to remain inside this
# function are given a 'local' here and set inside the 'initialize'
diff --git a/bin/completion.bash.in b/bin/completion.bash.in
index ac07be2..66cb168 100644
--- a/bin/completion.bash.in
+++ b/bin/completion.bash.in
@@ -376,7 +376,7 @@ _gnuastro_autocomplete_is_plaintext(){
_gnuastro_autocomplete_is_plaintext_table(){
# Only do the check if the file exists.
- if [ -f $1 ]; then
+ if [ -f "$1" ]; then
# If the file is not plain-text, it will contain an 'executable' or
# 'binary' in the output of the 'file' command.
@@ -409,9 +409,9 @@ _gnuastro_autocomplete_is_plaintext_table(){
# Return successfully if the first argument is a table.
_gnuastro_autocomplete_is_table(){
- if _gnuastro_autocomplete_fits_has_table $1; then return 0
- elif _gnuastro_autocomplete_is_plaintext_table $1; then return 0
- else return 1
+ if _gnuastro_autocomplete_fits_has_table "$1"; then return 0
+ elif _gnuastro_autocomplete_is_plaintext_table "$1"; then return 0
+ else return 1
fi
}
@@ -496,7 +496,7 @@ _gnuastro_autocomplete_first_in_arguments(){
-# Find the requested table from the entered command-line.
+# Find the requested file from the existing tokens on the command-line.
#
# INPUT ARGUMENTS:
# 1) Mode of file ('table' or 'image').
@@ -509,17 +509,34 @@ _gnuastro_autocomplete_given_file(){
# Set inputs (for each readability).
local mode="$1"
local name="$2"
+ local read_option_value=""
# If 'name' is emtpy, we should look in the arguments, otherwise, we
- # should loook into the options.
+ # should look into the options.
if [ x"$name" = x ]; then
if _gnuastro_autocomplete_first_in_arguments $mode; then
# given_file is written by the function as a side-effect.
local just_a_place_holder=1
fi
+
+ # We are looking for a certain option.
else
+ # Read the given option's value.
_gnuastro_autocomplete_read_option_value "$name"
- given_file="$read_option_value"
+
+ # If we are in image-mode, and the found file has an image, then
+ # put the name in 'given_file' (final output). Same for tables.
+ if [ x"$mode" = ximage ]; then
+ if _gnuastro_autocomplete_fits_has_image \
+ "$read_option_value"; then
+ given_file="$read_option_value"
+ fi
+ elif [ x"$mode" = xtable ]; then
+ if _gnuastro_autocomplete_is_table \
+ "$read_option_value"; then
+ given_file="$read_option_value"
+ fi
+ fi
fi
}
@@ -588,10 +605,37 @@ _gnuastro_autocomplete_given_file_and_hdu(){
#######################################################################
############ Completion replies ############
#######################################################################
+# Given a set of strings, select the one that matches the first argument
+_gnuastro_autocomplete_compreply_from_string(){
+
+ # Internal variables (for easy reading).
+ local string="$1"
+ local match="$2"
+
+ # When there isn't any match string, just add everything.
+ if [ x"$match" = x ]; then
+ for v in $string; do COMPREPLY+=("$v"); done
+
+ # When there is a match, limit it. We aren't using 'grep' because it
+ # can confuse a possible '--XXX', with its own options on some systems
+ # (and placing a '--' before the search string may not be portable).
+ else
+ for v in $(echo $string \
+ | awk '{for(i=1;i<=NF;++i) \
+ if($i ~ /^'$match'/) print $i}'); do
+ COMPREPLY+=("$v");
+ done
+ fi
+}
+
+
+
+
# Add completion replies for the values to '--searchin'.
_gnuastro_autocomplete_compreply_searchin(){
- for v in name unit comment; do COMPREPLY+=("$v"); done
+ _gnuastro_autocomplete_compreply_from_string \
+ "name unit comment" "$1"
}
@@ -600,7 +644,8 @@ _gnuastro_autocomplete_compreply_searchin(){
# Add completion replies for the values to '--searchin'.
_gnuastro_autocomplete_compreply_tableformat(){
- for v in fits-ascii fits-binary txt; do COMPREPLY+=("$v"); done
+ _gnuastro_autocomplete_compreply_from_string \
+ "fits-ascii fits-binary txt" "$1"
}
@@ -618,6 +663,27 @@ _gnuastro_autocomplete_compreply_numthreads(){
+# Values to the common '--interpmetric' option.
+_gnuastro_autocomplete_compreply_interpmetric(){
+ _gnuastro_autocomplete_compreply_from_string \
+ "radial manhattan" "$1"
+}
+
+
+
+
+
+# Values to the common '--type' option.
+_gnuastro_autocomplete_compreply_numbertype(){
+ _gnuastro_autocomplete_compreply_from_string \
+ "uint8 int8 uint16 int16 uint32 int32 uint64 int64 float32 float64" \
+ "$1"
+}
+
+
+
+
+
# Add matching options to the completion replies.
_gnuastro_autocomplete_compreply_options_all(){
@@ -680,11 +746,23 @@ _gnuastro_autocomplete_compreply_file(){
# INPUT ARGUMENTS
# 1) Mode of file ('table' or 'image').
# 2) Name of file.
+# 3) Existing argument.
_gnuastro_autocomplete_compreply_hdus(){
- if _gnuastro_autocomplete_is_fits "$2"; then
- for h in $("$gnuastro_prefix"/astfits "$2" --list"$1"hdus); do
- COMPREPLY+=("$h")
- done
+
+ # Local variables (for easy reading)
+ local mode="$1"
+ local given_file="$2"
+ local matchstr="$3"
+
+ if _gnuastro_autocomplete_is_fits "$given_file"; then
+
+ # Get list of the file's HDUs.
+ hdus=$("$gnuastro_prefix"/astfits "$given_file" \
+ --list"$mode"hdus)
+
+ # Add the matching ones into COMPREPLY.
+ _gnuastro_autocomplete_compreply_from_string \
+ "$hdus" "$matchstr"
fi
}
@@ -737,6 +815,53 @@ _gnuastro_autocomplete_compreply_directories(){
+# Fill the replies with all image formats (note that the 'image' of
+# '_gnuastro_autocomplete_compreply_files_certain' is only FITS files)
+_gnuastro_autocomplete_compreply_images_all(){
+
+ # Local variables to be filled by functions.
+ local arg="$1"
+ local ls_in=""
+ local files=""
+ local suffixes_jpeg=""
+ local suffixes_tiff=""
+
+ # Get the FITS images.
+ _gnuastro_autocomplete_compreply_files_certain image "$arg"
+
+ # If the given name doesn't have a suffix, then search for desired
+ # suffixes.
+ if [ x"$arg" = x"$(echo $arg | cut -d. -f1)" ]; then
+
+ # Since the other formats are checked by suffix and there are many
+ # suffixes, its easier to just call 'ls' once.
+ _gnuastro_autocomplete_compreply_suffixes_jpeg
+ _gnuastro_autocomplete_compreply_suffixes_tiff
+ for s in $suffixes_jpeg $suffixes_tiff; do
+ ls_in="$ls_in "$arg"*$s"
+ done
+
+ # The given argument already contains a suffix. So you can safely
+ # ignore the matched suffixes.
+ else
+ ls_in=$arg"*"
+ fi
+
+ # Find the matching files and add them to the replies.
+ files=($(ls -d $ls_in 2> /dev/null))
+ for f in ${files[*]}; do
+ if [ -d "$f" ]; then
+ COMPREPLY+=("$f/")
+ compopt -o nospace
+ else
+ _gnuastro_autocomplete_compreply_file "$arg" "$f"
+ fi
+ done
+}
+
+
+
+
# Fill the replies with certain files.
_gnuastro_autocomplete_compreply_files_certain(){
@@ -792,15 +917,30 @@ _gnuastro_autocomplete_compreply_table_columns(){
# Inputs
local table_file="$1"
local table_hdu="$2"
- local tomatch="$3"
+ local fullmatch="$3"
+ local continuematch="$4"
# Internal
+ local tomatch=""
local columns=""
local hdu_option=""
+ # If no file has been given, don't set anything, just return.
+ if [ x"$table_file" = x ]; then return 0; fi
+
# If a HDU is given, then add it to the options.
if [ x"$table_hdu" != x ]; then hdu_option="--hdu=$table_hdu"; fi
+ # Columns can usually be given in series (for example
+ # '--column=A,B,C'). In this case, the caller will give a non-empty
+ # value to the fourth argument ('continuematch'). To deal with it, we
+ # will take the last component of the comma-separated list.
+ if [ x"$continuematch" = x ]; then
+ tomatch="$fullmatch"
+ else
+ tomatch=$(echo $fullmatch | awk 'BEGIN{FS=","} {print $NF}')
+ fi
+
# Get the list of columns from the output of '--information': the
# column names are the second column of the lines that start with a
# number. If there is no column name, print the column number.
@@ -818,5 +958,35 @@ _gnuastro_autocomplete_compreply_table_columns(){
| grep ^$tomatch)
# Add the columns into the completion replies.
- for c in $columns; do COMPREPLY+=("$c"); done
+ if [ x"$continuematch" = x ]; then
+ for c in $columns; do COMPREPLY+=("$c"); done
+ else
+ # If there is only one match, include the previously specified
+ # columns in the final filled value and append an ',' to let the
+ # user specify more columns.
+ if [ $(echo $columns | wc -w) = 1 ]; then
+
+ # In the continue-mode we don't want the final value to be
+ # appended with a space.
+ compopt -o nospace
+
+ # When 'fullmatch' and 'tomatch' are the same, this was the
+ # first requested column, so we can safely just print it.
+ if [ x"$fullmatch" = x"$tomatch" ]; then
+ COMPREPLY+=("$columns,")
+
+ # This was not the first column, so we need to add the old ones
+ # as a prefix. But we first need to remove any possible start
+ # of the current column.
+ else
+ local oldcols=$(echo "$fullmatch" | sed -e's|'$tomatch'$||')
+ COMPREPLY+=("$oldcols$columns,")
+ fi
+
+ # There was more than one matching column, so continue suggesting
+ # with only the column names.
+ else
+ for c in $columns; do COMPREPLY+=("$c"); done
+ fi
+ fi
}
diff --git a/bin/convertt/Makefile.am b/bin/convertt/Makefile.am
index 33f2b3c..635c051 100644
--- a/bin/convertt/Makefile.am
+++ b/bin/convertt/Makefile.am
@@ -36,7 +36,8 @@ astconvertt_LDADD =
$(top_builddir)/bootstrapped/lib/libgnu.la \
astconvertt_SOURCES = main.c ui.c convertt.c color.c
-EXTRA_DIST = main.h authors-cite.h args.h ui.h convertt.h color.h
+EXTRA_DIST = main.h authors-cite.h args.h ui.h convertt.h color.h \
+ astconvertt-complete.bash
diff --git a/bin/buildprog/astbuildprog-complete.bash
b/bin/convertt/astconvertt-complete.bash
similarity index 67%
copy from bin/buildprog/astbuildprog-complete.bash
copy to bin/convertt/astconvertt-complete.bash
index ef82c4d..613065d 100644
--- a/bin/buildprog/astbuildprog-complete.bash
+++ b/bin/convertt/astconvertt-complete.bash
@@ -1,4 +1,4 @@
-# Bash autocompletion to Gnuastro's BuildProgram. See the comments above
+# Bash autocompletion to Gnuastro's ConvertType. See the comments above
# 'bin/completion.bash.in' for more.
#
# Original author:
@@ -34,28 +34,16 @@
#######################################################################
-############ Only for BuildProgram (this program) ############
+############ Only for ConvertType (this program) ############
#######################################################################
-# Fill the replies with available C compilers
-_gnuastro_autocomplete_compreply_c_compiler(){
- for f in gcc clang cc $CC; do
- if which $f &> /dev/null; then COMPREPLY+=("$f"); fi
- done
-}
-
-
-
-
-
-# Dealing with arguments: BuildProgram currently only takes C source files.
-_gnuastro_autocomplete_astbuildprog_arguments(){
- local given_file=""
- if _gnuastro_autocomplete_first_in_arguments source_c; then
- _gnuastro_autocomplete_compreply_options_all ""
- else
- _gnuastro_autocomplete_compreply_files_certain source_c "$argument"
- fi
+# 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"
}
@@ -63,42 +51,44 @@ _gnuastro_autocomplete_astbuildprog_arguments(){
# Fill option value (depends on option).
-_gnuastro_autocomplete_astbuildprog_option_value(){
+_gnuastro_autocomplete_astconvertt_option_value(){
# Internal variables.
- local junk=1
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
- -a|--la)
- _gnuastro_autocomplete_compreply_files_certain source_la "$current"
+ -h|--hdu|-g|--globalhdu)
+ _gnuastro_autocomplete_given_file image ""
+ _gnuastro_autocomplete_compreply_hdus \
+ image "$given_file" "$current"
;;
- -c|--cc)
- _gnuastro_autocomplete_compreply_c_compiler
+ --colormap)
+ _gnuastro_autocomplete_compreply_convertt_colormap
+ _gnuastro_autocomplete_compreply_from_string \
+ "$convertt_colormaps" "$current"
;;
- -I|--includedir|-L|--linkdir)
- _gnuastro_autocomplete_compreply_directories "$current"
+ -u|--quality)
+ _gnuastro_autocomplete_compreply_from_string \
+ "$(seq 100)" "$current"
;;
- -l|--linklib|-t|--tag|-W|--warning)
- # There is no easy way to guess which libraries the user wants
- # to link with, or the tag, or the warning level.
- junk=1
+ --wcslinearmatrix)
+ _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
;;
- -O|--optimize)
- for f in $(printf "0\n1\n2\n3" | grep ^"$current"); do
- COMPREPLY+=("$f");
- done
+ --numthreads)
+ _gnuastro_autocomplete_compreply_numthreads
;;
+
esac
}
@@ -106,14 +96,14 @@ _gnuastro_autocomplete_astbuildprog_option_value(){
-_gnuastro_autocomplete_astbuildprog(){
+_gnuastro_autocomplete_astconvertt(){
# The installation directory of Gnuastro. The '@PREFIX@' part will be
# replaced automatically during 'make install', with the user's given
# requested installation directory. Ff you are debugging, please
# correct it yourself (usually to '/usr/local/bin', but don't commit
# this particular change).
- local gnuastro_prefix="@PREFIX@";
+ local gnuastro_prefix="@PREFIX@"
# Basic initialization. The variables we want to remain inside this
# function are given a 'local' here and set inside the 'initialize'
@@ -149,7 +139,7 @@ _gnuastro_autocomplete_astbuildprog(){
# If 'option_name_complete==1', then we are busy filling in the option
# value.
if [ $option_name_complete = 1 ]; then
- _gnuastro_autocomplete_astbuildprog_option_value
+ _gnuastro_autocomplete_astconvertt_option_value
# When 'option_name' is not empty (and not yet complete), we are busy
# filling in the option name.
@@ -158,7 +148,7 @@ _gnuastro_autocomplete_astbuildprog(){
# In the case of "none-of-the-above", it is an argument.
else
- _gnuastro_autocomplete_astbuildprog_arguments
+ _gnuastro_autocomplete_astconvertt_arguments
fi
}
@@ -169,4 +159,4 @@ _gnuastro_autocomplete_astbuildprog(){
# 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_astbuildprog astbuildprog
+complete -o bashdefault -F _gnuastro_autocomplete_astconvertt astconvertt
diff --git a/bin/convertt/ui.c b/bin/convertt/ui.c
index 939dd08..98fe093 100644
--- a/bin/convertt/ui.c
+++ b/bin/convertt/ui.c
@@ -235,14 +235,17 @@ ui_colormap_sanity_check(struct converttparams *p)
size_t nparams=0;
int ccode=COLOR_INVALID;
- /* See how many parameters are necessary. */
+ /* See how many parameters are necessary.
+ Notes for TAB completion:
+ 1. Keep 'gray' and 'grey' in the same line.
+ 2. Keep a space after the ',' before the strings. */
strarr=p->colormap->array;
- if ( !strcmp(strarr[0],"hsv")) { ccode=COLOR_HSV; nparams=2; }
- else if( !strcmp(strarr[0],"sls")) { ccode=COLOR_SLS; nparams=0; }
- else if( !strcmp(strarr[0],"viridis")) { ccode=COLOR_VIRIDIS; nparams=0; }
- else if( !strcmp(strarr[0],"gray") || !strcmp(strarr[0],"grey"))
- { ccode=COLOR_GRAY; nparams=0; }
- else if( !strcmp(strarr[0],"sls-inverse"))
+ if ( !strcmp(strarr[0], "hsv")) { ccode=COLOR_HSV; nparams=2; }
+ else if( !strcmp(strarr[0], "sls")) { ccode=COLOR_SLS; nparams=0; }
+ else if( !strcmp(strarr[0], "viridis")) { ccode=COLOR_VIRIDIS; nparams=0; }
+ else if( !strcmp(strarr[0], "gray") || !strcmp(strarr[0], "grey"))
+ { ccode=COLOR_GRAY; nparams=0; }
+ else if( !strcmp(strarr[0], "sls-inverse"))
{ ccode=COLOR_SLS_INVERSE; nparams=0; }
else
error(EXIT_FAILURE, 0, "'%s' not recognized as a colormap given "
diff --git a/bin/table/asttable-complete.bash
b/bin/convolve/astconvolve-complete.bash
similarity index 63%
copy from bin/table/asttable-complete.bash
copy to bin/convolve/astconvolve-complete.bash
index d68c6dd..8d89913 100644
--- a/bin/table/asttable-complete.bash
+++ b/bin/convolve/astconvolve-complete.bash
@@ -1,10 +1,9 @@
-# Bash autocompletion to Gnuastro's Table program. See the comments above
-# 'bin/completion.bash.in' for more.
+# Bash autocompletion to Gnuastro's Convolve program. See the comments
+# above 'bin/completion.bash.in' for more.
#
# Original author:
-# Pedram Ashofteh Ardakani <pedramardakani@pm.me>
-# Contributing author(s):
# Mohammad Akhlaghi <mohammad@akhlaghi.org>
+# Contributing author(s):
# Copyright (C) 2021 Free Software Foundation, Inc.
#
# Gnuastro is free software: you can redistribute it and/or modify it under
@@ -35,16 +34,19 @@
#######################################################################
-############ Only for Table (this program) ############
+############ Only for Convolve (this program) ############
#######################################################################
-# Dealing with arguments: Table only takes one argument/file. So if a table
-# has been previously given on the command-line only print option names.
-_gnuastro_autocomplete_asttable_arguments(){
+# Dealing with arguments: Convolve only takes one argument/file (either an
+# image or a table). So if an image/table file has already been given on
+# the command-line only suggest option names.
+_gnuastro_autocomplete_astconvolve_arguments(){
local given_file=""
- if _gnuastro_autocomplete_first_in_arguments table; then
+ if _gnuastro_autocomplete_first_in_arguments image \
+ || _gnuastro_autocomplete_first_in_arguments table; then
_gnuastro_autocomplete_compreply_options_all ""
else
+ _gnuastro_autocomplete_compreply_files_certain image "$argument"
_gnuastro_autocomplete_compreply_files_certain table "$argument"
fi
}
@@ -54,76 +56,80 @@ _gnuastro_autocomplete_asttable_arguments(){
# Fill option value (depends on option).
-_gnuastro_autocomplete_asttable_option_value(){
+_gnuastro_autocomplete_astconvolve_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
- # Options that need a column from the main argument.
- -b|--noblank|-c|--column|--inpolygon|--outpolygon)
+ -c|--column)
_gnuastro_autocomplete_given_file_and_hdu table "" --hdu
_gnuastro_autocomplete_compreply_table_columns \
"$given_file" "$given_hdu" "$current"
;;
- # Options that take the column name as first component of value.
- -m|--colmetadata|-e|--equal|-n|--notequal)
-
- # Get the main argument's name (and possible HDU).
- _gnuastro_autocomplete_given_file_and_hdu table "" --hdu
- _gnuastro_autocomplete_compreply_table_columns \
- "$given_file" "$given_hdu" "$current"
-
- # Since these options take a column name as first value and the
- # user should continue with other details, we need to disable
- # the extra space on the command-line after the successful
- # match.
- compopt -o nospace
+ # Since Convolve takes both tables and images, if we can't find an
+ # already given image file, we'll search for a table.
+ --hdu|--khdu)
+ # Set the option name to check for the file.
+ local fileoption=""
+ if [ "$option_name" = "--khdu" ]; then fileoption="--kernel"; fi
+
+ # Find the matching HDUs.
+ _gnuastro_autocomplete_given_file image "$fileoption"
+ if [ x"$given_file" = x ]; then
+ _gnuastro_autocomplete_given_file table "$fileoption"
+ _gnuastro_autocomplete_compreply_hdus \
+ table "$given_file" "$current"
+ else
+ _gnuastro_autocomplete_compreply_hdus \
+ image "$given_file" "$current"
+ fi
;;
- -C|--catcolumns)
- _gnuastro_autocomplete_given_file_and_hdu \
- table --catcolumnfile --catcolumnhdu
+ --kernelcolumn)
+ _gnuastro_autocomplete_given_file_and_hdu table --kernel --khdu
_gnuastro_autocomplete_compreply_table_columns \
"$given_file" "$given_hdu" "$current"
;;
- -h|--hdu)
- _gnuastro_autocomplete_given_file table ""
- _gnuastro_autocomplete_compreply_hdus table "$given_file"
- ;;
-
- -L|--catcolumnfile)
+ -k|--kernel)
+ _gnuastro_autocomplete_compreply_files_certain image "$current"
_gnuastro_autocomplete_compreply_files_certain table "$current"
;;
--searchin)
- _gnuastro_autocomplete_compreply_searchin
+ _gnuastro_autocomplete_compreply_searchin "$current"
;;
- -u|--catcolumnhdu)
- _gnuastro_autocomplete_given_file table --catcolumnfile
- _gnuastro_autocomplete_compreply_hdus table "$given_file"
+ --interpmetric)
+ _gnuastro_autocomplete_compreply_interpmetric "$current"
;;
- -w|--wcsfile)
- _gnuastro_autocomplete_compreply_files_certain image "$current"
+ --type)
+ _gnuastro_autocomplete_compreply_numbertype "$current"
;;
- -W|--wcshdu)
- _gnuastro_autocomplete_given_file image --wcsfile
- _gnuastro_autocomplete_compreply_hdus image "$given_file"
+ --wcslinearmatrix)
+ _gnuastro_autocomplete_compreply_from_string "cd pc" "$current"
;;
- --tableformat)
- _gnuastro_autocomplete_compreply_tableformat
+ -d|--domain)
+ _gnuastro_autocomplete_compreply_from_string \
+ "spatial frequency" "$current"
;;
+
+ --numthreads)
+ _gnuastro_autocomplete_compreply_numthreads
+ ;;
+
+
esac
}
@@ -131,14 +137,14 @@ _gnuastro_autocomplete_asttable_option_value(){
-_gnuastro_autocomplete_asttable(){
+_gnuastro_autocomplete_astconvolve(){
# The installation directory of Gnuastro. The '@PREFIX@' part will be
# replaced automatically during 'make install', with the user's given
# requested installation directory. Ff you are debugging, please
# correct it yourself (usually to '/usr/local/bin', but don't commit
# this particular change).
- local gnuastro_prefix="@PREFIX@";
+ local gnuastro_prefix="@PREFIX@"
# Basic initialization. The variables we want to remain inside this
# function are given a 'local' here and set inside the 'initialize'
@@ -174,7 +180,7 @@ _gnuastro_autocomplete_asttable(){
# If 'option_name_complete==1', then we are busy filling in the option
# value.
if [ $option_name_complete = 1 ]; then
- _gnuastro_autocomplete_asttable_option_value
+ _gnuastro_autocomplete_astconvolve_option_value
# When 'option_name' is not empty (and not yet complete), we are busy
# filling in the option name.
@@ -183,7 +189,7 @@ _gnuastro_autocomplete_asttable(){
# In the case of "none-of-the-above", it is an argument.
else
- _gnuastro_autocomplete_asttable_arguments
+ _gnuastro_autocomplete_astconvolve_arguments
fi
}
@@ -194,4 +200,4 @@ _gnuastro_autocomplete_asttable(){
# 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_asttable asttable
+complete -o bashdefault -F _gnuastro_autocomplete_astconvolve astconvolve
diff --git a/bin/table/asttable-complete.bash b/bin/table/asttable-complete.bash
index d68c6dd..93fe6f0 100644
--- a/bin/table/asttable-complete.bash
+++ b/bin/table/asttable-complete.bash
@@ -65,26 +65,29 @@ _gnuastro_autocomplete_asttable_option_value(){
# with similar operations, keep the order within the '|'s.
case "$option_name" in
- # Options that need a column from the main argument.
- -b|--noblank|-c|--column|--inpolygon|--outpolygon)
- _gnuastro_autocomplete_given_file_and_hdu table "" --hdu
- _gnuastro_autocomplete_compreply_table_columns \
- "$given_file" "$given_hdu" "$current"
- ;;
+ # Options that take a columns from the main argument.
+
--column|--noblank|--inpolygon|--outpolygon|--colmetadata|--equal|--notequal)
- # Options that take the column name as first component of value.
- -m|--colmetadata|-e|--equal|-n|--notequal)
+ # The '--column' and '--noblank' options can (and usually
+ # will!) take more than one column name as value.
+ local continuematch=""
+ case "$option_name" in
+ --column|--noblank) continuematch=yes;;
+ esac
- # Get the main argument's name (and possible HDU).
+ # Find the suggestions.
_gnuastro_autocomplete_given_file_and_hdu table "" --hdu
_gnuastro_autocomplete_compreply_table_columns \
- "$given_file" "$given_hdu" "$current"
-
- # Since these options take a column name as first value and the
- # user should continue with other details, we need to disable
- # the extra space on the command-line after the successful
- # match.
- compopt -o nospace
+ "$given_file" "$given_hdu" "$current" "$continuematch"
+
+ # These options take a column name as first value, and the user
+ # should continue with other details. So when there is only one
+ # match, we need to disable the extra space that is printed by
+ # default and also add a ',' to prepare the user for entering
+ # other points.
+ case "$option_name" in
+ --colmetadata|--equal|--notequal) compopt -o nospace;;
+ esac
;;
-C|--catcolumns)
@@ -96,7 +99,8 @@ _gnuastro_autocomplete_asttable_option_value(){
-h|--hdu)
_gnuastro_autocomplete_given_file table ""
- _gnuastro_autocomplete_compreply_hdus table "$given_file"
+ _gnuastro_autocomplete_compreply_hdus \
+ table "$given_file" "$current"
;;
-L|--catcolumnfile)
@@ -104,12 +108,13 @@ _gnuastro_autocomplete_asttable_option_value(){
;;
--searchin)
- _gnuastro_autocomplete_compreply_searchin
+ _gnuastro_autocomplete_compreply_searchin "$current"
;;
-u|--catcolumnhdu)
_gnuastro_autocomplete_given_file table --catcolumnfile
- _gnuastro_autocomplete_compreply_hdus table "$given_file"
+ _gnuastro_autocomplete_compreply_hdus \
+ table "$given_file" "$current"
;;
-w|--wcsfile)
@@ -118,7 +123,8 @@ _gnuastro_autocomplete_asttable_option_value(){
-W|--wcshdu)
_gnuastro_autocomplete_given_file image --wcsfile
- _gnuastro_autocomplete_compreply_hdus image "$given_file"
+ _gnuastro_autocomplete_compreply_hdus \
+ image "$given_file" "$current"
;;
--tableformat)
@@ -138,7 +144,7 @@ _gnuastro_autocomplete_asttable(){
# requested installation directory. Ff you are debugging, please
# correct it yourself (usually to '/usr/local/bin', but don't commit
# this particular change).
- local gnuastro_prefix="@PREFIX@";
+ local gnuastro_prefix="@PREFIX@"
# Basic initialization. The variables we want to remain inside this
# function are given a 'local' here and set inside the 'initialize'
diff --git a/lib/gnuastro-internal/commonopts.h
b/lib/gnuastro-internal/commonopts.h
index 16fc496..68f4a5f 100644
--- a/lib/gnuastro-internal/commonopts.h
+++ b/lib/gnuastro-internal/commonopts.h
@@ -201,7 +201,7 @@ struct argp_option gal_commonopts_options[] =
{
"interpmetric",
GAL_OPTIONS_KEY_INTERPMETRIC,
- "INT",
+ "STR",
0,
"Interpolation metric (radial, manhattan).",
GAL_OPTIONS_GROUP_TESSELLATION,
diff --git a/lib/jpeg.c b/lib/jpeg.c
index 8dd09c7..fe3ec34 100644
--- a/lib/jpeg.c
+++ b/lib/jpeg.c
@@ -114,14 +114,14 @@ gal_jpeg_name_is_jpeg(char *name)
if(name)
{
len=strlen(name);
- if ( ( len>=3 && strcmp(&name[len-3], "jpg") == 0 )
- || ( len>=3 && strcmp(&name[len-3], "JPG") == 0 )
+ if ( ( len>=3 && strcmp(&name[len-3], "jpg") == 0 )
+ || ( len>=3 && strcmp(&name[len-3], "JPG") == 0 )
|| ( len>=4 && strcmp(&name[len-4], "jpeg") == 0 )
|| ( len>=4 && strcmp(&name[len-4], "JPEG") == 0 )
- || ( len>=3 && strcmp(&name[len-3], "jpe") == 0 )
- || ( len>=3 && strcmp(&name[len-3], "jif") == 0 )
+ || ( len>=3 && strcmp(&name[len-3], "jpe") == 0 )
+ || ( len>=3 && strcmp(&name[len-3], "jif") == 0 )
|| ( len>=4 && strcmp(&name[len-4], "jfif") == 0 )
- || ( len>=3 && strcmp(&name[len-3], "jfi") == 0 ) )
+ || ( len>=3 && strcmp(&name[len-3], "jfi") == 0 ) )
return 1;
else
return 0;
diff --git a/lib/tiff.c b/lib/tiff.c
index 219189c..6085e88 100644
--- a/lib/tiff.c
+++ b/lib/tiff.c
@@ -71,7 +71,7 @@ gal_tiff_name_is_tiff(char *name)
if(name)
{
len=strlen(name);
- if ( ( len>=3 && strcmp(&name[len-3], "tif") == 0 )
+ if ( ( len>=3 && strcmp(&name[len-3], "tif") == 0 )
|| ( len>=3 && strcmp(&name[len-3], "TIF") == 0 )
|| ( len>=4 && strcmp(&name[len-4], "tiff") == 0 )
|| ( len>=4 && strcmp(&name[len-4], "TIFF") == 0 ) )
- [gnuastro-commits] master 51daecd 30/62: Table: Completion, update copyright, minor edits, (continued)
- [gnuastro-commits] master 51daecd 30/62: Table: Completion, update copyright, minor edits, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e690fc5 37/62: Bash completion: renamed fixed file to completion.bash, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 229ac51 41/62: /bin/table/completion.bash: Refactor code, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 50026ec 48/62: Auto-completion: Rename boolean query functions, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 8150e1c 50/62: Auto-completion: Refactor FITS related functions, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master afadccf 52/62: Auto-completion: Call ..._last_table where needed, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 90f08c2 53/62: Auto-completion: Refactor ..._is_table function, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 4598eba 54/62: Auto-completion: clean re-implementation for Table, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 59669d9 61/62: Book: new section on known issues with Crop, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master b947f79 62/62: TAB completion: enabled in Fits program, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master acf58c1 58/62: TAB completion: now supported in ConvertType and Convolve,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 9ae830f 34/62: Table: Completion, replace double negative, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 7f1a203 35/62: Book: Autocompletion for developers example, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 6379566 36/62: Book: edits to the Bash auto-completion section, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 9335953 44/62: Auto-completion: Faster fits parse, use 'local', Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 284a32e 51/62: Auto-completion: Debug -i, improve performance, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e5707cd 28/62: Table: Completion, all options, update comments, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 88806f2 38/62: bin/table/completion.bash: improvements to find good table name, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 1bf469f 40/62: /bin/table/completion.bash: consider short opt '-i', Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e340452 42/62: Auto-completion: Minor polishing of the warning message, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e444941 45/62: Auto-completion: Call astfits/asttable consistently, Mohammad Akhlaghi, 2021/05/13