Exemplo n.º 1
0
/* session_save_file (const char *group, const char *content, gboolean * mark_group) {{{*/
static void
session_save_file(const char *groupname, const char *content, gboolean mark) 
{
    if (groupname == NULL || content == NULL)
        return;

    gboolean set = false;
    GString *buffer = g_string_new(NULL);
    char *group = NULL;

    char **groups = session_get_groups();
    if (groups) 
    {
        int i=1;
        group = g_strconcat(groupname,  "\n", NULL);
        int l = strlen(group);
        while(groups[i]) 
        {
            if (*groups[i] == '*') 
            {
                if (!strncmp(groups[i]+1, group, l-1)) 
                {
                    g_string_append_printf(buffer, "g:%s%s\n%s", mark ? "*" : "", groupname, content);
                    set = true;
                }
                else 
                    g_string_append_printf(buffer, "g:%s", groups[i]+1);

            }
            else if (strncmp(groups[i], group, l)) 
                g_string_append_printf(buffer, "g:%s", groups[i]);
            i++;
        }
    }
    if (!set) 
        g_string_append_printf(buffer, "g:%s%s\n%s", mark ? "*" : "", groupname, content);

    util_set_file_content(dwb.files[FILES_SESSION], buffer->str);
    g_string_free(buffer, true);
    g_free(group);
    g_strfreev(groups);
}/*}}}*/
Exemplo n.º 2
0
Arquivo: util.c Projeto: vifino/dwb
gboolean 
util_keyfile_do(char *path, KeyFileAction action, const void *data)
{
    char *content;
    gboolean result = false;
    GKeyFile *kf = g_key_file_new(); 
    if (kf == NULL)
        return result;

    if (g_key_file_load_from_file(kf, path, G_KEY_FILE_KEEP_COMMENTS, NULL))
    {
        if (action(kf, data))
        {
            if ((content = g_key_file_to_data(kf, NULL, NULL)) != NULL)
            {
                util_set_file_content(path, content);
                g_free(content);
                result = true;
            }
        }
    }
    g_key_file_free(kf);
    return result;
}
Exemplo n.º 3
0
Arquivo: util.c Projeto: vifino/dwb
/* util_file_add(const char *filename, const char *text, int append, int max){{{*/
gboolean
util_file_add(const char *filename, const char *text, int append, int max) 
{
    if (!text)
        return false;

    FILE *file;
    char buffer[STRING_LENGTH];
    GString *content = g_string_new(NULL);
    char *tmp;

    if (!append) 
        g_string_append_printf(content, "%s\n", text);

    gboolean ret = false;
    if ( (file = fopen(filename, "r"))) 
    {
        for (int i=0; fgets(buffer, sizeof(buffer), file) &&  (max < 0 || i < max); i++) 
        {
            tmp = buffer;
            while (g_ascii_isspace(*tmp) && *tmp != '\n')
                tmp++;
            if (*tmp == '#' || *tmp == '\n')
                g_string_append(content, buffer);
            else if (STRCMP_FIRST_WORD(text, tmp) && STRCMP_SKIP_NEWLINE(text, tmp) ) 
                g_string_append(content, buffer);
        }
        fclose(file);
    }
    if (append)
        g_string_append_printf(content, "%s\n", text);
    ret = util_set_file_content(filename, content->str);

    g_string_free(content, true);
    return ret;
}