#include #include #include #include "diawxgtk.h" /* Copy one word from a string. A word is a sequence of non white space. Return a pointer on the first blank character after the word. If there were no word, dest[0] == '\0' */ char *str_copyword(char *dest, const char *str) { if (str != NULL){ str = str_skip(str); while (*str > ' ') *dest++ = *str++; } *dest = '\0'; return (char*) str; } char *str_copyword(char *dest, const char *str, int size) { if (str != NULL){ str = str_skip(str); size--; while (*str > ' ' && size > 0){ *dest++ = *str++; } } *dest = '\0'; return (char*) str; } char *str_copywordq(char *dest, const char *str) { str = str_skip(str); if (str[0] == '"'){ str++; while (*str != '\0' && *str != '"') *dest++ = *str++; *dest = '\0'; if (*str == '"') str++; }else{ str = str_copyword (dest,str); } return (char*)str; } /* Check if a string start with a given word followed by a space or '\0'; Return != 0 if this is true. */ int str_isword (const char *str, const char *word) { int len = strlen (word); int ret = strncmp(str,word,len)==0; if (ret){ char car = str[len]; ret = (isspace(car) || car == '\0'); } return ret; } /* Like strncpy but make sure the '\0' is there size if the sizeof() of the destination. One byte is kept to put the '\0'; */ void strcpy_cut (char *dst, const char *src, int size) { size--; strncpy (dst,src,size); dst[size] = '\0'; } /* Move over one word */ char *str_skipword(const char *str) { str = str_skip(str); while (*str > ' ') str++; str = str_skip(str); return (char*) str; } /* Free all entry of the string table. */ void tbstr_free (char *tb[], int nb) { for (int i=0; i