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

patch for max columns related errors



[Note: Martin, spam protection is blocking your post.  Email says
Martin_Zampach@ while the list has zampach@.]

Hi,
   here's patch for errors related to max. columns change (resizing window
beyond max. column, etc).
I tried to be consistent with xwpe-1.5.21a behaviour , so right now setting max.
column affects all editor windows , but I'm not sure if line auto-wrapping over
max. column is desired in Watches or Messages window.

Martin Zampach
zampach@eurotel.cz

--- xwpe-1.5.21a/edit.h  Fri Nov 19 04:06:05 1999
+++ xwpe.new/edit.h Thu Dec  9 11:59:37 1999
@@ -154,8 +154,9 @@
 typedef struct BFF {
  STRING *bf;
  POINT b;
- POINT mx;
- int mxlines, cl, clsv;
+ POINT mx; /* maximum column and line */
+ int mxlines; /* number of lines */
+ int cl, clsv;
  Undo *ud, *rd;
  struct CNT *cn;
  struct FNST *f;
@@ -389,6 +390,7 @@

 /*this seems to include the scroll bar to the right*/
 /*it's values is always +1 to the actual visible columns*/
+#define NUM_COLS_ON_SCREEN_SAFE (((f->e.x - f->a.x) < (f->b->mx.x+1)) ? (f->e.x
 - f->a.x) : (f->b->mx.x+1))
 #define NUM_COLS_ON_SCREEN   (f->e.x - f->a.x)

 #define NUM_COLS_OFF_SCREEN_LEFT  (f->s->c.x)
Common subdirectories: xwpe-1.5.21a/old and xwpe.new/old
diff -u xwpe-1.5.21a/we_debug.c xwpe.new/we_debug.c
--- xwpe-1.5.21a/we_debug.c   Fri Nov 19 04:06:05 1999
+++ xwpe.new/we_debug.c  Wed Dec 22 16:26:51 1999
@@ -344,7 +344,7 @@
    BUFFER *b;
    SCHIRM *s;
    int ret, i, is, j, k;
-   char str[128];
+   char str[2049];

    for(i = cn->mxedt; i > 0 && strcmp(cn->f[i]->datnam, "Messages"); i--);
    if(i <= 0) {  e_edit(cn, "Messages");  i = cn->mxedt;  }
@@ -353,51 +353,21 @@
    s = cn->f[i]->s;
    if(b->bf[b->mxlines-1].len != 0)  e_new_line(b->mxlines, b);
    for(j = 0, i = is = b->mxlines-1;
-      (ret = e_d_line_read(wfildes[0], str, 128, 0, 0)) == 0; )
+      (ret = e_d_line_read(wfildes[0], str, 2048, 0, 0)) == 0; )
    {  if(ret == -1) return(ret);
-      k = 0;
-      do
-      {  if(j == 0) e_new_line(i, b);
-     for(; j < NUM_COLS_ON_SCREEN - 2 && str[k] != '\n'
-        && str[k] != '\0'; j++, k++) *(b->bf[i].s+j) = str[k];
-     if(str[k] != '\0')
-     {  *(b->bf[i].s+j) = '\n';
-        *(b->bf[i].s+j+1) = '\0';
-        b->bf[i].len = j;
-        b->bf[i].nrc = j + 1;
-        if(str[k] != '\n') i++;
-        j = 0;
-     }
-      }
-      while(str[k] != '\n' && str[k] != '\0');
-      if(str[k] != '\0')
-      {  b->b.y = i;
-     e_cursor(f, 1);
-     e_schirm(f, 1);
-     e_refresh();
-     i++;
-     j = 0;
-      }
+      print_to_end_of_buffer(b, str, b->mx.x);
    }
    if(ret == 1)
    {  e_new_line(i, b);
-      for(j = 0; j < NUM_COLS_ON_SCREEN - 2 && str[j] != '\n'
+      for(j = 0; j < NUM_COLS_ON_SCREEN_SAFE - 2 && str[j] != '\n'
      && str[j] != '\0'; j++) *(b->bf[i].s+j) = str[j];
       b->b.y = i;
       b->b.x = b->bf[i].len = j;
       b->bf[i].nrc = j;
    }
-   else
-   {  b->b.y = b->mxlines-1;
-      b->b.x = 0;
-   }
-/*
-      e_switch_window(save, cn->f[cn->mxedt]);
-*/ /*
-      e_cursor(f, 1);
-      e_schirm(f, 1);
-      e_refresh();
-*/
+   b->b.y = b->mxlines-1;
+   b->b.x = 0;
+
    e_rep_win_tree(cn);
    return(ret);
 }
