+2002-12-31 [christoph] 0.8.8claws27
+
+ * src/addrbook.c
+ * src/addrindex.c
+ * src/folder.c
+ * src/matcher.c
+ * src/prefs_account.c
+ * src/prefs_actions.c
+ * src/prefs_customheader.c
+ * src/prefs_display_header.c
+ * src/prefs_gtk.c
+ * src/procmime.c
+ * src/toolbar.c
+ * src/xmlprops.c
+ * src/common/prefs.[ch]
+ extend prefs file handling for reading and automatic handling
+ of blocks. When reading prefs_set_block_label will automatically
+ move on to the block. When writing it will copy all other blocks
+ automatically
+
+ * src/common/plugin.c
+ Now loading plugin filenames from [Plugins] block in
+ sylpheed rc file
+
2002-12-30 [christoph] 0.8.8claws26
* src/common/hooks.[ch]
MICRO_VERSION=8
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=claws26
+EXTRA_VERSION=claws27
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
dnl set $target
#ifdef DEV_STANDALONE
fclose(fp);
#else
- if (prefs_write_close( pfile ) < 0)
+ if (prefs_file_close( pfile ) < 0)
book->retVal = MGU_ERROR_WRITE;
#endif
}
#ifdef DEV_STANDALONE
fclose( fp );
#else
- if( prefs_write_close( pfile ) < 0 ) {
+ if( prefs_file_close( pfile ) < 0 ) {
addrIndex->retVal = MGU_ERROR_WRITE;
}
#endif
GSList *cur;
Plugin *plugin;
- rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "pluginsrc", NULL);
- if ((pfile = prefs_write_open(rcpath)) == NULL) {
+ rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
+ if ((pfile = prefs_write_open(rcpath)) == NULL ||
+ (prefs_set_block_label(pfile, "Plugins") < 0)) {
g_warning("failed to write plugin list\n");
g_free(rcpath);
return;
fprintf(pfile->fp, "%s\n", plugin->filename);
}
- if (prefs_write_close(pfile) < 0)
+ if (prefs_file_close(pfile) < 0)
g_warning("failed to write plugin list\n");
g_free(rcpath);
{
gchar *rcpath;
gchar buf[BUFFSIZE];
- FILE *fp;
+ PrefFile *pfile;
+ gchar *error;
- rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "pluginsrc", NULL);
- if ((fp = fopen(rcpath, "rb")) != NULL) {
- gchar *error;
+ rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
+ if ((pfile = prefs_read_open(rcpath)) == NULL ||
+ (prefs_set_block_label(pfile, "Plugins") < 0)) {
+ g_free(rcpath);
+ return;
+ }
- while(fgets(buf, sizeof(buf), fp) != NULL) {
- g_strstrip(buf);
+ while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
+ if (buf[0] == '[')
+ break;
- if (plugin_load(buf, &error) < 0) {
- debug_print("plugin loading error: %s\n", error);
- g_free(error);
- }
- }
-
- fclose(fp);
+ g_strstrip(buf);
+ if (plugin_load(buf, &error) < 0) {
+ debug_print("plugin loading error: %s\n", error);
+ g_free(error);
+ }
}
+ prefs_file_close(pfile);
g_free(rcpath);
}
# include "config.h"
#endif
+#include "defs.h"
+
#include <glib.h>
#include "prefs.h"
#include "utils.h"
+PrefFile *prefs_read_open(const gchar *path)
+{
+ PrefFile *pfile;
+ gchar *tmppath;
+ FILE *fp;
+
+ g_return_val_if_fail(path != NULL, NULL);
+
+ if ((fp = fopen(path, "rb")) == NULL) {
+ FILE_OP_ERROR(tmppath, "fopen");
+ return NULL;
+ }
+
+ pfile = g_new(PrefFile, 1);
+ pfile->fp = fp;
+ pfile->orig_fp = NULL;
+ pfile->path = g_strdup(path);
+ pfile->writing = FALSE;
+
+ return pfile;
+}
+
PrefFile *prefs_write_open(const gchar *path)
{
PrefFile *pfile;
pfile = g_new(PrefFile, 1);
pfile->fp = fp;
+ pfile->orig_fp = NULL;
pfile->path = g_strdup(path);
+ pfile->writing = TRUE;
return pfile;
}
-gint prefs_write_close(PrefFile *pfile)
+gint prefs_file_close(PrefFile *pfile)
{
- FILE *fp;
+ FILE *fp, *orig_fp;
gchar *path;
gchar *tmppath;
gchar *bakpath = NULL;
+ gchar buf[BUFFSIZE];
g_return_val_if_fail(pfile != NULL, -1);
fp = pfile->fp;
+ orig_fp = pfile->orig_fp;
path = pfile->path;
g_free(pfile);
+ if (!pfile->writing) {
+ fclose(fp);
+ return 0;
+ }
+
+ if (orig_fp) {
+ while (fgets(buf, sizeof(buf), orig_fp) != NULL) {
+ /* next block */
+ if (buf[0] == '[') {
+ if (fputs(buf, fp) == EOF) {
+ g_warning("failed to write configuration to file\n");
+ fclose(orig_fp);
+ prefs_file_close_revert(pfile);
+
+ return -1;
+ }
+ break;
+ }
+ }
+
+ while (fgets(buf, sizeof(buf), orig_fp) != NULL)
+ if (fputs(buf, fp) == EOF) {
+ g_warning("failed to write configuration to file\n");
+ fclose(orig_fp);
+ prefs_file_close_revert(pfile);
+
+ return -1;
+ }
+ }
+
tmppath = g_strconcat(path, ".tmp", NULL);
if (fclose(fp) == EOF) {
FILE_OP_ERROR(tmppath, "fclose");
return 0;
}
-gint prefs_write_close_revert(PrefFile *pfile)
+gint prefs_file_close_revert(PrefFile *pfile)
{
gchar *tmppath;
g_return_val_if_fail(pfile != NULL, -1);
- tmppath = g_strconcat(pfile->path, ".tmp", NULL);
+ if (pfile->orig_fp)
+ fclose(pfile->orig_fp);
+ if (pfile->writing)
+ tmppath = g_strconcat(pfile->path, ".tmp", NULL);
fclose(pfile->fp);
- if (unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink");
- g_free(tmppath);
+ if (pfile->writing) {
+ if (unlink(tmppath) < 0) FILE_OP_ERROR(tmppath, "unlink");
+ g_free(tmppath);
+ }
g_free(pfile->path);
g_free(pfile);
return result;
}
+
+gint prefs_set_block_label(PrefFile *pfile, const gchar *label)
+{
+ gchar *block_label;
+ gchar buf[BUFFSIZE];
+
+ block_label = g_strdup_printf("[%s]", label);
+ if (!pfile->writing) {
+ while (fgets(buf, sizeof(buf), pfile->fp) != NULL) {
+ gint val;
+
+ val = strncmp(buf, block_label, strlen(block_label));
+ if (val == 0) {
+ debug_print("Found %s\n", block_label);
+ break;
+ }
+ }
+ } else {
+ if ((pfile->orig_fp = fopen(pfile->path, "rb")) != NULL) {
+ gboolean block_matched = FALSE;
+
+ while (fgets(buf, sizeof(buf), pfile->orig_fp) != NULL) {
+ gint val;
+
+ val = strncmp(buf, block_label, strlen(block_label));
+ if (val == 0) {
+ debug_print("Found %s\n", block_label);
+ block_matched = TRUE;
+ break;
+ } else {
+ if (fputs(buf, pfile->fp) == EOF) {
+ g_warning("failed to write configuration to file\n");
+ fclose(pfile->orig_fp);
+ prefs_file_close_revert(pfile);
+ g_free(block_label);
+
+ return -1;
+ }
+ }
+ }
+
+ if (!block_matched) {
+ fclose(pfile->orig_fp);
+ pfile->orig_fp = NULL;
+ }
+
+ if (fputs(block_label, pfile->fp) == EOF ||
+ fputc('\n', pfile->fp) == EOF) {
+ g_warning("failed to write configuration to file\n");
+ fclose(pfile->orig_fp);
+ prefs_file_close_revert(pfile);
+ g_free(block_label);
+
+ return -1;
+ }
+ }
+ }
+
+ g_free(block_label);
+
+ return 0;
+}
struct _PrefFile {
FILE *fp;
+ FILE *orig_fp;
gchar *path;
+ gboolean writing;
};
+PrefFile *prefs_read_open (const gchar *path);
PrefFile *prefs_write_open (const gchar *path);
-gint prefs_write_close (PrefFile *pfile);
-gint prefs_write_close_revert (PrefFile *pfile);
+gint prefs_file_close (PrefFile *pfile);
+gint prefs_file_close_revert (PrefFile *pfile);
gboolean prefs_is_readonly (const gchar *path);
gboolean prefs_rc_is_readonly (const gchar *rcfile);
+gint prefs_set_block_label (PrefFile *pfile,
+ const gchar *block_label);
#endif
fputs("</folderlist>\n", pfile->fp);
- if (prefs_write_close(pfile) < 0)
+ if (prefs_file_close(pfile) < 0)
g_warning("failed to write folder list.\n");
}
g_free(rcpath);
- if (prefs_write_close(pfile) < 0) {
+ if (prefs_file_close(pfile) < 0) {
g_warning("failed to write configuration to file\n");
return;
}
tmp_ac_prefs.account_id) <= 0 ||
prefs_write_param(param, pfile->fp) < 0) {
g_warning("failed to write configuration to file\n");
- prefs_write_close_revert(pfile);
+ prefs_file_close_revert(pfile);
return;
}
if (cur->next) {
if (fputc('\n', pfile->fp) == EOF) {
FILE_OP_ERROR(rcpath, "fputc");
- prefs_write_close_revert(pfile);
+ prefs_file_close_revert(pfile);
return;
}
}
}
- if (prefs_write_close(pfile) < 0)
+ if (prefs_file_close(pfile) < 0)
g_warning("failed to write configuration to file\n");
}
if (fputs(act, pfile->fp) == EOF ||
fputc('\n', pfile->fp) == EOF) {
FILE_OP_ERROR(rcpath, "fputs || fputc");
- prefs_write_close_revert(pfile);
+ prefs_file_close_revert(pfile);
g_free(rcpath);
return;
}
g_free(rcpath);
- if (prefs_write_close(pfile) < 0) {
+ if (prefs_file_close(pfile) < 0) {
g_warning("failed to write configuration to file\n");
return;
}
if (fputs(chstr, pfile->fp) == EOF ||
fputc('\n', pfile->fp) == EOF) {
FILE_OP_ERROR(rcpath, "fputs || fputc");
- prefs_write_close_revert(pfile);
+ prefs_file_close_revert(pfile);
g_free(rcpath);
g_free(chstr);
return;
if (fputs(chstr, pfile->fp) == EOF ||
fputc('\n', pfile->fp) == EOF) {
FILE_OP_ERROR(rcpath, "fputs || fputc");
- prefs_write_close_revert(pfile);
+ prefs_file_close_revert(pfile);
g_free(rcpath);
g_free(chstr);
return;
all_hdrs = g_slist_remove(all_hdrs, ch);
}
- if (prefs_write_close(pfile) < 0) {
+ if (prefs_file_close(pfile) < 0) {
g_warning("failed to write configuration to file\n");
return;
}
if (fputs(dpstr, pfile->fp) == EOF ||
fputc('\n', pfile->fp) == EOF) {
FILE_OP_ERROR(rcpath, "fputs || fputc");
- prefs_write_close_revert(pfile);
+ prefs_file_close_revert(pfile);
g_free(rcpath);
g_free(dpstr);
return;
g_free(rcpath);
- if (prefs_write_close(pfile) < 0) {
+ if (prefs_file_close(pfile) < 0) {
g_warning("failed to write configuration to file\n");
return;
}
{ \
g_warning("failed to write configuration to file\n"); \
if (orig_fp) fclose(orig_fp); \
- prefs_write_close_revert(pfile); \
+ prefs_file_close_revert(pfile); \
g_free(rcpath); \
g_free(block_label); \
return; \
}
if (orig_fp) fclose(orig_fp);
- if (prefs_write_close(pfile) < 0)
+ if (prefs_file_close(pfile) < 0)
g_warning("failed to write configuration to file\n");
g_free(rcpath);
renderer->renderer);
}
- if (prefs_write_close(pfile) < 0) {
+ if (prefs_file_close(pfile) < 0) {
g_warning("failed to write configuration to file\n");
return;
}
fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
- if (prefs_write_close (pfile) < 0 )
+ if (prefs_file_close (pfile) < 0 )
g_warning("failed to write toolbar configuration to file\n");
} else
g_warning("failed to open toolbar configuration file for writing\n");
xmlprops_write_elem_e( fp, 0, XMLS_ELTAG_PROP_LIST );
props->retVal = MGU_SUCCESS;
- if( prefs_write_close( pfile ) < 0 ) {
+ if( prefs_file_close( pfile ) < 0 ) {
props->retVal = MGU_ERROR_WRITE;
}
}