コード例 #1
0
/* still unclear if it ever reports lbs */
static void uemis_get_weight(char *buffer, weightsystem_t *weight, int diveid)
{
	weight->weight.grams = uemis_get_weight_unit(diveid) ?
				   lbs_to_grams(ascii_strtod(buffer, NULL)) :
				   ascii_strtod(buffer, NULL) * 1000;
	weight->description = strdup(translate("gettextFromC", "unknown"));
}
コード例 #2
0
ファイル: formats.c プロジェクト: B-Rich/pyephem
/* convert sexagesimal string str A:B:C to double.
 *   Any missing A, B or C will be assumed 0.
 *   optional - and + can be anywhere.
 * return 0 if ok, -1 if can't find a thing or A, B or C are invalid numbers.
 */
int
f_scansexa (
const char *str0,	/* input string */
double *dp)		/* cracked value, if return 0 */
{
	double a, b, c;
	char str[256];
	char *neg, *s, *end;
	int isneg, status;

	/* copy str0 so we can play with it */
	strncpy (str, str0, sizeof(str)-1);
	str[sizeof(str)-1] = '\0';

	/* note first negative (but not fooled by neg exponent) */
	isneg = 0;
	neg = strchr(str, '-');
	if (neg && (neg == str || (neg[-1] != 'E' && neg[-1] != 'e'))) {
	    *neg = ' ';
	    isneg = 1;
	}

        /* These three calls replace an old, locale-sensitive sscanf.
           Note that, per the semantics of the strtod call, if we run
           out of valid numbers to parse, then the last few values will
           just get zero. */
        status = 0;
        s = str;
        a = ascii_strtod(s, &end);
        if (end == s) { /* since a will be -1 */
             a = 0.0;
             /* don't fail if A is an empty string */
             if ((*end != ':') && (*end != '\0')) status = -1;
        }
        s = end;
        if (*s == ':') s++;
        b = ascii_strtod(s, &end);
        if (end == s) { /* since b will be -1 */
             b = 0.0;
             /* don't fail if B is an empty string */
             if ((*end != ':') && (*end != '\0')) status = -1;
        }
        s = end;
        if (*s == ':') s++;
        c = ascii_strtod(s, &end);
        if (end == s) { /* since c will be -1 */
             c = 0.0;
             /* don't fail if C is an empty string */
             if ((*end != ':') && (*end != '\0')) status = -1;
        }

	/* back to one value, restoring neg */
	*dp = a + b/60.0 + c/3600.0;
	if (isneg)
	    *dp *= -1;
	return status;
}
コード例 #3
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static void sample_parser(char *line, struct divecomputer *dc)
{
	int m, s = 0;
	struct sample *sample = new_sample(dc);

	m = strtol(line, &line, 10);
	if (*line == ':')
		s = strtol(line+1, &line, 10);
	sample->time.seconds = m*60+s;

	for (;;) {
		char c;

		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		/* Less common sample entries have a name */
		if (c >= 'a' && c <= 'z') {
			line = parse_keyvalue_entry(parse_sample_keyvalue, sample, line);
		} else {
			const char *end;
			double val = ascii_strtod(line, &end);
			if (end == line) {
				report_error("Odd sample data: %s", line);
				break;
			}
			line = (char *)end;
			line = parse_sample_unit(sample, val, line);
		}
	}
	finish_sample(dc);
}
コード例 #4
0
/**
 * Parses a floating point number contained in a DBusString. Either
 * return parameter may be #NULL if you aren't interested in it. The
 * integer is parsed and stored in value_return. Return parameters are
 * not initialized if the function returns #FALSE.
 *
 * @param str the string
 * @param start the byte index of the start of the float
 * @param value_return return location of the float value or #NULL
 * @param end_return return location of the end of the float, or #NULL
 * @returns #TRUE on success
 */
