]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
More fixes to insettabular/text (and some missing features added).
[lyx.git] / src / buffer.C
index 869ab7d367bece7cc9a95b7e2a0a80637cbc3d30..d0b864ef9a9eb1cb287d85941835c1be66d9e774 100644 (file)
@@ -18,6 +18,7 @@
 #include <iomanip>
 
 #include <cstdlib>
+#include <cmath>
 #include <unistd.h>
 #include <sys/types.h>
 #include <utime.h>
@@ -484,7 +485,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                if (pp.first) {
                        params.textclass = pp.second;
                } else {
-                 lex.printError("Unknown textclass `$$Token'");
+                       WriteAlert(string(_("Textclass error")), 
+                               string(_("The document uses an unknown textclass \"")) + 
+                               lex.GetString() + string("\"."),
+                               string(_("LyX will not be able to produce output correctly.")));
                        params.textclass = 0;
                }
                if (!textclasslist.Load(params.textclass)) {
@@ -807,9 +811,14 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                int tmpret = lex.FindToken(string_align);
                if (tmpret == -1) ++tmpret;
                if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
+#if 0
                        int tmpret2 = 1;
                        for (; tmpret > 0; --tmpret)
                                tmpret2 = tmpret2 * 2;
+#else
+                       int const tmpret2 = int(pow(2.0, tmpret));
+#endif
+                       //lyxerr << "Tmpret2 = " << tmpret2 << endl;
                        par->align = LyXAlignment(tmpret2);
                }
        } else if (token == "\\added_space_top") {
@@ -1265,225 +1274,6 @@ bool Buffer::writeFile(string const & fname, bool flag) const
 }
 
 
