1 /* ncposr.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 NCPOSR (NOT character position, reverse) */
ncposr_(char * str,char * chars,integer * start,ftnlen str_len,ftnlen chars_len)9 integer ncposr_(char *str, char *chars, integer *start, ftnlen str_len,
10 ftnlen chars_len)
11 {
12 /* System generated locals */
13 integer ret_val;
14
15 /* Builtin functions */
16 integer i_len(char *, ftnlen), i_indx(char *, char *, ftnlen, ftnlen);
17
18 /* Local variables */
19 integer b;
20 logical found;
21 integer lenstr;
22
23 /* $ Abstract */
24
25 /* Find the first occurrence in a string of a character NOT */
26 /* belonging to a collection of characters, starting at a */
27 /* specified location, searching in reverse. */
28
29 /* $ Disclaimer */
30
31 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
32 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
33 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
34 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
35 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
36 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
37 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
38 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
39 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
40 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
41
42 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
43 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
44 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
45 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
46 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
47 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
48
49 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
50 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
51 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
52 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
53
54 /* $ Required_Reading */
55
56 /* SCANNING */
57
58 /* $ Keywords */
59
60 /* CHARACTER */
61 /* SEARCH */
62 /* UTILITY */
63
64 /* $ Declarations */
65 /* $ Brief_I/O */
66
67 /* VARIABLE I/O DESCRIPTION */
68 /* -------- --- -------------------------------------------------- */
69 /* STR I Any character string. */
70 /* CHARS I A collection of characters. */
71 /* START I Position to begin looking for one not in CHARS */
72
73 /* The function returns the index of the last character of STR */
74 /* at or before index START that is not in the collection CHARS. */
75
76 /* $ Detailed_Input */
77
78 /* STR is any character string. */
79
80 /* CHARS is a character string containing a collection of */
81 /* characters. Spaces in CHARS are significant. */
82
83 /* START is the position in STR to begin looking for */
84 /* characters not in CHARS. */
85
86 /* $ Detailed_Output */
87
88 /* The function returns the index of the last character of STR (at */
89 /* or before index START) that is not one of the characters in the */
90 /* string CHARS. No such character is found, the fucntion returns */
91 /* zero. */
92
93 /* $ Parameters */
94
95 /* None. */
96
97 /* $ Exceptions */
98
99 /* Error Free. */
100
101 /* 1) If START is less than 1, NCPOSR returns zero. */
102
103 /* 2) If START is greater than LEN(STRING), the search begins */
104 /* at the last character of the string. */
105
106 /* $ Files */
107
108 /* None. */
109
110 /* $ Particulars */
111
112 /* NCPOSR is case sensitive. */
113
114 /* An entire family of related SPICELIB routines (POS, CPOS, NCPOS, */
115 /* POSR, CPOSR, NCPOSR) is described in the Required Reading. */
116
117 /* Those familiar with the True BASIC language should note that */
118 /* these functions are equivalent to the True BASIC intrinsic */
119 /* functions with the same names. */
120
121 /* $ Examples */
122
123 /* Let STRING = 'BOB, JOHN, TED, AND MARTIN ' */
124 /* 123456789012345678901234567890 */
125
126 /* Let CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' */
127
128 /* Normal (Sequential) Searching: */
129 /* ------------------------------ */
130
131 /* NCPOSR( STRING, CHAR, 31 ) = 30 */
132 /* NCPOSR( STRING, CHAR, 29 ) = 29 */
133 /* NCPOSR( STRING, CHAR, 28 ) = 28 */
134 /* NCPOSR( STRING, CHAR, 27 ) = 27 */
135 /* NCPOSR( STRING, CHAR, 26 ) = 20 */
136 /* NCPOSR( STRING, CHAR, 19 ) = 16 */
137 /* NCPOSR( STRING, CHAR, 15 ) = 15 */
138 /* NCPOSR( STRING, CHAR, 14 ) = 11 */
139 /* NCPOSR( STRING, CHAR, 10 ) = 10 */
140 /* NCPOSR( STRING, CHAR, 9 ) = 5 */
141 /* NCPOSR( STRING, CHAR, 4 ) = 4 */
142 /* NCPOSR( STRING, CHAR, 3 ) = 0 */
143
144 /* START out of bounds: */
145 /* -------------------- */
146
147 /* NCPOSR( STRING, CHAR, 0 ) = 0 */
148 /* NCPOSR( STRING, CHAR, -4 ) = 0 */
149 /* NCPOSR( STRING, CHAR, 31 ) = 30 */
150 /* NCPOSR( STRING, CHAR, 123 ) = 30 */
151
152 /* Order within CHARS: */
153 /* ------------------- */
154
155 /* NCPOSR( STRING, 'JOHN', 7 ) = 5 */
156 /* NCPOSR( STRING, 'OHJN', 7 ) = 5 */
157
158 /* $ Restrictions */
159
160 /* None. */
161
162 /* $ Literature_References */
163
164 /* None. */
165
166 /* $ Author_and_Institution */
167
168 /* W.L. Taber (JPL) */
169 /* H.A. Neilan (JPL) */
170 /* B.V. Semenov (JPL) */
171
172 /* $ Version */
173
174 /* - SPICELIB Version 1.0.3, 31-JAN-2008 (BVS) */
175
176 /* Removed non-standard end-of-declarations marker */
177 /* 'C%&END_DECLARATIONS' from comments. */
178
179 /* - SPICELIB Version 1.0.2, 10-MAR-1992 (WLT) */
180
181 /* Comment section for permuted index source lines was added */
182 /* following the header. */
183
184 /* - SPICELIB Version 1.0.1, 26-MAR-1991 (HAN) */
185
186 /* The Required Reading file POSITION was renamed to SCANNING. */
187 /* This header was updated to reflect the change. */
188
189 /* - SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) */
190
191 /* -& */
192 /* $ Index_Entries */
193
194 /* backward search for position of unlisted character */
195
196 /* -& */
197
198 /* Local variables */
199
200 lenstr = i_len(str, str_len);
201 b = min(lenstr,*start);
202 found = FALSE_;
203 ret_val = 0;
204 while(! found) {
205 if (b <= 0) {
206 return ret_val;
207 } else if (i_indx(chars, str + (b - 1), chars_len, (ftnlen)1) == 0) {
208 ret_val = b;
209 return ret_val;
210 } else {
211 --b;
212 }
213 }
214 return ret_val;
215 } /* ncposr_ */
216
217