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 4e51a9b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 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

0 comments on commit 4e51a9b

Please sign in to comment.