From 8c963d2829ba5e108a17b472d47a7671a35748d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 25 Apr 2010 17:43:39 +0000 Subject: [PATCH] Make string arguments const where appropriate (patch by Colomban Wendling, thanks). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4862 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 7 +++++++ src/build.c | 39 ++++++++++++++++++++----------------- src/build.h | 2 +- src/callbacks.c | 6 +++--- src/dialogs.c | 2 +- src/editor.c | 4 ++-- src/encodings.c | 2 +- src/encodings.h | 4 ++-- src/gb.c | 2 +- src/geanyentryaction.c | 2 +- src/geanymenubuttonaction.c | 2 +- src/geanyobject.c | 2 +- src/geanywraplabel.c | 2 +- src/keyfile.c | 2 +- src/project.c | 6 +++--- src/sidebar.c | 2 +- src/socket.c | 2 +- src/symbols.c | 4 ++-- src/templates.c | 8 ++++---- src/ui_utils.c | 2 +- 20 files changed, 56 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index c24b12ea..1833351d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,13 @@ plugins/saveactions.c: Make string arguments const where appropriate (patch by Colomban Wendling, thanks). + * src/build.c, src/build.h, src/callbacks.c, src/editor.c, + src/encodings.c, src/encodings.h, src/gb.c, src/geanyentryaction.c, + src/geanymenubuttonaction.c, src/geanyobject.c, src/geanywraplabel.c, + src/keyfile.c, src/project.c, src/sidebar.c, src/socket.c, + src/symbols.c, src/templates.c, src/ui_utils.c: + Make string arguments const where appropriate (patch by + Colomban Wendling, thanks). 2010-04-22 Nick Treleaven diff --git a/src/build.c b/src/build.c index 3ff8d500..f36ab916 100644 --- a/src/build.c +++ b/src/build.c @@ -211,7 +211,7 @@ static GeanyBuildCommand **cl[GEANY_GBG_COUNT][GEANY_BCS_COUNT] = { /* for debug only, print the commands structures in priority order */ -static void printfcmds() +static void printfcmds(void) { GeanyFiletype *ft = NULL; GeanyDocument *doc; @@ -752,7 +752,8 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript, GeanyProject *project = app->project; GeanyBuildCommand *cmd = NULL; gchar *executable = NULL; - gchar *working_dir = NULL, *cmd_working_dir; + gchar *working_dir = NULL; + const gchar *cmd_working_dir; gboolean autoclose = FALSE; gboolean result = FALSE; gchar *tmp; @@ -1272,7 +1273,7 @@ static void on_build_menu_item(GtkWidget *w, gpointer user_data) } else build_command(doc, grp, cmd, NULL); -}; +} /* group codes for menu items other than the known commands @@ -1337,7 +1338,7 @@ static struct BuildMenuItemSpec { static void create_build_menu_item(GtkWidget *menu, GeanyKeyGroup *group, GtkAccelGroup *ag, - struct BuildMenuItemSpec *bs, gchar *lbl, gint grp, gint cmd) + struct BuildMenuItemSpec *bs, const gchar *lbl, gint grp, gint cmd) { GtkWidget *item = gtk_image_menu_item_new_with_mnemonic(lbl); if (bs->stock_id != NULL) @@ -1392,14 +1393,14 @@ static void create_build_menu(BuildMenuItems *build_menu_items) for (j = bs->build_cmd; j < build_groups_count[grp]; ++j) { GeanyBuildCommand *bc = get_build_cmd(NULL, grp, j, NULL); - gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc); + const gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc); create_build_menu_item(menu, keygroup, accel_group, bs, lbl, grp, j); } } else { GeanyBuildCommand *bc = get_build_cmd(NULL, bs->build_grp, bs->build_cmd, NULL); - gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc); + const gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc); create_build_menu_item(menu, keygroup, accel_group, bs, lbl, bs->build_grp, bs->build_cmd); } } @@ -1412,7 +1413,7 @@ static void create_build_menu(BuildMenuItems *build_menu_items) /* portability to various GTK versions needs checking * conforms to description of gtk_accel_label as child of menu item * NB 2.16 adds set_label but not yet set_label_mnemonic */ -static void geany_menu_item_set_label(GtkWidget *w, gchar *label) +static void geany_menu_item_set_label(GtkWidget *w, const gchar *label) { GtkWidget *c = gtk_bin_get_child(GTK_BIN(w)); gtk_label_set_text_with_mnemonic(GTK_LABEL(c), label); @@ -1484,7 +1485,7 @@ void build_menu_update(GeanyDocument *doc) for (cmd = bs->build_cmd; cmd < cmdcount; ++cmd) { GtkWidget *menu_item = menu_items.menu_item[grp][cmd]; - gchar *label; + const gchar *label; bc = get_build_cmd(doc, grp, cmd, NULL); if (bc) label = buildcmd_label(bc); @@ -1771,7 +1772,7 @@ static void on_label_button_clicked(GtkWidget *wid) /* Column headings, array NULL-terminated */ -static gchar *colheads[] = +static const gchar *colheads[] = { N_("Item"), N_("Label"), @@ -1785,11 +1786,11 @@ static gchar *colheads[] = #define DC_CLEAR 4 #define DC_N_COL 5 -static const int entry_x_padding = 3; -static const int entry_y_padding = 0; +static const guint entry_x_padding = 3; +static const guint entry_y_padding = 0; -static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gint row, +static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, guint row, GeanyBuildSource dst, gint grp, gint cmd, gboolean dir) { GtkWidget *label, *clear, *clearicon; @@ -1797,7 +1798,7 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gin GeanyBuildCommand *bc; gint src; enum GeanyBuildCmdEntries i; - gint column = 0; + guint column = 0; label = gtk_label_new(g_strdup_printf("%d:", cmd + 1)); gtk_table_attach(table, label, column, column + 1, row, row + 1, GTK_FILL, @@ -1837,7 +1838,7 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gin for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) { - gchar *str = ""; + const gchar *str = ""; if (bc != NULL && (str = bc->entries[i]) == NULL) str = ""; set_build_command_entry_text(roww->entries[i], str); @@ -1868,11 +1869,13 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD GtkWidget *label, *sep, *clearicon, *clear; TableFields *fields; GtkTable *table; - gchar **ch, *txt; - gint col, row, cmdindex, cmd; + const gchar **ch; + gchar *txt; + guint col, row, cmdindex; + gint cmd; gint src; gboolean sensitivity; - gint sep_padding = entry_y_padding + 3; + guint sep_padding = entry_y_padding + 3; table = GTK_TABLE(gtk_table_new(build_items_count + 12, 5, FALSE)); fields = g_new0(TableFields, 1); @@ -2580,7 +2583,7 @@ gint build_get_group_count(GeanyBuildGroup grp) static struct { - gchar *entries[GEANY_BC_CMDENTRIES_COUNT]; + const gchar *entries[GEANY_BC_CMDENTRIES_COUNT]; GeanyBuildCommand **ptr; gint index; } default_cmds[] = { diff --git a/src/build.h b/src/build.h index ac87116d..f985f959 100644 --- a/src/build.h +++ b/src/build.h @@ -127,7 +127,7 @@ typedef enum GeanyBuildCmdEntries GEANY_BC_LABEL, /**< The menu item label, _ marks mnemonic */ GEANY_BC_COMMAND, /**< The command to run. */ GEANY_BC_WORKING_DIR, /**< The directory to run in */ - GEANY_BC_CMDENTRIES_COUNT, /**< Count of entries */ + GEANY_BC_CMDENTRIES_COUNT /**< Count of entries */ } GeanyBuildCmdEntries; /** The command for a menu item. */ diff --git a/src/callbacks.c b/src/callbacks.c index 2013945b..42f8d6f9 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -470,7 +470,7 @@ on_reload_as_activate (GtkMenuItem *menuitem, GeanyDocument *doc = document_get_current(); gchar *base_name; gint i = GPOINTER_TO_INT(user_data); - gchar *charset = NULL; + const gchar *charset = NULL; g_return_if_fail(doc != NULL); g_return_if_fail(doc->file_name != NULL); @@ -1365,7 +1365,7 @@ on_comments_fileheader_activate (GtkMenuItem *menuitem, { GeanyDocument *doc = document_get_current(); gchar *text; - gchar *fname; + const gchar *fname; GeanyFiletype *ft; g_return_if_fail(doc != NULL); @@ -1385,7 +1385,7 @@ on_insert_date_activate (GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); - gchar *format = NULL; + const gchar *format = NULL; gchar *time_str; g_return_if_fail(doc != NULL); diff --git a/src/dialogs.c b/src/dialogs.c index 4e0316bf..02e86168 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -84,7 +84,7 @@ on_file_open_dialog_response (GtkDialog *dialog, gint encoding_idx = gtk_combo_box_get_active(GTK_COMBO_BOX( ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo"))); GeanyFiletype *ft = NULL; - gchar *charset = NULL; + const gchar *charset = NULL; gboolean ro = (response == GEANY_RESPONSE_VIEW); /* View clicked */ /* ignore detect from file item */ diff --git a/src/editor.c b/src/editor.c index 851b6186..419dcf28 100644 --- a/src/editor.c +++ b/src/editor.c @@ -99,7 +99,7 @@ static enum AUTOC_CANCELLED, AUTOC_SCOPE, AUTOC_TAGS, - AUTOC_DOC_WORDS, + AUTOC_DOC_WORDS } autocompletion_mode = AUTOC_CANCELLED; static gchar indent[100]; @@ -1951,7 +1951,7 @@ gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean forc gchar *linebuf, *root; ScintillaObject *sci; gboolean ret = FALSE; - gchar *wordchars; + const gchar *wordchars; GeanyFiletype *ft; if (! editor_prefs.auto_complete_symbols && ! force) diff --git a/src/encodings.c b/src/encodings.c index 7b67356a..c892d56f 100644 --- a/src/encodings.c +++ b/src/encodings.c @@ -523,7 +523,7 @@ gchar *encodings_convert_to_utf8(const gchar *buffer, gsize size, gchar **used_e { gchar *locale_charset = NULL; gchar *regex_charset = NULL; - gchar *charset; + const gchar *charset; gchar *utf8_content; gboolean check_regex = FALSE; gboolean check_locale = FALSE; diff --git a/src/encodings.h b/src/encodings.h index 82eb59e1..d24a53d7 100644 --- a/src/encodings.h +++ b/src/encodings.h @@ -63,9 +63,9 @@ typedef struct /** Internally used member for grouping */ GeanyEncodingGroup group; /** String representation of the encoding, e.g. "ISO-8859-3" */ - gchar *charset; + const gchar *charset; /** Translatable and descriptive name of the encoding, e.g. "South European" */ - gchar *name; + const gchar *name; } GeanyEncoding; diff --git a/src/gb.c b/src/gb.c index 211d3c22..6d7fff8c 100644 --- a/src/gb.c +++ b/src/gb.c @@ -44,7 +44,7 @@ gint points; gushort iconset; GtkWidget *image1, *image2, *image3, *image4, *label1, *label2, *label3, *okbutton1, *textview1; gchar info_texts[4][50]; -gchar *help_text; +const gchar *help_text; gboolean is_running; static GdkPixbuf **icons; diff --git a/src/geanyentryaction.c b/src/geanyentryaction.c index 9b543957..0469d1e5 100644 --- a/src/geanyentryaction.c +++ b/src/geanyentryaction.c @@ -52,7 +52,7 @@ enum static guint signals[LAST_SIGNAL]; -G_DEFINE_TYPE(GeanyEntryAction, geany_entry_action, GTK_TYPE_ACTION); +G_DEFINE_TYPE(GeanyEntryAction, geany_entry_action, GTK_TYPE_ACTION) static GtkWidget *geany_entry_action_create_tool_item(GtkAction *action) diff --git a/src/geanymenubuttonaction.c b/src/geanymenubuttonaction.c index 39b866e0..2515413e 100644 --- a/src/geanymenubuttonaction.c +++ b/src/geanymenubuttonaction.c @@ -56,7 +56,7 @@ enum static guint signals[LAST_SIGNAL]; -G_DEFINE_TYPE(GeanyMenubuttonAction, geany_menu_button_action, GTK_TYPE_ACTION); +G_DEFINE_TYPE(GeanyMenubuttonAction, geany_menu_button_action, GTK_TYPE_ACTION) static void geany_menu_button_action_finalize(GObject *object) diff --git a/src/geanyobject.c b/src/geanyobject.c index 8d5731e3..6e4d36e1 100644 --- a/src/geanyobject.c +++ b/src/geanyobject.c @@ -53,7 +53,7 @@ struct _GeanyObjectPrivate }; -G_DEFINE_TYPE(GeanyObject, geany_object, G_TYPE_OBJECT); +G_DEFINE_TYPE(GeanyObject, geany_object, G_TYPE_OBJECT) diff --git a/src/geanywraplabel.c b/src/geanywraplabel.c index 061a06f2..f204fdaf 100644 --- a/src/geanywraplabel.c +++ b/src/geanywraplabel.c @@ -57,7 +57,7 @@ static void geany_wrap_label_size_request (GtkWidget *widget, GtkRequisition *re static void geany_wrap_label_size_allocate (GtkWidget *widget, GtkAllocation *alloc); static void geany_wrap_label_set_wrap_width (GtkWidget *widget, gsize width); -G_DEFINE_TYPE(GeanyWrapLabel, geany_wrap_label, GTK_TYPE_LABEL); +G_DEFINE_TYPE(GeanyWrapLabel, geany_wrap_label, GTK_TYPE_LABEL) static void geany_wrap_label_class_init(GeanyWrapLabelClass *klass) diff --git a/src/keyfile.c b/src/keyfile.c index 3a83baa2..eb99546f 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -738,7 +738,7 @@ static void load_dialog_prefs(GKeyFile *config) if (vte_info.load_vte) { struct passwd *pw = getpwuid(getuid()); - gchar *shell = (pw != NULL) ? pw->pw_shell : "/bin/sh"; + const gchar *shell = (pw != NULL) ? pw->pw_shell : "/bin/sh"; vc = g_new0(VteConfig, 1); vte_info.dir = utils_get_setting_string(config, "VTE", "last_dir", NULL); diff --git a/src/project.c b/src/project.c index a9efe0b4..6aa616c6 100644 --- a/src/project.c +++ b/src/project.c @@ -89,7 +89,7 @@ static gboolean write_config(gboolean emit_signal); static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e); static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e); static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line); -static void apply_editor_prefs(); +static void apply_editor_prefs(void); #define SHOW_ERR(args) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args) @@ -1033,7 +1033,7 @@ static gboolean load_config(const gchar *filename) } -static void apply_editor_prefs() +static void apply_editor_prefs(void) { guint i; @@ -1135,7 +1135,7 @@ void project_save_prefs(GKeyFile *config) if (cl_options.load_session) { - gchar *utf8_filename = (project == NULL) ? "" : project->file_name; + const gchar *utf8_filename = (project == NULL) ? "" : project->file_name; g_key_file_set_string(config, "project", "session_file", utf8_filename); } diff --git a/src/sidebar.c b/src/sidebar.c index 2590b357..3cb45a51 100644 --- a/src/sidebar.c +++ b/src/sidebar.c @@ -184,7 +184,7 @@ static void create_default_tag_tree(void) gtk_scrolled_window_get_hadjustment(scrolled_window), gtk_scrolled_window_get_vadjustment(scrolled_window)); label = gtk_label_new(_("No tags found")); - gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.01); + gtk_misc_set_alignment(GTK_MISC(label), 0.1f, 0.01f); gtk_container_add(GTK_CONTAINER(tv.default_tag_tree), label); gtk_widget_show_all(tv.default_tag_tree); g_signal_connect(tv.default_tag_tree, "button-press-event", diff --git a/src/socket.c b/src/socket.c index 2ba5e2ef..f4ccd04e 100644 --- a/src/socket.c +++ b/src/socket.c @@ -122,7 +122,7 @@ static gint socket_fd_close (gint sock); -void send_open_command(gint sock, gint argc, gchar **argv) +static void send_open_command(gint sock, gint argc, gchar **argv) { gint i; gchar *filename; diff --git a/src/symbols.c b/src/symbols.c index 571216a0..67b95598 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -128,7 +128,7 @@ void symbols_reload_config_files(void) } -static gsize get_tag_count() +static gsize get_tag_count(void) { GPtrArray *tags = tm_get_workspace()->global_tags; gsize count = tags ? tags->len : 0; @@ -975,7 +975,7 @@ static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag) /* find the last word in "foo::bar::blah", e.g. "blah" */ -const gchar *get_parent_name(const TMTag *tag, filetype_id ft_id) +static const gchar *get_parent_name(const TMTag *tag, filetype_id ft_id) { const gchar *scope = tag->atts.entry.scope; const gchar *separator = symbols_get_context_separator(ft_id); diff --git a/src/templates.c b/src/templates.c index d0ca0746..9977362b 100644 --- a/src/templates.c +++ b/src/templates.c @@ -495,9 +495,9 @@ void templates_init(void) /* TODO make this function operating on a GString */ static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, guint indent) { - gchar *frame_start; /* to add before comment_text */ - gchar *frame_end; /* to add after comment_text */ - gchar *line_prefix; /* to add before every line in comment_text */ + gchar *frame_start; /* to add before comment_text */ + gchar *frame_end; /* to add after comment_text */ + const gchar *line_prefix; /* to add before every line in comment_text */ gchar *result; gchar *tmp; gchar *prefix; @@ -666,7 +666,7 @@ gchar *templates_get_template_function(GeanyDocument *doc, const gchar *func_nam gchar *templates_get_template_changelog(GeanyDocument *doc) { GString *result = g_string_new(templates[GEANY_TEMPLATE_CHANGELOG]); - gchar *file_type_name = (doc != NULL) ? doc->file_type->name : ""; + const gchar *file_type_name = (doc != NULL) ? doc->file_type->name : ""; replace_static_values(result); templates_replace_default_dates(result); diff --git a/src/ui_utils.c b/src/ui_utils.c index c65b7d25..38eb067f 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -770,7 +770,7 @@ void ui_sidebar_show_hide(void) void ui_document_show_hide(GeanyDocument *doc) { - gchar *widget_name; + const gchar *widget_name; GtkWidget *item; const GeanyIndentPrefs *iprefs;