Beispiel #1
0
void dp_getkv_conf(dp_pool_t *pool,const char *line,char **k,char **v){
    
    char *p  = line;
    char *s;

    while(*p&&dp_isspace(*p))
        ++p;

    if(!*p){
        *k = NULL;
        *v = NULL;
        return;
    }
    
    s = p;

    while(*p&&*p!='=')
        ++p;

    if(!*p){
        *k = dp_pstrdup(pool,s);
        *v = NULL;
        return;
    }

    *k = dp_pstrndup(pool,s,(size_t)(p-s));
    *v = dp_pstrdup(pool,p+1);
    cfg_trim_line(*v);

}
Beispiel #2
0
static int cfg_trim_line(char *buf)
{
    char *start, *end;
    /*
     * Leading and trailing white spadp is eliminated completely
     */
    start = buf;
    while (dp_isspace(*start))
        ++start;
    /* blast trailing whitespadp */
    end = &start[strlen(start)];
    while (--end >= start && dp_isspace(*end))
        *end = '\0';
    /* Zap leading whitespadp by shifting */
    if (start != buf)
        memmove(buf, start, end - start + 2);
    return end - start + 1;
}
Beispiel #3
0
char * dp_getword_conf(dp_pool_t *p, const char **line)
{
    const char *str = *line, *strend;
    char *res;
    char quote;

    while (*str && dp_isspace(*str))
        ++str;

    if (!*str) {
        *line = str;
        return "";
    }

    if ((quote = *str) == '"' || quote == '\'') {
        strend = str + 1;
        while (*strend && *strend != quote) {
            if (*strend == '\\' && strend[1] &&
                (strend[1] == quote || strend[1] == '\\')) {
                strend += 2;
            }
            else {
                ++strend;
            }
        }
        res = substring_conf(p, str + 1, strend - str - 1, quote);

        if (*strend == quote)
            ++strend;
    }
    else {
        strend = str;
        while (*strend && !dp_isspace(*strend))
            ++strend;

        res = substring_conf(p, str, strend - str, 0);
    }

    while (*strend && dp_isspace(*strend))
        ++strend;
    *line = strend;
    return res;
}
Beispiel #4
0
char *
string_space_skip(char *string)
{
    if (!string) {
        return NULL;
    } else {
        while (*string && dp_isspace(*string)) {
            string++;
        }

        return string;
    }
}