@@ -666,6 +636,7 @@
  SCHIRM *s;
  int iw, i, j, k = 0, l, ret;
  char str1[256], *str = str1;
+ char str2[2049];

  e_d_switch_out(0);
  if ((e_d_swtch > 2) && (e_d_p_stack(f, 0) == -1))
@@ -691,6 +662,9 @@
  b = cn->f[iw]->b;
  s = cn->f[iw]->s;
  e_p_red_buffer(b);
+ FREE(b->bf[0].s);
+ b->mxlines=0;
+
  for (i = 0, l = 0; l < e_d_nwtchs; l++)
  {
   /* Create appropriate command for the debugger */
@@ -763,47 +737,13 @@
    }
   }

-  /* Add lines to the buffer if needed */
-  if (i == b->mxlines) e_new_line(i, b);
   /* Print variable name */
-  strcpy(b->bf[i].s, e_d_swtchs[l]);
-  strcat(b->bf[i].s, ": ");
-  e_d_nrwtchs[l] = i;
-  do
-  {
-   for ( ; str[k] != '\0' && isspace(str[k]); k++);
-   for (j = strlen(b->bf[i].s);
-     j < NUM_COLS_ON_SCREEN - 2 && str[k] != '\n' && str[k] != '\0';
-     j++, k++)
-   {
-    *(b->bf[i].s+j) = str[k];
-   }
-   if (str[k] != '\n')
-   {
-    int it;
-
-    for (it = j - 1;
-      it > 0 && *(b->bf[i].s+it) != ',' && *(b->bf[i].s+it) != ';'; it--);
-    if(it > 0)
-    {
-     k -= (j - it - 1);
-     j = it + 1;
-    }
-   }
-   *(b->bf[i].s+j) = '\n';
-   *(b->bf[i].s+j+1) = '\0';
-   b->bf[i].len = j;
-   b->bf[i].nrc = j + 1;
-   i++;
-   j = 0;
-   if(str[k] != '\n')
-   {
-    if(i == b->mxlines) e_new_line(i, b);
-    strcpy(b->bf[i].s, "     ");
-   }
-  }
-  while(str[k] != '\n');
+  for ( ; str[k] != '\0' && isspace(str[k]); k++);
+  sprintf(str2,"%s: %s",e_d_swtchs[l],str);

+  print_to_end_of_buffer(b, str2, b->mx.x);
+  e_d_nrwtchs[l] = b->mxlines-1;
+
   /* Free any allocated string */
   if(str != str1)
   {
@@ -812,8 +752,6 @@
   }
  }

- /* Add a blank line if needed */
- if (i == b->mxlines) e_new_line(i, b);
  fk_cursor(1);
  if (b->b.y > i || sw) b->b.y = i;
  if (sw && iw != cn->mxedt) e_switch_window(cn->edt[iw], cn->f[cn->mxedt]);
@@ -950,7 +888,7 @@
    }
    for(; isspace(str[k]); k++)
     ;
-   for(; j < NUM_COLS_ON_SCREEN - 2 && str[k] != '\n' && str[k] != '\0';
+   for(; j < NUM_COLS_ON_SCREEN_SAFE - 2 && str[k] != '\n' && str[k] != '\0';
      j++, k++)
     *(b->bf[i].s+j) = str[k];
    if (str[k] != '\0')
diff -u xwpe-1.5.21a/we_prog.c xwpe.new/we_prog.c
--- xwpe-1.5.21a/we_prog.c    Fri Nov 19 04:06:05 1999
+++ xwpe.new/we_prog.c   Wed Dec 22 16:29:06 1999
@@ -215,7 +215,8 @@
   e_free_arg(e_arg, e_argc);
  }
  if (file != 0)
