/* ------------------------------------------------------------------------*//** * @FUNCTION irq_occurred_list_sort * @BRIEF sort list by irq occurrence decreasing order * @RETURNS 0 in case of success * IRQ_ERR_ARG * IRQ_ERR_INTERNAL * @param[in,out] list: populated list of IRQ stats. * @DESCRIPTION sort list by irq occurrence decreasing order. * Use bubble sort algorithm. *//*------------------------------------------------------------------------ */ int irq_occurred_list_sort(genlist *list) { unsigned int i, max, tmpmax; irq_info inf1, inf2; if (list == NULL) { fprintf(stderr, "%s(): list = NULL!\n", __func__); return IRQ_ERR_ARG; } max = genlist_getcount(list); while (max > 0) { tmpmax = 0; for (i = 0; i < max - 1; i++) { genlist_get(list, i, (irq_info *) &inf1); genlist_get(list, i + 1, (irq_info *) &inf2); if (inf1.count < inf2.count) { genlist_add(list, (void *) &inf2, sizeof(irq_info), i); genlist_remove(list, i + 2); tmpmax = i + 1; } } max = tmpmax; } return 0; }
/***************************************************************************** Called when the return key is pressed. *****************************************************************************/ static void luaconsole_input_return(GtkEntry *w, gpointer data) { const char *theinput; struct luaconsole_data *pdialog = luaconsole_dialog_get(); fc_assert_ret(pdialog); fc_assert_ret(pdialog->history_list); theinput = gtk_entry_get_text(w); if (*theinput) { luaconsole_printf(ftc_luaconsole_input, "(input)> %s", theinput); script_client_do_string(theinput); if (genlist_size(pdialog->history_list) >= MAX_LUACONSOLE_HISTORY) { void *data; data = genlist_get(pdialog->history_list, -1); genlist_remove(pdialog->history_list, data); free(data); } genlist_prepend(pdialog->history_list, fc_strdup(theinput)); pdialog->history_pos = -1; } gtk_entry_set_text(w, ""); }
/************************************************************************** Called when the return key is pressed. **************************************************************************/ static void inputline_return(GtkEntry *w, gpointer data) { const char *theinput; theinput = gtk_entry_get_text(w); if (*theinput) { if (client_state() == C_S_RUNNING && gui_gtk2_allied_chat_only && is_plain_public_message(theinput)) { char buf[MAX_LEN_MSG]; fc_snprintf(buf, sizeof(buf), ". %s", theinput); send_chat(buf); } else { send_chat(theinput); } if (genlist_size(history_list) >= MAX_CHATLINE_HISTORY) { void *data; data = genlist_get(history_list, -1); genlist_remove(history_list, data); free(data); } genlist_prepend(history_list, fc_strdup(theinput)); history_pos=-1; } gtk_entry_set_text(w, ""); }