text
stringlengths
0
357
const char* p1 = str;
while (1) {
const char* p2 = strstr(p1, delimiter);
if (p2==NULL) {
clist_append(list, (void*)strdup(p1));
break;
}
else {
clist_append(list, (void*)strndup(p1, p2-p1));
p1 = p2+strlen(delimiter);
}
}
}
return list;
}
int dc_str_to_color(const char* str)
{
char* str_lower = dc_strlower(str);
/* the colors must fulfill some criterions as:
- contrast to black and to white
- work as a text-color
- being noticable on a typical map
- harmonize together while being different enough
(therefore, we cannot just use random rgb colors :) */
static uint32_t colors[] = {
0xe56555, 0xf28c48, 0x8e85ee, 0x76c84d,
0x5bb6cc, 0x549cdd, 0xd25c99, 0xb37800,
0xf23030, 0x39B249, 0xBB243B, 0x964078,
0x66874F, 0x308AB9, 0x127ed0, 0xBE450C
};
int checksum = 0;
int str_len = strlen(str_lower);
for (int i = 0; i < str_len; i++) {
checksum += (i+1)*str_lower[i];
checksum %= 0x00FFFFFF;
}
int color_index = checksum % (sizeof(colors)/sizeof(uint32_t));
free(str_lower);
return colors[color_index];
}
/*******************************************************************************
* clist tools
******************************************************************************/
void clist_free_content(const clist* haystack)
{
for (clistiter* iter=clist_begin(haystack); iter!=NULL; iter=clist_next(iter)) {
free(iter->data);
iter->data = NULL;
}
}
int clist_search_string_nocase(const clist* haystack, const char* needle)
{
for (clistiter* iter=clist_begin(haystack); iter!=NULL; iter=clist_next(iter)) {
if (strcasecmp((const char*)iter->data, needle)==0) {
return 1;
}
}
return 0;
}
/*******************************************************************************
* date/time tools
******************************************************************************/
static int tmcomp(struct tm * atmp, struct tm * btmp) /* from mailcore2 */
{
int result = 0;
if ((result = (atmp->tm_year - btmp->tm_year))==0 &&
(result = (atmp->tm_mon - btmp->tm_mon))==0 &&
(result = (atmp->tm_mday - btmp->tm_mday))==0 &&
(result = (atmp->tm_hour - btmp->tm_hour))==0 &&
(result = (atmp->tm_min - btmp->tm_min))==0)
result = atmp->tm_sec - btmp->tm_sec;
return result;
}
time_t mkgmtime(struct tm * tmp) /* from mailcore2 */
{
int dir = 0;
int bits = 0;
int saved_seconds = 0;
time_t t = 0;
struct tm yourtm;