2 * c_argv - a custom function display info about its args
4 * Copyright (C) 1999-2006 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_argv.c,v 30.1 2007/03/16 11:10:04 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/custom/RCS/c_argv.c,v $
24 * Under source code control: 1997/03/09 20:27:37
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/
36 #include "have_const.h"
43 #include "have_unused.h"
46 * c_argv - a custom function display info about its args
49 * vals[i] and arg to display information about
56 c_argv(char UNUSED
*name
, int count
, VALUE
**vals
)
58 VALUE result
; /* what we will return */
59 ZVALUE zfilelen
; /* length of a file as a ZVALUE */
60 NUMBER
*filelen
; /* pointer to length of a file as a NUMER */
61 char *type
; /* the name of the arg type */
65 * print info on each arg
67 for (i
=0; i
< count
; ++i
) {
70 * print arg number with leading tab as configured
72 printf("%sarg[%d]", (conf
->tab_ok
? "\t" : ""), i
);
77 switch (vals
[i
]->v_type
) {
78 case V_NULL
: /* null value */
81 case V_INT
: /* normal integer */
84 case V_NUM
: /* number */
85 type
= "rational_value";
87 case V_COM
: /* complex number */
88 type
= "complex_value";
90 case V_ADDR
: /* address of variable value */
93 case V_STR
: /* address of string */
96 case V_MAT
: /* address of matrix structure */
99 case V_LIST
: /* address of list structure */
102 case V_ASSOC
: /* address of association structure */
105 case V_OBJ
: /* address of object structure */
108 case V_FILE
: /* opened file id */
111 case V_RAND
: /* address of additive 55 random state */
114 case V_RANDOM
: /* address of Blum random state */
115 type
= "random_state";
117 case V_CONFIG
: /* configuration state */
118 type
= "config_state";
120 case V_HASH
: /* hash state */
123 case V_BLOCK
: /* memory block */
124 type
= "octet_block";
126 case V_OCTET
: /* octet (unsigned char) */
133 printf("\t%-16s", type
);
136 * print size and sizeof information
138 * We have to treat files in a special way
139 * because their length can be very long.
141 if (vals
[i
]->v_type
== V_FILE
) {
142 /* get the file length */
143 if (getsize(vals
[i
]->v_file
, &zfilelen
) == 0) {
145 filelen
->num
= zfilelen
;
146 qprintfd(filelen
, 0L);
150 printf("\tsize=unknown");
152 printf("\tsizeof=%ld\n", (long int)lsizeof(vals
[i
]));
154 printf("\tsize=%ld\tsizeof=%ld\n",
155 elm_count(vals
[i
]), (long int)lsizeof(vals
[i
]));
162 result
.v_type
= V_NUM
;
163 result
.v_num
= itoq(count
);