[PD-cvs] externals/zexy/src msgfile.c,1.4,1.5

IOhannes m zmölnig zmoelnig at users.sourceforge.net
Sun Oct 2 18:07:46 CEST 2005


Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23911

Modified Files:
	msgfile.c 
Log Message:
fixed reentrant bug


Index: msgfile.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/msgfile.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** msgfile.c	9 Jun 2005 12:17:03 -0000	1.4
--- msgfile.c	2 Oct 2005 16:07:44 -0000	1.5
***************
*** 26,34 ****
  #include <fcntl.h>
  #include <string.h>
  #ifdef linux
! #include <unistd.h>
  #endif
  #ifdef __WIN32__
! #include <io.h>
  #endif
  
--- 26,35 ----
  #include <fcntl.h>
  #include <string.h>
+ 
  #ifdef linux
! # include <unistd.h>
  #endif
  #ifdef __WIN32__
! # include <io.h>
  #endif
  
***************
*** 110,137 ****
  }
  
! static void clear_currentnode(t_msgfile *x)
  {
!   t_msglist *dummy = x->current;
!   t_msglist *nxt;
!   t_msglist *prv;
! 
!   if (!dummy) return;
! 
!   freebytes(dummy->thislist, sizeof(dummy->thislist));
!   dummy->thislist = 0;
!   dummy->n = 0;
! 
!   prv = dummy->previous;
!   nxt = dummy->next;
! 
!   if (nxt) nxt->previous = prv;
!   if (prv) prv->next     = nxt;
  
!   if (!prv && !nxt) return;
  
!   x->current = (nxt)?nxt:prv;
!   freebytes(dummy, sizeof(t_msglist));
  }
! static void clear_emptynodes(t_msgfile *x)
  {
    t_msglist *dummy = x->current;
--- 111,136 ----
  }
  
! static void delete_currentnode(t_msgfile *x)
  {
!   if (x&&x->current){
!     t_msglist *dummy = x->current;
!     t_msglist *nxt=dummy->next;
!     t_msglist *prv=dummy->previous;
!     freebytes(dummy->thislist, sizeof(dummy->thislist));
!     dummy->thislist = 0;
!     dummy->n = 0;
!     dummy->next=0;
!     dummy->previous=0;
  
!     freebytes(dummy, sizeof(t_msglist));
!     dummy=0;
  
!     if (nxt) nxt->previous = prv;
!     if (prv) prv->next     = nxt;
!     
!     x->current = (nxt)?nxt:prv;
!   }
  }
! static void delete_emptynodes(t_msgfile *x)
  {
    t_msglist *dummy = x->current;
***************
*** 143,147 ****
    while (x->current && x->current->previous) x->current = x->current->previous;
    while (x->current && x->current->next) {
!     if (!x->current->thislist) clear_currentnode(x);
      else x->current = x->current->next;
    }
--- 142,146 ----
    while (x->current && x->current->previous) x->current = x->current->previous;
    while (x->current && x->current->next) {
!     if (!x->current->thislist) delete_currentnode(x);
      else x->current = x->current->next;
    }
***************
*** 168,172 ****
  
  
!   if (x->current->thislist) x->current = newnode;
  }
  static void insert_currentnode(t_msgfile *x)
--- 167,171 ----
  
  
!   x->current = newnode;
  }
  static void insert_currentnode(t_msgfile *x)
***************
*** 242,256 ****
  static void msgfile_clear(t_msgfile *x)
  {
    while (x->current && x->current->previous) x->current = x->current->previous;
  
!   while (x->current && (x->current->previous || x->current->next)) {
!     clear_currentnode(x);
!   }
!   if (x->current->thislist) {
!     freebytes(x->current->thislist, sizeof(x->current->thislist));
!     x->current->n = 0;
    }
  }
  
  static void delete_region(t_msgfile *x, int start, int stop)
  {
--- 241,255 ----
  static void msgfile_clear(t_msgfile *x)
  {
+   /* find the beginning */
    while (x->current && x->current->previous) x->current = x->current->previous;
  
!   while (x->current) {
!     delete_currentnode(x);
    }
  }
  
+ /* delete from line "start" to line "stop"
+  * if "stop" is negative, delete from "start" to the end
+  */
  static void delete_region(t_msgfile *x, int start, int stop)
  {
***************
*** 262,266 ****
--- 261,267 ----
    int counter = 0;
  
+   /* go to the beginning of the buffer */
    while (dummy && dummy->previous) dummy=dummy->previous;
+   /* go to the end of the buffer */
    while (dummy && dummy->next) {
      counter++;
***************
*** 277,281 ****
    msgfile_goto(x, start);
  
!   while (n--) clear_currentnode(x);
  
    if (newwhere+1) msgfile_goto(x, newwhere);
--- 278,282 ----
    msgfile_goto(x, start);
  
!   while (n--) delete_currentnode(x);
  
    if (newwhere+1) msgfile_goto(x, newwhere);
***************
*** 291,297 ****
      if (pos<0) return;
      if (oldwhere > pos) oldwhere--;
- 
      msgfile_goto(x, pos);
!     clear_currentnode(x);
      msgfile_goto(x, oldwhere);
    } else if (ac==2) {
--- 292,297 ----
      if (pos<0) return;
      if (oldwhere > pos) oldwhere--;
      msgfile_goto(x, pos);
!     delete_currentnode(x);
      msgfile_goto(x, oldwhere);
    } else if (ac==2) {
***************
*** 306,310 ****
        delete_region(x, 0, pos2);
      }
!   } else clear_currentnode(x);
  }
  
