Root/qpkg/jval.c

Source at commit 2787a45c436c35fc6fd0ed452903ad045fe9571d created 9 years 16 days ago.
By Werner Almesberger, qpkg: added James S. Plank's red-black trees
1/*
2Libraries for fields, doubly-linked lists and red-black trees.
3Copyright (C) 2001 James S. Plank
4
5This library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Lesser General Public
7License as published by the Free Software Foundation; either
8version 2.1 of the License, or (at your option) any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19---------------------------------------------------------------------------
20Please see http://www.cs.utk.edu/~plank/plank/classes/cs360/360/notes/Libfdr/
21for instruction on how to use this library.
22
23Jim Plank
24plank@cs.utk.edu
25http://www.cs.utk.edu/~plank
26
27Associate Professor
28Department of Computer Science
29University of Tennessee
30203 Claxton Complex
311122 Volunteer Blvd.
32Knoxville, TN 37996-3450
33
34     865-974-4397
35Fax: 865-974-4404
36 */
37#include <stdio.h>
38#include <string.h>
39#include "jval.h"
40
41Jval JNULL;
42
43Jval new_jval_i(int i) {
44  Jval j;
45  j.i = i;
46  return j;
47}
48  
49Jval new_jval_l(long l) {
50  Jval j;
51  j.l = l;
52  return j;
53}
54  
55Jval new_jval_f(float f) {
56  Jval j;
57  j.f = f;
58  return j;
59}
60  
61Jval new_jval_d(double d) {
62  Jval j;
63  j.d = d;
64  return j;
65}
66  
67Jval new_jval_v(void *v) {
68  Jval j;
69  j.v = v;
70  return j;
71}
72  
73Jval new_jval_s(char *s) {
74  Jval j;
75  j.s = s;
76  return j;
77}
78  
79Jval new_jval_c(char c) {
80  Jval j;
81  j.c = c;
82  return j;
83}
84  
85Jval new_jval_uc(unsigned char uc) {
86  Jval j;
87  j.uc = uc;
88  return j;
89}
90  
91Jval new_jval_sh(short sh) {
92  Jval j;
93  j.sh = sh;
94  return j;
95}
96  
97Jval new_jval_ush(unsigned short ush) {
98  Jval j;
99  j.ush = ush;
100  return j;
101}
102  
103Jval new_jval_ui(unsigned int i) {
104  Jval j;
105  j.i = i;
106  return j;
107}
108  
109Jval new_jval_iarray(int i0, int i1) {
110  Jval j;
111  j.iarray[0] = i0;
112  j.iarray[1] = i1;
113  return j;
114}
115  
116Jval new_jval_farray(float f0, float f1) {
117  Jval j;
118  j.farray[0] = f0;
119  j.farray[1] = f1;
120  return j;
121}
122  
123Jval new_jval_carray_nt(char *carray) {
124  Jval j;
125  int i;
126
127  for (i = 0; i < 8 && carray[i] != '\0'; i++) {
128    j.carray[i] = carray[i];
129  }
130  if (i < 8) j.carray[i] = carray[i];
131  return j;
132}
133  
134Jval new_jval_carray_nnt(char *carray) {
135  Jval j;
136
137  memcpy(j.carray, carray, 8);
138  return j;
139}
140
141int jval_i(Jval j) {
142  return j.i;
143}
144
145long jval_l(Jval j) {
146  return j.l;
147}
148
149float jval_f(Jval j) {
150  return j.f;
151}
152
153double jval_d(Jval j) {
154  return j.d;
155}
156
157void *jval_v(Jval j) {
158  return j.v;
159}
160
161char *jval_s(Jval j) {
162  return j.s;
163}
164
165char jval_c(Jval j) {
166  return j.c;
167}
168
169unsigned char jval_uc(Jval j) {
170  return j.uc;
171}
172
173short jval_sh(Jval j) {
174  return j.sh;
175}
176
177unsigned short jval_ush(Jval j) {
178  return j.ush;
179}
180
181unsigned int jval_ui(Jval j) {
182  return j.ui;
183}
184
185int *jval_iarray(Jval j) {
186  return j.iarray;
187}
188
189float *jval_farray(Jval j) {
190  return j.farray;
191}
192
193char *jval_carray(Jval j) {
194  return j.carray;
195}
196
197

Archive Download this file

Branches:
master



interactive