]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_iter.C
several changes and fixes. Read the ChangeLog
[lyx.git] / src / mathed / math_iter.C
index f1f2f1c2ce8795a28d8284d82459d55aa5a0026e..8968d10871d4540f2a79168fdbb57bdd4d447f53 100644 (file)
@@ -7,7 +7,7 @@
  *
  *  Dependencies: Xlib, XForms
  *
- *  Copyright: (c) 1996, Alejandro Aguilar Sierra
+ *  Copyright: 1996, Alejandro Aguilar Sierra
  *
  *   Version: 0.8beta.
  *
@@ -27,6 +27,8 @@
 #include "support/lstrings.h"
 #include "debug.h"
 
+using std::endl;
+
 const int SizeInset = sizeof(char*) + 2;
 const int SizeFont = 2;
 
@@ -36,7 +38,8 @@ extern int mathed_char_height(short, int, byte, int&, int&);
 
 // the builtin memcpy() is broken in egcs and gcc 2.95.x on alpha
 // stations. We provide a hand-made version instead. 
-inline void my_memcpy( void * ps_in, const void * pt_in, size_t n )
+inline
+void my_memcpy( void * ps_in, const void * pt_in, size_t n )
 {
     char * ps = static_cast<char *>(ps_in);
     char const * pt = static_cast<char const *>(pt_in);
@@ -65,21 +68,21 @@ byte MathedIter::GetChar()
 {
     if (IsFont()) { 
        fcode = array->bf[pos];
-       ++pos;
+       pos++;
     }
     return array->bf[pos];
 }
 
 
-byte * MathedIter::GetString(int& len)
+byte* MathedIter::GetString(int& len)
 {
     if (IsFont()) { 
        fcode = array->bf[++pos];
-       ++pos;
+       pos++;
     }
-    byte * s = &array->bf[pos];
+    byte *s = &array->bf[pos];
     len = pos;
-    while (array->bf[pos] >= ' ' && pos<array->last) ++pos;
+    while (array->bf[pos]>= ' ' && pos<array->last) pos++;
     len = pos-len;   
    
    return s;
@@ -88,7 +91,7 @@ byte * MathedIter::GetString(int& len)
 MathedInset* MathedIter::GetInset()
 {
    if (IsInset()) {
-      MathedInset * p;
+      MathedInset* p;
       my_memcpy(&p, &array->bf[pos+1], sizeof(p));
       return p;
    } else {
@@ -116,17 +119,17 @@ bool MathedIter::Next()
    
     if (array->bf[pos]<' ') {
        fcode = -1;     
-       if (IsTab()) ++col;
+       if (IsTab()) col++;
        if (IsCR())  {
            col = 0;
-           ++row;
+           row++;
        }
     }
        
     if (IsInset())
       pos += sizeof(char*) + 2;
     else 
-      ++pos;
+      pos++;
     
     if (IsFont()) {
        fcode = array->bf[pos++];
@@ -180,25 +183,25 @@ void MathedIter::Insert(byte c, MathedTextCodes t)
        
     if (IsFont() && array->bf[pos] == t) {
        fcode = t;
-       ++pos;
+       pos++;
     } else
       if (t!= fcode && pos>0 && MathIsFont(array->bf[pos-1])) {
-         --pos;
-         int k = pos - 1;
-         for (; k >= 0 && array->bf[k]>= ' '; --k);
+         pos--;
+         int k;
+         for (k= pos-1; k>= 0 && array->bf[k]>= ' '; k--);
          fcode = (k >= 0 && MathIsFont(array->bf[k])) ? array->bf[k]: -1;
       }
     short f = (array->bf[pos]<' ') ? 0: fcode;
     int shift = (t == fcode) ? 1: ((f) ? 3: 2);
     
     if (t == LM_TC_TAB || t == LM_TC_CR) {
-       --shift;
+       shift--;
        c = t;
        if (t == LM_TC_CR) {
-           ++row;
+           row++;
            col = 0;
        } else
-         ++col;
+         col++;
     }
  
     if (pos < array->last)
@@ -231,10 +234,10 @@ void MathedIter::split(int shift)
       bool fg = false;
       if (array->bf[pos]>= ' ') {
         if (pos> 0 && MathIsFont(array->bf[pos-1]))
-          --pos;
+          pos--;
         else { 
            fg = true; 
-           ++shift;
+           shift++;
         }
       }      
       array->Move(pos, shift);
@@ -252,18 +255,18 @@ void MathedIter::split(int shift)
 // I assume that both pos and pos2 are legal positions
 void MathedIter::join(int pos2)
 {   
-    if (!OK() || pos2 <= pos)
+    if (!OK() || pos2<= pos)
       return;    
 
-    short f = fcode;       
-    if (pos > 0 && array->bf[pos] >= ' ' && MathIsFont(array->bf[pos-1])) 
-      --pos;   
+    short f= fcode;        
+    if (pos>0 && array->bf[pos]>= ' ' && MathIsFont(array->bf[pos-1])) 
+      pos--;   
            
     if (MathIsFont(array->bf[pos2-1]))
-      --pos2;
+      pos2--;
     
-    if (array->bf[pos2] >= ' ') {
-       for (int p = pos2; p > 0; --p
+    if (array->bf[pos2]>= ' ') {
+       for (int p= pos2; p>0; p--
          if (MathIsFont(array->bf[p])) {
              f = array->bf[p];
              break;
@@ -300,8 +303,8 @@ bool MathedIter::Delete()
       if (MathIsFont(array->bf[pos-1]) && array->bf[pos+1]<' ') {
         int i;
         shift = 2;
-        --pos;
-        for (i = pos - 1; i > 0 && !MathIsFont(array->bf[i]); --i);
+        pos--;
+        for (i= pos-1; i>0 && !MathIsFont(array->bf[i]); i--);
         if (i>0 && MathIsFont(array->bf[i]))
           fcode = array->bf[i];
       } else
@@ -311,7 +314,7 @@ bool MathedIter::Delete()
        shift = sizeof(char*) + 2;
      else 
       if (c == LM_TC_TAB || c == LM_TC_CR) {
-        ++shift;
+        shift++;
 //      lyxerr <<"Es un tab.";
       }
      else {
@@ -338,24 +341,23 @@ LyxArrayBase *MathedIter::Copy(int pos1, int pos2)
       
 //   int posx = pos;
    ipush(); 
-   LyxArrayBase * t = array, *a;
+   LyxArrayBase *t= array, *a;
     
-   if (pos1 > 0 || pos2 <= array->last) {       
+   if (pos1>0 || pos2<= array->last) {       
        short fc= 0;
        if (pos1>0 && array->bf[pos1]>' ') {
-          for (int p = pos1; p >= 0; --p
+          for (int p= pos1; p>= 0; p--
             if (MathIsFont(array->bf[p])) {
                 if (p!= pos1-1)
                   fc = array->bf[p];
                 else
-                  --pos1;
+                  pos1--;
                 break;
             }
        }
 
-       if (pos2 > 0 && array->bf[pos2] >= ' '
-          && MathIsFont(array->bf[pos2-1])) 
-        --pos2;
+       if (pos2>0 && array->bf[pos2]>= ' ' && MathIsFont(array->bf[pos2-1])) 
+        pos2--;
 
        int dx = pos2 - pos1;
        a = new LyxArrayBase(dx+LyxArrayBase::ARRAY_MIN_SIZE);
@@ -363,7 +365,7 @@ LyxArrayBase *MathedIter::Copy(int pos1, int pos2)
        my_memcpy(&a->bf[(fc) ? 1: 0], &array->bf[pos1], dx);
        if (fc) {
           a->bf[0] = fc;
-          ++dx;
+          dx++;
        }
        a->last = dx;
        a->bf[dx] = '\0';
@@ -394,7 +396,7 @@ void MathedIter::Clear()
    Reset();  
    while (OK()) {
       if (IsInset()) {
-        MathedInset * inset = GetInset();
+        MathedInset* inset = GetInset();
          if (inset->GetType()!= LM_OT_MACRO_ARG)
            delete inset;
          Delete();
@@ -519,7 +521,7 @@ void MathedXIter::Merge(LyxArrayBase *a0)
                crow = r;
            } else {
                Delete();
-               --pos2;
+               pos2--;
            }
        }
         Next();    
@@ -591,25 +593,25 @@ bool MathedXIter::Next()
 {  
 //    lyxerr << "Ne[" << pos << "]";
    if (!OK()) return false;
-   int w= 0;
+   int w = 0;
 //   lyxerr << "xt ";
    if (IsInset()) {
-      MathedInset* px = GetInset();
+      MathedInset * px = GetInset();
       w = px->Width();
       if (px->GetType() == LM_OT_SCRIPT) {
-        if (w>sw) sw = w;
+        if (w > sw) sw = w;
         w = 0;
       } else
-       sx = (px->GetLimits()) ? w: 0;
+       sx = (px->GetLimits()) ? w : 0;
    } else {  
       byte c = GetChar();
-      if (c>= ' ') {
+      if (c >= ' ') {
 //       lyxerr << "WD[" << fcode << " " << size << " " << c << endl;
          w = mathed_char_width(fcode, size, c);
       } else
       if (c == LM_TC_TAB && p) {
 //      w = p->GetTab(col+1);
-         w = (crow) ? crow->getTab(col+1): 0;
+         w = (crow) ? crow->getTab(col + 1) : 0;
         //lyxerr << "WW[" << w << "]";
       } else
       if (c == LM_TC_CR && p) {
@@ -627,9 +629,9 @@ bool MathedXIter::Next()
 //       lyxerr <<"LNX " << pos << endl;
 //       if (sw>0 && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
 //        w = (sx>sw) ? 0: sw-sx;
-      if ((sw>0 || sx>0) && GetChar()!= LM_TC_UP && GetChar()!= LM_TC_DOWN) {
-         if (sw>0)
-           w = (sx>sw) ? 0: sw-sx;
+      if ((sw > 0 || sx > 0) && GetChar() != LM_TC_UP && GetChar() != LM_TC_DOWN) {
+         if (sw > 0)
+           w = (sx > sw) ? 0 : sw - sx;
          sx = sw = 0;
       }
       x += w;
@@ -814,7 +816,7 @@ void MathedXIter::ipop()
     if (p) {
        crow = p->getRowSt();
        if (crow)
-         for (int i = 0; i < row; ++i
+         for (int i= 0; i<row; i++
            crow = crow->next;
     }
 }