Trimming GtkEntry Text



Hello,

I have two problems I'm trying to work through that maybe someone here
can help me with.

I have a GtkEntry called a 'custom_command_entry'.  I would like to trim
white space from the beginning and end of what a user may enter in this
field.  custom_command_entry is a global.

This is what I have so far:

void on_executebutton_clicked (GtkWidget *widget, gpointer data)
{
        const gchar *custom_command;
        gchar *entry_wfo1, *entry_wfo2;

        /* GET THE BACKUP WFO SELECTION */
        entry_wfo1 = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox1));
        
        /* GET THE LOCALIZED WFO SELECTION */
        entry_wfo2 = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox2));
        
        /* GET THE CUSTOM COMMAND */
        custom_command =
g_strdup(gtk_entry_get_text(GTK_ENTRY(custom_command_entry)));
        g_strstrip(custom_command);
        
        if (custom_command == NULL || sizeof(custom_command) <= 0) {
                g_print("entry1 = %s :: entry2 = %s \n", entry_wfo1, entry_wfo2);
        } else {
                g_print("Custom Command: %s\n", custom_command);
        }
        
        gtk_widget_show(confirmdialog);
}

The 'if' statement above ALWAYS returns false, so that the custom
command is always printed to output even if there is nothing to print.

The idea is that the user can override the default command to run by
typing in a command in the 'custom_command_entry' GtkEntry field.  If
there is no command there, just whitespace, then the program needs to
run the default command.

Please help!

-- Tony





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]