1 /* fndnwd.f -- translated by f2c (version 19980913).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include "f2c.h"
7 
8 /* $Procedure      FNDNWD ( Find the next word after an index ) */
fndnwd_(char * string,integer * start,integer * b,integer * e,ftnlen string_len)9 /* Subroutine */ int fndnwd_(char *string, integer *start, integer *b,
10 	integer *e, ftnlen string_len)
11 {
12     /* System generated locals */
13     integer i__1;
14 
15     /* Builtin functions */
16     integer i_len(char *, ftnlen);
17 
18     /* Local variables */
19     integer size, i__, l, n, blank;
20     logical thisb, lastn;
21 
22 /* $ Abstract */
23 
24 /*     Find the beginning and end of the first word starting at */
25 /*     or after a specified character. */
26 
27 /* $ Disclaimer */
28 
29 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
30 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
31 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
32 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
33 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
34 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
35 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
36 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
37 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
38 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
39 
40 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
41 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
42 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
43 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
44 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
45 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
46 
47 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
48 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
49 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
50 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
51 
52 /* $ Required_Reading */
53 
54 /*     None. */
55 
56 /* $ Keywords */
57 
58 /*     PARSING,  SEARCH,  WORD */
59 
60 /* $ Declarations */
61 /* $ Brief_I/O */
62 
63 /*     VARIABLE  I/O  DESCRIPTION */
64 /*     --------  ---  -------------------------------------------------- */
65 /*     STRING     I   A string to examine for words. */
66 /*     START      I   Position in the string to start looking for words. */
67 /*     B          O   String position of first character of the word. */
68 /*     E          O   String position of last character of the word. */
69 
70 /* $ Detailed_Input */
71 
72 /*     STRING     Is a character string that potentially consists of */
73 /*                words of text. */
74 
75 /*     START      Is the index of a letter within the string from which */
76 /*                to start looking for the next word. */
77 
78 /* $ Detailed_Output */
79 
80 /*     B          Is the index of the first letter of the word substring */
81 /*                of STRING that begins at or after position START.  If */
82 /*                there are no such substrings I is returned as 0. */
83 
84 /*     E          Is the index of the last letter of the word substring */
85 /*                of STRING that begins at or after position START.  If */
86 /*                there are no such substrings J is returned as 0. */
87 
88 /* $ Parameters */
89 
90 /*     None. */
91 
92 /* $ Particulars */
93 
94 /*     Given a character string and location of a character within that */
95 /*     string, this routine finds the first full word of the string */
96 /*     that starts on or after the specified location. */
97 
98 /* $ Examples */
99 /*                       1         2         3         4         5 */
100 /*              12345678901234567890123456789012345678901234567890 */
101 /*     STRING: 'Now is the time for all good men to go home to bed' */
102 
103 /*     START    I      J */
104 /*     -----   ---    --- */
105 /*     1        1      3 */
106 /*     2        5      6 */
107 /*     3        5      6 */
108 /*     4        5      6 */
109 /*     5        5      6 */
110 /*     6        8      10 */
111 /*     7        8      10 */
112 /*     8        8      10 */
113 /*     9        12     15 */
114 
115 /*     48       48     50 */
116 /*     49       0      0 */
117 /*     111      0      0 */
118 
119 /* $ Restrictions */
120 
121 /*     None. */
122 
123 /* $ Exceptions */
124 
125 /*     Error free. */
126 
127 /* $ Files */
128 
129 /*     None. */
130 
131 /* $ Author_and_Institution */
132 
133 /*     W.L. Taber      (JPL) */
134 
135 /* $ Literature_References */
136 
137 /*     None. */
138 
139 /* $ Version */
140 
141 /* -    SPICELIB Version 2.0.0, 15-OCT-1993 (WLT) */
142 
143 /*        The routine was completely rewritten with a resulting */
144 /*        increase in execution speed of between 2000% and 6000%. */
145 
146 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
147 
148 /*        Comment section for permuted index source lines was added */
149 /*        following the header. */
150 
151 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) */
152 
153 /* -& */
154 /* $ Index_Entries */
155 
156 /*     find the next word after an index */
157 
158 /* -& */
159 /* $ Revisions */
160 
161 /* -     SPICELIB Version 2.0.0, 15-OCT-1993 (WLT) */
162 
163 /*         The routine was completely rewritten with a resulting */
164 /*         increase in execution speed of between 2000% and 6000%. */
165 /*         It was tested against the old version of the routine to */
166 /*         ensure that the functionality was exactly duplicated. */
167 
168 /* -& */
169 
170 /*     Local Variables */
171 
172 
173 /*     Set up neede parameters and check obvious out-of-bound cases. */
174 
175     blank = ' ';
176     size = i_len(string, string_len);
177     if (*start > size) {
178 	*b = 0;
179 	*e = 0;
180 	return 0;
181     }
182     n = max(1,*start);
183     l = n - 1;
184     if (l <= 0) {
185 	lastn = FALSE_;
186     } else {
187 	lastn = *(unsigned char *)&string[l - 1] != blank;
188     }
189     thisb = *(unsigned char *)&string[n - 1] == blank;
190 
191 /*     Search for the beginning of a word (the last character */
192 /*     blank and the current non-blank). */
193 
194     while(thisb || lastn) {
195 	++n;
196 	if (n > size) {
197 	    *b = 0;
198 	    *e = 0;
199 	    return 0;
200 	}
201 	lastn = ! thisb;
202 	thisb = *(unsigned char *)&string[n - 1] == blank;
203     }
204 
205 /*     If we get this far, we found the beginning of the */
206 /*     string.  To find the end look for the next blank and */
207 /*     back up one. */
208 
209     *b = n;
210     i__1 = size;
211     for (i__ = n + 1; i__ <= i__1; ++i__) {
212 	if (*(unsigned char *)&string[i__ - 1] == blank) {
213 	    *e = i__ - 1;
214 	    return 0;
215 	}
216     }
217 
218 /*     If we get this far, the word ends at the end of the */
219 /*     string. */
220 
221     *e = size;
222     return 0;
223 } /* fndnwd_ */
224 
225