gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 9bb47f3 051/125: New elements for argp_option


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 9bb47f3 051/125: New elements for argp_option for new option management
Date: Sun, 23 Apr 2017 22:36:35 -0400 (EDT)

branch: master
commit 9bb47f370ae44c7bc7f3cb43f65e6ece52c7c649
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    New elements for argp_option for new option management
    
    This is the first commit for task #14300 ("Option management using new root
    data structure."). The main purpose was to make it simple to read the
    options and their values from the command-line and configuration files. The
    way the system works now is to use `argp' for command-line options, and 3
    functions in each program's `ui.c' to read the command-line. These three
    functions are very repetative, and we have to keep the string value of each
    option twice. This is hard to maintain and buggy.
    
    To do this, in `bootstrap.conf', we add the two elements `value' and `type'
    to the definition of the argp_option' in the bootstrapped `argp.h'. Through
    `config.h', Gnulib gives its own headers higher precedence, so we can
    ignore the (possibly existing) `argp.h' in the user's own system and use
    these new elements. Also, the definition of `argp_option' is no longer
    static, so we can pass its pointer to the libraries.
    
    From the new data structure, we just needed the type macros, not a full
    `gal_data_t'. Also, a new type was added for string linked lists, mainly
    for this task (reading options), but later it can be useful to generally
    define linked list types too and unify all the linked list functions in
    `linkedlist.h' into one.
---
 bin/table/args.h    | 17 +++++++++++------
 bootstrap.conf      | 28 +++++++++++++++++++++++++++-
 lib/commonargs.h    | 46 ++++++++++++++++++++++++++++++----------------
 lib/gnuastro/data.h |  2 ++
 4 files changed, 70 insertions(+), 23 deletions(-)

diff --git a/bin/table/args.h b/bin/table/args.h
index 79bce89..c2e1587 100644
--- a/bin/table/args.h
+++ b/bin/table/args.h
@@ -85,7 +85,7 @@ const char doc[] =
    Options with keys (second structure element) larger than 500 do not
    have a short version.
  */
-static struct argp_option options[] =
+struct argp_option options[] =
   {
     {
       0, 0, 0, 0,
@@ -98,7 +98,8 @@ static struct argp_option options[] =
       "STR",
       0,
       "Column number (counting from 1) or search string.",
-      1
+      1,
+      NULL, GAL_DATA_TYPE_STRLL
     },
     {
       "searchin",
@@ -106,7 +107,8 @@ static struct argp_option options[] =
       "STR",
       0,
       "Search in column `name', `units', or `comments'.",
-      1
+      1,
+      NULL, GAL_DATA_TYPE_STRING
     },
     {
       "ignorecase",
@@ -114,7 +116,8 @@ static struct argp_option options[] =
       0,
       0,
       "Ignore case when matching column information.",
-      1
+      1,
+      NULL, GAL_DATA_TYPE_INT
     },
 
 
@@ -131,7 +134,8 @@ static struct argp_option options[] =
       "STR",
       0,
       "Output table type: `fits-ascii', `fits-binary'.",
-      2
+      2,
+      NULL, GAL_DATA_TYPE_STRING
     },
 
 
@@ -148,7 +152,8 @@ static struct argp_option options[] =
       0,
       0,
       "Only print table and columns information.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_INT
     },
 
 
