FACT++  1.0
void palIntin ( const char *  string,
int *  nstrt,
long *  ireslt,
int *  jflag 
)

Definition at line 112 of file palIntin.c.

References ISBLANK().

Referenced by t_intin().

113  {
114 
115  const char *strstart = NULL; /* Pointer to start of search */
116  const char * ctemp = NULL; /* Pointer into string */
117  char * endptr = NULL;/* Pointer to string after number */
118  int retval; /* Return value from strtol */
119  int hasminus; /* is this a -0 */
120 
121  /* strtol man page indicates that we should reset errno before
122  calling strtod */
123  errno = 0;
124 
125  /* Locate the start postion */
126  strstart = &(string[*nstrt-1]);
127 
128  /* We have to be able to deal with -0 so we have to search the
129  string first and look for the negative */
130  hasminus = 0;
131  ctemp = strstart;
132  while ( ctemp != '\0' ) {
133  if (isdigit(*ctemp)) break;
134  /* Reset so that - 12345 is not a negative number */
135  hasminus = 0;
136  /* Flag that we have found a minus */
137  if (*ctemp == '-') hasminus = 1;
138  ctemp++;
139  }
140 
141  /* Look for the number using the system call, offsetting using
142  1-based counter. */
143  retval = strtol( strstart, &endptr, 10 );
144  if (retval == 0.0 && endptr == strstart) {
145  /* conversion did not find anything */
146  *jflag = 1;
147 
148  /* but SLA compatibility requires that we step
149  through to remove leading spaces. We also step
150  through alphabetic characters since they can never
151  be numbers. Skip past a "+" since it doesn't gain
152  us anything and matches slalib. */
153  while (ISBLANK(*endptr) || isalpha(*endptr) || *endptr == '+' ) {
154  endptr++;
155  }
156 
157  } else if ( errno == ERANGE ) {
158  *jflag = 2;
159  } else {
160  if ( retval < 0 || hasminus ) {
161  *jflag = -1;
162  } else {
163  *jflag = 0;
164  }
165  }
166 
167  /* Sort out the position for the next index */
168  *nstrt = endptr - string + 1;
169 
170  /* Skip a comma */
171  if (*endptr == ',') {
172  (*nstrt)++;
173  } else {
174  /* jump past any leading spaces for the next part of the string */
175  ctemp = endptr;
176  while ( ISBLANK(*ctemp) ) {
177  (*nstrt)++;
178  ctemp++;
179  }
180  }
181 
182  /* And the result unless we found nothing */
183  if (*jflag != 1) *ireslt = retval;
184 
185 }
static int ISBLANK(int c)
Definition: palIntin.c:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function: