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/
36 #include "have_const.h"
43 #include "have_unused.h"
49 STATIC VALUE custom_reg
[CUSTOM_REG_MAX
+1];
53 * init_custreg - initialize custom registers
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);
73 * c_register - set or print a custom register value
76 * vals[i] and arg to display information about
83 c_register(char UNUSED
*name
, int count
, VALUE
**vals
)
85 VALUE result
; /* what we will return */
86 long reg
; /* register number */
91 result
.v_type
= V_NULL
;
92 if (vals
[0]->v_type
!= V_NUM
) {
93 math_error("Non-numeric register number");
96 if (qisfrac(vals
[0]->v_num
)) {
97 math_error("Non-integer register number");
100 if (qisneg(vals
[0]->v_num
)) {
101 math_error("register number < 0");
104 if (! qistiny(vals
[0]->v_num
)) {
105 math_error("register is huge");
108 reg
= qtoi(vals
[0]->v_num
);
109 if (reg
> CUSTOM_REG_MAX
) {
110 math_error("register is larger than CUSTOM_REG_MAX");
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 */
121 copyvalue(vals
[1], &custom_reg
[reg
]);