LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-13-2006, 05:36 AM   #1
joseftorelli
LQ Newbie
 
Registered: Jul 2006
Posts: 1

Rep: Reputation: 0
GLib problems with g_tree_insert()


Hi all,

I'm rebuilding a server written in C and using open-source GLib.
In particular, after initializing a tree, I would like to full it using the function g_tree_insert(), using a string as key and a struct as data. Here is the function:

void caricaValori(void) {
extern struct dbase head_db;
extern int revoche;
extern mpz_t espowa;
struct row *r1;
unsigned char str_xlow[DIM_STR_SERIALE],str_xhigh[DIM_STR_SERIALE],str_y[DIM_STR_Y],str_y_inv[DIM_STR_Y_INV],intestazione[DIM_INTESTAZIONE], str_in[DIM_STR_IN];
FILE *fd;
#ifdef DEBUG
printf("CARICA_VALORI: ... ");
#endif

strcpy(str_xlow,"");
strcpy(str_xhigh,"");
strcpy(str_y,"");
strcpy(str_y_inv,"");

revoche=0;


if((fd = fopen(nomefile1,"r")) == NULL) {perror("Impossibile aprire il file db in lettura");raise(SIGINT);}
if(fgets(intestazione,DIM_INTESTAZIONE,fd)==NULL) {perror("Niente da leggere nel file db in lettura");}
do {
fscanf(fd,"%s %s %s %s\n",str_xlow,str_xhigh,str_y,str_y_inv);
r1=(struct row*)malloc(sizeof(struct row));
if(strlen(str_xlow)!=0 && strlen(str_xhigh)!=0 && strlen(str_y)!=0 && strlen(str_y_inv)!=0) {
mpz_init_set_str(r1->stat.xlow,str_xlow,BASE);
mpz_init_set_str(r1->stat.xhigh,str_xhigh,BASE); // setta il parametro 1 dalla striga 2 con base BASE
mpz_init_set_str(r1->stat.y,str_y,BASE); // setta il parametro 1 dalla striga 2 con base BASE
mpz_init_set_str(r1->stat.y_inv,str_y_inv,BASE);
mpz_init(r1->stat.z);
r1->stat.valid_z=0; // z non �valido

if(head_db.tqh_first == NULL) { // TODO forse non importa
TAILQ_INSERT_HEAD(&head_db, r1, rows);
revoche++;
}
else {
TAILQ_INSERT_TAIL(&head_db, r1, rows);
revoche++;
}
}
else {
#ifdef DEBUG
printf("DB vuoto\n");
#endif
if(mpz_cmp_ui(espowa,1)!=0) {
perror("Valori di espowa non coerenti con DB vuoto (espowa!=1)");
raise(SIGINT);
}
if(revocaSeriale("0")<1) {
perror("Errore nella revoca di 0");
raise(SIGINT);
}
else revoche++;
break;
}
} while (!feof(fd));
fclose(fd);
if(mpz_cmp_ui(head_db.tqh_first->stat.xhigh,0)!=0 && mpz_cmp_ui(espowa,1)==0) {
perror("Valori di espowa non coerenti con DB pieno (espowa=1)");
raise(SIGINT);
}

r1 = head_db.tqh_first;
while(r1 != NULL) {
mpz_get_str (str_xlow, BASE, r1->stat.xlow);
mpz_get_str (str_xhigh, BASE, r1->stat.xhigh);
strcpy(str_in, "");
strncat(str_in,str_xlow,strlen(str_xlow));
strncat(str_in,str_xhigh,strlen(str_xhigh));
//printf("%s\n", str_in);
g_tree_insert(tree, str_in, r1);
r1 = r1->rows.tqe_next;
}

g_tree_foreach(tree, (GTraverseFunc)iter_all, NULL);

}


This function opens a text file, reads it, fulls a list with all values. Then it is supposed to fill up the tree reading all those values contained in the list, but when I look up the tree with g_tree_foreach, I see that I can find in the tree only the last value, as if the previous values were somehow overwritten. I need instead to fill up the tree with all the values read from the list (the list contains all the values correctly). I'm using GNU MP too.
Please, can anyone help me?

Thanks in advance and sorry for my bad english!

Marco
 
  


Reply

Tags
glib, overwrite, tree


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GLIB problems and more rochmndx Linux - Newbie 3 07-03-2005 12:18 PM
Problems with GLIB ??? burki Linux - Software 2 03-02-2005 04:58 PM
glib problems migu Mandriva 3 02-26-2005 05:02 PM
[GLIB] Problems Installing GLIB ThA_eLMo_GoD Linux - Newbie 2 09-04-2004 05:27 PM
Problems relating to glib 1.2.10 and glib 1.2.9 p3ngu!n Mandriva 10 05-23-2004 09:03 PM


All times are GMT -5. The time now is 11:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration