2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: A very simple line parser. Basically from archtool.c
13 #include <toollib/lineparser.h>
15 char *get_line(FILE *fd
)
24 count
= fread(&buffer
, 1, 1, fd
);
26 } while(count
!= 0 && buffer
!= '\n');
28 if(len
== 0 && count
== 0)
31 fseek(fd
, -len
, SEEK_CUR
);
32 line
= malloc( (len
+1) * sizeof(char) );
33 fread(line
, 1, len
, fd
);
37 while(isspace(line
[len
]) && len
>= 0)
46 char *keyword(char *line
)
54 while(line
[len
] && !isspace(line
[len
]))
57 key
= malloc(len
* sizeof(char));
58 strncpy(key
, &line
[1], len
- 1);
64 int get_words(char *line
, char ***outarray
)
70 /* Make sure that we have valid input */
71 if(!outarray
|| !line
)
73 fprintf(stderr
, "Passed NULL pointer to get_words()!\n");
77 /* Free the old array */
90 /* Now scan the list of words */
95 /* Find the start of this word */
96 while(*word
&& isspace(*word
) )
99 /* Find the end of this word */
101 while( word
[len
] && !isspace(word
[len
]) )
105 Copy this word into the array, making the array larger
106 in order to fit the pointer to the string.
111 array
= realloc(array
, num
* sizeof(char *));
112 array
[num
-1] = malloc((len
+1) * sizeof(char));
113 strncpy( array
[num
-1], word
, len
);
114 array
[num
-1][len
] = 0;
119 array
= realloc(array
, (num
+1) * sizeof(char *) );