GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/nrrd/comment.c Lines: 27 34 79.4 %
Date: 2017-05-26 Branches: 17 26 65.4 %

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 "nrrd.h"
25
#include "privateNrrd.h"
26
27
/*
28
******** nrrdCommentAdd()
29
**
30
** Adds a given string to the list of comments
31
** Leading spaces (' ') and comment chars ('#') are not included.
32
**
33
** This function does NOT use biff.
34
*/
35
int
36
nrrdCommentAdd(Nrrd *nrrd, const char *_str) {
37
  /* static const char me[]="nrrdCommentAdd";*/
38
  char *str;
39
  unsigned int ii;
40
41
110
  if (!(nrrd && _str)) {
42
    /*
43
    sprintf(err, "%s: got NULL pointer", me);
44
    biffMaybeAdd(NRRD, err, useBiff);
45
    */
46
    return 1;
47
  }
48
55
  _str += strspn(_str, " #");
49
55
  if (!strlen(_str)) {
50
    /* we don't bother adding comments with no length */
51
    return 0;
52
  }
53
93
  if (!strcmp(_str, _nrrdFormatURLLine0)
54
93
      || !strcmp(_str, _nrrdFormatURLLine1)) {
55
    /* sneaky hack: don't store the format URL comment lines */
56
34
    return 0;
57
  }
58
21
  str = airStrdup(_str);
59
21
  if (!str) {
60
    /*
61
    sprintf(err, "%s: couldn't strdup given string", me);
62
    biffMaybeAdd(NRRD, err, useBiff);
63
    */
64
    return 1;
65
  }
66
  /* clean out carraige returns that would screw up reader */
67
21
  airOneLinify(str);
68
21
  ii = airArrayLenIncr(nrrd->cmtArr, 1);
69
21
  if (!nrrd->cmtArr->data) {
70
    /*
71
    sprintf(err, "%s: couldn't lengthen comment array", me);
72
    biffMaybeAdd(NRRD, err, useBiff);
73
    */
74
    return 1;
75
  }
76
21
  nrrd->cmt[ii] = str;
77
21
  return 0;
78
55
}
79
80
/*
81
******** nrrdCommentClear()
82
**
83
** blows away comments, but does not blow away the comment airArray
84
*/
85
void
86
nrrdCommentClear(Nrrd *nrrd) {
87
88
4192
  if (nrrd) {
89
2096
    airArrayLenSet(nrrd->cmtArr, 0);
90
2096
  }
91
2096
}
92
93
/*
94
******** nrrdCommentCopy()
95
**
96
** copies comments from one nrrd to another
97
** Existing comments in nout are blown away
98
**
99
** This does NOT use biff.
100
*/
101
int
102
nrrdCommentCopy(Nrrd *nout, const Nrrd *nin) {
103
  /* static const char me[]="nrrdCommentCopy"; */
104
  int E;
105
  unsigned int numc, ii;
106
107
246
  if (!(nout && nin)) {
108
    /*
109
    sprintf(err, "%s: got NULL pointer", me);
110
    biffMaybeAdd(NRRD, err, useBiff);
111
    */
112
    return 1;
113
  }
114
123
  if (nout == nin) {
115
    /* can't satisfy semantics of copying with nout==nin */
116
    return 2;
117
  }
118
123
  nrrdCommentClear(nout);
119
123
  numc = nin->cmtArr->len;
120
  E = 0;
121

387
  for (ii=0; ii<numc; ii++) {
122
141
    if (!E) E |= nrrdCommentAdd(nout, nin->cmt[ii]);
123
  }
124
123
  if (E) {
125
    /*
126
    sprintf(err, "%s: couldn't add all comments", me);
127
    biffMaybeAdd(NRRD, err, useBiff);
128
    */
129
    return 3;
130
  }
131
123
  return 0;
132
123
}