/* $Id: convert.c,v 1.3 2003/09/28 09:03:00 jmuelmen Exp $ */ /* These routines convert between the various types */ /* Shell actions do *NO* error checking. The assumption is that this * is done before anything makes it into the parse buffer. */ #include #include #include #include "act.h" #include "parse.h" /* I wonder why the math.h file is broken. */ double rint (double); void conv_int (int *i, const value_t *v) { switch (v->val_type) { case val_int: *i = v->value.v_int; break; case val_float: /* round to integer */ *i = (int)rint(v->value.v_float); break; case val_string: *i = atoi(v->value.v_string); break; case val_time: *i = v->value.v_time; break; case val_period: *i = v->value.v_period; break; } } void conv_string (char *c, const value_t *v) { switch (v->val_type) { case val_int: snprintf(c, STRING_LIT_LEN, "%d", v->value.v_int); break; case val_float: snprintf(c, STRING_LIT_LEN, "%e", v->value.v_float); break; case val_string: strncpy(c, v->value.v_string, STRING_LIT_LEN); break; } } void conv_float (double *f, const value_t *v) { switch (v->val_type) { case val_int: *f = v->value.v_int; break; case val_float: *f = v->value.v_float; break; case val_string: /* dunno what to do here... */ break; case val_time: *f = v->value.v_time; break; case val_period: *f = v->value.v_period; break; } } void conv_time (time_t *t, const value_t *v) { switch (v->val_type) { case val_int: *t = v->value.v_int; break; case val_float: /* round to integer */ *t = (time_t)rint(v->value.v_float); break; case val_string: /* dunno what to do here... */ break; case val_time: *t = v->value.v_time; break; case val_period: *t = v->value.v_period; break; } }