modified: diffout.py
[GalaxyCodeBases.git] / c_cpp / etc / calc / custom / c_argv.c
blob2a83cc08dac0346ea10b3db02a9e7589984bc136
1 /*
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/
32 #if defined(CUSTOM)
34 #include <stdio.h>
36 #include "have_const.h"
37 #include "value.h"
38 #include "custom.h"
40 #include "config.h"
41 #include "calc.h"
43 #include "have_unused.h"
46 * c_argv - a custom function display info about its args
48 * given:
49 * vals[i] and arg to display information about
51 * returns:
52 * count
54 /*ARGSUSED*/
55 VALUE
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 */
62 int i;
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);
75 * print the arg type
77 switch (vals[i]->v_type) {
78 case V_NULL: /* null value */
79 type = "null";
80 break;
81 case V_INT: /* normal integer */
82 type = "int";
83 break;
84 case V_NUM: /* number */
85 type = "rational_value";
86 break;
87 case V_COM: /* complex number */
88 type = "complex_value";
89 break;
90 case V_ADDR: /* address of variable value */
91 type = "address";
92 break;
93 case V_STR: /* address of string */
94 type = "string";
95 break;
96 case V_MAT: /* address of matrix structure */
97 type = "matrix";
98 break;
99 case V_LIST: /* address of list structure */
100 type = "list";
101 break;
102 case V_ASSOC: /* address of association structure */
103 type = "assoc";
104 break;
105 case V_OBJ: /* address of object structure */
106 type = "ocject";
107 break;
108 case V_FILE: /* opened file id */
109 type = "file";
110 break;
111 case V_RAND: /* address of additive 55 random state */
112 type = "rand_state";
113 break;
114 case V_RANDOM: /* address of Blum random state */
115 type = "random_state";
116 break;
117 case V_CONFIG: /* configuration state */
118 type = "config_state";
119 break;
120 case V_HASH: /* hash state */
121 type = "hash_state";
122 break;
123 case V_BLOCK: /* memory block */
124 type = "octet_block";
125 break;
126 case V_OCTET: /* octet (unsigned char) */
127 type = "octet";
128 break;
129 default:
130 type = "unknown";
131 break;
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) {
144 filelen = qalloc();
145 filelen->num = zfilelen;
146 qprintfd(filelen, 0L);
147 qfree(filelen);
148 } else {
149 /* getsize error */
150 printf("\tsize=unknown");
152 printf("\tsizeof=%ld\n", (long int)lsizeof(vals[i]));
153 } else {
154 printf("\tsize=%ld\tsizeof=%ld\n",
155 elm_count(vals[i]), (long int)lsizeof(vals[i]));
160 * return count
162 result.v_type = V_NUM;
163 result.v_num = itoq(count);
164 return result;
167 #endif /* CUSTOM */