summaryrefslogtreecommitdiff
path: root/graphics/hpgl2ps/changesizes.c
blob: 113f866655946ce6618d622dc54a0f1d4cd9d145 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * This utility will take a string of real numbers seperated by commas and
 * put them in an array. 
 *
 * Don McCormick 
 */
#include "defn.h"

#define ERROR1 "Only 9 line sizes allowed"
#define ERROR2 "Too many decimal points in number"
#define ERROR3 "line size specification incorrect"
#define ERROR4 "Max no of characters for each line size is 5"

changesizes(sizebuf)
char    sizebuf[50];
{
    int     i;
    int     j = 0;
    int     k = 0;
    int     DECIMAL = 0;
    float   number;
    char    numbuf[5];

    for (i = 0; i < 50; i++)
    {
	if (sizebuf[i] == ',' || sizebuf[i] == NULL)
	{
	    if ((number = atof(numbuf)) >= 0.01 && number <= 10)
		pen_size[j] = number;	/* Put number in array */
	    else
		fprintf(stderr, "Warning: line size too large ignored \n");

	    if (sizebuf[i] == NULL) return;

	    if (j++ > 8)
	    {
		fprintf(stderr, "Error: %s\n", ERROR1);
		exit(1);
	    }
	    for (k = 0; k < 5; k++)
		numbuf[k] = NULL;	/* Clear number buffer */

	    k = 0;
	    DECIMAL = 0;	/* One decimal per number */

	    while (sizebuf[i + 1] == ',' && sizebuf[i + 1] != NULL)
		i++;		/* Get rid of extra commas */
	} else
	{
	    if ((sizebuf[i] >= '0' && sizebuf[i] <= '9')
		|| sizebuf[i] == '.')
	    {
		if (sizebuf[i] == '.')
		{
		    if (DECIMAL == 1)
		    {
		        fprintf(stderr, "Error: %s\n", ERROR2);
		        exit(1);
		    }
		    DECIMAL = 1;
		}
		numbuf[k] = sizebuf[i];
	    } else
	    {
		fprintf(stderr, "Error: %s\n", ERROR3);
		exit(1);
	    }
	    if (k++ > 5)
	    {
		fprintf(stderr, "Error: %s\n", ERROR4);
		exit(1);
	    }
	}
    }
}