=================================================================== RCS file: /home/cvs/OpenXM_contrib/gnuplot/Attic/util.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.3 diff -u -p -r1.1.1.1 -r1.1.1.3 --- OpenXM_contrib/gnuplot/Attic/util.c 2000/01/09 17:00:56 1.1.1.1 +++ OpenXM_contrib/gnuplot/Attic/util.c 2003/09/15 07:09:27 1.1.1.3 @@ -1,5 +1,5 @@ #ifndef lint -static char *RCSid = "$Id: util.c,v 1.1.1.1 2000/01/09 17:00:56 maekawa Exp $"; +static char *RCSid = "$Id: util.c,v 1.1.1.3 2003/09/15 07:09:27 ohara Exp $"; #endif /* GNUPLOT - util.c */ @@ -103,8 +103,10 @@ char *str; register int start = token[t_num].start_index; register int length = token[t_num].length; + if (!str) + return FALSE; if (!token[t_num].is_token) - return (FALSE); /* must be a value--can't be equal */ + return FALSE; /* must be a value--can't be equal */ for (i = 0; i < length + after; i++) { if (str[i] != input_line[start + i]) { if (str[i] != '$') @@ -190,16 +192,18 @@ int max; { register int i = 0; register int start = token[t_num].start_index; - register int count; + register int count = token[t_num].length; - if ((count = token[t_num].length) >= max) { + if (count >= max) { count = max - 1; FPRINTF((stderr, "str buffer overflow in copy_str")); } + do { str[i++] = input_line[start++]; } while (i != count); str[i] = NUL; + } /* length of token string */ @@ -272,10 +276,8 @@ int start, end; register int i, e; register char *s; - if (*str) /* previous pointer to malloc'd memory there */ - free(*str); e = token[end].start_index + token[end].length; - *str = gp_alloc((unsigned long) (e - token[start].start_index + 1), "string"); + *str = gp_realloc(*str, (e - token[start].start_index + 1), "string"); s = *str; for (i = token[start].start_index; i < e && input_line[i] != NUL; i++) *s++ = input_line[i]; @@ -291,21 +293,43 @@ void m_quote_capture(str, start, end) char **str; int start, end; { - register int i, e, escflag = 0; + register int i, e; register char *s; - if (*str) /* previous pointer to malloc'd memory there */ - free(*str); e = token[end].start_index + token[end].length - 1; - *str = gp_alloc((unsigned long) (e - token[start].start_index + 1), "string"); + *str = gp_realloc(*str, (e - token[start].start_index + 1), "string"); s = *str; for (i = token[start].start_index + 1; i < e && input_line[i] != NUL; i++) - if ((*s++ = input_line[i]) == '\\') ++escflag; + *s++ = input_line[i]; *s = NUL; - if (escflag) parse_esc(*str); + + if (input_line[token[start].start_index] == '"') + parse_esc(*str); + } +/* Our own version of strdup() + * Make copy of string into gp_alloc'd memory + * As with all conforming str*() functions, + * it is the caller's responsibility to pass + * valid parameters! + */ +char * +gp_strdup(s) +char *s; +{ + char *d; +#ifndef HAVE_STRDUP + d = gp_alloc(strlen(s) + 1, "gp_strdup"); + if (d) + memcpy (d, s, strlen(s) + 1); +#else + d = strdup(s); +#endif + return d; +} + void convert(val_ptr, t_num) struct value *val_ptr; int t_num; @@ -410,13 +434,13 @@ struct value *val; { switch (val->type) { case INTGR: - return ((val->v.int_val >= 0) ? 0.0 : Pi); + return ((val->v.int_val >= 0) ? 0.0 : M_PI); case CMPLX: if (val->v.cmplx_val.imag == 0.0) { if (val->v.cmplx_val.real >= 0.0) return (0.0); else - return (Pi); + return (M_PI); } return (atan2(val->v.cmplx_val.imag, val->v.cmplx_val.real));