5 ** Login <pierric@seignobosc.com>
7 ** Started on Thu Jan 24 18:36:47 2002 Pierric
8 ** Last update Mon Sep 23 18:02:02 2002 Pierric
13 #include "my_malloc.h"
15 static int count_words(char *str
, char delim
)
25 if (!strchr(str
+ 1, delim
))
27 str
= strchr(str
+ 1, delim
);
35 static char *get_word(char **str
, char delim
)
40 while (**str
== delim
)
44 tmp
= strchr(*str
, delim
);
52 my_malloc(new, tmp
- *str
+ 1);
53 new[tmp
- *str
] = '\0';
54 strncpy(new, *str
, tmp
- *str
);
59 void tab_free(char **tab
)
65 for (index
= 0; tab
[index
]; index
++)
70 char **tab_fill(char *str
, char delim
)
78 count
= count_words(str
, delim
);
81 my_malloc(tab
, (count
+ 1) * sizeof(char *));
82 for (index
= 0; (tab
[index
] = get_word(&str
, delim
)); index
++)
88 ** Deletes the first element of a wordtab, shifting the other
89 ** elements. The size of the malloced area stays the same, though
91 int tab_delete_first(char **tab
)
98 for (i
= 0; tab
[i
]; i
++)
103 int tab_count_words(char **tab
)
109 for (count
= 0; tab
[count
]; count
++)