GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/meet/meetGage.c Lines: 17 46 37.0 %
Date: 2017-05-26 Branches: 11 28 39.3 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
#include "meet.h"
25
26
27
gageKind * /*Teem: error if (!ret) */
28
_meetGageKindParse(const char *_str, int constOnly) {
29
  char *str;
30
  gageKind *ret;
31
32
64
  if (!_str) {
33
    return NULL;
34
  }
35
32
  str = airToLower(airStrdup(_str));
36
32
  if (!str) {
37
    return NULL;
38
  }
39
32
  if (!strcmp(gageKindScl->name, str)) {
40
8
    ret = gageKindScl;
41
32
  } else if (!strcmp(gageKind2Vec->name, str)) {
42
    ret = gageKind2Vec;
43
24
  } else if (!strcmp(gageKindVec->name, str)) {
44
8
    ret = gageKindVec;
45
24
  } else if (!strcmp(tenGageKind->name, str)) {
46
8
    ret = tenGageKind;
47

24
  } else if (!constOnly && !strcmp(TEN_DWI_GAGE_KIND_NAME, str)) {
48
8
    ret = tenDwiGageKindNew();
49
8
  } else {
50
    ret = NULL;
51
  }
52
32
  airFree(str);
53
32
  return ret;
54
32
}
55
56
gageKind * /*Teem: error if (!ret) */
57
meetGageKindParse(const char *_str) {
58
59
64
  return _meetGageKindParse(_str, AIR_FALSE);
60
}
61
62
const gageKind * /*Teem: error if (!ret) */
63
meetConstGageKindParse(const char *_str) {
64
65
  return _meetGageKindParse(_str, AIR_TRUE);
66
}
67
68
/*
69
** same as _meetHestGageKindParse below but without the DWI kind,
70
** which isn't const
71
*/
72
int
73
_meetHestConstGageKindParse(void *ptr, char *str, char err[AIR_STRLEN_HUGE]) {
74
  char me[] = "_meetHestGageConstKindParse";
75
  const gageKind **kindP;
76
77
  if (!(ptr && str)) {
78
    sprintf(err, "%s: got NULL pointer", me);
79
    return 1;
80
  }
81
  /* of course, the const correctness goes out the window with all
82
     the casting that's necessary with hest ... */
83
  kindP = (const gageKind **)ptr;
84
  *kindP = meetConstGageKindParse(str);
85
  if (!*kindP) {
86
    sprintf(err, "%s: \"%s\" not \"%s\", \"%s\", \"%s\", or \"%s\"", me, str,
87
            gageKindScl->name, gageKind2Vec->name,
88
            gageKindVec->name, tenGageKind->name);
89
    return 1;
90
  }
91
92
  return 0;
93
}
94
95
int
96
_meetHestGageKindParse(void *ptr, char *str, char err[AIR_STRLEN_HUGE]) {
97
  char me[] = "_meetHestGageKindParse";
98
  gageKind **kindP;
99
100
  if (!(ptr && str)) {
101
    sprintf(err, "%s: got NULL pointer", me);
102
    return 1;
103
  }
104
  kindP = (gageKind **)ptr;
105
  *kindP = meetGageKindParse(str);
106
  if (!*kindP) {
107
    sprintf(err, "%s: \"%s\" not \"%s\", \"%s\", \"%s\", \"%s\", or \"%s\"", me,
108
            str, gageKindScl->name, gageKind2Vec->name, gageKindVec->name,
109
            tenGageKind->name, TEN_DWI_GAGE_KIND_NAME);
110
    return 1;
111
  }
112
113
  return 0;
114
}
115
116
void *
117
_meetHestGageKindDestroy(void *ptr) {
118
  gageKind *kind;
119
120
  if (ptr) {
121
    kind = AIR_CAST(gageKind *, ptr);
122
    if (!strcmp(TEN_DWI_GAGE_KIND_NAME, kind->name)) {
123
      tenDwiGageKindNix(kind);
124
    }
125
  }
126
  return NULL;
127
}
128
129
static hestCB
130
_meetHestGageKind = {
131
  sizeof(gageKind *),
132
  "gageKind",
133
  _meetHestGageKindParse,
134
  _meetHestGageKindDestroy
135
};
136
137
static hestCB
138
_meetHestConstGageKind = {
139
  sizeof(gageKind *),
140
  "gageKind",
141
  _meetHestConstGageKindParse,
142
  NULL
143
};
144
145
/*
146
******** meetHestGageKind
147
**
148
** This provides a uniform way to parse gageKinds from the command-line
149
*/
150
hestCB *
151
meetHestGageKind = &_meetHestGageKind;
152
hestCB *
153
meetHestConstGageKind = &_meetHestConstGageKind;