1 /* lx4sgn.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      LX4SGN (Scan for signed integer) */
lx4sgn_(char * string,integer * first,integer * last,integer * nchar,ftnlen string_len)9 /* Subroutine */ int lx4sgn_(char *string, integer *first, integer *last,
10 	integer *nchar, ftnlen string_len)
11 {
12     /* Builtin functions */
13     integer i_len(char *, ftnlen);
14 
15     /* Local variables */
16     integer f, i__, l;
17     extern /* Subroutine */ int lx4uns_(char *, integer *, integer *, integer
18 	    *, ftnlen);
19 
20 /* $ Abstract */
21 
22 /*     Scan a string from a specified starting position for the */
23 /*     end of a signed integer. */
24 
25 
26 /* $ Disclaimer */
27 
28 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
29 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
30 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
31 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
32 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
33 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
34 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
35 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
36 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
37 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
38 
39 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
40 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
41 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
42 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
43 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
44 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
45 
46 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
47 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
48 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
49 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
50 
51 /* $ Required_Reading */
52 
53 /*      None. */
54 
55 /* $ Keywords */
56 
57 /*       PARSING */
58 
59 /* $ Declarations */
60 /* $ Brief_I/O */
61 
62 /*      VARIABLE  I/O  DESCRIPTION */
63 /*      --------  ---  -------------------------------------------------- */
64 /*      STRING     I   any character string */
65 /*      FIRST      I   first character to scan from in STRING */
66 /*      LAST       O   last character that is part of a signed integer */
67 /*      NCHAR      O   number of characters in the signed integer. */
68 
69 /* $ Detailed_Input */
70 
71 /*     STRING      is any character string. */
72 
73 /*     FIRST       is the location in the string to beginning scanning */
74 /*                 for a signed integer.  It is assumed that the */
75 /*                 signed integer begins at FIRST. */
76 
77 /* $ Detailed_Output */
78 
79 /*     LAST        is the last character at or after FIRST such that */
80 /*                 the substring STRING(FIRST:LAST) is a signed */
81 /*                 integer.  If there is no such substring, LAST */
82 /*                 will be returned with the value FIRST-1. */
83 
84 /*     NCHAR       is the number of characters in the signed integer */
85 /*                 that begins at FIRST and ends at last.  If there */
86 /*                 is no such string NCHAR will be given the value 0. */
87 
88 /* $ Parameters */
89 
90 /*      None. */
91 
92 /* $ Files */
93 
94 /*      None. */
95 
96 /* $ Exceptions */
97 
98 /*     Error free. */
99 
100 /*     1) If FIRST is beyond either end of the string, then */
101 /*        LAST will be returned with the value FIRST and NCHAR */
102 /*        will be returned with the value 0. */
103 
104 /*     2) If STRING(FIRST:FIRST) is not part of a signed integer */
105 /*        then LAST will be returned with the value FIRST-1 and NCHAR */
106 /*        will be returned with the value 0. */
107 
108 /* $ Particulars */
109 
110 /*     This routine allows you to scan forward in a string to locate */
111 /*     a signed integer that begins on the input character FIRST.  Note */
112 /*     that all unsigned integers are included in the list of signed */
113 /*     integers.  The signed integers may in addition have a leading */
114 /*     plus ('+') or minus ('-') sign. */
115 
116 
117 /* $ Examples */
118 
119 /*     Suppose you believe that a string has the form */
120 
121 /*        X%Y%Z */
122 
123 /*     where X, Y, and Z are signed integers of some unknown */
124 /*     length and % stands for some non-digit character. You could */
125 /*     use this routine to locate the signed integers in the */
126 /*     string as shown below.  We'll keep track of the beginning and */
127 /*     ending of the signed integers in the integer arrays B and E. */
128 
129 /*     FIRST = 1 */
130 /*     I     = 0 */
131 
132 /*     DO WHILE ( FIRST .LT. LEN(STRING) ) */
133 
134 /*        CALL LX4SGN ( STRING, FIRST, LAST, NCHAR ) */
135 
136 /*        IF ( NCHAR .GT. 0 ) THEN */
137 
138 /*           I     = I    + 1 */
139 /*           B(I)  = FIRST */
140 /*           E(I)  = LAST */
141 /*           FIRST = LAST + 2 */
142 
143 /*        ELSE */
144 
145 /*           FIRST = FIRST + 1 */
146 
147 /*        END IF */
148 
149 /*     END DO */
150 
151 
152 /* $ Restrictions */
153 
154 /*     None. */
155 
156 /* $ Author_and_Institution */
157 
158 /*      W.L. Taber      (JPL) */
159 
160 /* $ Literature_References */
161 
162 /*      None. */
163 
164 /* $ Version */
165 
166 /* -    SPICELIB Version 1.0.0, 12-JUL-1994 (WLT) */
167 
168 
169 /* -& */
170 /* $ Index_Entries */
171 
172 /*     Scan a string for a signed integer. */
173 
174 /* -& */
175     *last = *first - 1;
176     l = i_len(string, string_len);
177 
178 /*     If start is beyond the ends of the string, we  can quit now. */
179 
180     if (*first < 1 || *first > l) {
181 	*nchar = 0;
182 	return 0;
183     }
184 
185 /*     There are two cases to take care of (and in both cases */
186 /*     LX4UNS does almost all of the work). */
187 
188     i__ = *(unsigned char *)&string[*first - 1];
189     if (i__ == '+' || i__ == '-') {
190 
191 /*        Case 1. The string begins with a + or -.  There must */
192 /*        be an unsigned integer following. */
193 
194 	f = *first + 1;
195 	lx4uns_(string, &f, last, nchar, string_len);
196 	if (*nchar == 0) {
197 	    *last = *first - 1;
198 	} else {
199 	    ++(*nchar);
200 	}
201     } else {
202 
203 /*        Case 2.  The leading character is not a sign character. */
204 /*        We simply check to see how much unsigned integer we have. */
205 
206 	lx4uns_(string, first, last, nchar, string_len);
207     }
208     return 0;
209 } /* lx4sgn_ */
210 
211