Got it to build.

This commit is contained in:
Scott Anderson 2017-05-13 00:22:49 +12:00
parent 46a53704ad
commit a2896f33a4
55 changed files with 822 additions and 797 deletions

View file

@ -69,14 +69,14 @@ int lenient_strcmp(char *a, char *b) {
}
list_t *split_string(const char *str, const char *delims) {
list_t *res = create_list();
list_t *res = list_new(sizeof(char *), 0);
char *copy = strdup(str);
char *token;
token = strtok(copy, delims);
while(token) {
token = strdup(token);
list_add(res, token);
list_add(res, &token);
token = strtok(NULL, delims);
}
free(copy);
@ -84,11 +84,7 @@ list_t *split_string(const char *str, const char *delims) {
}
void free_flat_list(list_t *list) {
int i;
for (i = 0; i < list->length; ++i) {
free(list->items[i]);
}
list_free(list);
list_free_with(list, list_elem_free);
}
char **split_args(const char *start, int *argc) {
@ -315,22 +311,25 @@ char *join_list(list_t *list, char *separator) {
len += (list->length - 1) * sep_len;
}
for (int i = 0; i < list->length; i++) {
len += strlen(list->items[i]);
for (size_t i = 0; i < list->length; i++) {
char *item = *(char **)list_get(list, i);
len += strlen(item);
}
char *res = malloc(len);
char *p = res + strlen(list->items[0]);
strcpy(res, list->items[0]);
char *item = *(char **)list_get(list, 0);
char *p = res + strlen(item);
strcpy(res, item);
for (int i = 1; i < list->length; i++) {
for (size_t i = 1; i < list->length; i++) {
item = *(char **)list_get(list, i);
if (sep_len) {
memcpy(p, separator, sep_len);
p += sep_len;
}
strcpy(p, list->items[i]);
p += strlen(list->items[i]);
strcpy(p, item);
p += strlen(item);
}
*p = '\0';