-
Notifications
You must be signed in to change notification settings - Fork 2
/
strparse.c
96 lines (60 loc) · 1.44 KB
/
strparse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<strparse.h>
/*Strip comments from string*/
char strip_comments( char *l, char c ){
while( *l != '\0' ){
if( *l == c ){
*l = '\0' ;
return 0 ;
}
l++ ;
}
return 1 ;
}
/*Find if string is empty*/
/*Read K&R section 5.5*/
char is_string_blank( char *s )
{
while( *s != '\0' )
if( ! isspace( *s++ ) )
return 0 ;
return 1 ;
}
/*
** ------------------------
** get_first_string_element
** ------------------------
*//*
Gets the first group of non whitespace characters,
puts them into element and removes them from the
original string.
version 1.1 bug fixed by adding null termination
see (*) below.
*/
char get_first_string_element( line, element )
char *line;
char *element;
{
int i=0, j=0;
/* Check that we are not already */
/* at the end of the line */
if( *line == '\0' ) return( 0 );
/* Skip leading white space and */
/* return zero if end of string */
/* is encountered */
while( isspace( *(line+i) ) )
if( *(line+( ++i )) == '\0' ) return( 0 );
/* Put the first block of non white
space characters into element */
while( ! isspace( *(line+i) ) ){
if( ( element[j++] = *(line+(i++) ) ) == '\0' ){
*line = '\0';
return( 1 );
}
}
/*put a NULL terminator in at j - (*) */
element[ j ] = '\0' ;
/* Copy remainder of line into the beggining */
/* of itself */
for( j=0; ( *(line+j)=*(line+i) ) != '\0' ; ++j, ++i );
return( 1 );
}