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/
37 #include "have_string.h"
38 #if defined(HAVE_STRING_H)
42 #include "have_const.h"
50 #define CHECK_L_FORMAT
54 #include "endian_calc.h"
61 #include "have_unused.h"
65 * sys_info - names and values of selected #defines
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
,
76 {"BASE", "base for calculations", NULL
,
78 {"BASE1", "one less than base", NULL
,
80 {"BASEB", "bits in the calculation base", NULL
,
82 {"BASEDIG", "number of digits in base", NULL
,
84 {"BIG_ENDIAN", "Most Significant Byte first symbol", NULL
,
86 {"BLK_CHUNKSIZE", "default allocation chunk size for blocks", NULL
,
88 {"BLK_DEF_MAXPRINT", "default block octets to print", NULL
,
89 (FULL
)BLK_DEF_MAXPRINT
},
90 {"BLUM_PREGEN", "non-default predefined Blum generators", NULL
,
92 {"CALCEXT", "extension for files read in", CALCEXT
,
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
,
98 {"DEFAULTCALCBINDINGS", "default key bindings file", DEFAULTCALCBINDINGS
,
100 {"DEFAULTCALCHELP", "help file that -h prints", DEFAULTCALCHELP
,
102 {"DEFAULTCALCPAGER", "default pager", DEFAULTCALCPAGER
,
104 {"DEFAULTCALCPATH", "default :-separated search path", DEFAULTCALCPATH
,
106 {"DEFAULTCALCRC", "default :-separated startup file list", DEFAULTCALCRC
,
108 {"DEFAULTSHELL", "default shell to use", DEFAULTSHELL
,
110 {"DEV_BITS", "device number size in bits", NULL
,
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
,
120 {"E_USERDEF", "base of user defined errors", NULL
,
122 {"E__BASE", "calc errors start above here", NULL
,
124 {"E__COUNT", "number of calc errors", NULL
,
126 {"E__HIGHEST", "highest calc error", NULL
,
128 {"FALSE", "boolean false", NULL
,
130 {"FILEPOS_BITS", "file position size in bits", NULL
,
132 {"FULL_BITS", "bits in a FULL", NULL
,
134 {"HELPDIR", "location of the help directory", HELPDIR
,
136 {"HIST_BINDING_FILE", "Default binding file", HIST_BINDING_FILE
,
138 {"HIST_SIZE", "Default history size", NULL
,
140 {"INIT_J", "initial 1st walking a55 table index", NULL
,
142 {"INIT_K", "initial 2nd walking a55 table index", NULL
,
144 {"INODE_BITS", "inode number size in bits", NULL
,
146 {"LITTLE_ENDIAN", "Least Significant Byte first symbol",
147 NULL
, (FULL
)LITTLE_ENDIAN
},
148 {"LONG_BITS", "bit length of a long", NULL
,
150 {"MAP_POPCNT", "number of odd primes in pr_map", NULL
,
152 {"MAX_CALCRC", "maximum allowed length of $CALCRC", NULL
,
154 {"MAXCMD", "max length of command invocation", NULL
,
156 {"MAXDIM", "max number of dimensions in matrices", NULL
,
158 {"MAXERROR", "max length of error message string", NULL
,
160 {"MAXFILES", "max number of opened files", NULL
,
162 {"MAXFULL", "largest SFULL value", NULL
,
164 {"MAXHALF", "largest SHALF value", NULL
,
166 {"MAXLABELS", "max number of user labels in function", NULL
,
168 {"MAXLEN", "longest storage size allowed", NULL
,
170 {"MAXLONG", "largest long val", NULL
,
172 {"MAXPRINT_DEFAULT", "default number of elements printed", NULL
,
173 (FULL
)MAXPRINT_DEFAULT
},
174 {"MAXREDC", "number of entries in REDC cache", NULL
,
176 {"MAXSCANCOUNT", "default max scan errors before an abort", NULL
,
178 {"MAXSTACK", "max depth of evaluation stack", NULL
,
180 {"MAXSTRING", "max size of string constant", NULL
,
182 {"MAXUFULL", "largest FULL value", NULL
,
184 {"MAXULONG", "largest unsigned long val", NULL
,
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
,
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
,
194 {"MAX_SM_VAL", "larest 32 bit value", NULL
,
196 {"MUL_ALG2", "default size for alternative multiply", NULL
,
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
,
204 {"PIX_32B", "max pix() value", NULL
,
206 {"POW_ALG2", "default size for using REDC for powers", NULL
,
208 {"REDC_ALG2", "default size using alternative REDC alg", NULL
,
210 {"SBITS", "size of additive or shuffle entry in bits", NULL
,
212 {"SBYTES", "size of additive or shuffle entry in bytes", NULL
,
214 {"SCNT", "length of additive 55 table in FULLs", NULL
,
216 {"SEEDXORBITS", "low bits of a55 seed devoted to xor", NULL
,
218 {"SHALFS", "size of additive or shuffle entry in HALFs", NULL
,
220 {"SHUFCNT", "size of shuffle table in entries", NULL
,
222 {"SHUFLEN", "length of shuffle table in FULLs", NULL
,
224 {"SHUFMASK", "mask for shuffle table entry selection", NULL
,
226 {"SHUFPOW", "power of 2 size of the shuffle table", NULL
,
228 {"SLEN", "number of FULLs in a shuffle table entry", NULL
,
230 {"SQ_ALG2", "default size for alternative squaring", NULL
,
232 {"SYMBOLSIZE", "max symbol name size", NULL
,
234 {"TEN_MAX", "10^(2^TEN_MAX): largest base10 conversion const", NULL
,
236 {"TOPFULL", "highest bit in FULL", NULL
,
238 {"TOPHALF", "highest bit in a HALF", NULL
,
240 {"TOPLONG", "top long bit", NULL
,
242 {"TRUE", "boolean true", NULL
,
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
},
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
266 * vals[0] if given, name of #define to print
267 * otherwise a list of #defines are printed
270 * value of #define if given (int or string)
271 * null if no #define arg was given
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
294 /* dump the entire table */
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");
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 */
317 case 1: /* print all infonames and values */
320 case 2: /* print all values and meanings */
324 math_error("sysinfo: arg must be string, 0, 1 or 2");
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
)) {
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
);
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 */
373 math_error("sysinfo: arg must be string, 0, 1 or 2");
378 * return what we found or didn't find
385 * dump_name_meaning - print all infonames and meanings
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
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
);
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
);
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
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
);
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
);
455 printf("%s%-36.36s\t\"%s\"\n",
456 (conf
->tab_ok
? "\t" : ""), p
->meaning
, p
->str
);