t_num *get_numbers(int ac, char **av) { int i; int no_numbers; t_num *n; i = 1; no_numbers = 1; n = NULL; while (i < ac) { if (av[i][0] >= '0' && av[i][0] <= '9') { insert_numbers(av[i], &n); no_numbers = 0; } i = i + 1; } if (no_numbers == 1) { printf("Error : No numbers were given !\nPlease retry using the appropriate ones\n"); exit (84); } return (n); }
static void on_insert_numbers_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { InsertNumbersDialog d; GtkWidget *vbox, *label, *upper, *space, *button; GtkGrid *grid; GtkComboBoxText *combo; const char *case_tip = _("For base 11 and above"); gchar *base_text; gint result; d.dialog = gtk_dialog_new_with_buttons(_("Insert Numbers"), GTK_WINDOW(geany->main_widgets->window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); vbox = ui_dialog_vbox_new(GTK_DIALOG(d.dialog)); gtk_box_set_spacing(GTK_BOX(vbox), 9); #if GTK_CHECK_VERSION(3, 0, 0) grid = GTK_GRID(gtk_grid_new()); #else grid = GTK_TABLE(gtk_table_new(3, 6, FALSE)); #endif gtk_grid_set_row_spacing(grid, 6); gtk_grid_set_column_spacing(grid, 6); gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(grid), TRUE, TRUE, 0); label = gtk_label_new_with_mnemonic(_("_Start:")); gtk_grid_attach(grid, label, 0, 0, 1, 1); d.start = gtk_spin_button_new_with_range(RANGE_MIN, RANGE_MAX, 1); set_entry(d.start, RANGE_LEN, label, RANGE_TOOLTIP); gtk_grid_attach(grid, d.start, 1, 0, 2, 1); label = gtk_label_new_with_mnemonic(_("S_tep:")); gtk_grid_attach(grid, label, 3, 0, 1, 1); d.step = gtk_spin_button_new_with_range(RANGE_MIN, RANGE_MAX, 1); set_entry(d.step, RANGE_LEN, label, RANGE_TOOLTIP); gtk_grid_attach(grid, d.step, 4, 0, 2, 1); label = gtk_label_new_with_mnemonic(_("_Base:")); gtk_grid_attach(grid, label, 0, 1, 1, 1), combo = GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new_with_entry()); d.base = gtk_bin_get_child(GTK_BIN(combo)); set_entry(d.base, 2, label, "2..36"); g_signal_connect(d.base, "insert-text", G_CALLBACK(on_base_insert_text), NULL); gtk_combo_box_text_append_text(combo, "2"); gtk_combo_box_text_append_text(combo, "8"); gtk_combo_box_text_append_text(combo, "10"); gtk_combo_box_text_append_text(combo, "16"); #if GTK_CHECK_VERSION(3, 0, 0) gtk_grid_attach(grid, GTK_WIDGET(combo), 1, 1, 2, 1); gtk_widget_set_hexpand(GTK_WIDGET(combo), TRUE); #else gtk_table_attach(grid, GTK_WIDGET(combo), 1, 3, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0); #endif label = gtk_label_new(_("Letters:")); gtk_widget_set_tooltip_text(label, case_tip); gtk_grid_attach(grid, label, 3, 1, 1, 1); upper = gtk_radio_button_new_with_mnemonic(NULL, _("_Upper")); gtk_widget_set_tooltip_text(upper, case_tip); gtk_grid_attach(grid, upper, 4, 1, 1, 1); d.lower = gtk_radio_button_new_from_widget(GTK_RADIO_BUTTON(upper)); gtk_widget_set_tooltip_text(label, case_tip); label = gtk_label_new_with_mnemonic(_("_Lower")); gtk_widget_set_tooltip_text(label, case_tip); gtk_container_add(GTK_CONTAINER(d.lower), label); gtk_grid_attach(grid, d.lower, 5, 1, 1, 1); d.prefix = gtk_check_button_new_with_mnemonic(_("Base _prefix")); gtk_widget_set_tooltip_text(d.prefix, _("0 for octal, 0x for hex, + for positive decimal")); gtk_grid_attach(grid, d.prefix, 1, 2, 2, 1); label = gtk_label_new(_("Padding:")); gtk_grid_attach(grid, label, 3, 2, 1, 1); space = gtk_radio_button_new_with_mnemonic(NULL, _("Sp_ace")); gtk_grid_attach(grid, space, 4, 2, 1, 1); d.zero = gtk_radio_button_new_from_widget(GTK_RADIO_BUTTON(space)); label = gtk_label_new_with_mnemonic(_("_Zero")); gtk_container_add(GTK_CONTAINER(d.zero), label); gtk_grid_attach(grid, d.zero, 5, 2, 1, 1); button = gtk_button_new_from_stock(GTK_STOCK_OK); g_signal_connect(button, "clicked", G_CALLBACK(on_insert_numbers_ok_clicked), &d); gtk_box_pack_end(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(d.dialog))), button, TRUE, TRUE, 0); #if GTK_CHECK_VERSION(2, 18, 0) gtk_widget_set_can_default(button, TRUE); #else GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); #endif gtk_widget_grab_default(button); gtk_spin_button_set_value(GTK_SPIN_BUTTON(d.start), start_value); gtk_spin_button_set_value(GTK_SPIN_BUTTON(d.step), step_value); base_text = g_strdup_printf("%d", base_value); gtk_entry_set_text(GTK_ENTRY(d.base), base_text); g_free(base_text); gtk_button_clicked(GTK_BUTTON(lower_case ? d.lower : upper)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d.prefix), base_prefix); gtk_button_clicked(GTK_BUTTON(pad_zeros ? d.zero : space)); gtk_widget_show_all(d.dialog); result = gtk_dialog_run(GTK_DIALOG(d.dialog)); if (result == GTK_RESPONSE_ACCEPT) { if (can_insert_numbers()) { if (end_line - start_line < 1000) { /* quick version */ gtk_widget_hide(d.dialog); insert_numbers(NULL); } else { gboolean cancel = FALSE; gtk_widget_set_sensitive(GTK_WIDGET(grid), FALSE); gtk_widget_set_sensitive(button, FALSE); update_display(); g_signal_connect(d.dialog, "response", G_CALLBACK(on_insert_numbers_response), &cancel); insert_numbers(&cancel); } } else plugin_beep(); /* reloaded or something */ } gtk_widget_destroy(d.dialog); }