Problems with g_signal_connect_swapped()



Hello, this is my first post, I'm from México and my english is not good, I hope you understand my posts, by the way, I'm a begginer in Gtk+.
 
Well, I have a probem, I 've wriiten a small program that lexically analize words, those are: getc, gets, getch & getchar. My program uses an automata algorythm with its transition table. I made a GUI with Gtk that uses a GtkEntry that receive the word to analize and a button with label 'Analizar', when I type a word and make 'click' in the button, the program ends and the console shows a message: 'Segment viotation', the program should generate a dialog window with the message: 'Cadena Aceptada' or 'Cadena No Reconocida'.
 
The porgram in console mode runs normally and make the things good.
 
The code is the following:
 
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
gint tabla[6][5] = {1,-1,-1,-1, 2,
     -1, 3,-1,-1,-1,
      -1,-1,-1,-1,-1,
     -1,-1, 4,-1,-1,
      -1,-1,-1, 5,-1,
            -1,-1,-1,-1,-1};
gint Ei = 0, F[4] = {1,2,3,5};
gchar cadena[5] = {'c','h','a','r','s'};
gint salir(GtkWidget *win, gpointer dato)
{
 g_print("Saliendo de la aplicación...\n");
 gtk_main_quit();
 return FALSE;
}
gint mueve(gint St, gchar cad)
{
 int x;
 for (x = 0; x < 5; x++)
  if (cad == cadena[x])
   return tabla[St][x];
 return -1;
}
gint buscar(gint St)
{
 int x;
 for (x = 0; x < 4; x++)
  if (St == F[x])
   return 0;  
 return 1;
}
void lexico(GtkWidget *campo)
{
 GtkWidget *otra_win, *mensaje, *ok, *box;
 
 otra_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_window_set_title(GTK_WINDOW(otra_win),"Resultado");
 gtk_window_set_default_size(GTK_WINDOW(otra_win),200,80);
 gtk_container_border_width(GTK_CONTAINER(otra_win),15);
 ok = gtk_button_new_with_label("Hecho");
 box = gtk_vbox_new(FALSE,10);
 gchar *str, *res = '\0';
 gint S = Ei, i = 0, tot;
 strcpy(str,gtk_entry_get_text(GTK_ENTRY(campo)));
 tot = strlen(str);
 i = 3;
 if (!strncmp("get",str,3))
  while(i < tot)
  {
   if (S < 0)
    break;
   S = mueve(S, str[i]);
   i++;
  } if (!buscar(S))
  res = "Cadena Aceptada";
 else
  res = "Cadena No Reconocida";
 
 mensaje = gtk_label_new(res);
 gtk_box_pack_start(GTK_BOX(box),mensaje,FALSE,FALSE,0);
 gtk_box_pack_start(GTK_BOX(box),ok,FALSE,FALSE,0);
 g_signal_connect_swapped(G_OBJECT(ok),"clicked",G_CALLBACK(gtk_widget_destroy),G_OBJECT(otra_win));
 gtk_container_add(GTK_CONTAINER(otra_win),box);
 gtk_widget_show_all(otra_win);
}
int main(int argc, char *argv[])
{
 GtkWidget *win, *label, *entry, *btn_ok, *hbox, *vbox;
 gtk_init(&argc,&argv);
 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_window_set_title(GTK_WINDOW(win),"Analizador Léxico");
 gtk_container_border_width(GTK_CONTAINER(win),15);
 g_signal_connect(G_OBJECT(win),"delete_event",G_CALLBACK(salir),NULL);
 hbox = gtk_hbox_new(FALSE,5);
 vbox = gtk_vbox_new(FALSE,10);
 
 label = gtk_label_new("Cadena");
 entry = gtk_entry_new();
 btn_ok = gtk_button_new_with_label("Analizar");
 
 gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
 gtk_box_pack_start(GTK_BOX(hbox),entry,FALSE,FALSE,0);
 gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);
 gtk_box_pack_start(GTK_BOX(vbox),btn_ok,FALSE,FALSE,0);
 g_signal_connect_swapped(G_OBJECT(btn_ok),"clicked",G_CALLBACK(lexico),entry);
 gtk_container_add(GTK_CONTAINER(win),vbox);
 gtk_widget_show_all(win);
 gtk_main();
 return 0;
}

I used Gtk+ v.2.2.4, I hope you help me. Thanks



MSN. Más Útil Cada Día Haz clic aquí. 2 months FREE*

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