]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_write.C
my changes during the holidyas...i expect some compilers to have some problems, but...
[lyx.git] / src / mathed / math_write.C
index 3adbdfd25b918c7c37ca2429564c936898d7b8ba..959a5bcb7fb8115733dfabc0ebe1a6cef804ba80 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <config.h>
+
 #include "LString.h"
 #include "math_inset.h"
 #include "math_iter.h"
 #include "support/lstrings.h"
 #include "debug.h"
 
-extern char const *latex_mathenv[];
-extern char *latex_mathspace[];
+extern char const * latex_mathenv[];
+extern char * latex_mathspace[];
 
 // quite a hack i know. Should be done with return values...
 static int number_of_newlines;
 
-char const *math_font_name[] = {
+char const * math_font_name[] = {
    "mathrm",
    "mathcal",
    "mathbf",
@@ -41,19 +42,20 @@ char const *math_font_name[] = {
 
 
 void
-MathSpaceInset::Write(FILE *outf)
+MathSpaceInset::Write(ostream & os)
 { 
-   if (space>=0 && space<6) {
+   if (space >= 0 && space < 6) {
        string output;
        MathSpaceInset::Write(output);
-       fprintf(outf, "%s", output.c_str());
+       os << output;
    }
 }
 
+
 void
-MathSpaceInset::Write(string &outf)
+MathSpaceInset::Write(string & outf)
 { 
-   if (space>=0 && space<6) {
+   if (space >= 0 && space < 6) {
        outf += '\\';
        outf += latex_mathspace[space];
        outf += ' ';
@@ -62,15 +64,16 @@ MathSpaceInset::Write(string &outf)
 
 
 void
-MathDotsInset::Write(FILE *outf)
+MathDotsInset::Write(ostream & os)
 {
    string output;
    MathDotsInset::Write(output);
-   fprintf(outf, "%s", output.c_str());
-}   
+   os << output;
+}
+
 
 void
-MathDotsInset::Write(string &outf)
+MathDotsInset::Write(string & outf)
 {
    outf += '\\';
    outf += name;
@@ -78,14 +81,15 @@ MathDotsInset::Write(string &outf)
 }   
 
 
-void MathSqrtInset::Write(FILE *outf)
+void MathSqrtInset::Write(ostream & os)
 { 
    string output;
-   MathSqrtInset::Write(output);  
-   fprintf(outf, "%s", output.c_str());
+   MathSqrtInset::Write(output);
+   os << output;
 }
 
-void MathSqrtInset::Write(string &outf)
+
+void MathSqrtInset::Write(string & outf)
 { 
    outf += '\\';
    outf += name;
@@ -95,29 +99,30 @@ void MathSqrtInset::Write(string &outf)
 }
 
 
-void MathDelimInset::Write(FILE *outf)
+void MathDelimInset::Write(ostream & os)
 { 
     string output;
     MathDelimInset::Write(output);
-    fprintf(outf, "%s", output.c_str());
+    os << output;
 }
 
-void MathDelimInset::Write(string &outf)
+
+void MathDelimInset::Write(string & outf)
 { 
-    latexkeys* l = (left != '|') ? lm_get_key_by_id(left, LM_TK_SYM): 0;
-    latexkeys* r = (right != '|') ? lm_get_key_by_id(right, LM_TK_SYM): 0;
+    latexkeys * l = (left != '|') ? lm_get_key_by_id(left, LM_TK_SYM): 0;
+    latexkeys * r = (right != '|') ? lm_get_key_by_id(right, LM_TK_SYM): 0;
     outf += "\\left";
     if (l) {
         outf += '\\';
        outf += l->name;
        outf += ' ';
     } else {
-        if (left=='{' || left=='}') {
+        if (left == '{' || left == '}') {
            outf += '\\';
-           outf += (char) left;
+           outf += char(left);
            outf += ' ';
         } else {
-           outf += (char) left;
+           outf += char(left);
            outf += ' ';
         }
     }
@@ -128,28 +133,29 @@ void MathDelimInset::Write(string &outf)
        outf += r->name;
        outf += ' ';
    } else {
-       if (right=='{' || right=='}') {
+       if (right == '{' || right == '}') {
           outf += '\\';
-          outf += (char) right;
+          outf += char(right);
           outf += ' ';
       } else {
-          outf += (char) right;
+          outf += char(right);
           outf += ' ';
       }
    }        
 }
 
 
-void MathDecorationInset::Write(FILE *outf)
+void MathDecorationInset::Write(ostream & os)
 {
    string output;
    MathDecorationInset::Write(output);
-   fprintf(outf, "%s", output.c_str());
+   os << output;
 }
 
-void MathDecorationInset::Write(string &outf)
+
+void MathDecorationInset::Write(string & outf)
 { 
-   latexkeys* l = lm_get_key_by_id(deco, LM_TK_WIDE);
+   latexkeys * l = lm_get_key_by_id(deco, LM_TK_WIDE);
    outf += '\\';
    outf += l->name;
    outf += '{';
@@ -158,19 +164,20 @@ void MathDecorationInset::Write(string &outf)
 }
 
 
-void MathAccentInset::Write(FILE *outf)
+void MathAccentInset::Write(ostream & os)
 { 
     string output;
     MathAccentInset::Write(output);
-    fprintf(outf, "%s", output.c_str());
+    os << output;
 }
 
-void MathAccentInset::Write(string &outf)
+
+void MathAccentInset::Write(string & outf)
 { 
-    latexkeys* l = lm_get_key_by_id(code, LM_TK_ACCENT);
+    latexkeys * l = lm_get_key_by_id(code, LM_TK_ACCENT);
     outf += '\\';
     outf += l->name;
-    if (code!=LM_not)
+    if (code!= LM_not)
       outf += '{';
     else
       outf += ' ';
@@ -178,7 +185,7 @@ void MathAccentInset::Write(string &outf)
     if (inset) {
       inset->Write(outf);
     } else {
-      if (fn>=LM_TC_RM && fn<=LM_TC_TEXTRM) {
+      if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM) {
         outf += '\\';
         outf += math_font_name[fn-LM_TC_RM];
         outf += '{';
@@ -191,49 +198,51 @@ void MathAccentInset::Write(string &outf)
            outf += ' ';
           }
       } else
-        outf += (char) c;
+        outf += char(c);
 
-      if (fn>=LM_TC_RM && fn<=LM_TC_TEXTRM)
+      if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM)
         outf += '}';
     }
 
-    if (code!=LM_not)
+    if (code!= LM_not)
       outf += '}';
 }
 
 
-void MathBigopInset::Write(FILE *outf)
+void MathBigopInset::Write(ostream & os)
 { 
    string output;
    MathBigopInset::Write(output);
-   fprintf(outf, "%s", output.c_str());
+   os << output;
 }
 
-void MathBigopInset::Write(string &outf)
+
+void MathBigopInset::Write(string & outf)
 { 
     bool limp = GetLimits();
     
     outf += '\\';
     outf += name;
     
-    if (limp && !(sym!=LM_int && sym!=LM_oint && (GetStyle()==LM_ST_DISPLAY)))
+    if (limp && !(sym!= LM_int && sym!= LM_oint && (GetStyle() == LM_ST_DISPLAY)))
       outf += "\\limits ";
     else 
-    if (!limp && (sym!=LM_int && sym!=LM_oint && (GetStyle()==LM_ST_DISPLAY)))
+    if (!limp && (sym!= LM_int && sym!= LM_oint && (GetStyle() == LM_ST_DISPLAY)))
        outf += "\\nolimits ";
     else 
       outf += ' ';
 }
 
 
-void MathFracInset::Write(FILE *outf)
+void MathFracInset::Write(ostream & os)
 { 
    string output;
-   MathFracInset::Write(output);  
-   fprintf(outf, "%s", output.c_str());
+   MathFracInset::Write(output);
+   os << output;
 }
 
-void MathFracInset::Write(string &outf)
+
+void MathFracInset::Write(string & outf)
 { 
    outf += '\\';
    outf += name;
@@ -245,23 +254,23 @@ void MathFracInset::Write(string &outf)
 }
 
 
-void MathParInset::Write(FILE *outf)
+void MathParInset::Write(ostream & os)
 {
    if (!array) return;
    string output;
    MathParInset::Write(output);
-   fprintf(outf, "%s", output.c_str());
+   os << output;
 }
 
 
-void MathParInset::Write(string &outf)
+void MathParInset::Write(string & outf)
 {
    if (!array) return;
    int brace = 0;
-   latexkeys *l;
+   latexkeys * l;
    MathedIter data(array);
    // hack
-   MathedRowSt const* crow = getRowSt();   
+   MathedRowSt const * crow = getRowSt();   
    data.Reset();
     
    if (!Permit(LMPF_FIXED_SIZE)) { 
@@ -274,18 +283,18 @@ void MathParInset::Write(string &outf)
    }
    while (data.OK()) {
       byte cx = data.GetChar();
-      if (cx>=' ') {
+      if (cx>= ' ') {
         int ls;
-        byte *s = data.GetString(ls);
+        byte * s = data.GetString(ls);
        
-        if (data.FCode()>=LM_TC_RM && data.FCode()<=LM_TC_TEXTRM) {
+        if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM) {
             outf += '\\';
             outf += math_font_name[data.FCode()-LM_TC_RM];
             outf += '{';
         }
         while (ls>0) {
            if (MathIsSymbol(data.FCode())) {
-               l = lm_get_key_by_id(*s,(data.FCode()==LM_TC_BSYM)?LM_TK_BIGSYM:LM_TK_SYM);
+               l = lm_get_key_by_id(*s,(data.FCode() == LM_TC_BSYM)?LM_TK_BIGSYM:LM_TK_SYM);
               if (l) {
                 outf += '\\';
                 outf += l->name;
@@ -296,32 +305,32 @@ void MathParInset::Write(string &outf)
               }
            } else {
               // Is there a standard logical XOR?
-              if ((data.FCode()==LM_TC_TEX && *s!='{' && *s!='}') ||
-                  (data.FCode()==LM_TC_SPECIAL))
+              if ((data.FCode() == LM_TC_TEX && *s!= '{' && *s!= '}') ||
+                  (data.FCode() == LM_TC_SPECIAL))
                 outf += '\\';
               else {
-                 if (*s=='{') brace++;
-                 if (*s=='}') brace--;
+                 if (*s == '{') brace++;
+                 if (*s == '}') brace--;
               }
-              if (*s=='}' && data.FCode()==LM_TC_TEX && brace<0) 
+              if (*s == '}' && data.FCode() == LM_TC_TEX && brace<0) 
                       lyxerr <<"Math warning: Unexpected closing brace."
                              << endl;
               else            
-                outf += (char) *s;
+                outf += char(*s);
            }
            s++; ls--;
         }
-        if (data.FCode()>=LM_TC_RM && data.FCode()<=LM_TC_TEXTRM)
+        if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
           outf += '}';
       } else     
       if (MathIsInset(cx)) {
         MathedInset *p = data.GetInset();
-        if (cx==LM_TC_UP)
+        if (cx == LM_TC_UP)
           outf += "^{";
-        if (cx==LM_TC_DOWN)
+        if (cx == LM_TC_DOWN)
           outf += "_{";
         p->Write(outf);
-        if (cx==LM_TC_UP || cx==LM_TC_DOWN)
+        if (cx == LM_TC_UP || cx == LM_TC_DOWN)
           outf += '}';
         data.Next();
       } else
@@ -336,7 +345,7 @@ void MathParInset::Write(string &outf)
            {
                if (crow) {
                    if (!crow->isNumbered()) {  
-                       outf +="\\nonumber ";
+                       outf += "\\nonumber ";
                    }
                    if (crow->getLabel()) {
                        outf += "\\label{";
@@ -358,7 +367,7 @@ void MathParInset::Write(string &outf)
     
     if (crow) {
        if (!crow->isNumbered()) {
-           outf +="\\nonumber ";
+           outf += "\\nonumber ";
        }
        if (crow->getLabel()) {
            outf += "\\label{";
@@ -373,22 +382,23 @@ void MathParInset::Write(string &outf)
 }
 
 
-void MathMatrixInset::Write(FILE *outf)
+void MathMatrixInset::Write(ostream & os)
 {
     string output;
     MathMatrixInset::Write(output);
-    fprintf(outf, "%s", output.c_str());
+    os << output;
 }
 
-void MathMatrixInset::Write(string &outf)
+
+void MathMatrixInset::Write(string & outf)
 {
     if (GetType() == LM_OT_MATRIX){
        outf += "\\begin{";
        outf += name;
        outf += '}';
-       if (v_align=='t' || v_align=='b') {
+       if (v_align == 't' || v_align == 'b') {
            outf += '[';
-           outf += (char) v_align;
+           outf += char(v_align);
            outf += ']';
        }
        outf += '{';
@@ -406,22 +416,24 @@ void MathMatrixInset::Write(string &outf)
 }
 
 
-void mathed_write(MathParInset* p,  FILE* outf, int* newlines,  char fragile, char const* label)
+void mathed_write(MathParInset * p, ostream & os, int * newlines,
+                 char fragile, char const * label)
 {
    string output;
    mathed_write(p, output, newlines, fragile, label);
-   fprintf(outf, "%s", output.c_str());
+   os << output;
 }
 
+
 extern int tex_code_break_column;
 
-void mathed_write(MathParInset* p, string& outf, int* newlines,
-                  char fragile, char const* label)
+void mathed_write(MathParInset * p, string & outf, int * newlines,
+                  char fragile, char const * label)
 {  
    number_of_newlines = 0;
    short mathed_env = p->GetType();
 
-   if (mathed_env==LM_EN_INTEXT) {
+   if (mathed_env == LM_EN_INTEXT) {
      if (fragile) outf += "\\protect";
      outf += "\\( "; // changed from " \\( " (Albrecht Dress)
    } 
@@ -436,7 +448,7 @@ void mathed_write(MathParInset* p, string& outf, int* newlines,
        outf += "\n";
        number_of_newlines++;
      }
-     if (mathed_env==LM_EN_DISPLAY){
+     if (mathed_env == LM_EN_DISPLAY){
        outf += "\\[\n";
      }
      else {
@@ -447,7 +459,7 @@ void mathed_write(MathParInset* p, string& outf, int* newlines,
      number_of_newlines++;
    }
    
-   if (label && label[0]>' ' && mathed_env==LM_EN_EQUATION){
+   if (label && label[0]>' ' && mathed_env == LM_EN_EQUATION){
      outf += "\\label{";
      outf += label;
      outf += "}\n";
@@ -456,11 +468,11 @@ void mathed_write(MathParInset* p, string& outf, int* newlines,
 
    p->Write(outf);
    
-   if (mathed_env==LM_EN_INTEXT){
+   if (mathed_env == LM_EN_INTEXT){
      if (fragile) outf += "\\protect";
      outf += " \\)";
    }
-   else if (mathed_env==LM_EN_DISPLAY){
+   else if (mathed_env == LM_EN_DISPLAY){
      outf += "\\]\n";
      number_of_newlines++;
    }
@@ -468,7 +480,7 @@ void mathed_write(MathParInset* p, string& outf, int* newlines,
      outf += "\n\\end{";
      outf += latex_mathenv[mathed_env];
      outf += "}\n";
-     number_of_newlines+=2;
+     number_of_newlines+= 2;
    }
    *newlines = number_of_newlines;
 }