2 * $Id: ftype-integer.c,v 1.6 2001/07/13 00:55:56 guy Exp $
4 * Ethereal - Network traffic analyzer
5 * By Gerald Combs <gerald@zing.org>
6 * Copyright 2001 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef NEED_SNPRINTF_H
35 #include "ftypes-int.h"
40 int_fvalue_new(fvalue_t *fv)
42 fv->value.integer = 0;
46 set_integer(fvalue_t *fv, guint32 value)
48 fv->value.integer = value;
52 get_integer(fvalue_t *fv)
54 return fv->value.integer;
58 val_from_string(fvalue_t *fv, char *s, LogFunc log)
62 fv->value.integer = strtoul(s, &endptr, 0);
64 if (endptr == s || *endptr != '\0') {
65 /* This isn't a valid number. */
67 log("\"%s\" is not a valid number.", s);
70 if (errno == ERANGE) {
72 if (fv->value.integer == ULONG_MAX) {
73 log("\"%s\" causes an integer overflow.", s);
76 log("\"%s\" is not an integer.", s);
86 ipxnet_from_string(fvalue_t *fv, char *s, LogFunc log)
92 * Don't log a message if this fails; we'll try looking it
93 * up as an IPX network name if it does, and if that fails,
94 * we'll log a message.
96 if (val_from_string(fv, s, NULL)) {
100 val = get_ipxnet_addr(s, &known);
102 fv->value.integer = val;
106 log("\"%s\" is not a valid IPX network name or address.", s);
111 cmp_eq(fvalue_t *a, fvalue_t *b)
113 return a->value.integer == b->value.integer;
117 cmp_ne(fvalue_t *a, fvalue_t *b)
119 return a->value.integer != b->value.integer;
123 u_cmp_gt(fvalue_t *a, fvalue_t *b)
125 return (int)a->value.integer > (int)b->value.integer;
129 u_cmp_ge(fvalue_t *a, fvalue_t *b)
131 return (int)a->value.integer >= (int)b->value.integer;
135 u_cmp_lt(fvalue_t *a, fvalue_t *b)
137 return (int)a->value.integer < (int)b->value.integer;
141 u_cmp_le(fvalue_t *a, fvalue_t *b)
143 return (int)a->value.integer <= (int)b->value.integer;
147 s_cmp_gt(fvalue_t *a, fvalue_t *b)
149 return a->value.integer > b->value.integer;
153 s_cmp_ge(fvalue_t *a, fvalue_t *b)
155 return a->value.integer >= b->value.integer;
159 s_cmp_lt(fvalue_t *a, fvalue_t *b)
161 return a->value.integer < b->value.integer;
165 s_cmp_le(fvalue_t *a, fvalue_t *b)
167 return a->value.integer <= b->value.integer;
170 /* BOOLEAN-specific */
173 boolean_fvalue_new(fvalue_t *fv)
175 fv->value.integer = TRUE;
178 /* Checks for equality with zero or non-zero */
180 bool_eq(fvalue_t *a, fvalue_t *b)
182 if (a->value.integer) {
183 if (b->value.integer) {
191 if (b->value.integer) {
200 /* Checks for inequality with zero or non-zero */
202 bool_ne(fvalue_t *a, fvalue_t *b)
204 return (!bool_eq(a,b));
210 ftype_register_integers(void)
213 static ftype_t uint8_type = {
239 static ftype_t uint16_type = {
265 static ftype_t uint24_type = {
291 static ftype_t uint32_type = {
317 static ftype_t int8_type = {
343 static ftype_t int16_type = {
369 static ftype_t int24_type = {
395 static ftype_t int32_type = {
421 static ftype_t boolean_type = {
448 static ftype_t ipxnet_type = {
450 "IPX network number",
476 ftype_register(FT_UINT8, &uint8_type);
477 ftype_register(FT_UINT16, &uint16_type);
478 ftype_register(FT_UINT24, &uint24_type);
479 ftype_register(FT_UINT32, &uint32_type);
480 ftype_register(FT_INT8, &int8_type);
481 ftype_register(FT_INT16, &int16_type);
482 ftype_register(FT_INT24, &int24_type);
483 ftype_register(FT_INT32, &int32_type);
484 ftype_register(FT_BOOLEAN, &boolean_type);
485 ftype_register(FT_IPXNET, &ipxnet_type);