-  i = e_p_exec(file, f, pic);
+  i =
+  e_p_exec(file, f, pic);
  else
  {
   i = WPE_ESC;
@@ -233,6 +234,7 @@
  SCHIRM *s;
  char estr[256];
  int len, ret;
+ char str[2048];

  efildes[0] = efildes[1] = -1;
  wfildes[0] = wfildes[1] = -1;
@@ -285,10 +287,10 @@
  f = cn->f[cn->mxedt];
  b = cn->f[cn->mxedt]->b;
  s = cn->f[cn->mxedt]->s;
- e_new_line(b->mxlines, b);
- sprintf((char *)b->bf[b->mxlines-1].s, e_p_msg[ERR_RETCODE], ret);
- b->b.x = b->bf[b->mxlines-1].len =
-   b->bf[b->mxlines-1].nrc = strlen((char *)b->bf[b->mxlines-1].s);
+
+ sprintf(str, e_p_msg[ERR_RETCODE], ret);
+ print_to_end_of_buffer(b, str, b->mx.x);
+
  b->b.y = b->mxlines-1;
  e_cursor(f, 1);
  e_schirm(f, 1);
@@ -472,73 +474,30 @@
  BUFFER *b = cn->f[cn->mxedt]->b;
  int ret = 0, i = 0, is, j, k, l = 0, m = 0, fd, stat_loc;
  char str[128];
+ char *buff, *buff2;
+

  f = cn->f[cn->mxedt];
  while ((ret = wait(&stat_loc)) >= 0 && ret != e_save_pid)
   ;
  ret = 0;
- if (!b->mxlines || b->bf[b->mxlines-1].len != 0)
-  e_new_line(b->mxlines, b);
  for (is = b->mxlines-1, fd = efildes[0]; fd > 0; fd = wfildes[0])
  {
-  for (j = 0, i = b->mxlines-1; e_line_read(fd, str, 128) == 0; )
+  buff=MALLOC(1);
+  buff[0]='\0';
+  while( e_line_read(fd, str, 128) == 0 )
   {
-   k = 0;
-   do
-   {
-    if(j == 0)
-     e_new_line(i, b);
-    for (; j < NUM_COLS_ON_SCREEN - 2 && str[k] != '\n' && str[k] != '\0';
-      j++, k++)
-     *(b->bf[i].s+j) = str[k];
-    if (str[k] != '\0')
-    {
-     if (str[k] != '\n')
-     {
-      for (l = j-1; l > 0 && !isspace(b->bf[i].s[l]); l--)
-       ;
-      if (l > 0)
-      {
-       e_new_line(i+1, b);
-       for (m = l; m < j; m++)
-       {
-        b->bf[i+1].s[m-l] = b->bf[i].s[m];
-        b->bf[i].s[m] = ' ';
-       }
-      }
-      *(b->bf[i].s+j) = '\\';
-      j++;
-     }
-     *(b->bf[i].s+j) = '\n';
-     *(b->bf[i].s+j+1) = '\0';
-     b->bf[i].len = j;
-     b->bf[i].nrc = j + 1;
-     if (str[k] != '\n')
-     {
-      i++;
-      j = m - l;
-     }
-     else
-      j = 0;
-    }
-   } while (str[k] != '\n' && str[k] != '\0');
-   if (str[k] != '\0')
-   {
-    b->b.y = i;
-    e_cursor(f, 1);
-    e_schirm(f, 1);
-#ifndef NO_XWINDOWS
-    if (WpeIsXwin())
-     ret = (*e_u_change)(pic);
-#endif
-    e_refresh();
-    fflush(stdout);
-    i++;
-    j = 0;
-   }
+   buff2=REALLOC(buff, strlen(buff) + strlen(str) + 1);
+   buff=buff2;
+   strcat(buff, str);
+
+   fflush(stdout);
   }
-  if (fd == wfildes[0])
-   break;
+  print_to_end_of_buffer(b, buff, b->mx.x);
+  FREE(buff);
+
+  if( fd == wfildes[0] )
+    break;
  }
  b->b.y = b->mxlines-1;
  if (efildes[0] >= 0)
@@ -571,9 +530,9 @@
    e_show_error(err_no = 0, f);
   return(-1);
  }
- strcpy((char *)b->bf[b->mxlines-1].s, "Success");
- b->bf[b->mxlines-1].len = 7;
- b->bf[b->mxlines-1].nrc = 7;
+
+ print_to_end_of_buffer(b, "Success", b->mx.x);
+
  e_cursor(f, 1);
  e_schirm(f, 1);
  e_refresh();
@@ -1476,6 +1435,7 @@
  PIC *outp;
  FENSTER *f;

+
 #if  MOUSE
  g[0] = 2;
  fk_mouse(g);
@@ -1504,6 +1464,59 @@
  return(ret);
 }

