2 *******************************************************************************
5 * RCS: $Header: /home/matthew/cvs/bible-kjv-4.10/util.c,v 2.2 2005/01/22 00:28:09 matthew Exp $
6 * Description: Some general-purpose functions.
8 * Created: Mon Dec 21 13:29:17 1992
9 * Modified: Mon Apr 26 11:15:51 1993 (Chip Chapin) chip@hpclbis
12 * Status: Experimental (Do Not Distribute)
14 *******************************************************************************
18 * Fri Apr 23 09:49:40 1993 (Chip Chapin) chip@hpclbis
19 * Added Univ_Int stuff.
20 * Tue Dec 22 11:22:41 1992 (Chip Chapin) chip@hpclbis
21 * Rewrite without strtok (oops!).
22 * Mon Dec 21 20:43:01 1992 (Chip Chapin) chip@hpclbis
23 * Initial creation and release with Bible Retrieval System 2.0.
24 *******************************************************************************
26 * Revision 2.2 2005/01/22 00:28:09 matthew
27 * tidy up - parentheses around assignment as truth value, clear unused
30 * Revision 2.1 2005/01/22 00:20:49 matthew
33 * Revision 2.0 2003/01/08 15:29:52 matthew
34 * versions collected from the net
36 * Revision 1.4 93/04/26 11:18:15 11:18:15 chip (Chip Chapin)
38 * Public release of portable datafile version.
48 FILE *findfile(char *dfname,char *pathlist)
49 /*----------------------------------------------------------------------
54 | Given a file name and a path list, attempt to open the
55 | file using each possible path until it's opened
56 | successfully or the paths are exhausted.
58 | pathlist -- list of paths separated by blanks or ":".
59 | Returns a stream pointer (FILE*).
62 | 921221 cc Created by extraction from tsl.c
64 \*----------------------------------------------------------------------*/
73 /* Keep trying until we succeed or run out of possible paths */
74 while ((fp == NULL) && *pp) {
77 /* copy next item in pathlist into dfpath and */
78 /* advance pathlist pointer past separator */
79 while (*pp && *pp != ' ' && *pp != ':') *dp++ = *pp++;
80 while (*pp == ' ' || *pp == ':') pp++;
82 /* Ensure a '/' separator between path and filename */
86 /* Cat dfname onto dfpath, including trailing \0 */
87 for (np=dfname; (*dp++ = *np++); )
90 fp=fopen( dfpath, "r");
97 void univ_assign(Univ_Int dst,int src)
98 /*----------------------------------------------------------------------
103 | Assign value of "src", an int, to "dst", a Univ_Int.
104 | The Univ_Int is a 4-byte integer with the bytes in a
105 | pre-defined order for portability. This facilitates the
106 | construction of portable data files.
108 | The order of the bytes is as follows:
110 | dst[0] <- highest-order
111 | dst[1] <- next highest
112 | dst[2] <- next highest
113 | dst[3] <- lowest-order
116 | 930423 cc Initial creation.
118 \*----------------------------------------------------------------------*/
123 for (i=3; i>=0; i--) {
124 b = src & 0x000000ff;
131 void shortuniv_assign(Univ_Int dst,int src)
132 /*----------------------------------------------------------------------
137 | Assign value of "src", an int, to "dst", a Short_Univ_Int.
138 | The Short_Univ_Int is a 2-byte integer with the bytes in a
139 | pre-defined order for portability. This facilitates the
140 | construction of portable data files.
141 | IGNORES src out-of-range errors.
143 | The order of the bytes is as follows:
145 | dst[0] <- highest-order
146 | dst[1] <- lowest-order
149 | 930423 cc Initial creation.
151 \*----------------------------------------------------------------------*/
153 dst[0] = (src >> 8) & 0x000000ff;
154 dst[1] = src & 0x000000ff;
155 } /* shortuniv_assign */
158 int univ2int(Univ_Int src)
159 /*----------------------------------------------------------------------
164 | Return integer value of "src", where "src" is a Univ_Int
168 | 930423 cc Initial creation.
170 \*----------------------------------------------------------------------*/
175 for (i=0; i<=3; i++) {
183 int shortuniv2int(Short_Univ_Int src)
184 /*----------------------------------------------------------------------
189 | Return integer value of "src", where "src" is a Short_Univ_Int
193 | 930423 cc Initial creation.
195 \*----------------------------------------------------------------------*/
204 } /* shortuniv2int */