modified: diffout.py
[GalaxyCodeBases.git] / c_cpp / etc / calc / custom / c_sysinfo.c
blob1812c440e250c840f1352fdaa431378e54c8a173
1 /*
2 * c_sysinfo - names and values of selected #defines
4 * Copyright (C) 1999-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.3 $
21 * @(#) $Id: c_sysinfo.c,v 30.3 2013/08/11 08:41:38 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/custom/RCS/c_sysinfo.c,v $
24 * Under source code control: 1997/03/09 23:14:40
25 * File existed as early as: 1997
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>
35 #include <ctype.h>
37 #include "have_string.h"
38 #if defined(HAVE_STRING_H)
39 #include <string.h>
40 #endif
42 #include "have_const.h"
43 #include "value.h"
44 #include "custom.h"
46 #include "config.h"
47 #include "lib_calc.h"
48 #include "calc.h"
49 #include "longbits.h"
50 #define CHECK_L_FORMAT
51 #include "block.h"
52 #include "calcerr.h"
53 #include "conf.h"
54 #include "endian_calc.h"
55 #include "fposval.h"
56 #include "hist.h"
57 #include "prime.h"
58 #include "zrand.h"
59 #include "zrandom.h"
61 #include "have_unused.h"
65 * sys_info - names and values of selected #defines
67 struct infoname {
68 char *name; /* name of #define converted to all UPPER_CASE */
69 char *meaning; /* brief explanation of the #define */
70 char *str; /* non-NULL ==> value of #define is a string */
71 FULL nmbr; /* if str==NULL ==> value fo #define as a FULL */
73 STATIC struct infoname sys_info[] = {
74 {"S100", "slots in an subtractive 100 table", NULL,
75 (FULL)S100},
76 {"BASE", "base for calculations", NULL,
77 (FULL)BASE},
78 {"BASE1", "one less than base", NULL,
79 (FULL)BASE},
80 {"BASEB", "bits in the calculation base", NULL,
81 (FULL)BASEB},
82 {"BASEDIG", "number of digits in base", NULL,
83 (FULL)BASEDIG},
84 {"BIG_ENDIAN", "Most Significant Byte first symbol", NULL,
85 (FULL)BIG_ENDIAN},
86 {"BLK_CHUNKSIZE", "default allocation chunk size for blocks", NULL,
87 (FULL)BLK_CHUNKSIZE},
88 {"BLK_DEF_MAXPRINT", "default block octets to print", NULL,
89 (FULL)BLK_DEF_MAXPRINT},
90 {"BLUM_PREGEN", "non-default predefined Blum generators", NULL,
91 (FULL)BLUM_PREGEN},
92 {"CALCEXT", "extension for files read in", CALCEXT,
93 (FULL)0},
94 {"CALC_BYTE_ORDER", "Byte order (LITTLE_ENDIAN or BIG_ENDIAN)", NULL,
95 (FULL)CALC_BYTE_ORDER},
96 {"CUSTOMHELPDIR", "location of the custom help directory", CUSTOMHELPDIR,
97 (FULL)0},
98 {"DEFAULTCALCBINDINGS", "default key bindings file", DEFAULTCALCBINDINGS,
99 (FULL)0},
100 {"DEFAULTCALCHELP", "help file that -h prints", DEFAULTCALCHELP,
101 (FULL)0},
102 {"DEFAULTCALCPAGER", "default pager", DEFAULTCALCPAGER,
103 (FULL)0},
104 {"DEFAULTCALCPATH", "default :-separated search path", DEFAULTCALCPATH,
105 (FULL)0},
106 {"DEFAULTCALCRC", "default :-separated startup file list", DEFAULTCALCRC,
107 (FULL)0},
108 {"DEFAULTSHELL", "default shell to use", DEFAULTSHELL,
109 (FULL)0},
110 {"DEV_BITS", "device number size in bits", NULL,
111 (FULL)DEV_BITS},
112 {"DISPLAY_DEFAULT", "default digits for float display", NULL,
113 (FULL)DISPLAY_DEFAULT},
114 {"EPSILONPREC_DEFAULT", "2^-EPSILON_DEFAULT <= EPSILON_DEFAULT", NULL,
115 (FULL)EPSILONPREC_DEFAULT},
116 {"EPSILON_DEFAULT", "allowed error for float calculations",
117 EPSILON_DEFAULT, (FULL)0},
118 {"ERRMAX", "default errmax value", NULL,
119 (FULL)ERRMAX},
120 {"E_USERDEF", "base of user defined errors", NULL,
121 (FULL)E_USERDEF},
122 {"E__BASE", "calc errors start above here", NULL,
123 (FULL)E__BASE},
124 {"E__COUNT", "number of calc errors", NULL,
125 (FULL)E__COUNT},
126 {"E__HIGHEST", "highest calc error", NULL,
127 (FULL)E__HIGHEST},
128 {"FALSE", "boolean false", NULL,
129 (FULL)FALSE},
130 {"FILEPOS_BITS", "file position size in bits", NULL,
131 (FULL)FILEPOS_BITS},
132 {"FULL_BITS", "bits in a FULL", NULL,
133 (FULL)FULL_BITS},
134 {"HELPDIR", "location of the help directory", HELPDIR,
135 (FULL)0},
136 {"HIST_BINDING_FILE", "Default binding file", HIST_BINDING_FILE,
137 (FULL)0},
138 {"HIST_SIZE", "Default history size", NULL,
139 (FULL)HIST_SIZE},
140 {"INIT_J", "initial 1st walking a55 table index", NULL,
141 (FULL)INIT_J},
142 {"INIT_K", "initial 2nd walking a55 table index", NULL,
143 (FULL)INIT_K},
144 {"INODE_BITS", "inode number size in bits", NULL,
145 (FULL)INODE_BITS},
146 {"LITTLE_ENDIAN", "Least Significant Byte first symbol",
147 NULL, (FULL)LITTLE_ENDIAN},
148 {"LONG_BITS", "bit length of a long", NULL,
149 (FULL)LONG_BITS},
150 {"MAP_POPCNT", "number of odd primes in pr_map", NULL,
151 (FULL)MAP_POPCNT},
152 {"MAX_CALCRC", "maximum allowed length of $CALCRC", NULL,
153 (FULL)MAX_CALCRC},
154 {"MAXCMD", "max length of command invocation", NULL,
155 (FULL)MAXCMD},
156 {"MAXDIM", "max number of dimensions in matrices", NULL,
157 (FULL)MAXDIM},
158 {"MAXERROR", "max length of error message string", NULL,
159 (FULL)MAXERROR},
160 {"MAXFILES", "max number of opened files", NULL,
161 (FULL)MAXFILES},
162 {"MAXFULL", "largest SFULL value", NULL,
163 (FULL)MAXFULL},
164 {"MAXHALF", "largest SHALF value", NULL,
165 (FULL)MAXHALF},
166 {"MAXLABELS", "max number of user labels in function", NULL,
167 (FULL)MAXLABELS},
168 {"MAXLEN", "longest storage size allowed", NULL,
169 (FULL)MAXLEN},
170 {"MAXLONG", "largest long val", NULL,
171 (FULL)MAXLONG},
172 {"MAXPRINT_DEFAULT", "default number of elements printed", NULL,
173 (FULL)MAXPRINT_DEFAULT},
174 {"MAXREDC", "number of entries in REDC cache", NULL,
175 (FULL)MAXREDC},
176 {"MAXSCANCOUNT", "default max scan errors before an abort", NULL,
177 (FULL)MAXSCANCOUNT},
178 {"MAXSTACK", "max depth of evaluation stack", NULL,
179 (FULL)MAXSTACK},
180 {"MAXSTRING", "max size of string constant", NULL,
181 (FULL)MAXSTRING},
182 {"MAXUFULL", "largest FULL value", NULL,
183 (FULL)MAXUFULL},
184 {"MAXULONG", "largest unsigned long val", NULL,
185 (FULL)MAXULONG},
186 {"MAX_MAP_PRIME", "larest prime in pr_map", NULL,
187 (FULL)MAX_MAP_PRIME},
188 {"MAX_MAP_VAL", "larest bit in pr_map", NULL,
189 (FULL)MAX_MAP_VAL},
190 {"MAX_PFACT_VAL", "max x, for which pfact(x) is a long", NULL,
191 (FULL)MAX_PFACT_VAL},
192 {"MAX_SM_PRIME", "larest 32 bit prime", NULL,
193 (FULL)MAX_SM_PRIME},
194 {"MAX_SM_VAL", "larest 32 bit value", NULL,
195 (FULL)MAX_SM_VAL},
196 {"MUL_ALG2", "default size for alternative multiply", NULL,
197 (FULL)MUL_ALG2},
198 {"NXT_MAP_PRIME", "smallest odd prime not in pr_map", NULL,
199 (FULL)NXT_MAP_PRIME},
200 {"NXT_PFACT_VAL", "next prime for higher pfact values", NULL,
201 (FULL)NXT_PFACT_VAL},
202 {"OFF_T_BITS", "file offset size in bits", NULL,
203 (FULL)OFF_T_BITS},
204 {"PIX_32B", "max pix() value", NULL,
205 (FULL)PIX_32B},
206 {"POW_ALG2", "default size for using REDC for powers", NULL,
207 (FULL)POW_ALG2},
208 {"REDC_ALG2", "default size using alternative REDC alg", NULL,
209 (FULL)REDC_ALG2},
210 {"SBITS", "size of additive or shuffle entry in bits", NULL,
211 (FULL)SBITS},
212 {"SBYTES", "size of additive or shuffle entry in bytes", NULL,
213 (FULL)SBYTES},
214 {"SCNT", "length of additive 55 table in FULLs", NULL,
215 (FULL)SCNT},
216 {"SEEDXORBITS", "low bits of a55 seed devoted to xor", NULL,
217 (FULL)SEEDXORBITS},
218 {"SHALFS", "size of additive or shuffle entry in HALFs", NULL,
219 (FULL)SHALFS},
220 {"SHUFCNT", "size of shuffle table in entries", NULL,
221 (FULL)SHUFCNT},
222 {"SHUFLEN", "length of shuffle table in FULLs", NULL,
223 (FULL)SHUFLEN},
224 {"SHUFMASK", "mask for shuffle table entry selection", NULL,
225 (FULL)SHUFMASK},
226 {"SHUFPOW", "power of 2 size of the shuffle table", NULL,
227 (FULL)SHUFPOW},
228 {"SLEN", "number of FULLs in a shuffle table entry", NULL,
229 (FULL)SLEN},
230 {"SQ_ALG2", "default size for alternative squaring", NULL,
231 (FULL)SQ_ALG2},
232 {"SYMBOLSIZE", "max symbol name size", NULL,
233 (FULL)SYMBOLSIZE},
234 {"TEN_MAX", "10^(2^TEN_MAX): largest base10 conversion const", NULL,
235 (FULL)TEN_MAX},
236 {"TOPFULL", "highest bit in FULL", NULL,
237 (FULL)TOPFULL},
238 {"TOPHALF", "highest bit in a HALF", NULL,
239 (FULL)TOPHALF},
240 {"TOPLONG", "top long bit", NULL,
241 (FULL)TOPLONG},
242 {"TRUE", "boolean true", NULL,
243 (FULL)TRUE},
244 {"USUAL_ELEMENTS", "usual number of elements for objects", NULL,
245 (FULL)USUAL_ELEMENTS},
246 {"REGNUM_MAX", "highest custom register number", NULL,
247 (FULL)CUSTOM_REG_MAX},
249 /* must be last */
250 {NULL, NULL, NULL, (FULL)0}
255 * forward declarations
257 S_FUNC void dump_name_meaning(void); /* custom("sysinfo", 0) */
258 S_FUNC void dump_name_value(void); /* custom("sysinfo", 1) */
259 S_FUNC void dump_mening_value(void); /* custom("sysinfo", 2) */
263 * c_sysinfo - return a calc #define value
265 * given:
266 * vals[0] if given, name of #define to print
267 * otherwise a list of #defines are printed
269 * returns:
270 * value of #define if given (int or string)
271 * null if no #define arg was given
273 /*ARGSUSED*/
274 VALUE
275 c_sysinfo(char UNUSED *name, int count, VALUE **vals)
277 VALUE result; /* what we will return */
278 struct infoname *p; /* current infoname */
279 char *buf; /* upper case value of vals[0] */
280 char *q; /* to upper case converter */
281 char *r; /* to upper case converter */
284 * we will return NULL if a value was not found
286 result.v_type = V_NULL;
287 result.v_subtype = V_NOSUBTYPE;
290 * case 0: if no args, then dump the table with no values
292 if (count == 0) {
294 /* dump the entire table */
295 dump_name_meaning();
298 * case 1: numeric arg is given
300 } else if (vals[0]->v_type == V_NUM) {
302 /* firewall - must be a tiny non-negative integer */
303 if (qisneg(vals[0]->v_num) ||
304 qisfrac(vals[0]->v_num) ||
305 zge31b(vals[0]->v_num->num)) {
306 math_error("sysinfo: arg must be string, 0, 1 or 2");
307 /*NOTREACHED*/
311 * select action based on numeric value of arg
313 switch (z1tol(vals[0]->v_num->num)) {
314 case 0: /* print all infonames and meanings */
315 dump_name_meaning();
316 break;
317 case 1: /* print all infonames and values */
318 dump_name_value();
319 break;
320 case 2: /* print all values and meanings */
321 dump_mening_value();
322 break;
323 default:
324 math_error("sysinfo: arg must be string, 0, 1 or 2");
325 /*NOTREACHED*/
329 * case 2: string arg is given
331 * The string is taken to be the infoname we want to print.
333 } else if (vals[0]->v_type == V_STR) {
335 /* convert vals[0] to upper case string */
336 buf = (char *)malloc(strlen((char *)vals[0]->v_str->s_str)+1);
337 for (q = (char *)vals[0]->v_str->s_str, r = buf; *q; ++q, ++r)
339 if (isascii((int)*q) && islower((int)*q)) {
340 *r = *q - 'a' + 'A';
341 } else {
342 *r = *q;
345 *r = '\0';
347 /* search the table for the infoname */
348 for (p = sys_info; p->name != NULL; ++p) {
350 if (strcmp(p->name, buf) == 0) {
352 /* found the infoname */
353 if (p->str == NULL) {
354 /* return value as integer */
355 result.v_type = V_NUM;
356 result.v_num = utoq( p->nmbr);
357 } else {
358 /* return value as string */
359 result.v_type = V_STR;
360 result.v_subtype = V_NOSUBTYPE;
361 result.v_str = makestring(p->str);
364 /* return found infotype as value */
365 break;
370 * bad arg given
372 } else {
373 math_error("sysinfo: arg must be string, 0, 1 or 2");
374 /*NOTREACHED*/
378 * return what we found or didn't find
380 return result;
385 * dump_name_meaning - print all infonames and meanings
387 S_FUNC void
388 dump_name_meaning(void)
390 struct infoname *p; /* current infoname */
392 /* dump the entire table */
393 for (p = sys_info; p->name != NULL; ++p) {
394 printf("%s%-23s\t%s\n",
395 (conf->tab_ok ? "\t" : ""), p->name, p->meaning);
402 * dump_name_value - print all infonames and values
404 S_FUNC void
405 dump_name_value(void)
407 struct infoname *p; /* current infoname */
409 /* dump the entire table */
410 for (p = sys_info; p->name != NULL; ++p) {
411 if (p->str == NULL) {
412 #if LONG_BITS == FULL_BITS || FULL_BITS == 32
413 printf("%s%-23s\t%-8lu\t(0x%lx)\n",
414 (conf->tab_ok ? "\t" : ""), p->name,
415 (unsigned long)p->nmbr,
416 (unsigned long)p->nmbr);
417 #else
418 printf("%s%-23s\t%-8llu\t(0x%llx)\n",
419 (conf->tab_ok ? "\t" : ""), p->name,
420 (unsigned long long)p->nmbr,
421 (unsigned long long)p->nmbr);
422 #endif
423 } else {
424 printf("%s%-23s\t\"%s\"\n",
425 (conf->tab_ok ? "\t" : ""), p->name, p->str);
433 * dump_mening_value - print all values and meanings
435 S_FUNC void
436 dump_mening_value(void)
438 struct infoname *p; /* current infoname */
440 /* dump the entire table */
441 for (p = sys_info; p->name != NULL; ++p) {
442 if (p->str == NULL) {
443 #if LONG_BITS == FULL_BITS || FULL_BITS == 32
444 printf("%s%-36.36s\t%-8lu\t(0x%lx)\n",
445 (conf->tab_ok ? "\t" : ""), p->meaning,
446 (unsigned long)p->nmbr,
447 (unsigned long)p->nmbr);
448 #else
449 printf("%s%-36.36s\t%-8llu\t(0x%llx)\n",
450 (conf->tab_ok ? "\t" : ""), p->meaning,
451 (unsigned long long)p->nmbr,
452 (unsigned long long)p->nmbr);
453 #endif
454 } else {
455 printf("%s%-36.36s\t\"%s\"\n",
456 (conf->tab_ok ? "\t" : ""), p->meaning, p->str);
462 #endif /* CUSTOM */