+/* arranges string str into buffer b and eventually wrappes string around
wrap_limit columns */
+int print_to_end_of_buffer(BUFFER * b,char * str,int wrap_limit)
+{
+int i,k,j;
+
+ k = 0;
+ do
+ {
+  if(wrap_limit != 0)
+     for (j=0;((j < wrap_limit) && (!((str[j + k] == '\n') || (str[j + k] ==
'\0')))); j++) ;
+  else
+     for (j=0;(!((str[j + k] == '\n') || (str[j + k] == '\0'))); j++) ;
+
+// b->mxlines - count of lines in b
+// so add one more line at the end of buffer
+  e_new_line(b->mxlines,b);
+  i = b->mxlines-1;
+
+// copy char from string (str) to buffer
+
+  if(str[j + k]!='\0') b->bf[i].s=REALLOC(b->bf[i].s,j + 2);
+  else b->bf[i].s=REALLOC(b->bf[i].s,j + 1);
+  strncpy(b->bf[i].s,str + k,j);
+
+// if this is not end of string, then we created substring
+// if *(b->bf[i].s+j) is not '\0' then it is soft break is not written to file
+
+  if(str[j + k]!='\0') {
+    *(b->bf[i].s + j) = '\n';
+    *(b->bf[i].s + j + 1) = '\0';
+  }
+  else {
+    *(b->bf[i].s + j) = '\0';
+
+  }
+// update len of line in buffer
+  b->bf[i].len = j;
+  b->bf[i].nrc = j + 1;
+
+  if(str[j + k]=='\n') {
+    j++;
+  }
+
+  k+=j;
+
+// loop until end of string
+// } while (str[k] != '\n' && str[k] != '\0');
+ } while (str[k] != '\0');
+
+return 0;
+}
+
+/* print to message window */
 int e_d_p_message(char *str, FENSTER *f, int sw)
 {
  ECNT *cn = f->ed;
@@ -1522,26 +1535,22 @@
   else
    i = cn->mxedt;
  }
+
+// f - window
  f = cn->f[i];
+
+// b - buffer
  b = cn->f[i]->b;
+
+// s - content of window
  s = cn->f[i]->s;
- k = 0;
- do
- {
-  e_new_line(b->mxlines, b);
-  i = b->mxlines-1;
-  for (j = 0; j < NUM_COLS_ON_SCREEN - 2 && str[k] != '\n' && str[k] != '\0';
-    j++, k++)
-   *(b->bf[i].s+j) = str[k];
-  if (str[k] != '\0')
-  {
-   *(b->bf[i].s+j) = '\n';
-   *(b->bf[i].s+j+1) = '\0';
-  }
-  b->bf[i].len = j;
-  b->bf[i].nrc = j + 1;
- } while (str[k] != '\n' && str[k] != '\0');
+
+ print_to_end_of_buffer(b, str, b->mx.x);
+
+// place cursor on the last line
  b->b.y = b->mxlines-1;
+
+
  if (sw)
   e_rep_win_tree(cn);
  else if (WpeIsXwin())
diff -u xwpe-1.5.21a/we_progn.c xwpe.new/we_progn.c
--- xwpe-1.5.21a/we_progn.c   Fri Nov 19 04:06:05 1999
+++ xwpe.new/we_progn.c  Thu Dec  9 19:15:15 1999
@@ -481,7 +481,7 @@
    fsw = 1;
    break;
   }
- for (j = s->c.x; i < b->bf[y].len && j < NUM_COLS_ON_SCREEN + s->c.x - 1; i++,
 j++)
+ for (j = s->c.x; i < b->bf[y].len && j < NUM_COLS_ON_SCREEN_SAFE + s->c.x - 1;
 i++, j++)
  {
   e_mk_col(b->bf[y].s, i, frb, f->c_st, n_nd, n_bg);
   if ( y == s->da.y && i >= s->da.x && i < s->de.x )
@@ -491,7 +491,7 @@
   else if ( y == s->fa.y && i >= s->fa.x && i < s->fe.x )
    frb = s->fb->ek.fb;
 #else
- for (j = s->c.x; i < b->bf[y].len && j < NUM_COLS_ON_SCREEN + s->c.x - 1; i++,
 j++)
+ for (j = s->c.x; i < b->bf[y].len && j < NUM_COLS_ON_SCREEN_SAFE + s->c.x - 1;
 i++, j++)
  {
   e_mk_col(b->bf[y].s, i, frb, f->c_st, n_nd, n_bg);
   if ( y == s->fa.y && i >= s->fa.x && i < s->fe.x )
@@ -550,7 +550,7 @@

  e_mk_col(b->bf[y].s, i, frb, f->c_st, n_nd, n_bg);

- if (i == b->bf[y].len && f->dtmd == 's' && j < NUM_COLS_ON_SCREEN + s->c.x -
1)
+ if (i == b->bf[y].len && f->dtmd == 's' && j < NUM_COLS_ON_SCREEN_SAFE +
s->c.x - 1)
  {
   if ((y < s->mark_end.y && ( y > s->mark_begin.y ||
     (y == s->mark_begin.y && i >= s->mark_begin.x) ) ) ||