1 /*****************************************************************
2 * HMMER - Biological sequence analysis with profile HMMs
3 * Copyright (C) 1992-1999 Washington University School of Medicine
6 * This source code is distributed under the terms of the
7 * GNU General Public License. See the files COPYING and LICENSE
9 *****************************************************************/
13 * Finicky type checkers for strings. Return 1 (TRUE) if ok, 0 elsewise.
14 * Also, finicky type converters (sre_ntoh32() and friends)
16 * CVS $Id: types.c,v 1.1.1.1 2005/03/22 08:34:27 cmzmasek Exp $
25 * Returns TRUE if s points to something that atoi() will parse
26 * completely and convert to an integer.
33 if (s == NULL) {squid_errno = SQERR_PARAMETER; return 0; }
36 while (isspace((int) (*s))) s++;
37 /* skip leading sign */
38 if (*s == '-' || *s == '+') s++;
39 /* skip leading conversion signals */
40 if ((strncmp(s, "0x", 2) == 0 && (int) strlen(s) > 2) ||
41 (strncmp(s, "0X", 2) == 0 && (int) strlen(s) > 2))
46 else if (*s == '0' && (int) strlen(s) > 1)
48 /* examine remainder for garbage chars */
52 if (!isdigit((int) (*s))) return 0;
58 if (!isxdigit((int) (*s))) return 0;
68 * Purpose: Returns TRUE if s is a string representation
69 * of a valid floating point number.
78 if (s == NULL) return 0;
80 while (isspace((int) (*s))) s++; /* skip leading whitespace */
81 if (*s == '-' || *s == '+') s++; /* skip leading sign */
83 /* Examine remainder for garbage. Allowed one '.' and
84 * one 'e' or 'E'; if both '.' and e/E occur, '.'
89 if (isdigit((int) (*s)))
93 if (gotdecimal) return 0; /* can't have two */
94 if (gotexp) return 0; /* e/E preceded . */
97 else if (*s == 'e' || *s == 'E')
99 if (gotexp) return 0; /* can't have two */
102 else if (isspace((int) (*s)))
108 while (isspace((int) (*s))) s++; /* skip trailing whitespace */
109 if (*s == '\0' && gotreal) return 1;
114 /* Function: Byteswap()
116 * Purpose: Swap between big-endian and little-endian.
118 * int foo = 0x12345678;
119 * byteswap((char *) &foo, sizeof(int));
120 * printf("%x\n", foo)
123 * I don't fully understand byte-swapping issues.
124 * However, I have tested this on chars through floats,
125 * on various machines:
126 * SGI IRIX 4.0.5, SunOS 4.1.3, DEC Alpha OSF/1, Alliant
128 * Date: Sun Feb 12 10:26:22 1995
131 Byteswap(char *swap, int nbytes)
136 for (x = 0; x < nbytes / 2; x++)
138 byte = swap[nbytes - x - 1];
139 swap[nbytes - x - 1] = swap[x];
146 /* Functions: sre_ntoh16(), etc.
147 * Date: SRE, Sun Dec 31 11:26:53 2000 [St. Louis]
149 * Purpose: Provide functionality of ntohs(), etc; extended
150 * to 64-bit unsigned ints, and explicitly provided
151 * in case a machine doesn't have the ntohs()
154 * If we're using the host functions,
155 * USE_HOST_BYTESWAP_FUNCTIONS was set to 1 in
156 * squidconf.h, and we #define'd sre_hton16(x)=hton(x), etc.
157 * in squid.h. In doing this, we assumed that the
158 * host functions work on 16- and 32-bit unsigned quantities.
159 * If for some reason that's not true, set
160 * USE_HOST_BYTESWAP_FUNCTIONS to 0.
162 #ifndef USE_HOST_BYTESWAP_FUNCTIONS
164 sre_ntoh16(sqd_uint16 netshort)
166 #ifdef WORDS_BIGENDIAN
169 Byteswap((char *) &netshort, 2);
174 sre_ntoh32(sqd_uint32 netlong)
176 #ifdef WORDS_BIGENDIAN
179 Byteswap((char *) &netlong, 4);
184 sre_hton16(sqd_uint16 hostshort)
186 #ifdef WORDS_BIGENDIAN
189 Byteswap((char *) &hostshort, 2);
194 sre_hton32(sqd_uint32 hostlong)
196 #ifdef WORDS_BIGENDIAN
199 Byteswap((char *) &hostlong, 4);
203 #endif /*USE_HOST_BYTESWAP_FUNCTIONS*/
206 sre_ntoh64(sqd_uint64 net_int64)
208 #ifdef WORDS_BIGENDIAN
211 Byteswap((char *) &net_int64, 8);
216 sre_hton64(sqd_uint64 host_int64)
218 #ifdef WORDS_BIGENDIAN
221 Byteswap((char *) &host_int64, 8);