diff --git a/bootstrap.conf b/bootstrap.conf
index 8f977bd..99db2bb 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -97,7 +97,6 @@ gnulib_name="libgnu"
 # Processes to run after gnulib-tool and before autoreconf.
 bootstrap_post_import_hook()
 {
-
   # List of m4 files we need from the GNU Autoconf Archives (excluding the
   # `ax_' prefix and `.m4' suffix):
   neededm4s="pthread compare_version"
@@ -126,6 +125,33 @@ bootstrap_post_import_hook()
         
"http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_$m4name.m4";
 || die "Failed to download ax_$m4name.m4!"
     done
   fi
+
+  # Add a value pointer to `argp_option' for easy setting of option values.
+  awk '{                                            \
+         if($1=="struct" && $2=="argp_option")      \
+           inargp=1;                                \
+                                                    \
+         if(inargp==0)                              \
+           print;                                   \
+         else if($1=="};")                          \
+           {                                        \
+             printf "\n";                           \
+             print "  /* Pointer to value.";        \
+             print "     IMPORTANT: currently ONLY a Gnuastro addition. */"; \
+             print "  void *value;";                \
+                                                    \
+             printf "\n";                           \
+             print "  /* Type of value (see lib/gnuastro/data.h)."; \
+             print "     IMPORTANT: currently ONLY a Gnuastro addition. */"; \
+             print "  int type;";                   \
+                                                    \
+             print;                                 \
+             inargp=0;                              \
+          }                                         \
+         else                                       \
+          print;                                    \
+       }' bootstrapped/lib/argp.h > argp_tmp.h
+  mv argp_tmp.h bootstrapped/lib/argp.h
 }
 
 
diff --git a/lib/commonargs.h b/lib/commonargs.h
index 83caf0d..7ef8620 100644
--- a/lib/commonargs.h
+++ b/lib/commonargs.h
@@ -65,7 +65,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "Only report errors, remain quiet about steps.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "printparams",
@@ -73,7 +74,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "Print parameter values to be used and abort.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "setdirconf",
@@ -81,7 +83,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "Set default values for this directory and abort.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "setusrconf",
@@ -89,7 +92,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "Set default values for this user and abort.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "numthreads",
@@ -97,7 +101,8 @@ static struct argp_option gal_commonargs_options[] =
       "INT",
       0,
       "Number of CPU threads to use.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "cite",
@@ -105,7 +110,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "BibTeX citation for "SPACK_NAME".",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "onlydirconf",
@@ -113,7 +119,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "Only read current directory configuration file.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "onlyversion",
@@ -121,23 +128,26 @@ static struct argp_option gal_commonargs_options[] =
       "STR",
       0,
       "Only run if the program version is this.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
-      "nolog",
+      "log",
       1003,
       0,
       0,
       "No log file for programs which make one.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "minmapsize",
       1004,
-      0,
+      "INT",
       0,
       "Minimum no. bytes to map arrays to hdd/ssd.",
-      -1
+      -1,
+      NULL, GAL_DATA_TYPE_ULONG
     },
 
 
@@ -153,7 +163,8 @@ static struct argp_option gal_commonargs_options[] =
       "STR",
       0,
       "Extension name or number of input data.",
-      1
+      1,
+      NULL, GAL_DATA_TYPE_STRING
     },
 #endif
 
@@ -168,7 +179,8 @@ static struct argp_option gal_commonargs_options[] =
       "STR",
       0,
       "Output file or directory name.",
-      2
+      2,
+      NULL, GAL_DATA_TYPE_STRING
     },
     {
       "dontdelete",
@@ -176,7 +188,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "Don't delete output if it exists.",
-      2
+      2,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
     {
       "keepinputdir",
@@ -184,7 +197,8 @@ static struct argp_option gal_commonargs_options[] =
       0,
       0,
       "Do not remove input's dir info for output.",
-      2
+      2,
+      NULL, GAL_DATA_TYPE_UCHAR
     },
 
 
diff --git a/lib/gnuastro/data.h b/lib/gnuastro/data.h
index f5cd3cb..2be4e26 100644
--- a/lib/gnuastro/data.h
+++ b/lib/gnuastro/data.h
@@ -103,6 +103,8 @@ enum gal_data_types
   GAL_DATA_TYPE_DOUBLE,    /* double           (TDOUBLE).     */
   GAL_DATA_TYPE_COMPLEX,   /* Complex float    (TCOMPLEX).    */
   GAL_DATA_TYPE_DCOMPLEX,  /* Complex double   (TDBLCOMPLEX). */
+
+  GAL_DATA_TYPE_STRLL,     /* String linked list.             */
 };
 
 



reply via email to

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