22
24
#include "register.h"
23
25
#include "calctool.h"
26
do_sto_reg(int reg, int value[MP_SIZE])
28
if ((reg >= 0) && (reg <= 10))
29
mp_set_from_mp(value, v->MPmvals[reg]);
34
do_rcl_reg(int reg, int value[MP_SIZE])
36
if ((reg >= 0) && (reg <= 10))
37
mp_set_from_mp(v->MPmvals[reg], value);
29
static char constant_names[MAX_CONSTANTS][MAXLINE]; /* Selectable constant names. */
30
static int constant_values[MAX_CONSTANTS][MP_SIZE]; /* Selectable constants. */
32
static char function_names[MAX_FUNCTIONS][MAXLINE]; /* Function names from .gcalctoolcf. */
33
static char function_values[MAX_FUNCTIONS][MAXLINE]; /* Function defs from .gcalctoolcf. */
35
static int registers[MAX_REGISTERS][MP_SIZE]; /* Memory register values. */
37
static const char *default_constants[][2] =
39
/* Translators: This is the label for the default constant, the number of miles in one kilometer (0.621) */
40
{ N_("Kilometer-to-mile conversion factor"), "0.621" },
41
/* Translators: This is the label for the default constant, the square root of 2 (1.41421) */
42
{ N_("square root of 2"), "1.4142135623" },
43
/* Translators: This is the label for the default constant, Euler's number (2.71828) */
44
{ N_("Euler's Number (e)"), "2.7182818284" },
45
/* Translators: This is the label for the default constant, π (3.14159) */
46
{ N_("π"), "3.1415926536" },
47
/* Translators: This is the label for the default constant, the number of inches in a centimeter (0.39370) */
48
{ N_("Centimeter-to-inch conversion factor"), "0.3937007" },
49
/* Translators: This is the label for the default constant, the number of degrees in a radian (57.2958) */
50
{ N_("degrees in a radian"), "57.295779513" },
51
/* Translators: This is the label for the default constant, 2 to the power of 20 (1048576) */
52
{ N_("2 ^ 20"), "1048576.0" },
53
/* Translators: This is the label for the default constant, the number of ounces in one gram (0.0353) */
54
{ N_("Gram-to-ounce conversion factor"), "0.0353" },
55
/* Translators: This is the label for the default constant, the number of British Thermal Units in one Kilojoule (0.948) */
56
{ N_("Kilojoule-to-British-thermal-unit conversion factor"), "0.948" },
57
/* Translators: This is the label for the default constant, the number of cubic inches in one cubic centimeter (0.0610) */
58
{ N_("Cubic-centimeter-to-cubic-inch conversion factor"), "0.0610" }
64
for (i = 0; i < MAX_REGISTERS; i++) {
65
mp_set_from_integer(0, registers[i]);
68
for (i = 0; i < MAX_CONSTANTS; i++) {
69
char nkey[MAXLINE], *nline;
70
char vkey[MAXLINE], *vline = NULL;
73
SNPRINTF(nkey, MAXLINE, "constant%1dname", i);
74
nline = get_resource(nkey);
76
SNPRINTF(vkey, MAXLINE, "constant%1dvalue", i);
77
vline = get_resource(vkey);
83
mp_set_from_string(vline, 10, value);
84
constant_set(i, nline, value);
89
mp_set_from_string(default_constants[i][1], 10, value);
90
constant_set(i, default_constants[i][0], value);
94
for (i = 0; i < MAX_FUNCTIONS; i++) {
95
char nkey[MAXLINE], *nline;
96
char vkey[MAXLINE], *vline;
98
SNPRINTF(nkey, MAXLINE, "function%1dname", i);
99
nline = get_resource(nkey);
101
SNPRINTF(vkey, MAXLINE, "function%1dvalue", i);
102
vline = get_resource(vkey);
107
if (nline && vline) {
108
function_set(i, nline, convert(vline));
113
function_set(i, "", "");
120
register_set(int index, int value[MP_SIZE])
122
if ((index >= 0) && (index <= 10))
123
mp_set_from_mp(value, registers[index]);
128
register_get(int index, int value[MP_SIZE])
130
if ((index >= 0) && (index <= 10))
131
mp_set_from_mp(registers[index], value);
135
void constant_set(int index, const char *name, int value[MP_SIZE])
137
char key[MAXLINE], text[MAX_LOCALIZED];
139
STRNCPY(constant_names[index], name, MAXLINE - 1);
140
mp_set_from_mp(value, constant_values[index]);
142
SNPRINTF(key, MAXLINE, "constant%1dname", index);
143
set_resource(key, name);
145
/* NOTE: Constants are written out with no thousands separator and with a
146
radix character of ".". */
147
mp_cast_to_string(text, MAX_LOCALIZED, value, 10, MAX_DIGITS);
148
SNPRINTF(key, MAXLINE, "constant%1dvalue", index);
149
set_resource(key, text);
153
const char *constant_get_name(int index)
155
return constant_names[index];
159
const int *constant_get_value(int index)
161
return constant_values[index];
165
void function_set(int index, const char *name, const char *value)
169
STRNCPY(function_names[index], name, MAXLINE - 1);
170
STRNCPY(function_values[index], value, MAXLINE - 1);
172
SNPRINTF(key, MAXLINE, "function%1dname", index);
173
set_resource(key, name);
174
SNPRINTF(key, MAXLINE, "function%1dvalue", index);
175
set_resource(key, value);
179
const char *function_get_name(int index)
181
return function_names[index];
185
const char *function_get_value(int index)
187
return function_values[index];