IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 2, 2005, 6:02:44 PM (21 years ago)
Author:
eugene
Message:

cleaned handling of single quotes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/header/F_scan.c

    r2766 r3369  
    11# include "fits.h"
     2
     3char *fits_keyword_start (char *line);
     4char *fits_keyword_end (char *line);
    25
    36int fits_scan (Header *header, char *field, char *mode, int N,...) {
     
    1417int fits_vscan (Header *header, char *field, char *mode, int N, va_list argp) {
    1518
    16   char *p, *q, tmp[81];
     19  char *p, *q, *s, tmp[81];
    1720  int Nchar;
    1821  double value;
     
    2528  if (!strcmp (mode, "%S")) {
    2629    strncpy (va_arg (argp, char *), p + 8, FT_HISTORY_LENGTH);
    27     goto gotvalue;
     30    return (TRUE);
    2831  }
    2932
     
    4043    fits_stripwhite (tmp);
    4144    strcpy (va_arg (argp, char *), tmp);
    42     goto gotvalue;
     45    return (TRUE);
    4346  }
    4447
    4548  /* extract data into char array (exclude containing ' chars) */
    4649  if (!strcmp (mode, "%s")) {
    47     q = fits_keyword_end (p);
    48     q -= 1;
    49     p += 10;
     50    s = fits_keyword_start (p); /* points at first char (not ') */
     51    q = fits_keyword_end (p); /* points at following space or ' */
    5052
    51     /* exclude containing ' chars, if they exist */
    52     /* we are not requiring a string entry to have the quotes */
    53     if (*p == 0x27) p++;
    54     if (*q == 0x27) q--;
    55 
    56     Nchar = MAX (0, (q - p + 1));
     53    Nchar = MAX (0, (q - s));
    5754    bzero (tmp, 81);
    58     memcpy (tmp, p, Nchar);
     55    memcpy (tmp, s, Nchar);
    5956    fits_stripwhite (tmp);
    6057    strcpy (va_arg (argp, char *), tmp);
    61     goto gotvalue;
     58    return (TRUE);
    6259  }
    6360 
    6461  /* boolean data, requires int target */
    6562  if (!strcmp (mode, "%t")) {
    66     if (p[29]  == 'T')
     63    s = fits_keyword_start (p);
     64    if (*s == 'T') {
    6765      *va_arg (argp, int *) = TRUE;
    68     if (p[29]  == 'F')
     66      return (TRUE);
     67    }
     68    if (*s == 'F') {
    6969      *va_arg (argp, int *) = FALSE;   
    70     goto gotvalue;
     70      return (TRUE);
     71    }
    7172  }
    7273
    7374  /* remaining options are numerical data */
    7475  /* need to interpret 1.0d5 as 1.0e5 */
    75   if (p[10] == 0x27) p++;  /** skip over initial ' (SOME BAD sources write floats with '') **/
    76   value = strtod (p + 10, &q);
     76  s = fits_keyword_start (p); /* points at first char (not ') */
     77  q = fits_keyword_end (p); /* points at following space or ' */
     78  value = strtod (s, &q);
    7779  if ((*q == 'd') || (*q == 'D'))
    7880    value *= pow (10.0, atof (q + 1));
    7981
    80   if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; goto gotvalue; }
    81   if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; goto gotvalue; }
    82   if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; goto gotvalue; }
    83   if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; goto gotvalue; }
    84   if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; goto gotvalue; }
    85   if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; goto gotvalue; }
     82  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; return (TRUE); }
     83  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; return (TRUE); }
     84  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; return (TRUE); }
     85  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; return (TRUE); }
     86  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; return (TRUE); }
     87  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; return (TRUE); }
    8688
    8789  /* no valid mode found */
    8890  return (FALSE);
    89 
    90  gotvalue:
    91   return (TRUE);
    9291}
    9392
Note: See TracChangeset for help on using the changeset viewer.