[C/GTK]probleem met clists

Pagina: 1
Acties:

  • Thijsch
  • Registratie: Februari 2002
  • Laatst online: 22-08 19:17
hey, ik ben bezig met hottopics voor linux en ik loop tegen een vaag probleem aan:
als je een topic aan de lijst toevoegd:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
text = gtk_editable_get_chars((gpointer)entry,50,56);
     
  //printf("%s\n",text);
  topics->id = text;
  topics->title = NULL;
  topics->topicstarter = NULL;
  topics->lastReplier = NULL;
  topics->replies = NULL;
  topics->forumshort = NULL;
  printf("%s\n",topics->id);
  /* Get the text */
  gtk_entry_set_text(GTK_ENTRY(entry), ""); 
  current_topics = g_list_append(current_topics, (gpointer) topics);
  sync_clist(current_topics);


sync list update de clist, vervolgens word de xml ontcijferd:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
gboolean xml_to_topiclist(char *xmldata, int xmllen)
{
  xmlDocPtr doc;
  xmlNodePtr root, cur, topic;
  topicListItem *listItem;
  topicListItem *newlist3;
  GList *newtopics = NULL;
  //GList *current_topics\ = NULL;
  
  doc = xmlParseMemory(xmldata, xmllen);
  
  <knip>
              
              listItem->lastReplier = content;
                    
            g_free(content);
            topic = topic->next;
          }
          newtopics = g_list_append(newtopics, (gpointer) listItem);
          g_free(listItem);
        }
        cur = cur->next;
    }
    xmlFreeDoc(doc);
    current_topics = topiclist;
    topiclist = newtopics;
    

    newlist3 = (topicListItem *) topiclist;
    g_list_free(current_topics);
    g_list_foreach(topiclist, check, NULL);

    return TRUE;
}

en check:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void check(gpointer element, gpointer data)
{
<knip>
  for(row=0;row<rows;row++)
    {
      printf("rows: %d\n",rows);
      gtk_clist_get_text((gpointer) GTK_CLIST(clist),row,0,&topicid);
      printf("topicid: %d\n",(gint)topicid);
      gtk_clist_get_text((gpointer)GTK_CLIST(clist),row,4,&replies);
      printf("Replies: %d\n",(gint)replies);
      printf("Topicid_new: %d\n",(gint)newlist2->id);
           if((gint)topicid == (gint) newlist2->id)
    {
      printf("topicid hetzeluvde!\n");
      if((gint)replies >= 1)
        {
          if((gint)replies < (gint)newlist2->replies)
        {
          printf("WOEI! nieuwe reply!!!\n");
        }
        }
      printf("%s/%s/%s/%s/%s/%s\n", newlist2->id, newlist2->title,newlist2->forumshort,newlist2->replies,newlist2->topicstarter,newlist2->lastReplier);  
      topiclist2 = g_list_append(topiclist2, (gpointer) newlist2);
      sync_clist(topiclist2);
    }
      else {
    printf("nix gevonden :( \n");
    printf("%d\n",(gint)(gpointer)topicid);
      }
    }
  return;

}


het geeft als output(na het toevoegen van een topic en een update):

code:
1
2
3
4
5
6
7
626254      (het topicid dat is toegevoegd, klopt)
1              (het aantal rijen in de clist)
rows: 1       (in functie: check:  het aantal rijen: klopt)
topicid: 134809784   (topicid:  :? :? :? waar ie dit vandaan haalt  :?)
Replies: 134811120  (hetzelde verhaal :? :? )
Topicid_new: 1080796848  (het topic id dat is uit de xml haalt :?)
nix gevonden :(  (dat klopt)


de fout zit hem er dus in dat het topicID en de replies niet juist uit de clist gelezen worden EN dat het topicID uit de XML niet goed doorkomt. Als ik in de functie xml_to_topiclist dit zet: printf("%s\n",listItem->id);

staat daar het topicid goed. in het parsen zit het dus niet. dan zit het in het doorgeven van de ene naar de andere functie? maar ik zie niet wat er nou precies fout zit?

is er iemand die me hierbij kan helpen?

  • Thijsch
  • Registratie: Februari 2002
  • Laatst online: 22-08 19:17
ik denk dat ik het specifieker heb gevonden:

PHP:
1
2
3
4
 printf("1: %s\n",listItem->id);
 newtopics = g_list_append(newtopics, (gpointer) listItem);

 printf("%s\n",((topicListItem *)newtopics)->id);


de eerste printf gaat goed maar de 2e niet.

eerder werd de hele lijst doorgestuurt naar sync_clist(topiclist); en werd het weggeschreven , aangezien ik eerst wil controleren of het topic in de lijst staat, heb ik een functie( check_init) gemaakt :

PHP:
1
2
3
4
5
void check_init(GList *list)  
{
    g_list_foreach(list, check, NULL);
    return;
}


die exact hetzelfde is als sync_list op de functie die ie aanroept na. nu heb ik wat zitten prutsen en ziet de functie check er zo uit:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void check(gpointer element, gpointer data)
{
  topicListItem *newlist2 = (topicListItem *) element;
  GList *topiclist2 = NULL;
  gchar *topicid;
  gchar *replies;
  gint oldlist_id, oldlist_replies, row, newlist_id, newlist_replies;
  
  printf("5: %i\n",newlist2->id);
  for(row=0;row<rows;row++)
    {

      gtk_clist_get_text((gpointer) GTK_CLIST(clist),row,0,&topicid);
      gtk_clist_get_text((gpointer)GTK_CLIST(clist),row,4,&replies);

      printf("newlist2->id : %i\n", (gint)newlist2->id);
      newlist_id = atoi(newlist2->id);
      newlist_replies = atoi(newlist2->replies);
      oldlist_id = atoi(topicid);
      oldlist_replies = atoi(replies);

      if(oldlist_id == newlist_id)
    {
      printf("topicid hetzeluvde!\n");
      if(oldlist_replies >= 1)
        {
          if(oldlist_replies < newlist_replies)
        {
          printf("WOEI! nieuwe reply!!!\n");
        }
        }
      topiclist2 = g_list_append(topiclist2, (gpointer) newlist2);
      sync_clist(topiclist2);
    }
      else {
    printf("nix gevonden :( \n");
    printf("newlist_id: %d\n",newlist_id);
      }
    }
  return;

}


maar het werkt niet???
hij zegt dat newlist_id dit is:
newlist2->id : 1080796848

:? wat kan hier aan de hand zijn? ik denk dat dat met die pointers fout zit maar ik kom er maar niet achter wat PRECIES?