1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
.AUTHOR IPG-ESO Garching
33
.CATEGORY Independant string handling interfaces.
35
Handling of character strings. These routines normally return
36
a non-negative integer number on successful return.
37
Otherwise, a value of -1 is set to indicate an error
38
condition and the variable ``oserror'' contains the
41
.HISTORY [0.0] 25-Aug-1986 Definition J. D. Ponz
42
[1.0] 10-Apr-1987 Programmation B. Pirenne
43
[1.1] 04-Aug-1987 VMS Includes
44
[1.2] 910911 bzero removed CG.(memset can be used instead)
48
------------------------------------------------------------*/
53
#include <proto_os.h> /* ANSI-C prototyping */
58
int strsglen(char * str , char cha)
61
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
62
.PURPOSE Compute the length of the string up to '\0' or the character "cha"
64
.RETURNS Upon successful completion a positive or zero integer number is
66
.REMARKS System dependencies:
68
------------------------------------------------------------*/
69
char *str; /* IN : string to check */
70
char cha; /* IN : open mode */
76
for (i=0;*(str+i) != '\0' && *(str+i) != cha;i++);
83
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
85
translate the s2 character string to lower case and store the
87
.RETURNS The number of characters actually translated.
89
---------------------------------------------------------------*/
91
char *s1; /* OUT: ouptput string */
92
char *s2; /* IN : input string */
98
for (i=0;*(s2+i) != '\0';i++) {
99
if (*(s2+i) >= 'A' && *(s2+i) <= 'Z')
101
*(s1+i) = *(s2+i) + 32;
112
/*+++++++++++++++++++++++++++++ getline +++++++++++++++++++++++++
113
.PURPOSE get one record from standard input.
114
.RETURNS number of characters fetched.
115
-----------------------------------------------------------------*/
116
char *buf; /* buffer to contain the string read */
121
for(i=0;(c=getchar()) != '\n';i++) *(buf+i) = c;
128
/*++++++++++++++++++++++ truelen ++++++++++++++++++++++++++++++++
129
.PURPOSE Compute the 'true length' of a string of character by checking for
130
all valid characters. Valid characters taken into account are :
131
a..z, A..Z, ., *, -, _, 0..9.
132
.RETURNS The number of contiguous characters in the string satisfying the
134
------------------------------------------------------------------*/
135
char *string; /* The character string to check */
139
for (i = 0; (c = *(string + i)) == '.' || c == '-' || c == '_' ||
140
(c >= 'a' && c <= 'z') ||
141
(c >= 'A' && c <= 'Z') ||
142
(c >= '0' && c <= '9') ;
150
/*+++++++++++++++++++++++++++++ strin ++++++++++++++++++++++++++++++++++++++
151
.PURPOSE Pattern matching
152
.RETURNS 0 if pattern is not in string, 1 if found.
153
-------------------------------------------------------------------------*/
155
char *s1 /* IN : string to search */;
156
char *s2 /* IN : pattern to find */;
159
register char *t1,*t2;
165
for (;*t1 != '\0' && *t2 != '\0' && !found;t1++) {
176
if (*t2 == '\0') found = 1;
180
char * strstrs(s1,s2)
181
/*+++++++++++++++++++++++++++++ strstrs +++++++++++++++++++++++++++++++++++
182
.PURPOSE Pattern matching
183
.RETURNS returns a pointer to the first occurrence of the pattern string s2
184
in s1. Otherwise returns NULL
185
-------------------------------------------------------------------------*/
186
char *s1 /* IN : string to search */;
187
char *s2 /* IN : pattern to find */;
190
register char *t1,*t2;
196
for (;*t1 != '\0' && *t2 != '\0' ;t1++) {
197
if (*t1 == *t2) t2++;
205
if (*t2 == '\0') ptr = t1 - strlen(s2);