-#if 0
-void Buffer::writeFileAscii(string const & fname, int linelen) 
-{
-       Inset * inset;
-       char c;
-       char footnoteflag = 0;
-       char depth = 0;
-       string tmp;
-       LyXParagraph::size_type i;
-       int j;
-       int ltype = 0;
-       int ltype_depth = 0;
-       int actcell = 0;
-       int actpos = 0;
-       int currlinelen = 0;
-       int fpos = 0;
-       bool ref_printed = false;
-
-       ofstream ofs(fname.c_str());
-       if (!ofs) {
-               WriteFSAlert(_("Error: Cannot write file:"), fname);
-               return;
-       }
-
-       string const fname1 = lyx::tempName(); //TmpFileName();
-       LyXParagraph * par = paragraph;
-       while (par) {
-               int noparbreak = 0;
-               int islatex = 0;
-               if (
-#ifndef NEW_INSETS
-                       par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
-#endif
-                   !par->previous
-#ifndef NEW_INSETS
-                   || par->previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
-#endif
-                       ){
-
-#ifndef NEW_INSETS
-                       /* begins a footnote environment ? */ 
-                       if (footnoteflag != par->footnoteflag) {
-                               footnoteflag = par->footnoteflag;
-                               if (footnoteflag) {
-                                       j = strlen(string_footnotekinds[par->footnotekind])+4;
-                                       if (currlinelen + j > linelen)
-                                               ofs << "\n";
-                                       ofs << "(["
-                                           << string_footnotekinds[par->footnotekind] << "] ";
-                                       currlinelen += j;
-                               }
-                       }
-#endif
-        
-                       /* begins or ends a deeper area ?*/ 
-                       if (depth != par->depth) {
-                               if (par->depth > depth) {
-                                       while (par->depth > depth) {
-                                               ++depth;
-                                       }
-                               }
-                               else {
-                                       while (par->depth < depth) {
-                                               --depth;
-                                       }
-                               }
-                       }
-        
-                       /* First write the layout */
-                       tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
-                       if (tmp == "Itemize") {
-                               ltype = 1;
-                               ltype_depth = depth+1;
-                       } else if (tmp == "Enumerate") {
-                               ltype = 2;
-                               ltype_depth = depth+1;
-                       } else if (contains(tmp, "ection")) {
-                               ltype = 3;
-                               ltype_depth = depth+1;
-                       } else if (contains(tmp, "aragraph")) {
-                               ltype = 4;
-                               ltype_depth = depth+1;
-                       } else if (tmp == "Description") {
-                               ltype = 5;
-                               ltype_depth = depth+1;
-                       } else if (tmp == "Abstract") {
-                               ltype = 6;
-                               ltype_depth = 0;
-                       } else if (tmp == "Bibliography") {
-                               ltype = 7;
-                               ltype_depth = 0;
-                       } else {
-                               ltype = 0;
-                               ltype_depth = 0;
-                       }
-        
-                       /* maybe some vertical spaces */ 
-
-                       /* the labelwidthstring used in lists */ 
-        
-                       /* some lines? */ 
-        
-                       /* some pagebreaks? */ 
-        
-                       /* noindent ? */ 
-        
-                       /* what about the alignment */ 
-               } else {
-#ifndef NEW_INSETS
-                       /* dummy layout, that means a footnote ended */ 
-                       footnoteflag = LyXParagraph::NO_FOOTNOTE;
-                       ofs << ") ";
-                       noparbreak = 1;
-#else
-                       lyxerr << "Should this ever happen?" << endl;
-#endif
-               }
-      
-               LyXFont font1 =
-                       LyXFont(LyXFont::ALL_INHERIT, params.language);
-                actcell = 0;
-               for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
-                       if (!i && !footnoteflag && !noparbreak){
-                               ofs << "\n\n";
-                               for (j = 0; j < depth; ++j)
-                                       ofs << "  ";
-                               currlinelen = depth * 2;
-                               switch (ltype) {
-                               case 0: /* Standard */
-                               case 4: /* (Sub)Paragraph */
-                                case 5: /* Description */
-                                       break;
-                               case 6: /* Abstract */
-                                       ofs << "Abstract\n\n";
-                                       break;
-                               case 7: /* Bibliography */
-                                       if (!ref_printed) {
-                                               ofs << "References\n\n";
-                                               ref_printed = true;
-                                       }
-                                       break;
-                               default:
-                                       ofs << par->labelstring << " ";
-                                       break;
-                               }
-                               if (ltype_depth > depth) {
-                                       for (j = ltype_depth - 1; j > depth; --j)
-                                               ofs << "  ";
-                                       currlinelen += (ltype_depth-depth)*2;
-                               }
-                       }
-                       LyXFont font2 = par->GetFontSettings(params, i);
-                       if (font1.latex() != font2.latex()) {
-                               if (font2.latex() == LyXFont::OFF)
-                                       islatex = 0;
-                               else
-                                       islatex = 1;
-                       } else {
-                               islatex = 0;
-                       }
-                       c = par->GetChar(i);
-                       if (islatex)
-                               continue;
-                       switch (c) {
-                       case LyXParagraph::META_INSET:
-                               if ((inset = par->GetInset(i))) {
-                                       fpos = ofs.tellp();
-                                       inset->Ascii(this, ofs);
-                                       currlinelen += (ofs.tellp() - fpos);
-                                       actpos += (ofs.tellp() - fpos) - 1;
-                               }
-                               break;
-                       case LyXParagraph::META_NEWLINE:
-                               ofs << "\n";
-                               for (j = 0; j < depth; ++j)
-                                       ofs << "  ";
-                               currlinelen = depth * 2;
-                               if (ltype_depth > depth) {
-                                       for (j = ltype_depth;
-                                           j > depth; --j)
-                                               ofs << "  ";
-                                       currlinelen += (ltype_depth - depth) * 2;
-                               }
-                               break;
-                       case LyXParagraph::META_HFILL: 
-                               ofs << "\t";
-                               break;
-                       case '\\':
-                               ofs << "\\";
-                               break;
-                       default:
-                               if (currlinelen > linelen - 10
-                                    && c == ' ' && i + 2 < par->size()) {
-                                       ofs << "\n";
-                                       for (j = 0; j < depth; ++j)
-                                               ofs << "  ";
-                                       currlinelen = depth * 2;
-                                       if (ltype_depth > depth) {
-                                               for (j = ltype_depth;
-                                                   j > depth; --j)
-                                                       ofs << "  ";
-                                               currlinelen += (ltype_depth-depth)*2;
-                                       }
-                               } else if (c != '\0')
-                                       ofs << c;
-                               else if (c == '\0')
-                                       lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
-                               ++currlinelen;
-                               break;
-                       }
-               }
-               par = par->next;
-       }
-   
-       ofs << "\n";
-}
-//----------------------------------------------------------------------------
-#else
-//----------------------------------------------------------------------------
 string const Buffer::asciiParagraph(LyXParagraph const * par,
                                    unsigned int linelen) const
 {
@@ -1492,7 +1282,9 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
        LyXFont font2;
        Inset const * inset;
        char c;
+#ifndef NEW_INSETS
        LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
+#endif
        char depth = 0;
        int ltype = 0;
        int ltype_depth = 0;
@@ -1594,7 +1386,11 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
       
        font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
        for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
-               if (!i && !footnoteflag && !noparbreak){
+               if (!i &&
+#ifndef NEW_INSETS
+                   !footnoteflag &&
+#endif
+                   !noparbreak) {
                        if (linelen > 0)
                                buffer << "\n\n";
                        for (char j = 0; j < depth; ++j)
@@ -1722,7 +1518,7 @@ void Buffer::writeFileAscii(ostream & ofs, int linelen)
        }
        ofs << "\n";
 }
-#endif
+
 
 void Buffer::makeLaTeXFile(string const & fname, 
                           string const & original_path,
@@ -2714,7 +2510,9 @@ void Buffer::pop_tag(ostream & os, string const & tag,
 #warning Use a real stack! (Lgb)
 #endif
        // Please, Lars, do not remove the global variable. I already
-       // had to reintroduce it twice! (JMarc) 
+       // had to reintroduce it twice! (JMarc)
+       // but...but... I'll remove it anyway. (well not quite) (Lgb)
+#if 0
        int j;
        
         // pop all tags till specified one
@@ -2727,9 +2525,25 @@ void Buffer::pop_tag(ostream & os, string const & tag,
         // push all tags, but the specified one
         for (j = j + 1; j <= pos; ++j) {
                 os << "<" << stack[j] << ">";
-                strcpy(stack[j-1], stack[j]);
+                strcpy(stack[j - 1], stack[j]);
         }
         --pos;
+#else
+        // pop all tags till specified one
+       int j = pos;
+        for (int j = pos; (j >= 0) && (strcmp(stack[j], tag.c_str())); --j)
+                os << "</" << stack[j] << ">";
+
+        // closes the tag
+        os << "</" << tag << ">";
+       
+        // push all tags, but the specified one
+        for (int i = j + 1; i <= pos; ++i) {
+                os << "<" << stack[i] << ">";
+                strcpy(stack[i - 1], stack[i]);
+        }
+        --pos;
+#endif
 }