summaryrefslogtreecommitdiff
path: root/graphics/hpgl2ps/getval.c
blob: 3c4f3fcfc9112bf71790bc21fab04b39604f1625 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Returns a real number 
 */

#include "defn.h"

#define ERROR "Two or more decimal places in a number"

float
getval()
{
    char    valbuf[10];
    float   value;
    int     DECIMAL = 0;
    int     i;

    /* Null the value buffer "valbuf" */
    for (i = 0; i < 10; i++)
	valbuf[i] = NULL;

    i = 0;

    ch = getc(stream);

    while ((ch == ' ') || (ch == ','))
	ch = getc(stream);

    while ((ch >= '0' && ch <= '9') || ch == '.' || ch == '-' || ch == '+')
    {
	if (ch == '.')
	{
	    if (DECIMAL)
	    {
		fprintf(stderr,"Error: %s\n", ERROR);
		exit(1);
	    }
	    DECIMAL = 1;
	}
	valbuf[i++] = ch;
	ch = getc(stream);
    }
    ungetc(ch, stream);		/* Put non numeric char back */
    value = atof (valbuf);
    return (value);
}