Advertisement
Sildra

Curses bug panel

Jul 27th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. // Problem solved (line 51)
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <panel.h>
  6. #include <unistd.h>
  7.  
  8. struct list
  9. {
  10.     struct list *next;
  11.     WINDOW *window;
  12.     PANEL *panel;
  13. };
  14.  
  15. static struct list *the_list;
  16.  
  17. void add();
  18. void del();
  19. int count();
  20.  
  21. int main()
  22. {
  23.     initscr();
  24.     the_list = malloc(sizeof(struct list));
  25.     the_list->next = NULL;
  26.     while(1)
  27.     {
  28.     for(int i = 0; i < 100; i++)
  29.     {
  30.         //usleep(20000); // Debug (to slow the output)
  31.         add();
  32.         printf("%d\n", count()); // Debug
  33.         refresh();
  34.     }
  35.     for(int i = 0; i < 100; i++)
  36.     {
  37.         //usleep(20000);
  38.         del();
  39.         printf("%d\n", count());
  40.         refresh();
  41.     }
  42.     }
  43.     free(the_list);
  44.     return 0;
  45. }
  46.  
  47. void del()
  48. {
  49.     struct list **list = &the_list;
  50.     struct list *temp = the_list;
  51.     delwin((*list)->window); //this one must not occur before
  52.     del_panel((*list)->panel); // this one.
  53.     *list = (*list)->next;
  54.     free(temp);
  55. }
  56.  
  57. void add()
  58. {
  59.     struct list **list = &the_list;
  60.     while((*list)->next != NULL)
  61.         list = &(*list)->next;
  62.     (*list)->next = malloc(sizeof(struct list));
  63.     (*list)->next->next = NULL;
  64.     (*list)->window = newwin(0,0,0,0);
  65.     (*list)->panel = new_panel((*list)->window);
  66. }
  67.  
  68. // Just for debug
  69. int count()
  70. {
  71.     int nb = 0;
  72.     struct list **list = &the_list;
  73.     while((*list)->next != NULL)
  74.     {
  75.         list = &(*list)->next;
  76.         nb++;
  77.     }
  78.     return nb;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement