]> 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 2ea46c45b01e910d15ecca0d331b002a29251315..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;
 
@@ -34,10 +36,24 @@ extern int mathed_char_width(short type, int style, byte c);
 extern int mathed_string_width(short type, int style, byte const* s, int ls);
 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 )
+{
+    char * ps = static_cast<char *>(ps_in);
+    char const * pt = static_cast<char const *>(pt_in);
+    /*
+    for(size_t i = n; i--;)
+       *ps++ = *pt++;
+       */
+    while (n--) *ps++ = *pt++;
+}
+
 
 void MathedIter::Reset()
 {
-    if (array->last>0 && MathIsFont(array->bf[0])) {
+    if (array->last > 0 && MathIsFont(array->bf[0])) {
        fcode = array->bf[0];
        pos = 1;
     } else {
@@ -76,7 +92,7 @@ MathedInset* MathedIter::GetInset()
 {
    if (IsInset()) {
       MathedInset* p;
-      memcpy(&p, &array->bf[pos+1], sizeof(p));
+      my_memcpy(&p, &array->bf[pos+1], sizeof(p));
       return p;
    } else {
           lyxerr << "Math Error: This is not an inset["
@@ -87,10 +103,10 @@ MathedInset* MathedIter::GetInset()
 
 // An active math inset MUST be derived from MathParInset because it 
 // must have at least one paragraph to edit
-MathParInset* MathedIter::GetActiveInset()
+MathParInset * MathedIter::GetActiveInset()
 {
     if (IsActive()) {
-       return (MathParInset*)GetInset();
+       return static_cast<MathParInset*>(GetInset());
     } 
     
     lyxerr << "Math Error: This is not an active inset" << endl;
@@ -267,21 +283,10 @@ void MathedIter::Insert(MathedInset* p, int type)
     if (!MathIsInset(type))
       type = LM_TC_INSET;
     split(shift);
-//      array->bf[pos] = type;
-//      memcpy(&array->bf[pos+1], &p, sizeof(p));
-//      pos += SizeInset;
-//      array->bf[pos-1] = type;
-    {
-       unsigned char *pt = &array->bf[pos];
-       unsigned char *ps = reinterpret_cast<unsigned char*>(&p);
-       size_t i;
-       *pt++ = type;
-       for(i = 0; i < sizeof(p); i++) {
-           *pt++ = *ps++;
-       }
-       *pt = type;
-    }
+    array->bf[pos] = type;
+    my_memcpy(&array->bf[pos+1], &p, sizeof(p));
     pos += SizeInset;
+    array->bf[pos-1] = type;
     array->bf[array->last] = '\0';
     fcode = -1;
 }
@@ -357,7 +362,7 @@ LyxArrayBase *MathedIter::Copy(int pos1, int pos2)
        int dx = pos2 - pos1;
        a = new LyxArrayBase(dx+LyxArrayBase::ARRAY_MIN_SIZE);
 //       lyxerr << "VA " << pos2 << " " << pos2 << " " << dx << endl;
-       memcpy(&a->bf[(fc) ? 1: 0], &array->bf[pos1], dx);
+       my_memcpy(&a->bf[(fc) ? 1: 0], &array->bf[pos1], dx);
        if (fc) {
           a->bf[0] = fc;
           dx++;
@@ -371,7 +376,7 @@ LyxArrayBase *MathedIter::Copy(int pos1, int pos2)
       if (IsInset()) {
         MathedInset* inset = GetInset();
         inset = inset->Clone();
-        memcpy(&array->bf[pos+1], &inset, sizeof(inset));
+        my_memcpy(&array->bf[pos+1], &inset, sizeof(inset));
       }
       Next();
    }
@@ -588,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) {
@@ -624,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;
@@ -866,7 +871,7 @@ void MathedXIter::IMetrics(int pos2, int& width, int& ascent, int& descent)
   
     descent = ascent = width = 0;
     if (!array) return;
-    if (array->Empty()) return;
+    if (array->empty()) return;
 //    if  (pos2 > array->last) return;
     x1 = x; 
     while (pos<pos2) {