modified: diffout.py
[GalaxyCodeBases.git] / c_cpp / etc / calc / custom / c_register.c
blob12d2f50d727c3ce7c448c93b7ced18d9ae0c0358
1 /*
2 * c_register - set or print a custom register value
4 * Copyright (C) 2007 Landon Curt Noll
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.1 $
21 * @(#) $Id: c_register.c,v 30.1 2007/07/15 02:24:34 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/custom/RCS/c_register.c,v $
24 * Under source code control: 2007/07/14 20:23:46
25 * File existed as early as: 2007
27 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
28 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
32 #if defined(CUSTOM)
34 #include <stdio.h>
36 #include "have_const.h"
37 #include "value.h"
38 #include "custom.h"
40 #include "config.h"
41 #include "calc.h"
43 #include "have_unused.h"
47 * registers
49 STATIC VALUE custom_reg[CUSTOM_REG_MAX+1];
53 * init_custreg - initialize custom registers
55 void
56 init_custreg(void)
58 int i;
61 * set the registers to zero
63 for (i=0; i < CUSTOM_REG_MAX+1; ++i) {
64 custom_reg[i].v_type = V_NUM;
65 custom_reg[i].v_subtype = V_NOSUBTYPE;
66 custom_reg[i].v_num = itoq(0);
68 return;
73 * c_register - set or print a custom register value
75 * given:
76 * vals[i] and arg to display information about
78 * returns:
79 * count
81 /*ARGSUSED*/
82 VALUE
83 c_register(char UNUSED *name, int count, VALUE **vals)
85 VALUE result; /* what we will return */
86 long reg; /* register number */
89 * arg check
91 result.v_type = V_NULL;
92 if (vals[0]->v_type != V_NUM) {
93 math_error("Non-numeric register number");
94 /*NOTREACHED*/
96 if (qisfrac(vals[0]->v_num)) {
97 math_error("Non-integer register number");
98 /*NOTREACHED*/
100 if (qisneg(vals[0]->v_num)) {
101 math_error("register number < 0");
102 /*NOTREACHED*/
104 if (! qistiny(vals[0]->v_num)) {
105 math_error("register is huge");
106 /*NOTREACHED*/
108 reg = qtoi(vals[0]->v_num);
109 if (reg > CUSTOM_REG_MAX) {
110 math_error("register is larger than CUSTOM_REG_MAX");
111 /*NOTREACHED*/
115 * print info on each arg
117 /* save previous value */
118 copyvalue(&custom_reg[reg], &result);
119 /* set the new value if a 2nd arg was given */
120 if (count == 2) {
121 copyvalue(vals[1], &custom_reg[reg]);
125 * return result
127 return result;
130 #endif /* CUSTOM */