File: set.c

package info (click to toggle)
magic 7.5.220-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 17,860 kB
file content (198 lines) | stat: -rw-r--r-- 4,611 bytes parent folder | download | duplicates (2)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* set.c -
 *
 *	Generic routines for setting (from a string) and printing
 *      parameter values.  Error messages are printed for invalid
 *      input strings.
 *
 *     ********************************************************************* 
 *     * Copyright (C) 1985, 1990 Regents of the University of California. * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  The University of California        * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 */

#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-7.5/utils/set.c,v 1.2 2006/07/28 23:12:49 tim Exp $";
#endif  /* not lint */

#include <stdio.h>
#include <stdlib.h>

#include "utils/magic.h"
#include "utils/utils.h"
#include "utils/geometry.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "database/database.h"
#include "utils/list.h"


/*
 * ----------------------------------------------------------------------------
 *
 * SetNoisy<type> --
 *
 * Set parameter and print current value.
 * 
 * Results:
 *	None.  SetNoisyBool() now returns -2 on error, -1 ambiguous
 *	(but what's ambiguous about true/false??), 0 on success.  All
 *	of these routines should do the same!
 *
 * Side effects:
 *	If valueS is a nonnull string, interpret as <type> and set parm
 *      accordingly.
 *
 *      If valueS is null, the parameter value is left unaltered.
 *
 *      If file is nonnull parameter value is written to file.
 *
 *      If file is null, parameter value is written to magic text window via
 *      TxPrintf
 *	
 * ----------------------------------------------------------------------------
 */

/* SetNoisyInt -- */
void
SetNoisyInt(parm,valueS,file)
    int *parm;
    char *valueS;
    FILE *file;
{

    /* If value not null, set parm */
    if (valueS)
    {
	if(!StrIsInt(valueS))
	{
	    TxError("Noninteger value for integer parameter (\"%.20s\") ignored.\n",
		valueS);
	}
	else
	{
	    *parm = atoi(valueS);
	}
    }

    /* Print parm value */
    if(file)
	fprintf(file,"%8d ", *parm);
    else
	TxPrintf("%8d ", *parm);

    return;
}

/* SetNoisyBool --  */

int
SetNoisyBool(parm,valueS,file)
    bool *parm;
    char *valueS;
    FILE *file;
{
    int n, which, result;

    /* Bool string Table */
    static struct
    {
	char	*bS_name;	/* name */
	bool    bS_value;	/* procedure processing this parameter */
    } boolStrings[] = {
	"yes",		TRUE,
	"no",		FALSE,
	"true",		TRUE,
	"false",	FALSE,
	"1",		TRUE,
	"0",		FALSE,
	"on",		TRUE,
	"off",		FALSE,
	0
    };
    
    /* If value not null, set parm */
    if (valueS)
    {
	/* Lookup value string in boolString table */
	which = LookupStruct(
	    valueS, 
	    (LookupTable *) boolStrings, 
	    sizeof boolStrings[0]);

        /* Process result of lookup */
	if (which >= 0)
	{
	    /* string found - set parm */
	    *parm = boolStrings[which].bS_value;
	    result = 0;
	}
	else if (which == -1)
	{
	    /* ambiguous boolean value - complain */
	    TxError("Ambiguous boolean value: \"%s\"\n", 
		valueS);
	    result = -1;
	}
	else 
	{
	    TxError("Unrecognized boolean value: \"%s\"\n", valueS);
	    TxError("Valid values are:  ");
	    for (n = 0; boolStrings[n].bS_name; n++)
		TxError(" %s", boolStrings[n].bS_name);
	    TxError("\n");
	    result = -2;
	}
    }
    
    /* Print parm value */
    if(file)
	fprintf(file,"%8.8s ", *parm ? "YES" : "NO");
    else
	TxPrintf("%8.8s ", *parm ? "YES" : "NO");

    return result;
}

/* SetNoisyDI -- */
/* double size non-negative integer */
void
SetNoisyDI(parm,valueS,file)
    dlong *parm;		/* BY NP */
    char *valueS;
    FILE *file;
{
    /* If value not null, set parm */
    if (valueS)
    {
	if(!StrIsInt(valueS))
	{
	    TxError("Noninteger value for integer parameter (\"%.20s\") ignored.\n",
		valueS);
	}
	else
	{
	    /* BY NP */
	    *parm = (dlong)atoi(valueS);
	}
    }
    
    /* Print parm value */
    {
	if(file)
	{
	    fprintf(file,"%.0f ", (double) (*parm));	/* BY NP */
	}
	else
	{
	    TxPrintf("%.0f ", (double) (*parm));	/* BY NP */
	}
    }
    return;
}