dbus_bool_t
_dbus_string_parse_double (const DBusString *str,
                           int               start,
                           double           *value_return,
                           int              *end_return)
{
  double v;
  const char *p;
  char *end;

  p = _dbus_string_get_const_data_len (str, start,
                                       _dbus_string_get_length (str) - start);

  /* parsing hex works on linux but isn't portable, so intercept it
   * here to get uniform behavior.
   */
  if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X'))
    return FALSE;
  
  end = NULL;
  errno = 0;
  v = ascii_strtod (p, &end);
  if (end == NULL || end == p || errno != 0)
    return FALSE;

  if (value_return)
    *value_return = v;
  if (end_return)
    *end_return = start + (end - p);

  return TRUE;
}
コード例 #5
0
static bool parse_divespot(char *buf)
{
	char *bp = buf + 1;
	char *tp = next_token(&bp);
	char *tag, *type, *val;
	char locationstring[1024] = "";
	int divespot, len;
	double latitude = 0.0, longitude = 0.0;

	// dive spot got deleted, so fail here
	if (strstr(bp, "deleted{bool{true"))
		return false;
	// not a dive spot, fail here
	if (strcmp(tp, "divespot"))
		return false;
	do
		tag = next_token(&bp);
	while (*tag && strcmp(tag, "object_id"));
	if (!*tag)
		return false;
	next_token(&bp);
	val = next_token(&bp);
	divespot = atoi(val);
	do {
		tag = next_token(&bp);
		type = next_token(&bp);
		val = next_token(&bp);
		if (!strcmp(type, "string") && *val && strcmp(val, " ")) {
			len = strlen(locationstring);
			snprintf(locationstring + len, sizeof(locationstring) - len,
				 "%s%s", len ? ", " : "", val);
		} else if (!strcmp(type, "float")) {
			if (!strcmp(tag, "longitude"))
				longitude = ascii_strtod(val, NULL);
			else if (!strcmp(tag, "latitude"))
				latitude = ascii_strtod(val, NULL);
		}
	} while (tag && *tag);

	uemis_set_divelocation(divespot, locationstring, longitude, latitude);
	return true;
}
コード例 #6
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static fraction_t get_fraction(const char *line)
{
	fraction_t f;
	f.permille = rint(10*ascii_strtod(line, NULL));
	return f;
}
コード例 #7
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static int get_salinity(const char *line)
{
	return rint(10*ascii_strtod(line, NULL));
}
コード例 #8
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static pressure_t get_pressure(const char *line)
{
	pressure_t p;
	p.mbar = rint(1000*ascii_strtod(line, NULL));
	return p;
}
コード例 #9
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static weight_t get_weight(const char *line)
{
	weight_t w;
	w.grams = rint(1000*ascii_strtod(line, NULL));
	return w;
}
コード例 #10
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static volume_t get_volume(const char *line)
{
	volume_t v;
	v.mliter = rint(1000*ascii_strtod(line, NULL));
	return v;
}
コード例 #11
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static depth_t get_depth(const char *line)
{
	depth_t d;
	d.mm = rint(1000*ascii_strtod(line, NULL));
	return d;
}
コード例 #12
0
ファイル: load-git.c プロジェクト: AresDice/subsurface
static temperature_t get_temperature(const char *line)
{
	temperature_t t;
	t.mkelvin = C_to_mkelvin(ascii_strtod(line, NULL));
	return t;
}
コード例 #13
0
/* float minutes */
static void uemis_duration(char *buffer, duration_t *duration)
{
	duration->seconds = rint(ascii_strtod(buffer, NULL) * 60);
}
コード例 #14
0
ファイル: formats.c プロジェクト: B-Rich/pyephem
/* crack a floating date string, bp, of the form X/Y/Z determined by the
 *   PREF_DATE_FORMAT preference into its components. allow the day to be a
 *   floating point number,
 * the slashes may also be spaces or colons.
 * a lone component with a decimal point is considered a year.
 * Brandon Rhodes: 2011-11-24 supplemented this to allow dash separators.
 */
void
f_sscandate (
char *bp,
int pref,       /* one of PREF_X for PREF_DATE_FORMAT */
int *m,
double *d,
int *y)
{
        double X,Y,Z; /* the three components */
        char *s, *end;
	int n;

	X = Y = Z = 0.0;

        /* This replaces an old, locale-sensitive sscanf(). */
        X = ascii_strtod(bp, &end);
        if (bp == end) {
             n = 0;
             X = 0.0; /* X will be -1 */
        } else {
             s = end;
             if (*s == '-' || *s == '/' || *s == ':') s++;
             Y = ascii_strtod(s, &end);
             if (s == end) {
                  n = 1;
                  Y = 0.0; /* Y will be -1 */
             } else {
                  s = end;
                  if (*s == '-' || *s == '/' || *s == ':') s++;
                  Z = ascii_strtod(s, &end);
                  if (s == end) {
                       n = 2;
                       Z = 0.0; /* Z will be -1 */
                  } else {
                       n = 3;
                  }
             }
        }
        

	if (n == 1 && (strchr(bp, '.')
			|| (pref == PREF_MDY && (X < 1 || X > 12))
			|| (pref == PREF_DMY && (X < 1 || X > 31)))) {
	    double Mjd;
	    year_mjd (X, &Mjd);
	    mjd_cal (Mjd, m, d, y);
	} else {
	    switch (pref) {
	    case PREF_MDY:
		if (n > 0 && X != 0)
		    *m = (int)X;
		if (n > 1 && Y != 0)
		    *d = Y;
		if (n > 2 && Z != 0)
		    *y = (int)Z;
		break;
	    case PREF_YMD:
		if (n > 0 && X != 0)
		    *y = (int)X;
		if (n > 1 && Y != 0)
		    *m = (int)Y;
		if (n > 2 && Z != 0)
		    *d = Z;
		break;
	    case PREF_DMY:
		if (n > 0 && X != 0)
		    *d = X;
		if (n > 1 && Y != 0)
		    *m = (int)Y;
		if (n > 2 && Z != 0)
		    *y = (int)Z;
		break;
	    }
	}
}