--- 306,310 ----
        delete_region(x, 0, pos2);
      }
!   } else delete_currentnode(x);
  }
  
***************
*** 364,374 ****
  {
    t_msglist *cur = x->current;
! 
!   while (x->current && x->current->previous) x->current=x->current->previous;
!   while (x->current && x->current->thislist) {
!     outlet_list(x->x_obj.ob_outlet, gensym("list"), x->current->n, x->current->thislist);
!     x->current = x->current->next;
    }
-   x->current = cur;
  }
  static void msgfile_this(t_msgfile *x)
--- 364,372 ----
  {
    t_msglist *cur = x->current;
!   while (cur && cur->previous) cur=cur->previous;
!   while (cur && cur->thislist) {
!     outlet_list(x->x_obj.ob_outlet, gensym("list"), cur->n, cur->thislist);
!     cur = cur->next;
    }
  }
  static void msgfile_this(t_msgfile *x)
***************
*** 429,440 ****
  {
    int searching = 1;
!   t_msglist *found = x->current;
!   int actu = 0;
  
!   while ((searching) && (x->current) && (x->current->thislist)) {
!     int n = x->current->n;
      int equal = 1;
      t_atom *that = av;
!     t_atom *this = x->current->thislist;
      
      if (ac < n) n = ac;
--- 427,440 ----
  {
    int searching = 1;
!   t_msglist *found = 0;
!   t_msglist *cur=x->current;
  
!   while (cur) {
!     int n = cur->n;
      int equal = 1;
      t_atom *that = av;
!     t_atom *this = cur->thislist;
! 
!     if(0==this)continue;
      
      if (ac < n) n = ac;
***************
*** 450,468 ****
  
      if (equal) {
!       found = x->current;
!       outlet_float(x->x_secondout, node_wherearewe(x));
!       outlet_list(x->x_obj.ob_outlet, gensym("list"), x->current->n, x->current->thislist);
      }
  
!     searching = !(equal);
! 
!     if (x->current && x->current->thislist) {
!       if (x->current->next) x->current = x->current->next;
!       actu++;
!     }
    }
  
!   if (searching) outlet_bang(x->x_secondout);
!   x->current = found;
  }
  
--- 450,468 ----
  
      if (equal) {
!       found = cur;
!       break;
      }
  
!     cur=cur->next;
    }
  
!   if(found){
!     x->current = found;
!     outlet_float(x->x_secondout, node_wherearewe(x));
!     if(found->n && found->thislist)
!       outlet_list(x->x_obj.ob_outlet, gensym("list"), found->n, found->thislist);
!   } else {
!     outlet_bang(x->x_secondout);
!   }
  }
  
***************
*** 475,486 ****
  {
    t_msglist *cur = x->current;
! 
    post("--------- msgfile contents: -----------");
  
!   while (x->current && x->current->previous) x->current=x->current->previous;
!   while (x->current) {
!     t_msglist *dum=x->current;
      int i;
!     startpost("");
      for (i = 0; i < dum->n; i++) {
        t_atom *a = dum->thislist + i;
--- 475,487 ----
  {
    t_msglist *cur = x->current;
!   int j=0;
    post("--------- msgfile contents: -----------");
  
!   while (cur && cur->previous) cur=cur->previous;
!   while (cur) {
!     t_msglist *dum=cur;
      int i;
!     j++;
!     startpost("line %d:", j);
      for (i = 0; i < dum->n; i++) {
        t_atom *a = dum->thislist + i;
***************
*** 488,494 ****
      }
      endpost();
!     x->current = x->current->next;
    }
-   x->current = cur;
  }
  
--- 489,494 ----
      }
      endpost();
!     cur = cur->next;
    }
  }
  
***************
*** 507,511 ****
    }
  
!   clear_emptynodes(x);
  }
  
--- 507,511 ----
    }
  
!   delete_emptynodes(x);
  }
  
***************
*** 742,749 ****
  
      /* an empty node indicates the end of our listbuffer */
!     x->current = (t_msglist *)getbytes(sizeof(t_msglist));
!     x->current->n = 0;
!     x->current->thislist = 0;
!     x->current->previous = x->current->next = 0;
  
      if ((argc==1) && (argv->a_type == A_SYMBOL)) {
--- 742,752 ----
  
      /* an empty node indicates the end of our listbuffer */
!     x->current = 0;
!     /*
!       x->curent = (t_msglist *)getbytes(sizeof(t_msglist));
!       x->current->n = 0;
!       x->current->thislist = 0;
!       x->current->previous = x->current->next = 0;
!     */
  
      if ((argc==1) && (argv->a_type == A_SYMBOL)) {





More information about the Pd-cvs mailing list