Skip to content

Commit

Permalink
reduce the scope of some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0w committed May 9, 2024
1 parent 5cd8bf0 commit 58d877f
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 28 deletions.
4 changes: 3 additions & 1 deletion lapiz/bacon-message-connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,16 @@ find_file_with_pattern (const char *dir, const char *pattern)
static char *
socket_filename (const char *prefix)
{
char *pattern, *newfile, *path, *filename;
char *pattern, *path, *filename;
const char *tmpdir;

pattern = g_strdup_printf ("%s.%s.*", prefix, g_get_user_name ());
tmpdir = g_get_tmp_dir ();
filename = find_file_with_pattern (tmpdir, pattern);
if (filename == NULL)
{
char *newfile;

newfile = g_strdup_printf ("%s.%s.%u", prefix,
g_get_user_name (), g_random_int ());
path = g_build_filename (tmpdir, newfile, NULL);
Expand Down
3 changes: 2 additions & 1 deletion lapiz/lapiz-documents-panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ window_active_tab_changed (LapizWindow *window,
if (!_lapiz_window_is_removing_tabs (window))
{
CtkTreeIter iter;
CtkTreeSelection *selection;

get_iter_from_tab (panel, tab, &iter);

if (ctk_list_store_iter_is_valid (CTK_LIST_STORE (panel->priv->model),
&iter))
{
CtkTreeSelection *selection;

selection = ctk_tree_view_get_selection (
CTK_TREE_VIEW (panel->priv->treeview));

Expand Down
19 changes: 12 additions & 7 deletions lapiz/lapiz-io-error-message-area.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ set_message_area_text_and_icon (CtkWidget *message_area,
CtkWidget *image;
CtkWidget *vbox;
gchar *primary_markup;
gchar *secondary_markup;
CtkWidget *primary_label;
CtkWidget *secondary_label;

hbox_content = ctk_box_new (CTK_ORIENTATION_HORIZONTAL, 8);

Expand All @@ -139,6 +137,9 @@ set_message_area_text_and_icon (CtkWidget *message_area,

if (secondary_text != NULL)
{
gchar *secondary_markup;
CtkWidget *secondary_label;

secondary_markup = g_strdup_printf ("<small>%s</small>",
secondary_text);
secondary_label = ctk_label_new (secondary_markup);
Expand Down Expand Up @@ -209,12 +210,13 @@ parse_gio_error (gint code,
case G_IO_ERROR_NOT_SUPPORTED:
{
gchar *scheme_string;
gchar *scheme_markup;

scheme_string = g_uri_parse_scheme (uri);

if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL))
{
gchar *scheme_markup;

scheme_markup = g_markup_printf_escaped ("<i>%s:</i>", scheme_string);

/* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */
Expand Down Expand Up @@ -475,9 +477,7 @@ create_conversion_error_message_area (const gchar *primary_text,
CtkWidget *image;
CtkWidget *vbox;
gchar *primary_markup;
gchar *secondary_markup;
CtkWidget *primary_label;
CtkWidget *secondary_label;

message_area = ctk_info_bar_new ();

Expand Down Expand Up @@ -534,6 +534,9 @@ create_conversion_error_message_area (const gchar *primary_text,

if (secondary_text != NULL)
{
gchar *secondary_markup;
CtkWidget *secondary_label;

secondary_markup = g_strdup_printf ("<small>%s</small>",
secondary_text);
secondary_label = ctk_label_new (secondary_markup);
Expand Down Expand Up @@ -1025,8 +1028,6 @@ lapiz_unrecoverable_saving_error_message_area_new (const gchar *uri,
gchar *error_message = NULL;
gchar *message_details = NULL;
gchar *full_formatted_uri;
gchar *scheme_string;
gchar *scheme_markup;
gchar *uri_for_display;
gchar *temp_uri_for_display;
CtkWidget *message_area;
Expand All @@ -1051,10 +1052,14 @@ lapiz_unrecoverable_saving_error_message_area_new (const gchar *uri,

if (is_gio_error (error, G_IO_ERROR_NOT_SUPPORTED))
{
gchar *scheme_string;

scheme_string = g_uri_parse_scheme (uri);

if ((scheme_string != NULL) && g_utf8_validate (scheme_string, -1, NULL))
{
gchar *scheme_markup;

scheme_markup = g_markup_printf_escaped ("<i>%s:</i>", scheme_string);

/* Translators: %s is a URI scheme (like for example http:, ftp:, etc.) */
Expand Down
5 changes: 3 additions & 2 deletions lapiz/lapiz-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,16 @@ client_save_state_cb (EggSMClient *client,
gpointer user_data)
{
const GList *windows;
gchar *group_name;
int n;

windows = lapiz_app_get_windows (lapiz_app_get_default ());
n = 1;

while (windows != NULL)
{
group_name = g_strdup_printf ("lapiz window %d", n);
gchar *group_name;

group_name = g_strdup_printf ("lapiz window %d", n);
save_window_session (state_file,
group_name,
LAPIZ_WINDOW (windows->data));
Expand Down
17 changes: 12 additions & 5 deletions lapiz/lapiz-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ lapiz_utils_make_valid_utf8 (const char *name)
{
GString *string;
const char *remainder, *invalid;
int remaining_bytes, valid_bytes;
int remaining_bytes;

g_return_val_if_fail (name != NULL, NULL);

Expand All @@ -655,6 +655,8 @@ lapiz_utils_make_valid_utf8 (const char *name)
remaining_bytes = strlen (name);

while (remaining_bytes != 0) {
int valid_bytes;

if (g_utf8_validate (remainder, remaining_bytes, &invalid)) {
break;
}
Expand Down Expand Up @@ -1439,9 +1441,7 @@ lapiz_utils_decode_uri (const gchar *uri,
* functionality should be in glib/gio, but for now we implement it
* ourselves (see bug #546182) */

const char *p, *in, *hier_part_start, *hier_part_end;
char *out;
char c;
const char *p, *hier_part_start, *hier_part_end;

/* From RFC 3986 Decodes:
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Expand All @@ -1464,6 +1464,8 @@ lapiz_utils_decode_uri (const gchar *uri,

while (1)
{
char c;

c = *p++;

if (c == ':')
Expand All @@ -1478,6 +1480,9 @@ lapiz_utils_decode_uri (const gchar *uri,

if (scheme)
{
const char *in;
char *out;

*scheme = g_malloc (p - uri);
out = *scheme;

Expand All @@ -1493,7 +1498,7 @@ lapiz_utils_decode_uri (const gchar *uri,
if (hier_part_start[0] == '/' && hier_part_start[1] == '/')
{
const char *authority_start, *authority_end;
const char *userinfo_start, *userinfo_end;
const char *userinfo_end;
const char *host_start, *host_end;
const char *port_start;

Expand All @@ -1512,6 +1517,8 @@ lapiz_utils_decode_uri (const gchar *uri,

if (userinfo_end)
{
const char *userinfo_start;

userinfo_start = authority_start;

if (user)
Expand Down
4 changes: 2 additions & 2 deletions lapiz/lapiz-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -2115,11 +2115,11 @@ lapiz_view_drag_data_received (CtkWidget *widget,
guint info,
guint timestamp)
{
gchar **uri_list;

/* If this is an URL emit DROP_URIS, otherwise chain up the signal */
if (info == TARGET_URI_LIST)
{
gchar **uri_list;

uri_list = lapiz_utils_drop_get_uris (selection_data);

if (uri_list != NULL)
Expand Down
15 changes: 10 additions & 5 deletions lapiz/smclient/eggdesktopfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,23 +479,24 @@ gboolean
egg_desktop_file_can_launch (EggDesktopFile *desktop_file,
const char *desktop_environment)
{
char *try_exec, *found_program;
char **only_show_in, **not_show_in;
gboolean found;
int i;

if (desktop_file->type != EGG_DESKTOP_FILE_TYPE_APPLICATION &&
desktop_file->type != EGG_DESKTOP_FILE_TYPE_LINK)
return FALSE;

if (desktop_environment)
{
char **only_show_in, **not_show_in;

only_show_in = g_key_file_get_string_list (desktop_file->key_file,
EGG_DESKTOP_FILE_GROUP,
EGG_DESKTOP_FILE_KEY_ONLY_SHOW_IN,
NULL, NULL);
if (only_show_in)
{
int i;

for (i = 0, found = FALSE; only_show_in[i] && !found; i++)
{
if (!strcmp (only_show_in[i], desktop_environment))
Expand Down Expand Up @@ -529,12 +530,16 @@ egg_desktop_file_can_launch (EggDesktopFile *desktop_file,

if (desktop_file->type == EGG_DESKTOP_FILE_TYPE_APPLICATION)
{
char *try_exec;

try_exec = g_key_file_get_string (desktop_file->key_file,
EGG_DESKTOP_FILE_GROUP,
EGG_DESKTOP_FILE_KEY_TRY_EXEC,
NULL);
if (try_exec)
{
char found_program;

found_program = g_find_program_in_path (try_exec);
g_free (try_exec);

Expand Down Expand Up @@ -604,8 +609,6 @@ append_quoted_word (GString *str,
gboolean in_single_quotes,
gboolean in_double_quotes)
{
const char *p;

if (!in_single_quotes && !in_double_quotes)
g_string_append_c (str, '\'');
else if (!in_single_quotes && in_double_quotes)
Expand All @@ -615,6 +618,8 @@ append_quoted_word (GString *str,
g_string_append (str, s);
else
{
const char *p;

for (p = s; *p != '\0'; p++)
{
if (*p == '\'')
Expand Down
3 changes: 2 additions & 1 deletion plugins/filebrowser/lapiz-file-browser-messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ message_set_emblem_cb (LapizMessageBus *bus,
gchar *id = NULL;
gchar *emblem = NULL;
CtkTreePath *path;
LapizFileBrowserStore *store;

lapiz_message_get (message, "id", &id, "emblem", &emblem, NULL);

Expand All @@ -247,6 +246,8 @@ message_set_emblem_cb (LapizMessageBus *bus,

if (pixbuf)
{
LapizFileBrowserStore *store;

GValue value = { 0, };
CtkTreeIter iter;

Expand Down
2 changes: 1 addition & 1 deletion plugins/spell/lapiz-automatic-spell-checker.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ build_suggestion_menu (LapizAutomaticSpellChecker *spell, const gchar *word)
CtkWidget *mi;
GSList *suggestions;
GSList *list;
gchar *label_text;

topmenu = menu = ctk_menu_new();

Expand Down Expand Up @@ -432,6 +431,7 @@ build_suggestion_menu (LapizAutomaticSpellChecker *spell, const gchar *word)
/* build a set of menus with suggestions. */
while (suggestions != NULL)
{
gchar *label_text;
CtkWidget *label;

if (count == 10)
Expand Down
4 changes: 3 additions & 1 deletion plugins/spell/lapiz-spell-checker-language.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ create_name_for_language (const char *code)
{
char **str;
char *name = NULL;
const char *langname, *localename;
const char *langname;
int len;

g_return_val_if_fail (iso_639_table != NULL, NULL);
Expand All @@ -271,6 +271,8 @@ create_name_for_language (const char *code)
}
else if (len == 2 && langname != NULL)
{
const char *localename;

gchar *locale_code = g_ascii_strdown (str[1], -1);

localename = (const char *) g_hash_table_lookup (iso_3166_table, locale_code);
Expand Down
4 changes: 2 additions & 2 deletions plugins/taglist/lapiz-taglist-plugin-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,6 @@ static TagList* parse_taglist_dir(const gchar* dir)

TagList* create_taglist(const gchar* data_dir)
{
gchar* pdir;

lapiz_debug_message(DEBUG_PLUGINS, "ref_count: %d", taglist_ref_count);

if (taglist_ref_count > 0)
Expand All @@ -612,6 +610,8 @@ TagList* create_taglist(const gchar* data_dir)
home = g_get_home_dir ();
if (home != NULL)
{
gchar* pdir;

pdir = g_build_filename(home, ".config", USER_LAPIZ_TAGLIST_PLUGIN_LOCATION, NULL);
parse_taglist_dir(pdir);
g_free (pdir);
Expand Down

0 comments on commit 58d877f

Please sign in to comment.