[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 56bd4e5 03/16: checkset func for some option v
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 56bd4e5 03/16: checkset func for some option value allocations |
Date: |
Wed, 24 Aug 2016 22:27:43 +0000 (UTC) |
branch: master
commit 56bd4e58c4d5b0cbba4fcefa0104c43a2e4807f5
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
checkset func for some option value allocations
The `gal_checkset_allocate_copy_set' was defined to simplify the option
value allocation procedure and make the code more readable. It was
implemented in some utilities, but strangely it was not used in others. So
after a search through all `ui.c' and `args.h' files, it is now used in all
the places where it should have been used.
---
lib/gnuastro/commonargs.h | 14 ++--------
src/TEMPLATE/main.h | 2 +-
src/TEMPLATE/ui.c | 10 +------
src/header/ui.c | 10 +------
src/imgcrop/ui.c | 23 ++++-----------
src/noisechisel/ui.c | 68 ++++++++++-----------------------------------
src/subtractsky/ui.c | 66 ++++++++-----------------------------------
7 files changed, 37 insertions(+), 156 deletions(-)
diff --git a/lib/gnuastro/commonargs.h b/lib/gnuastro/commonargs.h
index 7d85c60..8e5fe5d 100644
--- a/lib/gnuastro/commonargs.h
+++ b/lib/gnuastro/commonargs.h
@@ -248,19 +248,11 @@ gal_checkset_commonargs_cparse_opt(int key, char *arg,
struct argp_state *state)
/* Input/output: */
case 'h':
- errno=0;
- cp->hdu=malloc(strlen(arg)+1);
- if(cp->hdu==NULL) error(EXIT_FAILURE, 0, "space for hdu");
- strcpy(cp->hdu, arg);
- cp->hduset=1;
+ gal_checkset_allocate_copy_set(arg, &cp->hdu, &cp->hduset);
break;
case 'o':
- errno=0;
- cp->output=malloc(strlen(arg)+1);
- if(cp->output==NULL) error(EXIT_FAILURE, 0, "space for output");
- strcpy(cp->output, arg); /* This allocation is done so cp->output */
- cp->outputset=1; /* Can always be freed when set, because */
- break; /* It usually needs modifications. */
+ gal_checkset_allocate_copy_set(arg, &cp->output, &cp->outputset);
+ break;
case 'D':
cp->dontdelete=1;
break;
diff --git a/src/TEMPLATE/main.h b/src/TEMPLATE/main.h
index 4ebd0f5..ff49659 100644
--- a/src/TEMPLATE/main.h
+++ b/src/TEMPLATE/main.h
@@ -48,7 +48,7 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
struct uiparams
{
- char *inputname; /* Name of input file. */
+ char *inputname; /* Name of input file. */
};
diff --git a/src/TEMPLATE/ui.c b/src/TEMPLATE/ui.c
index 2f8352a..7cd2d1c 100644
--- a/src/TEMPLATE/ui.c
+++ b/src/TEMPLATE/ui.c
@@ -112,15 +112,7 @@ readconfig(char *filename, struct TEMPLATEparams *p)
/* Inputs: */
if(strcmp(name, "hdu")==0)
- {
- if(cp->hduset) continue;
- errno=0;
- cp->hdu=malloc(strlen(value)+1);
- if(cp->hdu==NULL)
- error(EXIT_FAILURE, errno, "space for HDU");
- strcpy(cp->hdu, value);
- cp->hduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
diff --git a/src/header/ui.c b/src/header/ui.c
index 19f1719..f2819aa 100644
--- a/src/header/ui.c
+++ b/src/header/ui.c
@@ -102,15 +102,7 @@ readconfig(char *filename, struct headerparams *p)
/* Inputs: */
if(strcmp(name, "hdu")==0)
- {
- if(cp->hduset) continue;
- errno=0;
- cp->hdu=malloc(strlen(value)+1);
- if(cp->hdu==NULL)
- error(EXIT_FAILURE, errno, "space for HDU");
- strcpy(cp->hdu, value);
- cp->hduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
diff --git a/src/imgcrop/ui.c b/src/imgcrop/ui.c
index 82679ff..61cc70f 100644
--- a/src/imgcrop/ui.c
+++ b/src/imgcrop/ui.c
@@ -217,25 +217,12 @@ readconfig(char *filename, struct imgcropparams *p)
up->checkcenterset=1;
}
else if(strcmp(name, "output")==0)
- {
- if(cp->outputset) continue;
- errno=0;
- cp->output=malloc(strlen(value)+1);
- if(cp->output==NULL)
- error(EXIT_FAILURE, errno, "space for output");
- strcpy(cp->output, value);
- cp->outputset=1;
- }
+ gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
+
else if(strcmp(name, "suffix")==0)
- {
- if(up->suffixset) continue;
- errno=0;
- p->suffix=malloc(strlen(value)+1);
- if(p->suffix==NULL)
- error(EXIT_FAILURE, errno, "space for prefix");
- strcpy(p->suffix, value);
- up->suffixset=1;
- }
+ gal_checkset_allocate_copy_set(value, &p->suffix, &up->suffixset);
+
+
/* Read options common to all programs */
GAL_CONFIGFILES_READ_COMMONOPTIONS_FROM_CONF
diff --git a/src/noisechisel/ui.c b/src/noisechisel/ui.c
index afa1971..3df6e97 100644
--- a/src/noisechisel/ui.c
+++ b/src/noisechisel/ui.c
@@ -102,55 +102,22 @@ readconfig(char *filename, struct noisechiselparams *p)
/* Inputs: */
if(strcmp(name, "hdu")==0)
- {
- if(cp->hduset) continue;
- errno=0;
- cp->hdu=malloc(strlen(value)+1);
- if(cp->hdu==NULL)
- error(EXIT_FAILURE, errno, "space for HDU");
- strcpy(cp->hdu, value);
- cp->hduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
+
else if(strcmp(name, "mask")==0)
- {
- if(up->masknameset) continue;
- errno=0;
- up->maskname=malloc(strlen(value)+1);
- if(up->maskname==NULL)
- error(EXIT_FAILURE, errno, "space for mask name");
- strcpy(up->maskname, value);
- up->masknameset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->maskname,
+ &up->masknameset);
+
else if(strcmp(name, "mhdu")==0)
- {
- if(up->mhduset) continue;
- errno=0;
- up->mhdu=malloc(strlen(value)+1);
- if(up->mhdu==NULL)
- error(EXIT_FAILURE, errno, "space for mask HDU");
- strcpy(up->mhdu, value);
- up->mhduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->mhdu, &up->mhduset);
+
else if(strcmp(name, "kernel")==0)
- {
- if(up->kernelnameset) continue;
- errno=0;
- up->kernelname=malloc(strlen(value)+1);
- if(up->kernelname==NULL)
- error(EXIT_FAILURE, errno, "space for kernel name");
- strcpy(up->kernelname, value);
- up->kernelnameset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->kernelname,
+ &up->kernelnameset);
+
else if(strcmp(name, "khdu")==0)
- {
- if(up->khduset) continue;
- errno=0;
- up->khdu=malloc(strlen(value)+1);
- if(up->khdu==NULL)
- error(EXIT_FAILURE, errno, "space for kernel HDU");
- strcpy(up->khdu, value);
- up->khduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->khdu, &up->khduset);
+
else if(strcmp(name, "skysubtracted")==0)
{
if(up->skysubtractedset) continue;
@@ -177,15 +144,8 @@ readconfig(char *filename, struct noisechiselparams *p)
/* Outputs */
else if(strcmp(name, "output")==0)
- {
- if(cp->outputset) continue;
- errno=0;
- cp->output=malloc(strlen(value)+1);
- if(cp->output==NULL)
- error(EXIT_FAILURE, errno, "space for output");
- strcpy(cp->output, value);
- cp->outputset=1;
- }
+ gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
+
else if(strcmp(name, "grownclumps")==0)
{
if(up->grownclumpsset) continue;
diff --git a/src/subtractsky/ui.c b/src/subtractsky/ui.c
index d73f9e5..eb68215 100644
--- a/src/subtractsky/ui.c
+++ b/src/subtractsky/ui.c
@@ -102,69 +102,27 @@ readconfig(char *filename, struct subtractskyparams *p)
/* Inputs: */
if(strcmp(name, "hdu")==0)
- {
- if(cp->hduset) continue;
- errno=0;
- cp->hdu=malloc(strlen(value)+1);
- if(cp->hdu==NULL)
- error(EXIT_FAILURE, errno, "space for HDU");
- strcpy(cp->hdu, value);
- cp->hduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
+
else if(strcmp(name, "mask")==0)
- {
- if(up->masknameset) continue;
- errno=0;
- up->maskname=malloc(strlen(value)+1);
- if(up->maskname==NULL)
- error(EXIT_FAILURE, errno, "space for mask name");
- strcpy(up->maskname, value);
- up->masknameset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->maskname,
+ &up->masknameset);
+
else if(strcmp(name, "mhdu")==0)
- {
- if(up->mhduset) continue;
- errno=0;
- up->mhdu=malloc(strlen(value)+1);
- if(up->mhdu==NULL)
- error(EXIT_FAILURE, errno, "space for mask HDU");
- strcpy(up->mhdu, value);
- up->mhduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->mhdu, &up->mhduset);
+
else if(strcmp(name, "kernel")==0)
- {
- if(up->kernelnameset) continue;
- errno=0;
- up->kernelname=malloc(strlen(value)+1);
- if(up->kernelname==NULL)
- error(EXIT_FAILURE, errno, "space for kernel name");
- strcpy(up->kernelname, value);
- up->kernelnameset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->kernelname,
+ &up->kernelnameset);
+
else if(strcmp(name, "khdu")==0)
- {
- if(up->khduset) continue;
- errno=0;
- up->khdu=malloc(strlen(value)+1);
- if(up->khdu==NULL)
- error(EXIT_FAILURE, errno, "mpace for kernel HDU");
- strcpy(up->khdu, value);
- up->khduset=1;
- }
+ gal_checkset_allocate_copy_set(value, &up->khdu, &up->khduset);
/* Outputs */
else if(strcmp(name, "output")==0)
- {
- if(cp->outputset) continue;
- errno=0;
- cp->output=malloc(strlen(value)+1);
- if(cp->output==NULL)
- error(EXIT_FAILURE, errno, "space for output");
- strcpy(cp->output, value);
- cp->outputset=1;
- }
+ gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
/* Mesh grid: */
- [gnuastro-commits] master updated (a1e40c8 -> b78b0c7), Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master 474db42 07/16: Table and TEMPLATE added to the genauthors, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master 56bd4e5 03/16: checkset func for some option value allocations,
Mohammad Akhlaghi <=
- [gnuastro-commits] master c113fc3 09/16: Allocation for FITS types by datatype, not bitpix, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master 9c7d9a0 10/16: Blank replacement function now accepts datatype, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master 2071999 08/16: Blank CFITSIO pointers set by datatype, not bitpix, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master 01dfb1b 05/16: Some code management in Table, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master d09e850 04/16: FITS table column information printed by Table, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master 5606978 11/16: Configuration file in tests/during-dev.sh, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master c719806 06/16: Table accepts specified column number, name and regex, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master 647406f 02/16: Table utility bare minimum structure in place, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master ad16c2a 12/16: Cosmetic changes in fits and txtarray libraries, Mohammad Akhlaghi, 2016/08/24
- [gnuastro-commits] master b16c7a4 15/16: New Section added to the book for Table, Mohammad Akhlaghi, 2016/08/24