Exemple #1
0
/*--------------------------------------------------------------------------*/
static line_status iniparser_line(
    char * input_line,
    char * section,
    char * key,
    char * value)
{   
    line_status sta ;
    char        line[ASCIILINESZ+1];
	char        l[ASCIILINESZ+1];
    int         len ;

    strcpy(line, strstrip(l, input_line));
    len = (int)strlen(line);

    sta = LINE_UNPROCESSED ;
    if (len<1) {
        /* Empty line */
        sta = LINE_EMPTY ;
    } else if (line[0]=='#') {
        /* Comment line */
        sta = LINE_COMMENT ; 
    } else if (line[0]=='[' && line[len-1]==']') {
        /* Section name */
        sscanf(line, "[%[^]]", section);
        strcpy(section, strstrip(l, section));
        strcpy(section, strlwc(l, section));
        sta = LINE_SECTION ;
    } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2
           ||  sscanf (line, "%[^=] = '%[^\']'",   key, value) == 2
           ||  sscanf (line, "%[^=] = %[^;#]",     key, value) == 2) {
        /* Usual key=value, with or without comments */
        strcpy(key, strstrip(l, key));
        strcpy(key, strlwc(l, key));
        strcpy(value, strstrip(l, value));
        /*
         * sscanf cannot handle '' or "" as empty values
         * this is done here
         */
        if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) {
            value[0]=0 ;
        }
        sta = LINE_VALUE ;
    } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2
           ||  sscanf(line, "%[^=] %[=]", key, value) == 2) {
        /*
         * Special cases:
         * key=
         * key=;
         * key=#
         */
        strcpy(key, strstrip(l, key));
        strcpy(key, strlwc(l, key));
        value[0]=0 ;
        sta = LINE_VALUE ;
    } else {
        /* Generate syntax error */
        sta = LINE_ERROR ;
    }
    return sta ;
}
Exemple #2
0
dictionary * iniparser_load(const char * ininame)
{
    dictionary  *   d ;
    char        lin[ASCIILINESZ+1];
    char        sec[ASCIILINESZ+1];
    char        key[ASCIILINESZ+1];
    char        val[ASCIILINESZ+1];
    char    *   where ;
    FILE    *   ini ;
    int         lineno ;

    if ((ini=fopen(ininame, "r"))==NULL) {
        return NULL ;
    }

    sec[0]=0;

    /*
     * Initialize a new dictionary entry
     */
    if (!(d = dictionary_new(0))) {
	    fclose(ini);
	    return NULL;
    }
    lineno = 0 ;
    while (fgets(lin, ASCIILINESZ, ini)!=NULL) {
        lineno++ ;
        where = strskp(lin); /* Skip leading spaces */
        if (*where==';' || *where=='#' || *where==0)
            continue ; /* Comment lines */
        else {
            if (sscanf(where, "[%[^]]", sec)==1) {
                /* Valid section name */
                strcpy(sec, strlwc(sec));
                iniparser_add_entry(d, sec, NULL, NULL);
            } else if (sscanf (where, "%[^=] = \"%[^\"]\"", key, val) == 2
                   ||  sscanf (where, "%[^=] = '%[^\']'",   key, val) == 2
                   ||  sscanf (where, "%[^=] = %[^;#]",     key, val) == 2) {
                strcpy(key, strlwc(strcrop(key)));
                /*
                 * sscanf cannot handle "" or '' as empty value,
                 * this is done here
                 */
                if (!strcmp(val, "\"\"") || !strcmp(val, "''")) {
                    val[0] = (char)0;
                } else {
                    strcpy(val, strcrop(val));
                }
                iniparser_add_entry(d, sec, key, val);
            }
        }
    }
    fclose(ini);
    return d ;
}
Exemple #3
0
/*--------------------------------------------------------------------------*/
int iniparser_getsecnkeys(const dictionary * d, const char * s)
{
    int     seclen, nkeys ;
    char    keym[ASCIILINESZ+1];
    int j ;

    nkeys = 0;

    if (d==NULL) return nkeys;
    if (! iniparser_find_entry(d, s)) return nkeys;

    seclen  = (int)strlen(s);
    strlwc(s, keym, sizeof(keym));
    keym[seclen] = ':';

    for (j=0 ; j<d->size ; j++) {
        if (d->key[j]==NULL)
            continue ;
        if (!strncmp(d->key[j], keym, seclen+1))
            nkeys++;
    }

    return nkeys;

}
Exemple #4
0
MODULE get_command (THREAD *thread)
{
    char
    *value;
    tcb = thread-> tcb;                 /*  Point to thread's context        */
    strcrop (buffer);
    strlwc  (buffer);
    value = strskp (buffer);
    if (value != buffer)
        strcpy (buffer, value);

    if (strnull (buffer))
        the_next_event = none_event;
    else if (streq (buffer, "help"))
        the_next_event = help_event;
    else if (strchr (buffer, '?'))
        the_next_event = help_event;
    else if (strncmp (buffer, "set server", 10) == 0)
        the_next_event = server_ip_event;
    else if (streq (buffer, "set debug"))
        the_next_event = debug_event;
    else if (streq (buffer, "set recursive"))
        the_next_event = recursive_event;
    else if (streq (buffer, "exit"))
        the_next_event = exit_event;
    else if (streq (buffer, "quit"))
        the_next_event = exit_event;
    else
    {
        if (strchr (buffer, ' ') != NULL)
            the_next_event = invalid_event;
        else
            the_next_event = request_event;
    }
}
Exemple #5
0
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, const char * entry)
{
    char* lc_entry = xstrdup(entry);
    strlwc(lc_entry);
    dictionary_unset(ini, lc_entry);
    free(lc_entry);
}
Exemple #6
0
/*--------------------------------------------------------------------------*/
char * iniparser_getstring(dictionary * d, char * key, char * def)
{
    char lc_key[ASCIILINESZ+1];

    if (d==NULL || key==NULL)
        return def ;
    return dictionary_get(d, strlwc(key, lc_key), def);
}
Exemple #7
0
/*--------------------------------------------------------------------------*/
int iniparser_set(dictionary * ini, const char * entry, const char * val)
{
    int result = 0;
    char *lc_entry = xstrdup(entry);
    strlwc(lc_entry);
    result = dictionary_set(ini, lc_entry, val) ;
    free(lc_entry);
    return result;
}
Exemple #8
0
/*--------------------------------------------------------------------------*/
char * iniparser_getstring(dictionary * d, const char * key, char * def) {
	char * lc_key;
	char * sval;

	if (d == NULL || key == NULL)
		return def;

	lc_key = strlwc(key);
	sval = dictionary_get(d, lc_key, def);
	return sval;
}
Exemple #9
0
int main(int argc, char * argv[])
{
    char * str ;

    str = "\t\tI'm a lumberkack and I'm OK      " ;
    printf("lowercase: [%s]\n", strlwc(str));
    printf("uppercase: [%s]\n", strupc(str));
    printf("skipped  : [%s]\n", strskp(str));
    printf("cropped  : [%s]\n", strcrop(str));
    printf("stripped : [%s]\n", strstrip(str));

    return 0 ;
}
Exemple #10
0
/*--------------------------------------------------------------------------*/
const char * iniparser_getstring(const dictionary * d, const char * key, const char * def)
{
    const char * lc_key ;
    const char * sval ;
    char tmp_str[ASCIILINESZ+1];

    if (d==NULL || key==NULL)
        return def ;

    lc_key = strlwc(key, tmp_str, sizeof(tmp_str));
    sval = dictionary_get(d, lc_key, def);
    return sval ;
}
Exemple #11
0
const char *rtl_ini_get_string(const rtl_dict_t *d, const char *key,
							   const char *def)
{
	const char *lc_key;
	const char *sval;
	char tmp_str[ASCIILINESZ + 1];

	if (d == NULL || key == NULL)
		return def;

	lc_key = strlwc(key, tmp_str, sizeof(tmp_str));
	sval = rtl_dict_get(d, lc_key, def);
	return sval;
}
/*--------------------------------------------------------------------------*/
char*
iniparser_getstring (dictionary * d, char * key, char * def)
{
    char * lc_key;
    char * sval;

    if (!d || !key)
	return def;

    lc_key = strdup (strlwc (key));
    sval = dictionary_get (d, lc_key, def);
    free (lc_key);

    return sval;
}
Exemple #13
0
/*--------------------------------------------------------------------------*/
char * iniparser_getstring(dictionary * d, const char * key, char * def)
{
    char * lc_key ;
    char * sval ;

    if (d==NULL || key==NULL)
        return def ;

    if (!(lc_key = strdup(strlwc(key)))) {
	    return NULL;
    }
    sval = dictionary_get(d, lc_key, def);
    free(lc_key);
    return sval ;
}
Exemple #14
0
char *
ini_dyn_value (
    SYMTAB *symtab,
    const char *section,
    const char *keyword,
    const char *default_value)
{
    ASSERT (section);
    if (keyword && *keyword)
        snprintf (ini_keyword, sizeof (ini_keyword), "%s:%s", section, keyword);
    else
        strncpy  (ini_keyword, section, sizeof (ini_keyword));

    strlwc (ini_keyword);
    return (sym_get_value (symtab, ini_keyword, default_value));
}
Exemple #15
0
MODULE get_confirmation_for_stop (THREAD *thread)
{
    printf ("Do you really want to stop all tasks (n)? ");
    fflush (stdout);
    if (fgets (input_line, LINE_MAX, stdin) == NULL)
        strclr (input_line);            /*  Treat EOF as empty               */
    strlwc (input_line);

    if (input_line [0] == 'y')
        the_next_event = ok_event;
    else
      {
        the_next_event = cancel_event;
        printf ("syscli> 211 - cancelled\n");
     }
}
Exemple #16
0
MODULE invoke_active_program (void)
{
    int
        prognbr,                        /*  Index into program list          */
        rc;

    strlwc (session.program_name);      /*  Compare lwc with lwc             */

    rc = FEEDBACK_UNKNOWN;              /*  Assume not found                 */
    for (prognbr = 0; wtp_broker_map [prognbr].name; prognbr++)
      {
        if (streq (session.program_name, wtp_broker_map [prognbr].name))
          {
            rc = ((ATP_FCT) wtp_broker_map [prognbr].function) (&session);
            break;
          }
      }
    switch (rc)
      {
        case FEEDBACK_SHOW:
            the_next_event = show_event;
            break;
        case FEEDBACK_CALL:
            the_next_event = call_event;
            break;
        case FEEDBACK_RETURN:
            the_next_event = return_event;
            break;
        case FEEDBACK_UNKNOWN:
            the_next_event = not_found_event;
            break;
        case FEEDBACK_ERROR:
            the_next_event = error_event;
            break;
        default:
            the_next_event = exit_event;
            break;
      }
     if (dbio_commit () != TRUE)
       {
         fprintf (stderr, "Error on commit: %d: %s",
                           dbio_error_code    (),
                           dbio_error_message ());
       }
}
Exemple #17
0
MODULE store_time_slot_specification (THREAD *thread)
{
    struct_smtslot_specification
        *message;
    SPEC
        *spec;                          /*  Spec we create                   */

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    /*  Get fields from event body; just copy, don't parse them yet          */
    get_smtslot_specification (thread-> event-> body, &message);

    tcb-> reply_to = thread-> event-> sender;

    if ((spec = node_create (tcb-> specs.prev, sizeof (SPEC))) == NULL)
        send_smtslot_error (&tcb-> reply_to, "Out of memory");
    else
        /*  Store day and times for slot     */
        spec-> times = strlwc (mem_strdup (message-> times));

    free_smtslot_specification (&message);
}
Exemple #18
0
MODULE get_next_argument (THREAD *thread)
{
    char
        *value;

    tcb = thread-> tcb;                 /*  Point to thread's context        */
    if (++tcb-> arg_index <= tcb-> argc)
      {
        value = tcb-> argv [tcb-> arg_index - 1];
        if (*value == '-')
          {
            value++;
            strcrop (value);
            strlwc  (value);
            value = strskp (value);
            if (streq (value, "debug"))
                strcpy (buffer, "set debug");
            else
            if (streq (value, "rec"))
                strcpy (buffer, "set recursive");
            else
            if (streq (value, "server"))
              {
                if (++tcb-> arg_index <= tcb-> argc)
                    xstrcpy (buffer, "set server ",
                             tcb-> argv [tcb-> arg_index - 1], NULL);
                else
                    strcpy  (buffer, "set server");
              }
            else
                strcpy (buffer, value);
          }
        else
            strcpy (buffer, value);
      }
    else
        buffer [0] = '\0';
}
Exemple #19
0
int
conv_str_day (
    const char *string)
{
    static
        char *day_name [] =
          { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
    int
        day;
    char
        day_comp [4];

    /*  Get up to three letters of day name and convert to lower case        */
    strncpy (day_comp, string, 3);
    day_comp [3] = '\0';
    strlwc (day_comp);

    /*  I don't like magic constants, but "7" is pretty safe for now         */
    for (day = 0; day < 7; day++)
        if (streq (day_name [day], day_comp))
            break;

    return (day >= 7? -1: day);
}
Exemple #20
0
/*--------------------------------------------------------------------------*/
int iniparser_set(dictionary * ini, char * entry, char * val)
{
    return dictionary_set(ini, strlwc(entry), val) ;
}
Exemple #21
0
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, char * entry)
{
    dictionary_unset(ini, strlwc(entry));
}
Exemple #22
0
/*--------------------------------------------------------------------------*/
static line_status iniparser_line(
    const char * input_line,
    char * section,
    char * key,
    char * value)
{
    line_status sta ;
    char * line = NULL;
    size_t      len ;

    line = xstrdup(input_line);
    len = strstrip(line);

    sta = LINE_UNPROCESSED ;
    if (len<1) {
        /* Empty line */
        sta = LINE_EMPTY ;
    } else if (line[0]=='#' || line[0]==';') {
        /* Comment line */
        sta = LINE_COMMENT ;
    } else if (line[0]=='[' && line[len-1]==']') {
        /* Section name */
        sscanf(line, "[%[^]]", section);
        strstrip(section);
        strlwc(section, section, len);
        sta = LINE_SECTION ;
    } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2
           ||  sscanf (line, "%[^=] = '%[^\']'",   key, value) == 2) {
        /* Usual key=value with quotes, with or without comments */
        strstrip(key);
        strlwc(key, key, len);
        /* Don't strip spaces from values surrounded with quotes */
        sta = LINE_VALUE ;
    } else if (sscanf (line, "%[^=] = %[^;#]", key, value) == 2) {
        /* Usual key=value without quotes, with or without comments */
        strstrip(key);
        strlwc(key, key, len);
        strstrip(value);
        /*
         * sscanf cannot handle '' or "" as empty values
         * this is done here
         */
        if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) {
            value[0]=0 ;
        }
        sta = LINE_VALUE ;
    } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2
           ||  sscanf(line, "%[^=] %[=]", key, value) == 2) {
        /*
         * Special cases:
         * key=
         * key=;
         * key=#
         */
        strstrip(key);
        strlwc(key, key, len);
        value[0]=0 ;
        sta = LINE_VALUE ;
    } else {
        /* Generate syntax error */
        sta = LINE_ERROR ;
    }

    free(line);
    return sta ;
}
Exemple #23
0
void Test_iniparser_strlwc(CuTest *tc)
{
    char out_buffer[128];

    /* NULL ptr as input */
    CuAssertPtrEquals(tc, NULL, strlwc(NULL, NULL, 0));
    CuAssertPtrEquals(tc, NULL, strlwc(NULL, out_buffer, sizeof (out_buffer)));
    CuAssertPtrEquals(tc, NULL, strlwc("", NULL, sizeof (out_buffer)));
    CuAssertPtrEquals(tc, NULL, strlwc("", out_buffer, 0));
    CuAssertPtrEquals(tc, NULL, strlwc(NULL, NULL, 0));

    /* empty string */
    CuAssertStrEquals(tc, "", strlwc("", out_buffer, sizeof (out_buffer)));

    CuAssertStrEquals(tc, "  ", strlwc("  ", out_buffer, sizeof (out_buffer)));
    CuAssertStrEquals(tc, "test", strlwc("test", out_buffer, sizeof (out_buffer)));
    CuAssertStrEquals(tc, "test", strlwc("TEST", out_buffer, sizeof (out_buffer)));
    CuAssertStrEquals(tc, "test", strlwc("TeSt", out_buffer, sizeof (out_buffer)));
    CuAssertStrEquals(tc, "test test",
                      strlwc("TEST TEST", out_buffer, sizeof (out_buffer)));
    CuAssertStrEquals(tc, "very long string !!!!!!!",
                      strlwc("very long string !!!!!!!", out_buffer, sizeof (out_buffer)));
    CuAssertStrEquals(tc, "cutted string", strlwc("cutted string<---here", out_buffer, 14));

    /* test using same buffer as input and output */
    strcpy(out_buffer, "OVERWRITE ME !");
    CuAssertPtrNotNull(tc, strlwc(out_buffer, out_buffer, sizeof(out_buffer)));
    CuAssertStrEquals(tc, "overwrite me !", out_buffer);
}
Exemple #24
0
/*--------------------------------------------------------------------------*/
int iniparser_set(dictionary * ini, const char * entry, const char * val)
{
    char tmp_str[ASCIILINESZ+1];
    return dictionary_set(ini, strlwc(entry, tmp_str, sizeof(tmp_str)), val) ;
}
Exemple #25
0
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, const char * entry)
{
    char tmp_str[ASCIILINESZ+1];
    dictionary_unset(ini, strlwc(entry, tmp_str, sizeof(tmp_str)));
}
Exemple #26
0
/*--------------------------------------------------------------------------*/
int iniparser_set(dictionary * ini, char * entry, char * val)
{
	char l[ASCIILINESZ+1];
    return dictionary_set(ini, strlwc(l, entry), val) ;
}
Exemple #27
0
/*--------------------------------------------------------------------------*/
void iniparser_unset(dictionary * ini, char * entry)
{
	char l[ASCIILINESZ+1];
    dictionary_unset(ini, strlwc(l, entry));
}
Exemple #28
0
int ciniparser_set(dictionary *d, char *entry, char *val)
{
	return dictionary_set(d, strlwc(entry), val);
}
Exemple #29
0
/*--------------------------------------------------------------------------*/
static line_status iniparser_line(
    int line_size,
    const char * input_line,
    char ** section_out,
    char ** key_out,
    char ** value_out)
{
    line_status sta ;
    int len = line_size-1;
    char * line = malloc(line_size);
    char * key = NULL;
    char * value = NULL;
    char * equals = NULL;

    if (!line) {
        fprintf(stderr, "iniparser: memory alloc error\n");
        return LINE_ERROR;
    }

    *line = 0;


    strcpy(line, input_line);
    strstrip(line);
    len = (int)strlen(line);

    /* only allocate necessary space for key & val */
    equals = strchr(line, '=');
    if (equals) {
        value = malloc((len + line) - equals + 1);
        key = malloc(equals - line + 1);
       *value = 0;
    } else {
        key = malloc(line_size + 1);
    }

    if (!key || (equals && !value)) {
        fprintf(stderr, "iniparser: memory alloc error\n");
        sta = LINE_ERROR;
        goto out;
    }

    *key = 0;

    sta = LINE_UNPROCESSED ;
    if (len<1) {
        /* Empty line */
        sta = LINE_EMPTY ;
    } else if (line[0]=='#' || line[0]==';') {
        /* Comment line */
        sta = LINE_COMMENT ;
    } else if (line[0]=='[' && line[len-1]==']') {
        /* Section name */
        sscanf(line, "[%[^]]", key);
        strstrip(key);
        strlwc(key);
        sta = LINE_SECTION ;
        *section_out=key;
        /* don't free key's memory */
        key = NULL;
    } else if (equals && (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2
           ||  sscanf (line, "%[^=] = '%[^\']'",   key, value) == 2
           ||  sscanf (line, "%[^=] = %[^;#]",     key, value) == 2)) {
        /* Usual key=value, with or without comments */
        strstrip(key);
        strlwc(key);
        strstrip(value);
        /*
         * sscanf cannot handle '' or "" as empty values
         * this is done here
         */
        if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) {
            value[0]=0 ;
        }
        *key_out = key;
        *value_out = value;
        key = NULL;
        value = NULL;
        sta = LINE_VALUE ;
    } else if (equals && (sscanf(line, "%[^=] = %[;#]", key, value)==2
           ||  sscanf(line, "%[^=] %[=]", key, value) == 2)) {
        /*
         * Special cases:
         * key=
         * key=;
         * key=#
         */
        strstrip(key);
        strlwc(key);
        value[0]=0 ;
        *key_out = key;
        *value_out = value;

        /* don't free out params key or val's memory */
        key = NULL;
        value = NULL;
        sta = LINE_VALUE ;
    } else {
        /* Generate syntax error */
        sta = LINE_ERROR ;
    }

out:
    if (line) {
        free(line);
        line = NULL;
    }
    if (key) {
        free(key);
        key = NULL;
    }
    if (value) {
        free(value);
        value= NULL;
    }
    return sta ;
}
/*--------------------------------------------------------------------------*/
int
iniparser_setstr (dictionary * ini, char * entry, char * val)
{
    dictionary_set (ini, strlwc (entry), val);
    return 0;
}