Ejemplo n.º 1
0
genlist *
genlist_insert(genlist *list, void *data, int position)
{
    genlist *p;
    genlist *h = genlist_first(list);
    
    /* assume the length was checked by user.
       0 is prepend, length is append */
    while(position--)
    {
        h = h->next;
    }

    if(!h)
    {
        return genlist_append(list, data);
    }

    if(!h->prev)
    {
        return genlist_prepend(list, data);
    }
    
    p = genlist_alloc();
    p->data = data;

    p->prev = h->prev;
    p->next = h;

    h->prev->next = p;
    h->prev = p;

    return p;
}
Ejemplo n.º 2
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, "");
}
Ejemplo n.º 3
0
/**************************************************************************
  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, "");
}