5 int pos(char *haystack, char *needle)
7 if (strstr(haystack, needle)) {
8 return (int) strstr(haystack, needle) - (int) haystack;
14 void cutto(char *str, int len)
16 memmove(str, str + len, strlen(str) - len + 1);
19 void mystrncpy(char *dest, char *src, int len)
21 strncpy(dest, src, len);
25 int replace(char *str, char *what, char *by)
27 char *foo, *bar = str;
29 while ((foo = strstr(bar, what))) {
30 bar = foo + strlen(by);
32 foo + strlen(what), strlen(foo + strlen(what)) + 1);
33 memcpy(foo, by, strlen(by));
40 /* int_from_list(char *list, int n)
41 * returns the n'th integer element from a string like '2,5,12-15,20-23'
42 * if n is out of range or *list is out of range, -1 is returned.
45 int int_from_list(char *list, int n)
48 int count = -1, firstrun = 1;
50 str = (char *) malloc(sizeof(char) * (strlen(list) + 2));
54 memset(str, 0, strlen(list) + 2);
55 strncpy(str, list, strlen(list));
57 /* apppend ',' to the string so we can always use strtok() */
58 str[strlen(list)] = ',';
62 tok = strtok(str, ",");
64 tok = strtok(NULL, ",");
66 if (!tok || *tok == '\0') {
71 if (strchr(tok, '-')) {
75 end = strchr(tok, '-');
78 if (!*start || !*end) {
84 if (s < 1 || e < 1 || e < s) {
91 return (e - (count - n));