File: chk_scale.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (85 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <string.h>
#include "local_proto.h"
/****************************************************************
 *
 * check_scale (text)
 *
 *   text of scale request to be checked
 ***************************************************************/

int check_scale (char *text)
{
    char unit1[30];
    char unit2[30];
    char equals[30];
    char dummy[2];
    long n1,n2;
    double u1;

/*
 * absolute horizontal width specification
 *   x inches
 *   x panels
 * convert text to 1 : n
 */
    u1 = 0;
    *unit1 = 0;
    *dummy = 0;
    if (sscanf (text, "%lf %s %1s", &u1, unit1, dummy) == 2 && *dummy == 0)
    {
	if (strncmp (unit1,"panel",5) == 0 && u1 > 0)
	    return 1;
	if (strncmp (unit1,"inch",4) == 0 && u1 > 0)
	    return 1;
    }

/*
 * unitless ratio specification
 *    n : m
 */
    *dummy = 0;
    n1 = n2 = 0;
    if (sscanf (text,"%ld : %ld%1s", &n1,&n2,dummy) == 2)
    {
	if (n1 <= 0 || n2 <= 0 || *dummy)
	    return 0;
	return 1;
    }

/*
 *
 * ratio specification with unit conversions
 *    x inches equals y miles
 *    x inches equals y meters
 *    x inches equals y kilometers
 */

    *unit1 = 0;
    *unit2 = 0;
    *equals = 0;
    n1 = n2 = 0;
    if (sscanf (text, "%ld %s %s %ld %s", &n1, unit1, equals, &n2, unit2) == 5)
    {
	if (n1 <= 0 || n2 <= 0)
	    return 0 ;
	if (strcmp (equals, "=") != 0 && strncmp (equals,"equal",5) != 0)
	    return 0 ;

/* unit1: inches */
	if (strncmp (unit1,"inch",4) == 0)
	    u1 = 1;
	else
	    return 0;

/* unit2: meters, miles, kilometers */
	if (strncmp (unit2,"mile",4) == 0)
	    return 1;
	if (strncmp (unit2,"meter",5) == 0)
	    return 1;
	if (strncmp (unit2, "kilometer", 9) == 0)
	    return 1;

    }
    return 0;
}