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 count
= fread(line
, 1, len
, fd
);
41 while(isspace(line
[len
]) && len
>= 0)
50 char *keyword(char *line
)
58 while(line
[len
] && !isspace(line
[len
]))
61 key
= malloc(len
* sizeof(char));
62 strncpy(key
, &line
[1], len
- 1);
68 int get_words(char *line
, char ***outarray
)
74 /* Make sure that we have valid input */
75 if(!outarray
|| !line
)
77 fprintf(stderr
, "Passed NULL pointer to get_words()!\n");
81 /* Free the old array */
94 /* Now scan the list of words */
99 /* Find the start of this word */
100 while(*word
&& isspace(*word
) )
103 /* Find the end of this word */
105 while( word
[len
] && !isspace(word
[len
]) )
109 Copy this word into the array, making the array larger
110 in order to fit the pointer to the string.
115 array
= realloc(array
, num
* sizeof(char *));
116 array
[num
-1] = malloc((len
+1) * sizeof(char));
117 strncpy( array
[num
-1], word
, len
);
118 array
[num
-1][len
] = 0;
123 array
= realloc(array
, (num
+1) * sizeof(char *) );