Add hidden option -g to generate filetype_extensions.conf

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@661 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2006-08-01 21:07:46 +00:00
parent 794ad69ad1
commit a591dd027f
4 changed files with 65 additions and 31 deletions

View File

@ -23,6 +23,8 @@
Install a system filetype_extensions.conf which can be overridden. Install a system filetype_extensions.conf which can be overridden.
* src/filetypes.c data/filetype_extensions.conf: * src/filetypes.c data/filetype_extensions.conf:
Add Make pattern to recognise makefile*. Add Make pattern to recognise makefile*.
* src/keyfile.c, src/keyfile.h, src/main.c:
Add hidden option -g to generate filetype_extensions.conf.
2006-07-31 Enrico Tröger <enrico.troeger@uvena.de> 2006-07-31 Enrico Tröger <enrico.troeger@uvena.de>

View File

@ -39,7 +39,10 @@ static gint hpan_position;
static gint vpan_position; static gint vpan_position;
void configuration_save(void) static void generate_filetype_extensions(const gchar *output_dir);
void configuration_save()
{ {
gint i = 0, j = 0, idx, max; gint i = 0, j = 0, idx, max;
gboolean config_exists; gboolean config_exists;
@ -210,7 +213,7 @@ void configuration_save(void)
else \ else \
value = default_value; value = default_value;
gboolean configuration_load(void) gboolean configuration_load()
{ {
gboolean config_exists; gboolean config_exists;
guint i, geo_len; guint i, geo_len;
@ -386,7 +389,7 @@ gboolean configuration_load(void)
} }
gboolean configuration_open_files(void) gboolean configuration_open_files()
{ {
gint i; gint i;
guint x, pos, ft_id, y, len; guint x, pos, ft_id, y, len;
@ -450,7 +453,7 @@ gboolean configuration_open_files(void)
/* set some settings which are already read from the config file, but need other things, like the /* set some settings which are already read from the config file, but need other things, like the
* realisation of the main window */ * realisation of the main window */
void configuration_apply_settings(void) void configuration_apply_settings()
{ {
if (scribble_text) if (scribble_text)
{ // update the scribble widget, because now it's realized { // update the scribble widget, because now it's realized
@ -493,46 +496,64 @@ void configuration_apply_settings(void)
} }
#if 0 /* Generate the config files in "data/" from defaults */
void configuration_generate_data_files()
{
gchar *cur_dir, *gen_dir;
cur_dir = g_get_current_dir();
gen_dir = g_strconcat(cur_dir, G_DIR_SEPARATOR_S, "data", NULL);
g_free(cur_dir);
if (! g_file_test(gen_dir, G_FILE_TEST_IS_DIR))
{
g_print("%s does not exist!\n", gen_dir);
return;
}
g_print("Generating system files in %s:\n", gen_dir);
generate_filetype_extensions(gen_dir);
g_free(gen_dir);
}
/* This will write the default settings for the system filetype_extensions.conf */ /* This will write the default settings for the system filetype_extensions.conf */
static void generate_filetype_extensions(const gchar *output_dir) static void generate_filetype_extensions(const gchar *output_dir)
{ {
guint i; guint i;
gsize len = 0;
gchar *configfile = g_strconcat(output_dir, G_DIR_SEPARATOR_S, "filetype_extensions.conf", NULL); gchar *configfile = g_strconcat(output_dir, G_DIR_SEPARATOR_S, "filetype_extensions.conf", NULL);
gchar *data, *comment; gchar *data, *basename;
GKeyFile *config;
config = g_key_file_new(); config = g_key_file_new();
// add missing keys // add filetype keys
for (i = 0; i < GEANY_MAX_FILE_TYPES; i++) for (i = 0; i < GEANY_MAX_FILE_TYPES; i++)
{
if (! g_key_file_has_key(config, "Extensions", filetypes[i]->name, NULL))
{ {
g_key_file_set_string_list(config, "Extensions", filetypes[i]->name, g_key_file_set_string_list(config, "Extensions", filetypes[i]->name,
(const gchar**) filetypes[i]->pattern, g_strv_length(filetypes[i]->pattern)); (const gchar**) filetypes[i]->pattern, g_strv_length(filetypes[i]->pattern));
} }
} // add comment
// add comment, if it doesn't exist
comment = g_key_file_get_comment(config, NULL, NULL, NULL);
if (!comment || strlen(comment) == 0)
{
g_key_file_set_comment(config, "Extensions", NULL, g_key_file_set_comment(config, "Extensions", NULL,
"Filetype extension configuration file for Geany\n" "Filetype extension configuration file for Geany\n"
"Insert as many items as you want, seperate them with a \";\".\n" "Insert as many items as you want, seperate them with a \";\".\n"
"See Geany's main documentation for details.", NULL); "See Geany's main documentation for details.", NULL);
}
g_free(comment);
// write the file // write the file
g_print("%s: ", __func__);
data = g_key_file_to_data(config, NULL, NULL); data = g_key_file_to_data(config, NULL, NULL);
utils_write_file(configfile, data); basename = g_path_get_basename(configfile);
if (utils_write_file(configfile, data) == 0)
g_print("wrote file %s.\n", basename);
else
g_print("*** ERROR: error writing file %s\n", basename);
g_free(basename);
g_free(data); g_free(data);
g_key_file_free(config); g_key_file_free(config);
} }
#endif
void configuration_read_filetype_extensions(void) void configuration_read_filetype_extensions()
{ {
guint i; guint i;
gsize len = 0; gsize len = 0;

View File

@ -24,16 +24,19 @@
#define GEANY_KEYFILE_H 1 #define GEANY_KEYFILE_H 1
void configuration_save(void); void configuration_save();
gboolean configuration_load(void); gboolean configuration_load();
gboolean configuration_open_files(void); gboolean configuration_open_files();
void configuration_read_filetype_extensions(void); void configuration_read_filetype_extensions();
/* set some settings which are already read from the config file, but need other things, like the /* set some settings which are already read from the config file, but need other things, like the
* realisation of the main window */ * realisation of the main window */
void configuration_apply_settings(void); void configuration_apply_settings();
/* Generate the config files in "data/" from defaults */
void configuration_generate_data_files();
#endif #endif

View File

@ -69,6 +69,8 @@ static gchar *alternate_config = NULL;
static gboolean no_vte = FALSE; static gboolean no_vte = FALSE;
static gchar *lib_vte = NULL; static gchar *lib_vte = NULL;
#endif #endif
static gboolean generate_datafiles = FALSE;
static GOptionEntry entries[] = static GOptionEntry entries[] =
{ {
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, N_("runs in debug mode (means being verbose)"), NULL }, { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug_mode, N_("runs in debug mode (means being verbose)"), NULL },
@ -83,6 +85,7 @@ static GOptionEntry entries[] =
{ "vte-lib", 'l', 0, G_OPTION_ARG_FILENAME, &lib_vte, N_("filename of libvte.so"), NULL }, { "vte-lib", 'l', 0, G_OPTION_ARG_FILENAME, &lib_vte, N_("filename of libvte.so"), NULL },
#endif #endif
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("show version and exit"), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("show version and exit"), NULL },
{ "generate-data-files", 'g', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &generate_datafiles, "", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL } { NULL, 0, 0, 0, NULL, NULL, NULL }
}; };
@ -555,6 +558,11 @@ gint main(gint argc, gchar **argv)
app->fifo_ioc = ioc; app->fifo_ioc = ioc;
#endif #endif
filetypes_init_types(); filetypes_init_types();
if (generate_datafiles)
{
configuration_generate_data_files();
exit(0);
}
configuration_read_filetype_extensions(); configuration_read_filetype_extensions();
gtk_window_set_icon(GTK_WINDOW(app->window), utils_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE)); gtk_window_set_icon(GTK_WINDOW(app->window), utils_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE));