Debian Codegraph @

libsrc/os/vms/osstr.c

raw
1 /* @(#)osstr.c 19.1 (ES0-DMD) 02/25/03 13:56:14 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 .TYPE Module
31 .NAME str
32 .LANGUAGE C
33 .AUTHOR IPG-ESO Garching
34 .CATEGORY Independant string handling interfaces.
35 .COMMENTS
36 Handling of character strings. These routines normally return
37 a non-negative integer number on successful return.
38 Otherwise, a value of -1 is set to indicate an error
39 condition and the variable ``oserror'' contains the
40 symbolic error code.
41
42 .HISTORY [0.0] 25-Aug-1986 Definition J. D. Ponz
43 [1.0] 10-Apr-1987 Programmation B. Pirenne
44 [1.1] 04-Aug-1987 VMS Includes
45 [1.2] 910911 bzero removed CG.(memset can be used instead)
46 ------------------------------------------------------------*/
47 #include <errno.h>
48
49 #include <osparms.h>
50
51 int strsglen(str,cha)
52 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53 .PURPOSE Compute the length of the string up to '\0' or the character "cha"
54 (typically a ' ').
55 .RETURNS Upon successful completion a positive or zero integer number is
56 returned.
57 .REMARKS System dependencies:
58 -- UNIX: none
59 ------------------------------------------------------------*/
60
61 char *str; /* IN : string to check */
62 char cha; /* IN : open mode */
63
64 {
65 register i;
66
67 for (i=0;*(str+i) != '\0' && *(str+i) != cha;i++);
68 *(str+i) = '\0';
69 return(i);
70 }
71
72 strtolower(s1,s2)
73 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
74 .PURPOSE
75 translate the s2 character string to lower case and store the
76 result in s1.
77 .RETURNS The number of characters actually translated.
78
79 ---------------------------------------------------------------*/
80
81 char *s1; /* OUT: ouptput string */
82 char *s2; /* IN : input string */
83
84 {
85
86 register i,c;
87
88 c = 0;
89 for (i=0;*(s2+i) != '\0';i++) {
90 if (*(s2+i) >= 'A' && *(s2+i) <= 'Z')
91 {
92 *(s1+i) = *(s2+i) + 32;
93 c++;
94 }
95 else
96 *(s1+i) = *(s2+i);
97 }
98 return(c);
99 }
100
101
102 strgetline(buf)
103 /*+++++++++++++++++++++++++++++ getline +++++++++++++++++++++++++
104 .PURPOSE get one record from standard input.
105 .RETURNS number of characters fetched.
106 -----------------------------------------------------------------*/
107 char *buf; /* buffer to contain the string read */
108 {
109 int i;
110 char c;
111
112 for(i=0;(c=getchar()) != '\n';i++) *(buf+i) = c;
113 *(buf+i+1) = '\0';
114 return(i);
115 }
116
117
118 truelen(string)
119 /*++++++++++++++++++++++ truelen ++++++++++++++++++++++++++++++++
120 .PURPOSE Compute the 'true length' of a string of character by checking for
121 all valid characters. Valid characters taken into account are :
122 a..z, A..Z, ., *, -, _, 0..9.
123 .RETURNS The number of contiguous characters in the string satisfying the
124 above condition.
125 ------------------------------------------------------------------*/
126 char *string; /* The character string to check */
127 {
128 register i,c;
129
130 for (i = 0; (c = *(string + i)) == '.' || c == '-' || c == '_' ||
131 c >= 'a' && c <= 'z' ||
132 c >= 'A' && c <= 'Z' ||
133 c >= '0' && c <= '9' ;
134 i++)
135 ;
136 *(string+i) = '\0';
137 return(i);
138 }
139
140 int strin(s1,s2)
141 /*+++++++++++++++++++++++++++++ strin ++++++++++++++++++++++++++++++++++++++
142 .PURPOSE Pattern matching
143 .RETURNS 0 if pattern is not in string, 1 if found.
144 -------------------------------------------------------------------------*/
145
146 char *s1 /* IN : string to search */;
147 char *s2 /* IN : pattern to find */;
148
149 {
150 register char *t1,*t2;
151 int found;
152
153 found = 0;
154 t2 = s2;
155 t1 = s1;
156 for (;*t1 != '\0' && *t2 != '\0' && !found;t1++) {
157 if (*t1 == *t2)
158 t2++;
159 else {
160 if (*t2 != *s2)
161 {
162 t1 -= t2 - s2;
163 t2 = s2;
164 }
165 }
166 }
167 if (*t2 == '\0') found = 1;
168 return(found);
169 }
170
171 char * strstrs(s1,s2)
172 /*+++++++++++++++++++++++++++++ strstrs +++++++++++++++++++++++++++++++++++
173 .PURPOSE Pattern matching
174 .RETURNS returns a pointer to the first occurrence of the pattern string s2
175 in s1. Otherwise returns NULL
176 -------------------------------------------------------------------------*/
177 char *s1 /* IN : string to search */;
178 char *s2 /* IN : pattern to find */;
179
180 {
181 register char *t1,*t2;
182 char *ptr;
183
184 ptr = (char *)0;
185 t2 = s2;
186 t1 = s1;
187 for (;*t1 != '\0' && *t2 != '\0' ;t1++) {
188 if (*t1 == *t2) t2++;
189 else {
190 if (*t2 != *s2) {
191 t1 -= t2 - s2;
192 t2 = s2;
193 }
194 }
195 }
196 if (*t2 == '\0') ptr = t1 - strlen(s2);
197 return(ptr);
198 }