FACT++  1.0
void palDfltin ( const char *  string,
int *  nstrt,
double *  dreslt,
int *  jflag 
)

Definition at line 146 of file palDfltin.c.

References ISBLANK().

Referenced by palDafin(), and t_flotin().

147  {
148 
149  char * ctemp = NULL; /* Pointer into string */
150  char * endptr = NULL;/* Pointer to string after number */
151  double retval; /* Return value from strtod */
152 
153  /* We have to copy the string in order to modify the exponents
154  from Fortran style. Rather than using malloc we have a static
155  buffer. Technically we only have to do the copy if we have a
156  D or d in the string. */
157  char tempbuf[256];
158 
159 #if SCAN_FOR_MINUS
160  int dreslt_sign = 1;
161  int ipos = *nstrt;
162  const char * cctemp = NULL;
163 
164  /* Scan the string looking for a minus sign. Then update the
165  start position for the subsequent copy iff we find a '-'.
166  Note that commas are a special delimiter so we stop looking for a
167  minus if we find one or if we find a digit. */
168  cctemp = &(string[ipos-1]);
169  while (!isdigit(*cctemp) && (*cctemp != ',') && (*cctemp != '\0')) {
170  if (*cctemp == '-') {
171  *nstrt = ipos;
172  dreslt_sign = -1;
173  break;
174  }
175  ipos++;
176  cctemp++;
177  }
178 #endif
179 
180  /* Correct for SLA use of fortran convention */
181 #if HAVE_STAR_UTIL_H
182  star_strlcpy( tempbuf, &(string[*nstrt-1]), sizeof(tempbuf) );
183 #else
184 # if HAVE_STRLCPY
185  strlcpy( tempbuf, &(string[*nstrt-1]), sizeof(tempbuf) );
186 # else
187  /* Use standard C interface */
188  strncpy( tempbuf, &(string[*nstrt-1]), sizeof(tempbuf));
189  tempbuf[sizeof(tempbuf)-1] = '\0';
190 # endif
191 #endif
192 
193  /* Convert d or D to E */
194  ctemp = tempbuf;
195  while (*ctemp != '\0') {
196  if (*ctemp == 'd' || *ctemp == 'D') *ctemp = 'E';
197  ctemp++;
198  }
199 
200  /* strtod man page indicates that we should reset errno before
201  calling strtod */
202  errno = 0;
203 
204  /* We know we are starting at the beginning of the string now */
205  retval = strtod( tempbuf, &endptr );
206  if (retval == 0.0 && endptr == tempbuf) {
207  /* conversion did not find anything */
208  *jflag = 1;
209 
210  /* but SLA compatibility requires that we step
211  through to remove leading spaces. We also step
212  through alphabetic characters since they can never
213  be numbers standalone (no number starts with an 'E') */
214  while (ISBLANK(*endptr) || isalpha(*endptr) ) {
215  endptr++;
216  }
217 
218  } else if ( errno == ERANGE ) {
219  *jflag = 2;
220  } else {
221 #if SCAN_FOR_MINUS
222  *jflag = (dreslt_sign < 0 ? -1 : 0);
223 #else
224  if ( retval < 0.0 ) {
225  *jflag = -1;
226  } else if ( retval == 0.0 ) {
227  /* Need to distinguish -0 from +0 */
228  double test = copysign( 1.0, retval );
229  if ( test < 0.0 ) {
230  *jflag = -1;
231  } else {
232  *jflag = 0;
233  }
234  } else {
235  *jflag = 0;
236  }
237 #endif
238  }
239 
240  /* Sort out the position for the next index */
241  *nstrt += endptr - tempbuf;
242 
243  /* Skip a comma */
244  if (*endptr == ',') {
245  (*nstrt)++;
246  } else {
247  /* jump past any leading spaces for the next part of the string */
248  ctemp = endptr;
249  while ( ISBLANK(*ctemp) ) {
250  (*nstrt)++;
251  ctemp++;
252  }
253  }
254 
255  /* And the result unless we found nothing */
256  if (*jflag != 1) *dreslt = retval;
257 
258 }
static int ISBLANK(int c)
Definition: palDfltin.c:116

+ Here is the call graph for this function:

+ Here is the caller graph for this function: