]> git.lyx.org Git - lyx.git/commitdiff
my changes during the holidyas...i expect some compilers to have some problems, but...
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 6 Jan 2000 02:44:26 +0000 (02:44 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 6 Jan 2000 02:44:26 +0000 (02:44 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@403 a592a061-630c-0410-9148-cb99ea01b6c8

52 files changed:
ChangeLog
Makefile.am
autogen.sh
config/ltconfig
configure.in
src/BufferView.C
src/BufferView.h
src/FontInfo.C
src/Makefile.am
src/Spacing.C
src/Spacing.h
src/buffer.C
src/bufferlist.C
src/debug.C
src/debug.h
src/filedlg.C
src/insets/Makefile.am
src/insets/figinset.C
src/kbmap.C
src/layout.C
src/layout.h
src/lyx_cb.C
src/lyxfunc.C
src/lyxlex.C
src/lyxlex.h
src/lyxparagraph.h
src/lyxserver.C
src/lyxtext.h
src/mathed/Makefile.am
src/mathed/formula.C
src/mathed/formulamacro.C
src/mathed/math_defs.h
src/mathed/math_hash.C
src/mathed/math_inset.h
src/mathed/math_panel.C
src/mathed/math_parser.C
src/mathed/math_root.h
src/mathed/math_symbols.C
src/mathed/math_utils.C
src/mathed/math_write.C
src/paragraph.C
src/support/DebugStream.C
src/support/filetools.C
src/support/filetools.h
src/support/lstrings.C
src/support/syscall.C
src/table.C
src/table.h
src/undo.C
src/undo.h
src/vspace.C
src/vspace.h

index d0319e8247870def95245f54f2810d198b2a01ca..d31dc98696702a002b21513c498415f783121782 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2000-01-06  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * src/BufferView.C: first go at a TextCache to speed up switching
+       between documents.
+
 2000-01-05  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * lib/examples/ItemizeBullets.lyx: update from Tino Meinen. 
        know when a user has cancelled input. Fixes annoying problems with
        inserting labels and version control.
 
+1999-12-29  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * src/support/lstrings.C (tostr): rewritten to use strstream and
+       stringstream
+
+1999-12-28  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * src/support/filetools.C (IsFileWriteable): use fstream to check
+       (IsDirWriteable): use fileinfo to check
+
+       * src/support/filetools.h (FilePtr): whole class deleted
+
+       * src/insets/figinset.C (GetPSSizes): rewritten to use ifstream.
+
+       * src/lyxparagraph.h (readSimpleWholeFile): make arg istream
+
+       * src/lyx_cb.C (InsertAsciiFile): use ifstream instead of FilePtr
+
+       * src/bufferlist.C (write): use ifstream and ofstream instead of
+       FILE*
+
+       * src/Spacing.h: use istrstream instead of sscanf
+
+       * src/mathed/math_defs.h: change first arg to istream from FILE*
+
+       * src/buffer.C (insertLyXFile): use ifstream instead of FilePtr
+
+       * src/mathed/math_parser.C: have yyis to be an istream 
+       (LexGetArg): use istream (yyis)
+       (yylex): ditto
+       (mathed_parse): ditto
+       (mathed_parser_file): first arg istream instead of FILE*, set yyis
+
+       * src/mathed/formula.C (Read): rewritten to use istream
+
+       * src/mathed/formulamacro.C (Read): rewritten to use istream
+
+       * src/lyxlex.h (~LyXLex): deleted desturctor 
+       (getStream): new function, returns an istream
+       (getFile): deleted funtion
+       (IsOK): return is.good();
+
+       * src/lyxlex.C (LyXLex): delete file and owns_file
+       (setFile): open an filebuf and assign that to a istream instead of
+       using FILE*
+       (setStream): new function, takes an istream as arg. 
+       (setFile): deleted function
+       (EatLine): rewritten us use istream instead of FILE*
+       (next): ditto
+       (nextToken): ditto
+
+       * src/table.C (LyXTable): use istream instead of FILE*
+       (Read): rewritten to take an istream instead of FILE*
+
 1999-12-28  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * src/buffer.C (Dispatch): remove an extraneous break statement.
index 5da61745cfa6903712df1fdb4e0dd37cceb8cab9..dfa8b9cb328c72b5a0776504f7bda88010ffcc5d 100644 (file)
@@ -5,7 +5,7 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure \
 SUBDIRS = intl po src lib
 
 EXTRA_DIST = ANNOUNCE OLD-CHANGES INSTALL.OS2 INSTALL.autoconf README.OS2 \
-       UPGRADING NEWS acconfig.h lyx.man \
+       UPGRADING lyx.man \
        config development forms images
 ETAGS_ARGS = --c++
 man_MANS = lyx.1
index 997cb75362ab8bab9ea9dbdfd0d49baa4ee0f9ae..ffbf543bcd79f133df393239d0f55be190e8acf5 100755 (executable)
@@ -42,9 +42,21 @@ fi
 # Autogenerate lib/configure.m4. We need GNU m4 for that and thus have
 # to try several ones.  
 ok=no
+#for prog in $M4 gm4 gnum4 m4 ; do
+#  case `$prog --help < /dev/null 2>&1 | grep traditional` in
+#    *traditional*) echo "Building lib/configure"
+#                 rm -f lib/configure
+#                 $prog lib/configure.m4 >lib/configure
+#                 chmod a+x lib/configure
+#                 ok=yes
+#                 break ;;
+#    *) ;;
+#  esac
+#done
+# Why not use --version ? (Lgb)
 for prog in $M4 gm4 gnum4 m4 ; do
-  case `$prog --help < /dev/null 2>&1 | grep traditional` in
-    *traditional*) echo "Building lib/configure"
+  case `$prog --version 2>&1` in
+    *GNU*) echo "Building lib/configure"
                   rm -f lib/configure
                   $prog lib/configure.m4 >lib/configure
                   chmod a+x lib/configure
index 65ec6f65d0f6f19d0654b0caa89169d685aae684..03e18f5299a3fee9deed8bf6527aae270b2e12e9 100755 (executable)
@@ -1715,7 +1715,11 @@ reload_flag=
 reload_cmds='$LD$reload_flag -o $output$reload_objs'
 echo $ac_n "checking for $LD option to reload object files... $ac_c" 1>&6
 # PORTME Some linkers may need a different reload flag.
+if [ x$with_gnu_ld = xyes ] ; then
+reload_flag='-Ur'
+else
 reload_flag='-r'
+fi
 echo "$ac_t$reload_flag" 1>&6
 test -n "$reload_flag" && reload_flag=" $reload_flag"
 
index 1a73c4124a9a253be1e6c1bfb5f6d273422b509a..6b97c2f2f39d5940683f80480ecb256f6e5c07bb 100644 (file)
@@ -72,7 +72,7 @@ LYX_CXX_CHEADERS
 LYX_STD_COUNT
 dnl we disable rtti for now
 dnl LYX_CXX_RTTI
-AC_CHECK_HEADERS(ostream istream)
+AC_CHECK_HEADERS(ostream istream sstream)
 LYX_CXX_STL_MODERN_STREAMS
 
 ### We need a regex implementation, so we provide our own if none is found.
index c6ab81144be94ff7c440c77d47d32fa159d5c916..96b13d625100c3bfa230ccd3a5385f538a464044 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <config.h>
 
+#include <algorithm>
 #include <cstdlib>
 #include <csignal>
 
@@ -42,6 +43,8 @@
 #include "gettext.h"
 #include "layout.h"
 
+using std::find_if;
+
 extern BufferList bufferlist;
 void sigchldhandler(pid_t pid, int * status);
 
@@ -88,14 +91,126 @@ BufferView::~BufferView()
        delete text;
 }
 
+// This is only the very first implemetation and use of the TextCache,
+// operations on it needs to be put into a class or a namespace, that part
+// is _NOT_ finished so don't bother to come with too many comments on it
+// (unless you have some nice ideas on where/how to do it)
+//
+// I think we need a TextCache that is common for all BufferViews,
+// please tell if you don't agree.
+//
+// Q. What are we caching?
+// A. We are caching the screen representations (LyXText) of the
+//    documents (Buffer,LyXParagraph) for specific BufferView widths.
+// Q. Why the cache?
+// A. It is not really needed, but it speeds things up a lot
+//    when you have more than one document loaded at once since a total
+//    rebreak (reformatting) need not be done when switching between
+//    documents. When the cache is in function a document only needs to be
+//    formatted upon loading and when the with of the BufferView changes.
+//    Later it will also be unneccessary to reformat when having two
+//    BufferViews of equal width with the same document, a simple copy
+//    of the LyXText structure will do.
+// Invariant for the TextCache:
+//        - The buffer of the text  in the TextCache _must_ exists
+//          in the bufferlist.
+//        - For a text in the TextCache there _must not_ be an equivalent
+//          text in any BufferView. (same buffer and width).
+// Among others this mean:
+//        - When a document is closed all trace of it must be removed from
+//          the TextCache.
+// Senarios:
+//    I belive there are only three possible senarios where the two first
+//    are also covered by the third.
+//        - The simplest senario is what we have now, a single BufferView only.
+//          o Opening
+//            Nothing to do with the TextCache is done when opening a file.
+//          o Switching
+//            We switch from buffer A to buffer B.
+//            * A's text is cached in TextCache.
+//            * We make a search for a text in TextCache that fits B
+//              (same buffer and same width).
+//          o Horisontal resize
+//            If the BufferView's width (LyXView) is horisontaly changed all
+//            the entries in the TextCache is deleted. (This causes
+//            reformat of all loaded documents when next viewed)
+//          o Close
+//            When a buffer is closed we don't have to do anything, becuase
+//            to close a single buffer it is required to only exist in the
+//            BufferView and not in the TextCache. Upon LFUN_QUIT we
+//            don't really care since everything is deleted anyway.
+//        - The next scenario is when we have several BufferViews (in one or
+//          more LyXViews) of equal width.
+//          o Opening
+//            Nothing to do with the TextCache is done when opening a file.
+//          o Switching
+//            We switch from buffer A to buffer B.
+//            * If A is in another Bufferview we do not put it into TextCache.
+//              else we put A into TextCache.
+//            * If B is viewed in another BufferView we make a copy of its
+//              text and use that, else we search in TextCache for a match.
+//              (same buffer same width)
+//          o Horisontal resize
+//            If the BufferView's width (LyXView) is horisontaly changed all
+//            the entries in the TextCache is deleted. (This causes
+//            reformat of all loaded documents when next viewed)
+//          o Close
+//        - The last scenario should cover both the previous ones, this time
+//          we have several BufferViews (in one or more LyXViews) with no
+//          limitations on width. (And if you wonder why the two other
+//          senarios are needed... I used them to get to this one.)
+//          o Opening
+//            Nothing to do with the TextCache is done when opening a file.
+//          o Switching
+//            We switch from buffer A to buffer B.
+//          o Horisontal resize
+//          o Close
+
+typedef vector<LyXText*> TextCache;
+TextCache textcache;
+
+class text_fits {
+public:
+       text_fits(Buffer * b, unsigned short p)
+               : buf(b), pw(p) {}
+       bool operator()(TextCache::value_type & vt) {
+               if (vt->params == buf && vt->paperWidth() == pw) return true;
+               return false;
+       }
+private:
+       Buffer * buf;
+       unsigned short pw;
+};
+
+
+class show_text {
+public:
+       show_text(ostream & o) : os(o) {}
+       void operator()(TextCache::value_type & vt) {
+               os << "Buffer: " << vt->params
+                  << "\nWidth: " << vt->paperWidth() << endl;
+       }
+private:
+       ostream & os;
+};
 
+void showTextCache(string const & str)
+{
+       lyxerr << "TextCache: " << str << endl;
+       for_each(textcache.begin(), textcache.end(), show_text(lyxerr));
+}
+
+             
 void BufferView::buffer(Buffer * b)
 {
        lyxerr[Debug::INFO] << "Setting buffer in BufferView" << endl;
        if (buffer_) {
                buffer_->InsetSleep();
                buffer_->delUser(this);
-               delete text;
+               // Put the old text into the TextCache.
+               textcache.push_back(text);
+               showTextCache("buffer");
+               // delete text;
                text = 0;
        }
 
@@ -135,6 +250,13 @@ void BufferView::buffer(Buffer * b)
                owner_->getMenus()->hideMenus();
                updateScrollbar();
                fl_redraw_object(work_area);
+               // Also remove all remaining text's from the testcache.
+               showTextCache("buffer delete all");
+               while (!textcache.empty()) {
+                       LyXText * tt = textcache.front();
+                       textcache.erase(textcache.begin());
+                       delete tt;
+               }
        }
        // should update layoutchoice even if we don't have a buffer.
        owner_->updateLayoutChoice();
@@ -293,9 +415,24 @@ int BufferView::resizeCurrentBuffer()
                selection = text->selection;
                mark_set = text->mark_set;
                delete text;
+               text = new LyXText(work_area->w, buffer_);
+       } else {
+               // See if we have a text in TextCache that fits
+               // the new buffer_ with the correct width.
+               TextCache::iterator it =
+                       find_if(textcache.begin(),
+                               textcache.end(),
+                               text_fits(buffer_,
+                                         work_area->w));
+               if (it != textcache.end()) {
+                       text = *it;
+                       // take it out of textcache.
+                       textcache.erase(it);
+                       showTextCache("resizeCurrentBuffer");
+               } else {
+                       text = new LyXText(work_area->w, buffer_);
+               }
        }
-       text = new LyXText(work_area->w, buffer_);
-
        updateScreen();
 
        if (par) {
@@ -1266,6 +1403,14 @@ int BufferView::workAreaExpose()
                if (widthChange) {
                        // All buffers need a resize
                        bufferlist.resize();
+
+                       // Remove all texts from the textcache
+                       showTextCache("Expose delete all");
+                       while(!textcache.empty()) {
+                               LyXText * tt = textcache.front();
+                               textcache.erase(textcache.begin());
+                               delete tt;
+                       }
                } else if (heightChange) {
                        // Rebuild image of current screen
                        updateScreen();
@@ -1568,3 +1713,29 @@ void BufferView::update(signed char f)
                }
        }
 }
+
+
+void BufferView::smallUpdate(signed char f)
+{
+       getScreen()->SmallUpdate();
+       if (getScreen()->TopCursorVisible()
+           != getScreen()->first) {
+               update(f);
+               return;
+       }
+
+       fitCursor();
+       updateScrollbar();
+
+       if (!text->selection)
+               text->sel_cursor = text->cursor;
+
+       if (f == 1 || f == -1) {
+               if (buffer()->isLyxClean()) {
+                       buffer()->markDirty();
+                       owner()->getMiniBuffer()->setTimer(4);
+               } else {
+                       buffer()->markDirty();
+               }
+       }
+}
index 2ec4f88575b3d429ccb059b3d87840a9fce95ea9..ba4b2f573335560170648007089b12adbfa1cf4d 100644 (file)
@@ -50,6 +50,8 @@ public:
        ///
        void update(signed char f);
        ///
+       void smallUpdate(signed char f);
+       ///
        void updateScrollbar();
        ///
        void redoCurrentBuffer();
index 95f44c8f2eb90f04ed42adb59c0f90d40be04341..cfc7143588d7e832dac823a1b4b9a5d3b1eb77ea 100644 (file)
@@ -74,8 +74,8 @@ string FontInfo::resize(string const & font, int size) const
        string ret(font);
        // Find the position of the size spec
        int cut = 0;
-       string::iterator before = 0;
-       string::iterator after = 0;
+       string::iterator before = string::iterator(0);
+       string::iterator after = string::iterator(0);
        for (string::iterator sit = ret.begin();
             sit != ret.end(); ++sit)
                if ((*sit) == '-') {
index efb3142a7138f8e71138f9262c30b1063ac6fd92..b4b61f54eeeb3145ecd875275c020aa01ecd893f 100644 (file)
@@ -3,7 +3,7 @@ SUBDIRS = mathed insets support
 DISTCLEANFILES = libintl.h config.h
 MAINTAINERCLEANFILES = Makefile.in config.h.in
 bin_PROGRAMS = lyx
-lyx_DEPENDENCIES = mathed/libmathed.la insets/libinsets.la support/libsupport.la
+lyx_DEPENDENCIES = mathed/libmathed.o insets/libinsets.o support/libsupport.o
 lyx_LDADD = $(lyx_DEPENDENCIES) @INTLLIBS@ $(LYX_LIBS)
 EXTRA_DIST = config.h.in stamp-h.in cheaders
 ETAGS_ARGS = --c++
index 6e5cd60292a0b601f9edc1cdef51434fb93b09a0..4ec657432c4842b6e57a1a1bb194e890b8e57c9b 100644 (file)
@@ -1,6 +1,5 @@
 #include <config.h>
 
-#include <cstdio>
 #include "Spacing.h"
 using std::ios;
 
index 50ecc64daa2849e8e4be4772144913f250d404f3..bf593a19f55a3cfafc3e26565b84d2214c9d9e40 100644 (file)
 #ifndef SPACING_H
 #define SPACING_H
 
-#include <cstdio>
-#include "support/LOstream.h"
+#ifdef HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream>
+#endif
 
+#include "support/LOstream.h"
 
 ///
 class Spacing {
@@ -69,7 +73,12 @@ public:
        void set(Spacing::Space sp, char const * val)
        {
                float fval;
-               sscanf(val, "%f", &fval);
+#ifdef HAVE_SSTREAM
+               istringstream istr(val);
+#else
+               istrstream istr(val);
+#endif
+               istr >> fval;
                set(sp, fval);
        }
        ///
index 4a7e081b18ec3e3ab939aad5cb8393a5073bd650..dfa419d17b56a7c2e20229808d6a903c34bcf853 100644 (file)
@@ -101,7 +101,6 @@ using std::setw;
 
 // all these externs should eventually be removed.
 extern BufferList bufferlist;
-extern void SmallUpdate(signed char);
 extern unsigned char GetCurrentTextClass();
 extern void BeforeChange();
 
@@ -244,17 +243,17 @@ bool Buffer::insertLyXFile(string const & filen)
        
        BeforeChange();
 
-       FilePtr myfile(fname, FilePtr::read);
-       if (!myfile()) {
+       ifstream ifs(fname.c_str());
+       if (!ifs) {
                WriteAlert(_("Error!"),
                           _("Cannot open specified file: "),
                           MakeDisplayPath(fname, 50));
                return false;
        }
        LyXLex lex(0, 0);
-       lex.setFile(myfile);
-       int c = fgetc(myfile());
-       ungetc(c, myfile);
+       lex.setStream(ifs);
+       char c; ifs.get(c);
+       ifs.putback(c);
 
        bool res = true;
 
@@ -331,10 +330,10 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        continue;
                else if (token[0] != '\\') {
                        int n = token.length();
-                       for (int i = 0; i < n; i++) {
+                       for (int i = 0; i < n; ++i) {
                                par->InsertChar(pos, token[i]);
                                par->SetFont(pos, font);
-                               pos++;
+                               ++pos;
                        }
                } else if (token == "\\i") {
                        inset = new InsetLatexAccent;
@@ -389,7 +388,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        font = LyXFont(LyXFont::ALL_INHERIT);
                } else if (token == "\\begin_float") {
                        tmpret = lex.FindToken(string_footnotekinds);
-                       if (tmpret == -1) tmpret++;
+                       if (tmpret == -1) ++tmpret;
                        if (tmpret != LYX_LAYOUT_DEFAULT) 
                                footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
                        if (footnotekind == LyXParagraph::FOOTNOTE
@@ -398,19 +397,19 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        else 
                                footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
                } else if (token == "\\begin_deeper") {
-                       depth++;
+                       ++depth;
                } else if (token == "\\end_deeper") {
                        if (!depth) {
                                lex.printError("\\end_deeper: "
                                               "depth is already null");
                        }
                        else
-                               depth--;
+                               --depth;
                } else if (token == "\\begin_preamble") {
                        params.readPreamble(lex);
                } else if (token == "\\textclass") {
                        lex.EatLine();
-                       pair<bool, LyXTextClassList::ClassList::size_type> pp = 
+                       pair<bool, LyXTextClassList::size_type> pp = 
                                textclasslist.NumberOfClass(lex.GetString());
                        if (pp.first) {
                                params.textclass = pp.second;
@@ -434,7 +433,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        lex.EatLine();
                        params.options = lex.GetString();
                } else if (token == "\\language") {
-                       params.readLanguage(lex);           
+                       params.readLanguage(lex);    
                } else if (token == "\\fontencoding") {
                        lex.EatLine();
                } else if (token == "\\inputencoding") {
@@ -470,11 +469,11 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                } else if (token == "\\defskip") {
                        lex.nextToken();
                        params.defskip = VSpace(lex.GetString());
-               } else if (token == "\\no_isolatin1") {
+               } else if (token == "\\no_isolatin1") { // obsolete
                        lex.nextToken();
-               } else if (token == "\\no_babel") {
+               } else if (token == "\\no_babel") { // obsolete
                        lex.nextToken();
-               } else if (token == "\\no_epsfig") {
+               } else if (token == "\\no_epsfig") { // obsolete
                        lex.nextToken();
                } else if (token == "\\epsfig") { // obsolete
                        // Indeed it is obsolete, but we HAVE to be backwards
@@ -642,7 +641,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                } else if (token == "\\tocdepth") {
                        lex.nextToken();
                        params.tocdepth = lex.GetInteger();
-               } else if (token == "\\baselinestretch") { // now obsolete
+               } else if (token == "\\baselinestretch") { // obsolete
                        lex.nextToken(); // should not be used directly
                        // anymore.
                        // Will probably keep a kind of support just for
@@ -667,7 +666,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                } else if (token == "\\float_placement") {
                        lex.nextToken();
                        params.float_placement = lex.GetString();
-               } else if (token == "\\cursor") {
+               } else if (token == "\\cursor") { // obsolete
                        // this is obsolete, so we just skip it.
                        lex.nextToken();
                } else if (token == "\\family") { 
@@ -720,13 +719,13 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                } else if (token == "\\align") {
                        tmpret = lex.FindToken(string_align);
                        if (tmpret == -1) tmpret++;
-                       if (tmpret != LYX_LAYOUT_DEFAULT) {
+                       if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
                                tmpret2 = 1;
-                               for (; tmpret>0; tmpret--)
+                               for (; tmpret > 0; --tmpret)
                                        tmpret2 = tmpret2 * 2;
                                par->align = LyXAlignment(tmpret2);
                        }
-               } else if (token == "\\added_space_top"){
+               } else if (token == "\\added_space_top") {
                        lex.nextToken();
                        par->added_space_top = lex.GetString();
                } else if (token == "\\added_space_bottom") {
@@ -900,6 +899,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                                par->InsertInset(pos, inset);
                                par->SetFont(pos, font);
                                pos++;
+#if 0
                        } else if (tmptok == "Label") {
                                // Kept for compability. Remove in 0.13.
                                if (lex.EatLine()) {
@@ -912,6 +912,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                                        par->SetFont(pos, font);
                                        pos++;
                                }
+#endif
                        } else if (tmptok == "Info") {
                                inset = new InsetInfo;
                                inset->Read(lex);
@@ -950,9 +951,11 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                                        if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
                                                inset = new InsetRef(inscmd, this);
                                        }
-                                       /* This condition comes from a temporary solution
-                                          to the latexdel ref inset that was transformed to an empty ref
-                                          inset plus the body surronded by latexdel insets */
+                                       // This condition comes from a
+                                       // temporary solution to the latexdel
+                                       // ref inset that was transformed to
+                                       // an empty ref inset plus the body
+                                       // surronded by latexdel insets
                                        else {
                                                string cont, opt, tmptmptok, cmdname;
                                                lex.next();
@@ -1013,7 +1016,10 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                                        inset = new InsetPrintIndex(this);
                                } else if (inscmd.getCmdName() == "lyxparent") {
                                        inset = new InsetParent(inscmd.getContents(), this);
-                               } else 
+                               }
+#if 0
+                               // Do we need this at all now?
+                               else 
                                        // The following three are only for compatibility
                                        if (inscmd.getCmdName() == "-") {
                                                inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
@@ -1023,12 +1029,13 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                                                inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
                                        } else
                                                inset = inscmd.Clone();
+#endif
                               
                                if (inset) {
                                        par->InsertChar(pos, LyXParagraph::META_INSET);
                                        par->InsertInset(pos, inset);
                                        par->SetFont(pos, font);
-                                       pos++;
+                                       ++pos;
                                }
                        }
                } else if (token == "\\InsetQuotes") {
@@ -1037,7 +1044,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        par->InsertChar(pos, LyXParagraph::META_INSET); 
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
 #if 0
                } else if (token == "\\InsetLatex") {
                        inset = new InsetLatex;
@@ -1045,7 +1052,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        par->InsertChar(pos, LyXParagraph::META_INSET); 
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                } else if (token == "\\InsetLatexDel") {
                        lex.printError(_("Warning: Ignoring Old Inset"));
 #endif
@@ -1055,35 +1062,35 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        par->InsertChar(pos, LyXParagraph::META_INSET); 
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                } else if (token == "\\SpecialChar") {
                        inset = new InsetSpecialChar;
                        inset->Read(lex);
                        par->InsertChar(pos, LyXParagraph::META_INSET); 
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                } else if (token == "\\Figure") {
                        inset = new InsetFig(100, 100, this);
                        inset->Read(lex);
                        par->InsertChar(pos, LyXParagraph::META_INSET); 
                        par->InsertInset(pos, inset);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                } else if (token == "\\newline") {
                        par->InsertChar(pos, LyXParagraph::META_NEWLINE);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                } else if (token == "\\LyXTable") {
                        par->table = new LyXTable(lex);
                } else if (token == "\\hfill") {
                        par->InsertChar(pos, LyXParagraph::META_HFILL);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                } else if (token == "\\protected_separator") {
                        par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                } else if (token == "\\bibitem") {  // ale970302
                        if (!par->bibkey)
                                par->bibkey = new InsetBibKey;
@@ -1091,7 +1098,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                }else if (token == "\\backslash") {
                        par->InsertChar(pos, '\\');
                        par->SetFont(pos, font);
-                       pos++;
+                       ++pos;
                }else if (token == "\\the_end") {
                        the_end_read = true;
                } else {
@@ -1099,10 +1106,10 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
                        lex.printError("Unknown token `$$Token'. "
                                       "Inserting as text.");
                        int n = token.length();
-                       for (int i = 0; i < n; i++) {
+                       for (int i = 0; i < n; ++i) {
                                par->InsertChar(pos, token[i]);
                                par->SetFont(pos, font);
-                               pos++;
+                               ++pos;
                        }
                }
        }
@@ -1607,7 +1614,7 @@ void Buffer::makeLaTeXFile(string const & fname,
        }
        lyxerr.debug() << "lyx header finished" << endl;
        // There are a few differences between nice LaTeX and usual files:
-       // usual is \batchmode, uses \listfiles and has a 
+       // usual is \batchmode and has a 
        // special input@path to allow the including of figures
        // with either \input or \includegraphics (what figinsets do).
        // batchmode is not set if there is a tex_code_break_column.
@@ -1621,9 +1628,6 @@ void Buffer::makeLaTeXFile(string const & fname,
                        LFile += "\\batchmode\n"; // changed
                        // from \nonstopmode
                        texrow.newline();
-                       // We don't need listfiles anymore
-                       //LFile += "\\listfiles\n";
-                       //texrow.newline();
                }
                if (!original_path.empty()) {
                        LFile += "\\makeatletter\n";
@@ -2452,18 +2456,16 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
 void Buffer::push_tag(ostream & os, char const * tag,
                      int & pos, char stack[5][3])
 {
-       int j;
-
        /* pop all previous tags */
-       for (j = pos; j >= 0; --j)
+       for (int j = pos; j >= 0; --j)
                os << "</" << stack[j] << ">";
 
        /* add new tag */
        sprintf(stack[++pos], "%s", tag);
 
        /* push all tags */
-       for (j = 0; j <= pos; ++j)
-               os << "<" << stack[j] << ">";
+       for (int i = 0; i <= pos; ++i)
+               os << "<" << stack[i] << ">";
 }
 
 
@@ -2471,19 +2473,17 @@ void Buffer::push_tag(ostream & os, char const * tag,
 void Buffer::pop_tag(ostream & os, char const * tag,
                     int & pos, char stack[5][3])
 {
-       int j;
-
        // pop all tags till specified one
-       for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
+       for (int j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
                os << "</" << stack[j] << ">";
 
        // closes the tag
        os << "</" << tag << ">";
 
        // push all tags, but the specified one
-       for (j = j + 1; j <= pos; ++j) {
-               os << "<" << stack[j] << ">";
-               strcpy(stack[j-1], stack[j]);
+       for (int i = i + 1; i <= pos; ++i) {
+               os << "<" << stack[i] << ">";
+               strcpy(stack[i - 1], stack[i]);
        }
        --pos;
 }
@@ -2750,7 +2750,6 @@ void Buffer::makeDocBookFile(string const & fname, int column)
                return;
        }
    
-       //ResetTexRow();
        texrow.reset();
 
        ofs << "<!doctype " << top_element
index fdfc33a96fecf9c39edc7458cf8bdab887ade94b..cc9098ce4b4d3f8bf3610ff506787c239fcbded7 100644 (file)
@@ -35,7 +35,6 @@
 #include "LyXView.h"
 
 extern BufferView * current_view;
-extern void SmallUpdate(signed char);
 extern void BeforeChange();
 extern int RunLinuxDoc(int, string const &);
 
@@ -169,27 +168,20 @@ bool BufferList::write(Buffer * buf, bool makeBackup)
                        times->modtime = finfo.getModificationTime();
                        long blksize = finfo.getBlockSize();
                        lyxerr.debug() << "BlockSize: " << blksize << endl;
-                       FilePtr fin(buf->fileName(), FilePtr::read);
-                       FilePtr fout(s, FilePtr::truncate);
-                       if (fin() && fout()) {
-                               char * cbuf = new char[blksize+1];
-                               size_t c_read = 0;
-                               size_t c_write = 0;
-                               do {
-                                       c_read = fread(cbuf, 1, blksize, fin);
-                                       if (c_read != 0)
-                                               c_write = 
-                                                       fwrite(cbuf, 1,
-                                                              c_read, fout);
-                               } while (c_read);
-                               fin.close();
-                               fout.close();
+                       ifstream ifs(buf->fileName().c_str());
+                       ofstream ofs(s.c_str(), ios::out|ios::trunc);
+                       if (ifs && ofs) {
+                               char c = 0;
+                               while (ifs.get(c)) {
+                                       ofs.put(c);
+                               };
+                               ifs.close();
+                               ofs.close();
                                chmod(s.c_str(), fmode);
                                
                                if (utime(s.c_str(), times)) {
                                        lyxerr << "utime error." << endl;
                                }
-                               delete [] cbuf;
                        } else {
                                lyxerr << "LyX was not able to make "
                                        "backupcopy. Beware." << endl;
index bb260cd308390cce6d508dd6cd3262bcb4399162..abee30ac35f15c3bd7a8468c1cae1244ca92a038 100644 (file)
@@ -39,6 +39,7 @@ static error_item errorTags[] = {
        { Debug::LYXSERVER,     "lyxserver",    "External control interface"},
        { Debug::ROFF,          "roff",         "Keep *roff temporary files"},
        { Debug::ACTION,        "action",       "User commands"},
+       { Debug::LYXLEX,        "lyxlex",       "The LyX Lexxer"},
        { Debug::NONE,          "none",         "No debugging message"},
         { Debug::ANY,          "any",          "All debugging messages"}
 };
@@ -93,6 +94,3 @@ void Debug::showTags(ostream & os)
                   << "  " << errorTags[i].desc << '\n';
        os.flush();
 }
-
-
-
index be866a258d56a47a29dfe9f09703160232e2541a..c7fcb43fa86c21d92b0dd929cd49f8ba68b7628f 100644 (file)
@@ -45,13 +45,15 @@ struct Debug {
                ///
                ROFF       = (1 << 13),  // 8192
                ///
-               ACTION     = (1 << 14)   // 16384
+               ACTION     = (1 << 14),   // 16384
+               ///
+               LYXLEX     = (1 << 15)
        };
        ///
        static const type ANY = type(INFO | INIT | KEY | TOOLBAR |
                                     PARSER | LYXRC | KBMAP | LATEX |
                                     MATHED | FONT | TCLASS | LYXVC |
-                                    LYXSERVER | ROFF | ACTION);
+                                    LYXSERVER | ROFF | ACTION | LYXLEX);
        ///
        friend inline void operator|=(Debug::type & d1, Debug::type d2);
        
index 388318e3c34925d166d5766fb2adbdb9f4f6d736..80dc5fd49c047fba3eedd74d28e18447b233c9d9 100644 (file)
@@ -12,7 +12,6 @@
 #include <config.h>
 
 #include <unistd.h>
-#include <cstdio>
 #include <cstdlib>
 #include <pwd.h>
 #include <grp.h>
index cb0e3b132fcc3d9b0e6c1095456f60fcf012c71c..46a10ba9689a585fecd8ef650b912fd153aadd04 100644 (file)
@@ -1,11 +1,11 @@
 AUTOMAKE_OPTIONS = foreign
 MAINTAINERCLEANFILES = Makefile.in
-noinst_LTLIBRARIES = libinsets.la
+noinst_LTLIBRARIES = libinsets.o
 LIBS =
 ETAGS_ARGS = --c++
 INCLUDES = -I${srcdir}/../ 
 
-libinsets_la_SOURCES = \
+libinsets_o_SOURCES = \
        figinset.C \
        figinset.h \
        form_url.C \
index 4e4bea58d2043b1af74b76b7ffdc5ee93513ac3e..dcc77e153235a8a314d93517a3ef7613e5f5b833 100644 (file)
@@ -1006,20 +1006,16 @@ static void UnregisterFigure(InsetFig * fi)
 }
 
 
-static char * NextToken(FILE * myfile)
+static string NextToken(istream & is)
 {
-       char * token = 0;
+       string token;
        char c;
-       int i = 0;
-   
-       if (!feof(myfile)) {
-               token = new char[256];
+       if (!is.eof()) {
                do {
-                       c = fgetc(myfile);
-                       token[i++]= c;
-               } while (!feof(myfile) && !isspace(c));
-      
-               token[i-1]= '\0';         /* just the end of a command  */
+                       is.get(c);
+                       token += c;
+               } while (!is.eof() && !isspace(c));
+               token.erase(token.length() - 1); // remove the isspace
        }
        return token;
 }
@@ -1718,11 +1714,7 @@ void InsetFig::Recompute()
 
 void InsetFig::GetPSSizes()
 {
-#ifdef WITH_WARNINGS
-#warning rewrite this method to use ifstream
-#endif
        /* get %%BoundingBox: from postscript file */
-       char * p = 0;
        
        /* defaults to associated size
         * ..just in case the PS-file is not readable (Henner, 24-Aug-97) 
@@ -1733,10 +1725,10 @@ void InsetFig::GetPSSizes()
        pshgh = hgh;
 
        if (fname.empty()) return;
+       string p;
+       ifstream ifs(fname.c_str());
 
-       FilePtr f(fname, FilePtr::read);
-
-       if (!f()) return;       // file not found !!!!
+       if (!ifs) return;       // file not found !!!!
 
        /* defaults to A4 page */
        psx = 0;
@@ -1744,30 +1736,29 @@ void InsetFig::GetPSSizes()
        pswid = 595;
        pshgh = 842;
 
-       int lastchar = fgetc(f);
+       char lastchar = 0; ifs.get(lastchar);
        for (;;) {
-               int c = fgetc(f);
-               if (c == EOF) {
+               char c = 0; ifs.get(c);
+               if (ifs.eof()) {
                        lyxerr.debug() << "End of (E)PS file reached and"
                                " no BoundingBox!" << endl;
                        break;
                }
                if (c == '%' && lastchar == '%') {
-                       p = NextToken(f);
-                       if (!p) break;
+                       p = NextToken(ifs);
+                       if (p.empty()) break;
                        // we should not use this, with it we cannot
                        // discover bounding box and end of file.
                        //if (strcmp(p, "EndComments") == 0) break;
-                       if (strcmp(p, "BoundingBox:") == 0) {
+                       lyxerr.debug() << "Token: `" << p << "'" << endl;
+                       if (p == "BoundingBox:") {
                                float fpsx, fpsy, fpswid, fpshgh;
-                               if (fscanf(f, "%f %f %f %f", &fpsx, &fpsy,
-                                          &fpswid, &fpshgh) == 4) {
+                               if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
                                        psx = int(fpsx);
                                        psy = int(fpsy);
                                        pswid = int(fpswid);
                                        pshgh = int(fpshgh);
-                               } 
-
+                               }
                                if (lyxerr.debugging()) {
                                        lyxerr << "%%%%BoundingBox:"
                                               << psx << ' '
@@ -1778,12 +1769,9 @@ void InsetFig::GetPSSizes()
                                break;
                        }
                        c = 0;
-                       delete[] p;
-                       p = 0;
                }
                lastchar = c;
        }
-       if (p) delete[] p;
        pswid -= psx;
        pshgh -= psy;
 
index 3a491f334df26a9c3f6ff5bd179d0f64479dcef2..b95f8aeaee05b3c6574221cf0d97ce807cce60d6 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <config.h>
 #include <cstring>
-#include <cstdio>
 #include "support/lstrings.h"
 #include "gettext.h"
 
index d54b8c1c069ee9d7567bfa762e788903a82da41e..c8a55e8aa20af365e3ed3191a5bd691c8dc831c2 100644 (file)
@@ -1208,7 +1208,7 @@ void LyXTextClass::load()
 //////////////////////////////////////////
 
 // Gets textclass number from name
-pair<bool, LyXTextClassList::ClassList::size_type>
+pair<bool, LyXTextClassList::size_type>
 LyXTextClassList::NumberOfClass(string const & textclass) const
 {
        for (ClassList::const_iterator cit = classlist.begin();
@@ -1216,14 +1216,14 @@ LyXTextClassList::NumberOfClass(string const & textclass) const
                if ((*cit).name() == textclass)
                        return make_pair(true, cit - classlist.begin());
        }
-       return make_pair(false, 0);
+       return make_pair(false, size_type(0));
 }
 
 
 // Gets layout structure from style number and textclass number
 LyXLayout const &
-LyXTextClassList::Style(LyXTextClassList::ClassList::size_type textclass,
-                       LyXTextClass::LayoutList::size_type layout) const
+LyXTextClassList::Style(LyXTextClassList::size_type textclass,
+                       LyXTextClass::size_type layout) const
 {
        classlist[textclass].load();
        if (layout < classlist[textclass].numLayouts())
@@ -1233,8 +1233,9 @@ LyXTextClassList::Style(LyXTextClassList::ClassList::size_type textclass,
 
 
 // Gets layout number from name and textclass number
-pair<bool, LyXTextClass::LayoutList::size_type>
-LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::size_type textclass, string const & name) const
+pair<bool, LyXTextClass::size_type>
+LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
+                                string const & name) const
 {
        classlist[textclass].load();
        for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
@@ -1243,23 +1244,23 @@ LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::size_type textclas
        }
        if (name == "dummy")
                return make_pair(true, LYX_DUMMY_LAYOUT);
-       return make_pair(false, 0); // not found
+       return make_pair(false, LyXTextClass::LayoutList::size_type(0)); // not found
 }
 
 
 // Gets a layout (style) name from layout number and textclass number
 string const &
-LyXTextClassList::NameOfLayout(LyXTextClassList::ClassList::size_type textclass,
-                              LyXTextClass::LayoutList::size_type layout) const
+LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
+                              LyXTextClass::size_type layout) const
 {
        static string dummy("dummy");
-#if 1
+#if 0
        static string end("@@end@@");
 #endif
        classlist[textclass].load();
        if (layout < classlist[textclass].numLayouts())
                return classlist[textclass][layout].name();
-#if 1
+#if 0
        else if (layout == LYX_DUMMY_LAYOUT)
                return dummy;
        else
@@ -1272,21 +1273,21 @@ LyXTextClassList::NameOfLayout(LyXTextClassList::ClassList::size_type textclass,
 
 // Gets a textclass name from number
 string const &
-LyXTextClassList::NameOfClass(LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
 {
        static string dummy("dummy");
-#if 1
+#if 0
        static string end("@@end@@");
 #endif
        if (classlist.size() == 0) {
-#if 1
+#if 0
                if (number == 0) return dummy;
                else return end;
 #else
                return dummy;
 #endif
        }
-#if 1
+#if 0
        if (number < classlist.size())
                return classlist[number].name();
        else
@@ -1300,22 +1301,22 @@ LyXTextClassList::NameOfClass(LyXTextClassList::ClassList::size_type number) con
 
 // Gets a textclass latexname from number
 string const &
-LyXTextClassList::LatexnameOfClass(LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
 {
        static string dummy("dummy");
-#if 1
+#if 0
        static string end("@@end@@");
 #endif
        classlist[number].load();
        if (classlist.size() == 0) {
-#if 1
+#if 0
                if (number == 0) return dummy;
                else return end;
 #else
                return dummy;
 #endif
        }
-#if 1
+#if 0
        if (number < classlist.size())
                return classlist[number].latexname();
        
@@ -1330,21 +1331,21 @@ LyXTextClassList::LatexnameOfClass(LyXTextClassList::ClassList::size_type number
 
 // Gets a textclass description from number
 string const &
-LyXTextClassList::DescOfClass(LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
 {
        static string dummy("dummy");
-#if 1
+#if 0
        static string end("@@end@@");
 #endif
        if (classlist.size() == 0) {
-#if 1
+#if 0
                if (number == 0) return dummy;
                else return end;
 #else
                return dummy;
 #endif
        }
-#if 1
+#if 0
        if (number < classlist.size())
                return classlist[number].description();
        else
@@ -1358,7 +1359,7 @@ LyXTextClassList::DescOfClass(LyXTextClassList::ClassList::size_type number) con
 
 // Gets a textclass structure from number
 LyXTextClass const &
-LyXTextClassList::TextClass(LyXTextClassList::ClassList::size_type textclass) const
+LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
 {
        classlist[textclass].load();
        if (textclass < classlist.size())
@@ -1407,7 +1408,11 @@ bool LyXTextClassList::Read ()
                // compiled in... (Lgb)
        }
 
-       lex.setFile(real_file);
+       if (!lex.setFile(real_file)) {
+               lyxerr << "LyXTextClassList::Read: "
+                       "lyxlex was not able to set file: "
+                      << real_file << endl;
+       }
        
        if (!lex.IsOK()) {
                lyxerr << "LyXTextClassList::Read: unable to open "
@@ -1468,7 +1473,7 @@ bool LyXTextClassList::Read ()
    Returns false if this fails
 */
 bool
-LyXTextClassList::Load (LyXTextClassList::ClassList::size_type number) const
+LyXTextClassList::Load (LyXTextClassList::size_type number) const
 {
        bool result = true;
        if (number < classlist.size()) {
index 3926f99bbeb5fa7f51db8414032bd27d5c1943b3..58cb39ce3bd7a2c3cd3a02dee18aebe7da1f4fe7 100644 (file)
@@ -258,16 +258,16 @@ public:
        Spacing spacing;
 
        ///
-       LyXAlignment align; // add approp. signedness
+       LyXAlignment align;
 
        ///
-       LyXAlignment alignpossible; // add approp. signedness
+       LyXAlignment alignpossible;
 
        ///
-       char labeltype; // add approp. signedness
+       char labeltype; // add approp. type
 
        ///
-       char margintype; // add approp. signedness
+       char margintype; // add approp. type
 
        ///
        bool fill_top;
@@ -340,7 +340,8 @@ public:
        typedef vector<LyXLayout> LayoutList;
        ///
        typedef LayoutList::const_iterator const_iterator;
-
+       ///
+       typedef LayoutList::size_type size_type;
        ///
        LyXTextClass (string const & = string(), 
                      string const & = string(), 
@@ -422,9 +423,9 @@ public:
         ///
        int maxcounter() const { return maxcounter_; }
        ///
-       LayoutList::size_type numLayouts() const { return layoutlist.size(); }
+       size_type numLayouts() const { return layoutlist.size(); }
        ///
-       LyXLayout const & operator[](LayoutList::size_type i) const {
+       LyXLayout const & operator[](size_type i) const {
                return layoutlist[i];
        }
 private:
@@ -512,41 +513,43 @@ public:
        ///
        typedef ClassList::const_iterator const_iterator;
        ///
+       typedef ClassList::size_type size_type;
+       ///
        const_iterator begin() const { return classlist.begin(); }
        ///
        const_iterator end() const { return classlist.end(); }
        
        /// Gets layout structure from layout number and textclass number
-       LyXLayout const & Style(ClassList::size_type textclass,
-                               LyXTextClass::LayoutList::size_type layout) const;
+       LyXLayout const & Style(size_type textclass,
+                               LyXTextClass::size_type layout) const;
 
        /// Gets layout number from textclass number and layout name
-       pair<bool, LyXTextClass::LayoutList::size_type>
-       NumberOfLayout(ClassList::size_type textclass,
+       pair<bool, LyXTextClass::size_type>
+       NumberOfLayout(size_type textclass,
                       string const & name) const;
 
        /// Gets a layout name from layout number and textclass number
        string const &
-       NameOfLayout(ClassList::size_type textclass,
-                    LyXTextClass::LayoutList::size_type layout) const;
+       NameOfLayout(size_type textclass,
+                    LyXTextClass::size_type layout) const;
 
        /** Gets textclass number from name.
            Returns -1 if textclass name does not exist
        */
-       pair<bool, ClassList::size_type>
+       pair<bool, size_type>
        NumberOfClass(string const & textclass) const;
 
        ///
-       string const & NameOfClass(ClassList::size_type number) const;
+       string const & NameOfClass(size_type number) const;
 
        ///
-       string const & LatexnameOfClass(ClassList::size_type number) const;
+       string const & LatexnameOfClass(size_type number) const;
 
        ///
-       string const & DescOfClass(ClassList::size_type number) const;
+       string const & DescOfClass(size_type number) const;
 
        ///
-       LyXTextClass const & TextClass(ClassList::size_type textclass) const;
+       LyXTextClass const & TextClass(size_type textclass) const;
 
        /** Read textclass list.
            Returns false if this fails
@@ -556,7 +559,7 @@ public:
        /** Load textclass.
            Returns false if this fails
        */
-       bool Load(ClassList::size_type number) const;
+       bool Load(size_type number) const;
 private:
        ///
        mutable ClassList classlist;
index b81d045c74c373f05ae142d0d3a4a53a800d94c7..263f6707ea3e4521683f350cc6d21bd0a84ab7f3 100644 (file)
@@ -300,35 +300,6 @@ void BeforeChange()
 }
 
 
-// candidate for move to BufferView
-void SmallUpdate(signed char f)
-{
-       current_view->getScreen()->SmallUpdate();
-       if (current_view->getScreen()->TopCursorVisible()
-           != current_view->getScreen()->first) {
-               current_view->update(f);
-               return;
-       }
-
-       current_view->fitCursor();
-       current_view->updateScrollbar();
-
-       if (!current_view->text->selection)
-               current_view->text->sel_cursor = 
-                       current_view->text->cursor;
-
-       if (f == 1 || f == -1) {
-               if (current_view->buffer()->isLyxClean()) {
-                       current_view->buffer()->markDirty();
-                       current_view->owner()->getMiniBuffer()->setTimer(4);
-               }
-               else {
-                       current_view->buffer()->markDirty();
-               }
-       }
-}
-
-
 //
 // Menu callbacks
 //
@@ -1190,14 +1161,14 @@ void InsertAsciiFile(string const & f, bool asParagraph)
                return;
        }
 
-       FilePtr myfile(fname, FilePtr::read);
-       if (!myfile()) {
+       ifstream ifs(fname.c_str());
+       if (!ifs) {
                WriteFSAlert(_("Error! Cannot open specified file: "),
                             MakeDisplayPath(fname, 50));
                return;
        }
        LyXParagraph * tmppar = new LyXParagraph;
-       tmppar->readSimpleWholeFile(myfile);
+       tmppar->readSimpleWholeFile(ifs);
        
        // set the end of the string
 #ifdef WITH_WARNINGS
index d226829be0bd53cb3f7d26e905017654f4256145..d355691697d3ecb117972b67905d1e5a7412ae36 100644 (file)
@@ -110,7 +110,6 @@ extern void MenuSeparator();
 extern void HFill();
 extern void MenuUndo();
 extern void MenuRedo();
-extern void SmallUpdate(signed char);
 extern void SetUpdateTimer(float timer = 0.3);
 extern void FreeUpdateTimer();
 extern bool MenuPreview(Buffer *);
@@ -330,19 +329,21 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
                                                   LyXAction::ReadOnly)) {
                                // no
                                setErrorMessage(N_("Document is read-only"));
-                               flag = func_status(flag | LyXFunc::Disabled);
+                               flag |= LyXFunc::Disabled;
                        }
                } else {
                        // no
                        setErrorMessage(N_("Command not allowed with"
                                           "out any document open"));
-                       flag = func_status(flag | LyXFunc::Disabled);
+                       flag |= LyXFunc::Disabled;
                }
        }
 
        if (flag & LyXFunc::Disabled)
                return flag;
 
+       // I would really like to avoid having this switch and rather try to
+       // encode this in the function itself.
         static bool noLaTeX = lyxrc->latex_command == "none";
         bool disable = false;
         switch (action) {
@@ -1565,7 +1566,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_BREAKLINE:
                BeforeChange();
                owner->view()->text->InsertChar(LyXParagraph::META_NEWLINE);
-               SmallUpdate(1);
+               owner->view()->smallUpdate(1);
                SetUpdateTimer(0.01);
                moveCursorUpdate(false);
                break;
@@ -1574,7 +1575,7 @@ string LyXFunc::Dispatch(int ac,
                BeforeChange();
                owner->view()->text->
                        InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
-               SmallUpdate(1);
+               owner->view()->smallUpdate(1);
                SetUpdateTimer();
                 moveCursorUpdate(false);
                break;
@@ -1600,7 +1601,7 @@ string LyXFunc::Dispatch(int ac,
                        owner->view()->text->Delete();
                        owner->view()->text->sel_cursor = 
                                owner->view()->text->cursor;
-                       SmallUpdate(1);
+                       owner->view()->smallUpdate(1);
                        // It is possible to make it a lot faster still
                        // just comment out the lone below...
                        owner->view()->getScreen()->ShowCursor();
@@ -1640,13 +1641,13 @@ string LyXFunc::Dispatch(int ac,
                                        owner->view()->text->Delete();
                                        owner->view()->text->sel_cursor = 
                                                owner->view()->text->cursor;
-                                       SmallUpdate(1);
+                                       owner->view()->smallUpdate(1);
                                }
                        } else {
                                owner->view()->text->Delete();
                                owner->view()->text->sel_cursor = 
                                        owner->view()->text->cursor;
-                               SmallUpdate(1);
+                               owner->view()->smallUpdate(1);
                        }
                } else {
                        CutCB();
@@ -1712,7 +1713,7 @@ string LyXFunc::Dispatch(int ac,
                                owner->view()->text->Backspace();
                                owner->view()->text->sel_cursor = 
                                        owner->view()->text->cursor;
-                               SmallUpdate(1);
+                               owner->view()->smallUpdate(1);
                                // It is possible to make it a lot faster still
                                // just comment out the lone below...
                                owner->view()->getScreen()->ShowCursor();
@@ -1748,7 +1749,7 @@ string LyXFunc::Dispatch(int ac,
                                owner->view()->text->Backspace();
                                owner->view()->text->sel_cursor 
                                        = cursor;
-                               SmallUpdate (1);
+                               owner->view()->smallUpdate (1);
                        }
                } else
                        CutCB();
@@ -1760,7 +1761,7 @@ string LyXFunc::Dispatch(int ac,
        {
                BeforeChange();
                owner->view()->text->BreakParagraph(0);
-               SmallUpdate(1);
+               owner->view()->smallUpdate(1);
                SetUpdateTimer(0.01);
                owner->view()->text->sel_cursor = 
                        owner->view()->text->cursor;
@@ -1771,7 +1772,7 @@ string LyXFunc::Dispatch(int ac,
        {
                BeforeChange();
                owner->view()->text->BreakParagraph(1);
-               SmallUpdate(1);
+               owner->view()->smallUpdate(1);
                SetUpdateTimer(0.01);
                owner->view()->text->sel_cursor = 
                        owner->view()->text->cursor;
@@ -1802,7 +1803,7 @@ string LyXFunc::Dispatch(int ac,
                }
                else {
                        owner->view()->text->BreakParagraph(0);
-                       SmallUpdate(1);
+                       owner->view()->smallUpdate(1);
                }
                SetUpdateTimer(0.01);
                owner->view()->text->sel_cursor = cursor;
@@ -1812,7 +1813,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_QUOTE:
                BeforeChange();
                owner->view()->text->InsertChar('\"');  // This " matches the single quote in the code
-               SmallUpdate(1);
+               owner->view()->smallUpdate(1);
                SetUpdateTimer();
                 moveCursorUpdate(false);
                break;
@@ -1982,7 +1983,7 @@ string LyXFunc::Dispatch(int ac,
                keyseq.length = 0;
                
                // copied verbatim from do_accent_char
-               SmallUpdate(1);
+               owner->view()->smallUpdate(1);
                SetUpdateTimer();
                owner->view()->text->sel_cursor = 
                        owner->view()->text->cursor;
@@ -2339,7 +2340,7 @@ string LyXFunc::Dispatch(int ac,
                        owner->view()->text->InsertChar(argument[i]);
                        // This needs to be in the loop, or else we
                        // won't break lines correctly. (Asger)
-                       SmallUpdate(1);
+                       owner->view()->smallUpdate(1);
                }
                SetUpdateTimer();
                owner->view()->text->sel_cursor = 
@@ -2405,7 +2406,7 @@ string LyXFunc::Dispatch(int ac,
                                        owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->view()->text);
                        }
                        
-                       SmallUpdate(1);
+                       owner->view()->smallUpdate(1);
                        SetUpdateTimer();
 
                        owner->view()->text->sel_cursor = 
index c35caaca7bb48150c83edd82a65be4a5f0bc04f0..bb55e8b971382b7b75660fbd7e6e1e261512d496 100644 (file)
 #include "support/filetools.h"
 
 LyXLex::LyXLex(keyword_item * tab, int num)
-       : table(tab), no_items(num)
+       : is(&fb__), table(tab), no_items(num)
 {
-       file = 0;
-       owns_file = false;
+       
        status = 0;
        pushed = 0;
 }
@@ -74,45 +73,45 @@ void LyXLex::printError(string const & message) const
 
 bool LyXLex::setFile(string const & filename)
 {
-        if (file)
-               lyxerr << "Error in LyXLex::setFile: file already set." <<endl;
-       file = fopen(filename.c_str(), "r");
+       if (fb__.is_open())
+               lyxerr << "Error in LyXLex::setFile: "
+                       "file or stream already set." << endl;
+       fb__.open(filename.c_str(), ios::in);
+       is.rdbuf(&fb__);
        name = filename;
-       owns_file = true;
        lineno = 0;
-       return (file ? true : false);
+       return fb__.is_open() && is.good();
 }
 
 
-void LyXLex::setFile(FILE * f)
+void LyXLex::setStream(istream & i)
 {
-        if (file) 
-               lyxerr << "Error in LyXLex::setFile: file already set."
-                      << endl;
-       file = f;
-       owns_file = false;
-       lineno = 0; // this is bogus if the file already has been read from
+       if (fb__.is_open() || is.rdbuf()->in_avail())
+               lyxerr << "Error in LyXLex::setStream: "
+                       "file or stream already set." << endl;
+       is.rdbuf(i.rdbuf());
+       lineno = 0;
 }
 
 
 int LyXLex::lex()
 {
        //NOTE: possible bug.
-   if (next() && status == LEX_TOKEN)
-       return search_kw(buff);
-   else
-       return status;
+       if (next() && status == LEX_TOKEN)
+               return search_kw(buff);
+       else
+               return status;
 }
 
 
 int LyXLex::GetInteger() const
 {
-   if (buff[0] > ' ')   
-       return atoi(buff);
-   else {
-       printError("Bad integer `$$Token'");
-       return -1;
-   }
+       if (buff[0] > ' ')   
+               return atoi(buff);
+       else {
+               printError("Bad integer `$$Token'");
+               return -1;
+       }
 }
 
 
@@ -185,26 +184,26 @@ string LyXLex::getLongString(string const & endtoken)
 
 bool LyXLex::GetBool() const
 {
-   if (compare(buff, "true") == 0)
-       return true;
-   else if (compare(buff, "false") != 0)
-       printError("Bad boolean `$$Token'. Use \"false\" or \"true\"");
-   return false;
+       if (compare(buff, "true") == 0)
+               return true;
+       else if (compare(buff, "false") != 0)
+               printError("Bad boolean `$$Token'. Use \"false\" or \"true\"");
+       return false;
 }
 
 
 bool LyXLex::EatLine()
 {
        int i = 0;
-       int c = '\0'; // getc() returns an int
+       unsigned char c = '\0';
 
-       while (!feof(file) && c!= '\n' && i!= (LEX_MAX_BUFF-1)) {
-               c = getc(file);
+       while(is && c != '\n' && i != (LEX_MAX_BUFF - 1)) {
+               is.get(c);
                if (c != '\r')
                        buff[i++] = c;
        }
-       if (i == (LEX_MAX_BUFF-1) && c != '\n') {
-               printError("Line too long");
+       if (i == (LEX_MAX_BUFF - 1) && c != '\n') {
+               printError("Line too long");
                c = '\n'; // Pretend we had an end of line
                --lineno; // but don't increase line counter (netto effect)
                ++i; // and preserve last character read.
@@ -249,14 +248,15 @@ int LyXLex::search_kw(char const * const tag) const
 bool LyXLex::next(bool esc)
 {
        if (!esc) {
-               int c; // getc() returns an int
+               unsigned char c; // getc() returns an int
                
                status = 0;
-               while (!feof(file) && !status) { 
-                       c = getc(file);
+               while (is && !status) { 
+                       is.get(c);
                        if (c == '#') {
                                // Read rest of line (fast :-)
-                               fgets(buff, sizeof(buff), file);
+                               is.get(buff, sizeof(buff));
+                               lyxerr[Debug::LYXLEX] << "Comment read: " << c << buff << endl;
                                ++lineno;
                                continue;
                        }
@@ -264,19 +264,19 @@ bool LyXLex::next(bool esc)
                        if (c == '\"') {
                                int i = -1;
                                do {
-                                       c = getc(file);
+                                       is.get(c);
                                        if (c != '\r')
                                                buff[++i] = c;
-                               } while (c!= '\"' && c!= '\n' && !feof(file) &&
-                                        i!= (LEX_MAX_BUFF-2));
+                               } while (c != '\"' && c != '\n' && is &&
+                                        i != (LEX_MAX_BUFF - 2));
                                
-                               if (i == (LEX_MAX_BUFF-2)) {
+                               if (i == (LEX_MAX_BUFF - 2)) {
                                        printError("Line too long");
                                        c = '\"'; // Pretend we got a "
                                        ++i;
                                }
                                
-                               if (c!= '\"') {
+                               if (c != '\"') {
                                        printError("Missing quote");
                                        if (c == '\n')
                                                ++lineno;
@@ -289,27 +289,35 @@ bool LyXLex::next(bool esc)
                        
                        if (c == ',')
                                continue;              /* Skip ','s */
-                       
-                       if (c > ' ' && !feof(file))  {
+
+                       // using relational operators with chars other
+                       // than == and != is not safe. And if it is done
+                       // the type _have_ to be unsigned. It usually a
+                       // lot better to use the functions from cctype
+                       if (c > ' ' && is)  {
+#warning Verify this! (Lgb)
+                               //if (isalnum(static_cast<unsigned char>(c)) && is) {
                                int i = 0;
                                do {
                                        buff[i++] = c;
-                                       c = getc(file);
-                               } while (c > ' ' && c != ',' && !feof(file) &&
-                                        (i != LEX_MAX_BUFF-1) );
-                               if (i == LEX_MAX_BUFF-1) {
+                                       is.get(c);
+                               } while (c > ' ' && c != ',' && is
+                               //} while (isalnum(static_cast<unsigned char>(c))
+                                        //&& c != ',' && is
+                                        && (i != LEX_MAX_BUFF - 1) );
+                               if (i == LEX_MAX_BUFF - 1) {
                                        printError("Line too long");
                                }
                                buff[i] = '\0';
                                status = LEX_TOKEN;
                        }
                        
-                       if (c == '\r' && !feof(file)) {
+                       if (c == '\r' && is) {
                                // The Windows support has lead to the
                                // possibility of "\r\n" at the end of
                                // a line.  This will stop LyX choking
                                // when it expected to find a '\n'
-                               c = getc(file);
+                               is.get(c);
                        }
 
                        if (c == '\n')
@@ -318,15 +326,15 @@ bool LyXLex::next(bool esc)
                }
                if (status) return true;
                
-               status = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
+               status = is.eof() ? LEX_FEOF: LEX_UNDEF;
                buff[0] = '\0';
                return false;
        } else {
-               int c; // getc() returns an int
+               unsigned char c; // getc() returns an int
                
                status = 0;
-               while (!feof(file) && !status) { 
-                       c = getc(file);
+               while (is && !status) {
+                       is.get(c);
 
                        // skip ','s
                        if (c == ',') continue;
@@ -337,13 +345,15 @@ bool LyXLex::next(bool esc)
                                do {
                                        if (c == '\\') {
                                                // escape the next char
-                                               c = getc(file);
+                                               is.get(c);
                                        }
                                        buff[i++] = c;
-                                       c = getc(file);
-                               } while (c > ' ' && c != ',' && !feof(file) &&
-                                        (i != LEX_MAX_BUFF-1) );
-                               if (i == LEX_MAX_BUFF-1) {
+                                       is.get(c);
+                               } while (c > ' ' && c != ',' && is
+                               //} while (isalnum(static_cast<unsigned char>(c))
+                                        //&& c != ',' && is
+                                        && (i != LEX_MAX_BUFF - 1) );
+                               if (i == LEX_MAX_BUFF - 1) {
                                        printError("Line too long");
                                }
                                buff[i] = '\0';
@@ -353,7 +363,8 @@ bool LyXLex::next(bool esc)
                        
                        if (c == '#') {
                                // Read rest of line (fast :-)
-                               fgets(buff, sizeof(buff), file);
+                               is.get(buff, sizeof(buff));
+                               lyxerr[Debug::LYXLEX] << "Comment read: " << c << buff << endl;
                                ++lineno;
                                continue;
                        }
@@ -364,26 +375,26 @@ bool LyXLex::next(bool esc)
                                bool escaped = false;
                                do {
                                        escaped = false;
-                                       c = getc(file);
+                                       is.get(c);
                                        if (c == '\r') continue;
                                        if (c == '\\') {
                                                // escape the next char
-                                               c = getc(file);
+                                               is.get(c);
                                                escaped = true;
                                        }
                                        buff[++i] = c;
                                
                                        if (!escaped && c == '\"') break;
-                               } while (c!= '\n' && !feof(file) &&
-                                        i!= (LEX_MAX_BUFF-2));
+                               } while (c != '\n' && is &&
+                                        i != (LEX_MAX_BUFF - 2));
                                
-                               if (i == (LEX_MAX_BUFF-2)) {
+                               if (i == (LEX_MAX_BUFF - 2)) {
                                        printError("Line too long");
                                        c = '\"'; // Pretend we got a "
                                        ++i;
                                }
                                
-                               if (c!= '\"') {
+                               if (c != '\"') {
                                        printError("Missing quote");
                                        if (c == '\n')
                                                ++lineno;
@@ -394,25 +405,27 @@ bool LyXLex::next(bool esc)
                                break; 
                        }
                        
-                       if (c > ' ' && !feof(file))  {
+                       if (c > ' ' && is) {
+                               //if (isalnum(static_cast<unsigned char>(c)) && is) {
                                int i = 0;
                                do {
                                        if (c == '\\') {
                                                // escape the next char
-                                               c = getc(file);
+                                               is.get(c);
                                                //escaped = true;
                                        }
                                        buff[i++] = c;
-                                       c = getc(file);
-                               } while (c > ' ' && c != ',' && !feof(file) &&
-                                        (i != LEX_MAX_BUFF-1) );
+                                       is.get(c);
+                               } while (c > ' ' && c != ',' && is
+                               //} while (isalnum(static_cast<unsigned char>(c))
+                                        //!= ',' && is
+                                        && (i != LEX_MAX_BUFF-1) );
                                if (i == LEX_MAX_BUFF-1) {
                                        printError("Line too long");
                                }
                                buff[i] = '\0';
                                status = LEX_TOKEN;
                        }
-
                        // new line
                        if (c == '\n')
                                ++lineno;
@@ -420,7 +433,7 @@ bool LyXLex::next(bool esc)
                
                if (status) return true;
                
-               status = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
+               status = is.eof() ? LEX_FEOF: LEX_UNDEF;
                buff[0] = '\0';
                return false;   
        }
@@ -430,30 +443,36 @@ bool LyXLex::next(bool esc)
 bool LyXLex::nextToken()
 {
         status = 0;
-       while (!feof(file) && !status) { 
-               int c = getc(file); // getc() returns an int
+       while (is && !status) { 
+               unsigned char c;
+               is.get(c);
           
-               if (c >= ' ' && !feof(file))  {
+               if (c >= ' ' && is) {
+                       //if (isprint(static_cast<unsigned char>(c)) && is) {
                        int i = 0;
                        if (c == '\\') { // first char == '\\'
                                do {
                                        buff[i++] = c;
-                                       c = getc(file);
-                               } while (c > ' ' && c != '\\' && !feof(file) &&
-                                        i != (LEX_MAX_BUFF-1));
+                                       is.get(c);
+                               } while (c > ' ' && c != '\\' && is
+                               //} while (isalnum(static_cast<unsigned char>(c))
+                               //       && c != '\\' && is
+                                        && i != (LEX_MAX_BUFF-1));
                        } else {
                                do {
                                        buff[i++] = c;
-                                       c = getc(file);
-                               } while (c >= ' ' && c != '\\' && !feof(file)
+                                       is.get(c);
+                               } while (c >= ' ' && c != '\\' && is
+                               //} while (isprint(static_cast<unsigned char>(c))
+                                        // && c != '\\' && is
                                         && i != (LEX_MAX_BUFF-1));
                        }
 
-                       if (i == (LEX_MAX_BUFF-1)) {
+                       if (i == (LEX_MAX_BUFF - 1)) {
                                printError("Line too long");
                        }
 
-                       if (c == '\\') ungetc(c, file); // put it back
+                       if (c == '\\') is.putback(c); // put it back
                        buff[i] = '\0';
                        status = LEX_TOKEN;
                }
@@ -464,7 +483,7 @@ bool LyXLex::nextToken()
        }
         if (status)  return true;
         
-        status = (feof(file)) ? LEX_FEOF: LEX_UNDEF;
+        status = is.eof() ? LEX_FEOF: LEX_UNDEF;
         buff[0] = '\0';
         return false;
 }
index b581a7bb36039bb4875ca9a8d5235917c85910ac..74a8054d9c18c8deb62bfaed519e7d93efd85697 100644 (file)
@@ -11,7 +11,7 @@
 #pragma interface
 #endif
 
-#include <cstdio>
+#include <fstream>
 #include "LString.h"
 
 ///
@@ -32,8 +32,6 @@ class LyXLex {
 public:
        ///
        LyXLex (keyword_item *, int);
-       ///
-       ~LyXLex() { if (file && owns_file) fclose(file); };
 
        /// Lex basic codes
        enum {
@@ -51,12 +49,10 @@ public:
        bool IsOK() const;
        /// return true if able to open file, else false
        bool setFile(string const & filename);
-       /// if file is already read from, line numbers will be wrong.
-       // should be removed
-       void setFile(FILE * f);
        ///
-       // should be removed
-       FILE * getFile() { return file; }
+       void setStream(istream & i);
+       ///
+       istream & getStream() { return is; }
        /// Danger! Don't use it unless you know what you are doing.
        void setLineNo(int l) { lineno = l; }
        /// returns a lex code
@@ -137,10 +133,10 @@ protected:
                int table_siz;
        };
 
-       ///
-       FILE * file;
-        ///
-        bool owns_file;
+       /// fb__ is only used to open files, the stream is accessed through is
+       filebuf fb__;
+       /// the stream that we use.
+       istream is;
        /// 
        string name;
        ///
@@ -163,9 +159,10 @@ protected:
 inline
 bool LyXLex::IsOK() const
 {
-       return (file && !feof(file));
+       return is.good();
 }
 
+
 // This is needed to ensure that the pop is done upon exit from methods
 // with more than one exit point or that can return as a response to
 // exceptions. (Lgb)
index e8162459e8b4623a549ad303e6bb3e0f160c3a79..5b6adafb762f94b1e82e7aa7b11d86ca08b35ad6 100644 (file)
@@ -136,9 +136,9 @@ public:
 
        ///
        void read();
-       
+
        ///
-       void readSimpleWholeFile(FILE *);
+       void readSimpleWholeFile(istream &);
 
        ///
        LyXParagraph * TeXOnePar(string & file, TexRow & texrow,
index 58e1af34971cfca48a3825a8f3634bf795ffd51c..8449f9a4209633d6b6c9ef69163d85a2e084fbdb 100644 (file)
@@ -38,7 +38,6 @@
 #include <config.h>
 
 #include <cstring>
-#include <cstdio>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
index f46b05edbe416cead1e300f0ebf768974d7da51e..ee644335c46f112e601a7729175a825613a1388a 100644 (file)
@@ -182,6 +182,9 @@ public:
          cursor in a text (and thus not in a buffer). By keeping this it is
          (I think) impossible to have several views with the same buffer, but
          the cursor placed at different places.
+         [later]
+         Since the LyXText now has been moved from Buffer to BufferView
+         it should not be absolutely needed to move the cursor...
          */
        LyXCursor cursor;
    
@@ -461,8 +464,13 @@ public:
         bool IsEmptyTableCell() const;
         ///
         void toggleAppendix();
+       ///
+       unsigned short paperWidth() const { return paperwidth; }
 
 private:
+       /// width of the paper
+       unsigned short  paperwidth;
+
        ///
        Row * firstrow;
        ///
@@ -478,8 +486,6 @@ private:
        Row * currentrow;               /* pointer to the current row  */
        /// position in the text 
        long  currentrow_y;
-       /// width of the paper
-       unsigned short  paperwidth;
    
        /** inserts a new row behind the specified row, increments
         * the touched counters */
index 791fe931cc33cafa5b788c8b972594f101d8a6ce..b43390441cd8fc2b08911fca72df1d6ec1777129 100644 (file)
@@ -1,11 +1,11 @@
 AUTOMAKE_OPTIONS = foreign 1.4
 MAINTAINERCLEANFILES = Makefile.in
-noinst_LTLIBRARIES = libmathed.la
+noinst_LTLIBRARIES = libmathed.o
 LIBS=
 ETAGS_ARGS = --c++
 INCLUDES = -I${top_srcdir}/images -I${srcdir}/../ 
 
-libmathed_la_SOURCES = array.h \
+libmathed_o_SOURCES = array.h \
        formula.C \
        formula.h \
        formulamacro.C \
index d59847f6864bb82a877e0aac5e11befe069a7678..82565a529881c2888ace6290353eabca2366d090 100644 (file)
@@ -380,27 +380,26 @@ void InsetFormula::Validate(LaTeXFeatures & features) const
 
 void InsetFormula::Read(LyXLex & lex)
 {
-    FILE * file = lex.getFile();
+       istream & is = lex.getStream();
     
-    mathed_parser_file(file, lex.GetLineNo());   
+       mathed_parser_file(is, lex.GetLineNo());   
    
-   // Silly hack to read labels. 
-   mathed_label = 0;
-   mathed_parse(0, 0, &par);
-   par->Metrics();
-   disp_flag = (par->GetType() > 0);
-   
-    // Update line number
-    lex.setLineNo(mathed_parser_lineno());
-    
-   if (mathed_label) {
-      label = mathed_label;
-      mathed_label = 0;
-   }
+       // Silly hack to read labels. 
+       mathed_label = 0;
+       mathed_parse(0, 0, &par);
+       par->Metrics();
+       disp_flag = (par->GetType() > 0);
+       
+       // Update line number
+       lex.setLineNo(mathed_parser_lineno());
+       
+       if (mathed_label) {
+               label = mathed_label;
+               mathed_label = 0;
+       }
    
 #ifdef DEBUG
-   Write(stdout);
-   fflush(stdout);
+       Write(lyxerr);
 #endif
 }
 
index abc12fe4a45bfa7491878b72ca845e3ab3abcda7..773bd83d951ab7ff6577ff667d70e424a5c5b923 100644 (file)
@@ -103,16 +103,16 @@ int InsetFormulaMacro::DocBook(string &/*file*/)
 
 void InsetFormulaMacro::Read(LyXLex & lex)
 {
-    FILE * file = lex.getFile();
-    mathed_parser_file(file, lex.GetLineNo());   
-    mathed_parse(0, 0, reinterpret_cast<MathParInset **>(&tmacro));
+       istream & is = lex.getStream();
+       mathed_parser_file(is, lex.GetLineNo());   
+       mathed_parse(0, 0, reinterpret_cast<MathParInset **>(&tmacro));
     
-    // Update line number
-    lex.setLineNo(mathed_parser_lineno());
-    
-    MathMacroTable::mathMTable.addTemplate(tmacro);
-    name = tmacro->GetName();
-    par = tmacro;
+       // Update line number
+       lex.setLineNo(mathed_parser_lineno());
+       
+       MathMacroTable::mathMTable.addTemplate(tmacro);
+       name = tmacro->GetName();
+       par = tmacro;
 }
 
 
index 669de5783cbd51522475cbed51c14d1dfe34ca35..74317388e87f603d310a19b50293c718f08fe8fb 100644 (file)
 #pragma interface
 #endif
 
-#include <cstdio>
 #include "LString.h"
 #include "debug.h"
 
 #include "array.h"
 
-
 ///
 enum math_align {
        ///
@@ -543,14 +541,12 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * data,
 ///
 void mathed_write(MathParInset *, ostream &, int *, char fragile,
                  char const * label = 0);
-///
-//void mathed_write(MathParInset *, FILE *, int *, char fragile,
-//               char const * label = 0);
+
 ///
 void mathed_write(MathParInset *, string &, int *, char fragile,
                  char const * label = 0);
 ///
-void mathed_parser_file(FILE *, int);
+void mathed_parser_file(istream &, int);
 ///
 int mathed_parser_lineno();
 ///
index 19ff2b7a6254cb11f561ab8d45c7970b94a183e3..90b623d4f2bf0601bc5f74b385d431b92933e0dc 100644 (file)
@@ -1,7 +1,7 @@
 /* C code produced by gperf version 2.5 (GNU C++ version) */
 /* Command-line: gperf -a -p -o -t -G -D keywords  */
 #include <config.h>
-#include <cstdio>
+
 #include <cstdlib>
 #include <cstring>
 
index 959e784ffdafd80349281c0f2660bcbebefdfa18..536e83458db58f0b2d22756811ea4a1ff24c344c 100644 (file)
@@ -26,7 +26,6 @@
 #pragma interface
 #endif
 
-#include <cstdio>
 #include "math_defs.h"
 #include "symbol_def.h"
 #include "LString.h"
index 40067b44f4458e3342e5e3168f7620ef549e8387..250de2aa6a5fc5079bb1cc768a10ff137efa5457 100644 (file)
@@ -15,7 +15,6 @@
 #include <config.h>
 
 #include FORMS_H_LOCATION
-#include <cstdio>
 #include <cstdlib>
 
 #include "lyx_gui_misc.h" 
index 3b10d551f21e926fa06cd07f1d8b526bd94f0b79..5bb466ed6d41e92d65e30005585b45f65ef46859 100644 (file)
@@ -86,13 +86,13 @@ enum lexcode_enum {
 static lexcode_enum lexcode[256];  
 static char yytext[256];
 static int yylineno;
-static FILE * yyin;
+static istream * yyis;
 static bool yy_mtextmode= false;
            
 inline
 char * strnew(char const * s)
 {
-       char *s1 = new char[strlen(s)+1]; // this leaks when not delete[]'ed
+       char * s1 = new char[strlen(s) + 1]; // this leaks when not delete[]'ed
        strcpy(s1, s);
        return s1;
 }
@@ -136,14 +136,14 @@ static void LexInitCodes()
 
 static char LexGetArg(char lf, bool accept_spaces= false)
 {
-   char c, rg, * p = &yytext[0];
+   char rg, * p = &yytext[0];
    int bcnt = 1;
-   
-   while (!feof(yyin)) {
-      c = getc(yyin); 
-      if (c>' ') {
+   unsigned char c;
+   while (yyis->good()) {
+      yyis->get(c);
+      if (c > ' ') {
         if (!lf) lf = c; else
-        if (c!= lf)
+        if (c != lf)
                 lyxerr << "Math parse error: unexpected '"
                        << c << "'" << endl;
         break;
@@ -156,11 +156,11 @@ static char LexGetArg(char lf, bool accept_spaces= false)
       return '\0';
    } 
    do {
-      c = getc(yyin); 
-      if (c == lf) bcnt++;
-      if (c == rg) bcnt--;
-      if ((c>' ' || (c == ' ' && accept_spaces)) && bcnt>0) *(p++) = c;
-   } while (bcnt>0 && !feof(yyin));
+      yyis->get(c);
+      if (c == lf) ++bcnt;
+      if (c == rg) --bcnt;
+      if ((c > ' ' || (c == ' ' && accept_spaces)) && bcnt>0) *(p++) = c;
+   } while (bcnt > 0 && yyis->good());
    *p = '\0';
    return rg;
 }
@@ -173,8 +173,8 @@ static int yylex(void)
    
    if (!init_done) LexInitCodes();
    
-   while (!feof(yyin)) { 
-      c = getc(yyin);
+   while (yyis->good()) { 
+      yyis->get(c);
        
       if (yy_mtextmode && c == ' ') {
          yylval.i= ' ';
@@ -182,12 +182,12 @@ static int yylex(void)
       }
        
        if (lexcode[c] == LexNewLine) {
-          yylineno++
+          ++yylineno
           continue;
        }
         
       if (lexcode[c] == LexComment) 
-       do c = getc(yyin); while (c!= '\n' % !feof(yyin));  // eat comments
+       do yyis->get(c); while (c != '\n' % yyis->good());  // eat comments
     
       if (lexcode[c] == LexDigit || lexcode[c] == LexOther || lexcode[c] == LexMathSpace) 
         { yylval.i= c; return LM_TK_STR; }
@@ -195,7 +195,7 @@ static int yylex(void)
       if (lexcode[c] == LexBOP)   { yylval.i= c; return LM_TK_BOP; }
       if (lexcode[c] == LexSelf)  { return c; }   
       if (lexcode[c] == LexArgument)   { 
-         c = getc(yyin);
+         yyis->get(c);
          yylval.i = c - '0';
          return LM_TK_ARGUMENT; 
       }
@@ -203,7 +203,7 @@ static int yylex(void)
       if (lexcode[c] == LexClose)   { return LM_TK_CLOSE; }
       
       if (lexcode[c] == LexESC)   {
-        c = getc(yyin);
+        yyis->get(c);
         if (c == '\\') { return LM_TK_NEWLINE; }
         if (c == '(')  { yylval.i = LM_EN_INTEXT; return LM_TK_BEGIN; }
         if (c == ')')  { yylval.i = LM_EN_INTEXT; return LM_TK_END; }
@@ -215,20 +215,20 @@ static int yylex(void)
         }  
         if (lexcode[c] == LexMathSpace) {
            int i;
-           for (i= 0; i<4 && c!= latex_mathspace[i][0]; i++);
-           yylval.i = (i<4) ? i: 0; 
+           for (i = 0; i < 4 && c != latex_mathspace[i][0]; ++i);
+           yylval.i = (i < 4) ? i: 0; 
            return LM_TK_SPACE; 
         }
         if (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
-           char* p = &yytext[0];
+           char * p = &yytext[0];
            while (lexcode[c] == LexAlpha || lexcode[c] == LexDigit) {
               *p = c;
-              c = getc(yyin);
+              yyis->get(c);
               p++;
            }
            *p = '\0';
-           if (!feof(yyin)) ungetc(c, yyin);
-           latexkeys *l = in_word_set (yytext, strlen(yytext));
+           if (yyis->good()) yyis->putback(c);
+           latexkeys * l = in_word_set (yytext, strlen(yytext));
            if (l) {
               if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) { 
                  int i;
@@ -236,7 +236,7 @@ static int yylex(void)
 //               for (i= 0; i<5 && strncmp(yytext, latex_mathenv[i],
 //                             strlen(latex_mathenv[i])); i++);
                  
-                 for (i= 0; i<6 && strcmp(yytext, latex_mathenv[i]); i++);
+                 for (i = 0; i < 6 && strcmp(yytext, latex_mathenv[i]); i++);
                  yylval.i = i;
               } else
               if (l->token == LM_TK_SPACE) 
@@ -258,7 +258,7 @@ static int yylex(void)
 int parse_align(char * hor, char *)
 {
    int nc = 0;
-   for (char * c = hor; c && *c > ' '; ++c) nc++;
+   for (char * c = hor; c && *c > ' '; ++c) ++nc;
    return nc;
 }
 
@@ -280,8 +280,8 @@ MathedInset * doAccent(byte c, MathedTextCodes t)
 {
        MathedInset * ac = 0;
        
-       for (int i= accent-1; i>= 0; i--) {
-               if (i == accent-1)
+       for (int i = accent - 1; i >= 0; --i) {
+               if (i == accent - 1)
                  ac = new MathAccentInset(c, t, nestaccent[i]);
                else 
                  ac = new MathAccentInset(ac, nestaccent[i]);
@@ -296,8 +296,8 @@ MathedInset * doAccent(MathedInset * p)
 {
        MathedInset * ac = 0;
        
-       for (int i= accent-1; i>= 0; i--) {
-               if (i == accent-1)
+       for (int i = accent - 1; i >= 0; --i) {
+               if (i == accent - 1)
                  ac = new MathAccentInset(p, nestaccent[i]);
                else 
                  ac = new MathAccentInset(ac, nestaccent[i]);
@@ -308,8 +308,6 @@ MathedInset * doAccent(MathedInset * p)
 }
 
 
-
-
 LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
                            MathParInset ** mtx)
 {
@@ -318,14 +316,14 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
    static int plevel = -1;
    static int size = LM_ST_TEXT;
    MathedTextCodes varcode = LM_TC_VAR;
-   MathedInset* binset = 0;
-   static MathMacroTemplate *macro= 0;
+   MathedInset * binset = 0;
+   static MathMacroTemplate * macro= 0;
    
    int brace = 0;
    int acc_brace = 0;
    int acc_braces[8];
    MathParInset * mt = (mtx) ? *mtx: 0;//(MathParInset*)0;
-    MathedRowSt * crow = (mt) ? mt->getRowSt(): 0;
+    MathedRowSt * crow = (mt) ? mt->getRowSt() : 0;
 
    ++plevel;
    if (!array) array = new LyxArrayBase;
@@ -364,10 +362,10 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
          LexGetArg('{');
          // This name lives until quitting, for that reason
          // I didn't care on deleting explicitly. Later I will.
-         char const *name = strnew(&yytext[1]);
+         char const * name = strnew(&yytext[1]);
          // ugly trick to be removed soon (lyx3)
-         char c = getc(yyin);
-         ungetc(c, yyin);
+         char c; yyis->get(c);
+         yyis->putback(c);
          if (c == '[') {
              LexGetArg('[');
              na = atoi(yytext);
@@ -441,7 +439,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
       {
         if (flags & FLAG_BRACK_ARG) {
           flags &= ~FLAG_BRACK_ARG;
-          char rg= LexGetArg('[');
+          char rg = LexGetArg('[');
           if (rg!= ']') {
              mathPrintError("Expected ']'");
              panic = true;
@@ -464,7 +462,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
 
     case '^':
       {  
-        MathParInset *p = new MathParInset(size, "", LM_OT_SCRIPT);
+        MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
         LyxArrayBase * ar = mathed_parse(FLAG_BRACE_OPT|FLAG_BRACE_LAST, 0);
         p->SetData(ar);
 //      lyxerr << "UP[" << p->GetStyle() << "]" << endl;
@@ -530,7 +528,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
            } else
            data.Insert (yylval.l->id, tc);
         } else {
-           MathFuncInset *bg = new MathFuncInset(yylval.l->name);
+           MathFuncInset * bg = new MathFuncInset(yylval.l->name);
             if (accent) {
                     data.Insert(doAccent(bg));
             } else
@@ -555,7 +553,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
       }
     case LM_TK_SPACE:
       {
-        if (yylval.i>= 0) {
+        if (yylval.i >= 0) {
            MathSpaceInset * sp = new MathSpaceInset(yylval.i);
            data.Insert(sp);
         }
@@ -566,7 +564,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
         MathDotsInset * p = new MathDotsInset(yylval.l->name, yylval.l->id);
         data.Insert(p);
         break;
-      }     
+      }
     case LM_TK_STACK:
        fractype = LM_OT_STACKREL;
     case LM_TK_FRAC:
@@ -582,7 +580,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
       {            
         MathParInset * rt;
          
-        char c = getc(yyin);
+        char c; yyis->get(c);
          
         if (c == '[') {
             rt = new MathRootInset(size);
@@ -590,7 +588,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
             rt->SetData(mathed_parse(FLAG_BRACK_END, 0, &rt));
             rt->setArgumentIdx(1);
         } else {
-            ungetc(c, yyin);
+                yyis->putback(c);
             rt = new MathSqrtInset(size);
         }
         rt->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST, 0, &rt));
@@ -678,7 +676,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
             data.Insert(doAccent(p), p->getTCode());
           else
             data.Insert(p, p->getTCode());
-          for (int i= 0; p->setArgumentIdx(i); i++)
+          for (int i = 0; p->setArgumentIdx(i); i++)
             p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
        }
        else {
@@ -710,7 +708,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
         if (yylval.i == LM_EN_ARRAY) {
            char ar[120], ar2[8];
            ar[0] = ar2[0] = '\0'; 
-            char rg= LexGetArg(0);
+            char rg = LexGetArg(0);
            if (rg == ']') {
               strcpy(ar2, yytext);
               rg = LexGetArg('{');
@@ -722,7 +720,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
                    data.Insert(mm, LM_TC_ACTIVE_INSET);
             mathed_parse(FLAG_END, mm->GetData(), &mm);
         } else
-        if (yylval.i>= LM_EN_INTEXT && yylval.i<= LM_EN_EQNARRAY) {
+        if (yylval.i >= LM_EN_INTEXT && yylval.i<= LM_EN_EQNARRAY) {
             if (plevel!= 0) {
                 mathPrintError("Misplaced environment");
                 break;
@@ -833,9 +831,9 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
 }
 
 
-void mathed_parser_file(FILE * file, int lineno)
+void mathed_parser_file(istream & is, int lineno)
 {
-    yyin = file;
+    yyis = &is;
     yylineno = lineno;
     if (!MathMacroTable::built)
        MathMacroTable::mathMTable.builtinMacros();
index 0429aadff9ba83fda09b9d13dab048e8fd203408..b9e5569a53e5fda5132052129760e3be77578b0a 100644 (file)
@@ -19,7 +19,6 @@
 #pragma interface
 #endif
 
-#include <cstdio>
 #include "math_defs.h"
 #include "math_inset.h"
 #include "symbol_def.h"
index 3b86cbc7adda65c9992e627376968e9aa300b13b..8d268a9a93ff8add142c9eb4420cd518f9186664 100644 (file)
@@ -39,7 +39,6 @@ using std::max;
 #include "math_panel.h"                 
 #include "math_parser.h"
 
-extern void SmallUpdate(signed char);
 extern void BeforeChange();
 extern void Update(signed char);
 extern int UnlockInset(UpdatableInset *);
index cb6da98baf7db601345b84f5b4ccf50bb6248c58..89f758519d829b2eb6613ac41862e54eeebaf913 100644 (file)
@@ -11,7 +11,8 @@
 
 #include <config.h>
 
-#include <stdlib.h>
+#include <cstdlib>
+
 #include "math_defs.h"
 #include "symbol_def.h"
 
index 82a8b1e3dfa6a27c09746a9d2033aeb33f0b57e2..959a5bcb7fb8115733dfabc0ebe1a6cef804ba80 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <config.h>
+
 #include "LString.h"
 #include "math_inset.h"
 #include "math_iter.h"
index 0c39863afed2e5ae644f5172ed82e04b5ec2d51e..49439cd2613a35f0040f3a0af802319b571887c5 100644 (file)
@@ -2226,18 +2226,14 @@ int LyXParagraph::GetPositionOfInset(Inset * inset) const
 }
 
 
-void LyXParagraph::readSimpleWholeFile(FILE * myfile)
+void LyXParagraph::readSimpleWholeFile(istream & is)
 {
-       rewind(myfile);
-   
-       if (!feof(myfile)) {
-               char c = 0;
-               do {
-                       c = fgetc(myfile);
-                       InsertChar(text.size(), c);
-               } while (!feof(myfile));
-      
-       }
+       is.seekg(0);
+       char c = 0;
+       while(!is.eof()) {
+               is.get(c);
+               InsertChar(text.size(), c);
+       };
 }
 
 
index ad610636ff30cc68e3d563fc85502b75ecb87bca..ea6bbab2313ad67c778c725f2f32480ce4267cf7 100644 (file)
@@ -48,11 +48,19 @@ protected:
                // fakes a purge of the buffer by returning n
                return n;
        }
+#ifdef MODERN_STL_STREAMS
+       ///
+       virtual int_type overflow(int_type c = traits_type::eof()) {
+               // fakes success by returning c
+               return c == traits_type::eof() ? ' ' : c;
+       }
+#else
        ///
        virtual int_type overflow(int_type c = EOF) {
                // fakes success by returning c
                return c == EOF ? ' ' : c;
        }
+#endif
 };
 
 /** A streambuf that sends the output to two different streambufs. These
@@ -64,40 +72,41 @@ public:
        teebuf(streambuf * b1, streambuf * b2)
                : streambuf(), sb1(b1), sb2(b2) {}
 protected:
-#ifndef MODERN_STL_STREAMS
-       typedef char char_type;
-       typedef int int_type;
-#endif
+#ifdef MODERN_STL_STREAMS
        ///
        virtual int sync() {
-#ifdef MODERN_STL_STREAMS
                sb2->pubsync();
                return sb1->pubsync();
-#else
-               sb2->sync();
-               return sb1->sync();
-#endif
        }
        ///
        virtual streamsize xsputn(char_type const * p, streamsize n) {
-#ifdef MODERN_STL_STREAMS
                sb2->sputn(p, n);
                return sb1->sputn(p, n);
+       }
+       ///
+       virtual int_type overflow(int_type c = traits_type::eof()) {
+               sb2->sputc(c);
+               return sb1->sputc(c);
+       }
 #else
+       typedef char char_type;
+       typedef int int_type;
+       ///
+       virtual int sync() {
+               sb2->sync();
+               return sb1->sync();
+       }
+       ///
+       virtual streamsize xsputn(char_type const * p, streamsize n) {
                sb2->xsputn(p, n);
                return sb1->xsputn(p, n);
-#endif
        }
        ///
        virtual int_type overflow(int_type c = EOF) {
-#ifdef MODERN_STL_STREAMS
-               sb2->sputc(c);
-               return sb1->sputc(c);
-#else
                sb2->overflow(c);
                return sb1->overflow(c);
-#endif
        }
+#endif
 private:
        ///
        streambuf * sb1;
@@ -112,34 +121,35 @@ public:
        debugbuf(streambuf * b)
                : streambuf(), sb(b) {}
 protected:
-#ifndef MODERN_STL_STREAMS
-       typedef char char_type;
-       typedef int int_type;
-#endif
+#ifdef MODERN_STL_STREAMS
        ///
        virtual int sync() {
-#ifdef MODERN_STL_STREAMS
                return sb->pubsync();
-#else
-               return sb->sync();
-#endif
        }
        ///
        virtual streamsize xsputn(char_type const * p, streamsize n) {
-#ifdef MODERN_STL_STREAMS
                return sb->sputn(p, n);
+       }
+       ///
+       virtual int_type overflow(int_type c = traits_type::eof()) {
+               return sb->sputc(c);
+       }
 #else
+       typedef char char_type;
+       typedef int int_type;
+       ///
+       virtual int sync() {
+               return sb->sync();
+       }
+       ///
+       virtual streamsize xsputn(char_type const * p, streamsize n) {
                return sb->xsputn(p, n);
-#endif
        }
        ///
        virtual int_type overflow(int_type c = EOF) {
-#ifdef MODERN_STL_STREAMS
-               return sb->sputc(c);
-#else
                return sb->overflow(c);
-#endif
        }
+#endif
 private:
        ///
        streambuf * sb;
index d511683bc5c32bc213f40a3a5b06856fd9b9182a..53120ecd86e72be04718d876da8331c201f4dc37 100644 (file)
@@ -17,6 +17,7 @@
 #include <config.h>
 
 #include <cctype>
+#include <fstream>
 #include <utility>
 using std::make_pair;
 using std::pair;
@@ -153,15 +154,13 @@ bool IsFileReadable (string const & path)
 //      -1 error (doesn't exist, no access, anything else) 
 int IsFileWriteable (string const & path)
 {
-       FilePtr fp(path, FilePtr::update);
-       if (!fp()) {
-               if ((errno == EACCES) || (errno == EROFS)) {
-                       fp.reopen(path, FilePtr::read);
-                       if (fp()) {
-                               return 0;
-                       }
-               }
-               return -1;
+       fstream fs(path.c_str(), ios::out|ios::ate);
+       if (!fs) {
+               fs.open(path.c_str(), ios::in|ios::ate);
+               if (fs)
+                       return 0;
+               else
+                       return -1;
        }
        return 1;
 }
@@ -179,23 +178,10 @@ int IsDirWriteable (string const & path)
                             _("Could not test if directory is writeable"));
                return -1;
        } else {
-       FilePtr fp(tmpfl, FilePtr::truncate);
-       if (!fp()) {
-               if (errno == EACCES) {
-                       return 0;
-               } else { 
-                       WriteFSAlert(_("LyX Internal Error!"), 
-                                    _("Cannot open directory test file"));
-                       return -1;
-               }
-               }
-       }
-               if (remove(tmpfl.c_str())) {
-                       WriteFSAlert(_("LyX Internal Error!"), 
-                                   _("Created test file but cannot remove it?"));
-                       return -1;
+               FileInfo fi(path);
+               if (fi.writable()) return 1;
+               return 0;
        }
-       return 1;
 }
 
 
@@ -334,7 +320,10 @@ bool PutEnv(string const & envstr)
         // this leaks, but what can we do about it?
         //   Is doing a getenv() and a free() of the older value 
         //   a good idea? (JMarc)
-        int retval = putenv(const_cast<PUTENV_TYPE_ARG>((new string(envstr))->c_str()));
+       // Actually we don't have to leak...calling putenv like this
+       // should be enough:
+       int retval = putenv(const_cast<PUTENV_TYPE_ARG>(envstr.c_str()));
+       //int retval = putenv(const_cast<PUTENV_TYPE_ARG>((new string(envstr))->c_str()));
 #else
 #ifdef HAVE_SETENV 
         string varname;
@@ -979,7 +968,7 @@ static cmdret do_popen(string const & cmd)
        // create our own popen based on fork, exec, pipe
        // of course the best would be to have a
        // pstream (process stream), with the
-       // variants ipstream, opstream and
+       // variants ipstream, opstream
        FILE * inf = popen(cmd.c_str(), "r");
        string ret;
        int c = fgetc(inf);
index 72752f1a15ac00bb8d970b10395eaefcac19b2c2..f171e94d8e1ba0c7dd246f430581c62a65461311 100644 (file)
 #pragma interface
 #endif
 
-#include <cstdio>
 #include <cstdlib>
 #include <fcntl.h>
 #include <cerrno>
+
 #include "debug.h"
 #include "LString.h"
 #include "support/lstrings.h"
 
-/** A file class.
-  Use this instead of FILE *, it gives a much better structure.
-  It should prehaps do a bit more error checking than it does now.
-  Currently it is a verbatim copy from p309 of Bjarne Stroupstrups
-  The C++ Programming Language. + some additions.
- */
-class FilePtr {
-public:
-       ///
-       enum file_mode {
-               read,
-               write,
-               update,
-               truncate
-       };
-       ///
-       FilePtr(string const & name, file_mode mode) {
-               init();
-               do_open(name, mode);
-       }
-       ///
-       FilePtr(FILE * pp) { init(); p = pp; }
-       ///
-       ~FilePtr() { close(); }
-
-       /** Use this if you want to rebind the FilePtr to another file.
-        */
-       FilePtr & reopen(string const & name, file_mode mode) {
-               // close the file it it is already open
-               close();
-               // Now open the file.
-               do_open(name, mode);
-
-               return *this;
-       }
-       /** Close the file.
-           Use this with some carefullness. After it has been used
-           the FilePtr is unusable. Only use it if it is important
-           that the file is closed before the FilePtr goes out
-           of scope. */
-       int close() { 
-               if (p) {
-                       int result = fclose(p); 
-                       p = 0; 
-                       return result;
-               } else 
-                       return 0;
-       }
-       /// automatic converson to FILE* if that is needed.
-       operator FILE*() { return p; }
-       ///
-       FilePtr & operator=(FILE * f) { p= f; return *this;}
-       ///
-       FILE * operator()() { return p; }
-private:
-       ///
-       void do_open(string const & name, file_mode mode) {
-               string modestr;
-               
-               switch(mode) {
-                       // do appropiate #ifdef here so support EMX
-#ifndef __EMX__
-               case read: modestr = "r"; break;
-               case write: modestr = "w"; break;
-#else
-               case read: modestr = "rt"; break; // Can read both DOS & UNIX text files.
-               case write: modestr = "w"; break; // Write UNIX text files.
-#endif
-                       
-               case update: modestr = "r+"; break;
-               case truncate: modestr = "w+"; break;
-               }
-               // Should probably be rewritten to use open(2)
-               if((p = fopen(name.c_str(), modestr.c_str()))) {
-                       // file succesfully opened.
-                       if (fcntl(fileno(p), F_SETFD, FD_CLOEXEC) == -1) {
-                               p = 0;
-                       }
-               } else {
-                       // we have an error let's check what it is.
-                       switch(errno) {
-                       case EINVAL:
-                               // Internal LyX error.
-                               lyxerr << "FilePtr: Wrong parameter given to fopen." << endl;
-                               break;
-                       default:
-                               // unknown error
-                               break;
-                       }
-               }
-       }
-       ///
-       void init() { p = 0; }
-       ///
-       FILE * p;
-};
-
 
 ///
 string CreateBufferTmpDir (string const & pathfor = string());
index 06875d2159097c8322a1233b83991582abdf5471..27f398dd4ad81672884ccacfb5187e149ea2a858 100644 (file)
@@ -1,16 +1,27 @@
 #include <config.h>
 
 #include <algorithm>
+#ifdef __GLIBCPP__
+#include <ctype.h>
+#else
 #include <cctype>
-#include <cstdio>
+#endif
 #include <cstdlib>
 
+#ifdef HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream>
+#endif
+
 #include "LString.h"
 #include "lstrings.h"
 #include "LRegex.h"
 
 using std::count;
 using std::transform;
+using std::tolower;
+using std::toupper;
 
 int compare_no_case(string const & s, string const & s2)
 {
@@ -34,6 +45,7 @@ int compare_no_case(string const & s, string const & s2)
        return 1;
 }
 
+
 int compare_no_case(string const & s, string const & s2, unsigned int len)
 {
 //#warning verify this func please
@@ -56,6 +68,7 @@ int compare_no_case(string const & s, string const & s2, unsigned int len)
        return 1;
 }
 
+
 bool isStrInt(string const & str)
 {
        if (str.empty()) return false;
@@ -90,7 +103,15 @@ int  strToInt(string const & str)
 string lowercase(string const & a)
 {
        string tmp(a);
+#ifdef __GLIBCPP__
+       string::iterator result = tmp.begin();
+       for (string::iterator first = tmp.begin();
+            first != tmp.end(); ++first, ++result) {
+               *result = tolower(*first);
+       }
+#else
        transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
+#endif
        return tmp;
 }
 
@@ -98,26 +119,50 @@ string lowercase(string const & a)
 string uppercase(string const & a)
 {
        string tmp(a);
+#ifdef __GLIBCPP__
+       string::iterator result = tmp.begin();
+       for (string::iterator first = tmp.begin();
+            first != tmp.end(); ++first, ++result) {
+               *result = toupper(*first);
+       }
+#else
        transform(tmp.begin(), tmp.end(), tmp.begin(), toupper);
+#endif
        return tmp;
 }
 
 
 string tostr(long i)
 {
-       // should use string stream
+#ifndef HAVE_SSTREAM
+       // "Hey!", you say. "Why do we need the char str[30]?".
+       // Since strstream does not handle memory for us we have to do
+       // that ourselves, if we don't pass str in we have to capture
+       // oss.str() in a tmp variable and delete that manually.
+       // Thus we then require more temporary variables and the code
+       // gets more obfuscated.
        char str[30];
-       sprintf(str, "%ld", i);
-       return string(str);
+       ostrstream oss(str, 30);
+       oss << i << '\0';
+#else
+       ostringstream oss;
+       oss << i;
+#endif
+       return oss.str();
 }
 
 
 string tostr(unsigned long i)
 {
-       // should use string stream
+#ifndef HAVE_SSTREAM   
        char str[30];
-       sprintf(str, "%lu", i);
-       return string(str);
+       ostrstream oss(str, 30);
+       oss << i << '\0';
+#else
+       ostringstream oss;
+       oss << i;
+#endif
+       return oss.str();
 }
 
 
@@ -153,10 +198,15 @@ string tostr(bool b)
 
 string tostr(double d)
 {
-       // should use string stream
+#ifndef HAVE_SSTREAM
        char tmp[40];
-       sprintf(tmp, "%f", d);
-       return string(tmp);
+       ostrstream oss(tmp, 40);
+       oss << d << '\0';
+#else
+       ostringstream oss;
+       oss << d;
+#endif
+       return oss.str();
 }
 
 
index f9264cd96fadd20d10b74c84082ed31b92094add..c12e755aa5ec9f38867b5776c52d6bb9c6ed8d88 100644 (file)
@@ -9,7 +9,6 @@
 #include <sys/wait.h>
 #include <csignal>
 #include <cstdlib>
-#include <cstdio>
 #include <unistd.h>
 #include "debug.h"
 #include "syscall.h"
index ac5b6487d300a15e690bb75a1be7a64c52b7852b..ef46bb9a27d53a938d0f45d29afde7a30ce5ad27 100644 (file)
@@ -32,10 +32,10 @@ LyXTable::LyXTable(int rows_arg, int columns_arg)
 }
 
 
-LyXTable::LyXTable(LyXLex &lex)
+LyXTable::LyXTable(LyXLex & lex)
 {
-       FILE * file = lex.getFile();
-       Read(file);
+       istream & is = lex.getStream();
+       Read(is);
 }
 
 
@@ -844,140 +844,113 @@ void LyXTable::Write(ostream & os)
 }
 
 
-void LyXTable::Read(FILE * file)
+void LyXTable::Read(istream & is)
 {
-    int version;
-    int i, j;
-    int rows_arg = 0;
-    int columns_arg = 0;
-    int is_long_table_arg = false;
-    int rotate_arg = false;
-    string s;
-    int a = 0;
-    int b = 0;
-    int c = 0;
-    int d = 0;
-    int e = 0;
-    int f = 0;
-    int g = 0;
-    int h = 0;
-    char vtmp[100], stmp[100], atmp[100];
-
-    fscanf(file, "%s\n", vtmp);
-    s = vtmp;
-    if (s.length() > 8)
-        version = atoi(s.c_str() + 8);
-    else
-        version = 1;
+       int version;
+       int i, j;
+       int rows_arg = 0;
+       int columns_arg = 0;
+       int is_long_table_arg = false;
+       int rotate_arg = false;
+       int a = -1;
+       int b = -1;
+       int c = -1;
+       int d = -1;
+       int e = 0;
+       int f = 0;
+       int g = 0;
+       int h = 0;
+       
+       string s;
+       getline(is, s);
+       if (s.length() > 8)
+               version = atoi(s.c_str() + 8);
+       else
+               version = 1;
 #ifdef WITH_WARNINGS
 #warning Insert a error message window here that this format is not supported anymore
 #endif
-    a = b = c = d = -1;
-    if (version < 5) {
-       lyxerr << "Tabular format < 5 is not supported anymore\n"
-           "Get an older version of LyX (< 1.1.x) for conversion!"
-              << endl;
-       if (version > 2) {
-           fgets(vtmp,sizeof(vtmp),file);
-           sscanf(vtmp, "%d %d %d %d %d %d %d %d\n",
-                  &rows_arg, &columns_arg,
-                  &is_long_table_arg, &rotate_arg, &a, &b, &c, &d);
-       } else
-           fscanf(file, "%d %d\n",
-                  &rows_arg, &columns_arg);
+       if (version < 5) {
+               lyxerr << "Tabular format < 5 is not supported anymore\n"
+                       "Get an older version of LyX (< 1.1.x) for conversion!"
+                      << endl;
+               if (version > 2) {
+                       is >> rows_arg >> columns_arg >> is_long_table_arg
+                          >> rotate_arg >> a >> b >> c >> d;
+               } else
+                       is >> rows_arg >> columns_arg;
+               Init(rows_arg, columns_arg);
+               SetLongTable(is_long_table_arg);
+               SetRotateTable(rotate_arg);
+               string tmp;
+               for (i = 0; i < rows; ++i) {
+                       getline(is, tmp);
+               }
+               for (i = 0; i < columns; ++i) {
+                       getline(is, tmp);
+               }
+               for (i = 0; i < rows; ++i) {
+                       for (j = 0; j < columns; ++j) {
+                               getline(is, tmp);
+                       }
+               }
+               set_row_column_number_info();
+               return;
+       }
+       is >> rows_arg >> columns_arg >> is_long_table_arg
+          >> rotate_arg >> a >> b >> c >> d;
        Init(rows_arg, columns_arg);
        SetLongTable(is_long_table_arg);
        SetRotateTable(rotate_arg);
-       for (i = 0; i<rows; i++){
-           fgets(vtmp, sizeof(vtmp), file);
+       endhead = a;
+       endfirsthead = b;
+       endfoot = c;
+       endlastfoot = d;
+       for (i = 0; i < rows; ++i) {
+               a = b = c = d = e = f = g = h = 0;
+               is >> a >> b >> c >> d;
+               row_info[i].top_line = a;
+               row_info[i].bottom_line = b;
+               row_info[i].is_cont_row = c;
+               row_info[i].newpage = d;
        }
-       for (i = 0; i<columns; i++){
-           fgets(vtmp, sizeof(vtmp), file);
+       for (i = 0; i < columns; ++i) {
+               string s1;
+               string s2;
+               is >> a >> b >> c;
+               char ch; // skip '"'
+               is >> ch;
+               getline(is, s1, '"');
+               is >> ch; // skip '"'
+               getline(is, s2, '"');
+               column_info[i].alignment = static_cast<char>(a);
+               column_info[i].left_line = b;
+               column_info[i].right_line = c;
+               column_info[i].p_width = s1;
+               column_info[i].align_special = s2;
        }
        for (i = 0; i < rows; ++i) {
-           for (j = 0; j < columns; ++j) {
-               fgets(vtmp, sizeof(vtmp), file);
-           }
+               for (j = 0; j < columns; ++j) {
+                       string s1;
+                       string s2;
+                       is >> a >> b >> c >> d >> e >> f >> g;
+                       char ch;
+                       is >> ch; // skip '"'
+                       getline(is, s1, '"');
+                       is >> ch; // skip '"'
+                       getline(is, s2, '"');
+                       cell_info[i][j].multicolumn = static_cast<char>(a);
+                       cell_info[i][j].alignment = static_cast<char>(b);
+                       cell_info[i][j].top_line = static_cast<char>(c);
+                       cell_info[i][j].bottom_line = static_cast<char>(d);
+                       cell_info[i][j].has_cont_row = static_cast<bool>(e);
+                       cell_info[i][j].rotate = static_cast<bool>(f);
+                       cell_info[i][j].linebreaks = static_cast<bool>(g);
+                       cell_info[i][j].align_special = s1;
+                       cell_info[i][j].p_width = s2;
+               }
        }
        set_row_column_number_info();
-       return;
-    }
-    fgets(vtmp, sizeof(vtmp), file);
-    sscanf(vtmp, "%d %d %d %d %d %d %d %d\n", &rows_arg, &columns_arg,
-          &is_long_table_arg, &rotate_arg, &a, &b, &c, &d);
-    Init(rows_arg, columns_arg);
-    SetLongTable(is_long_table_arg);
-    SetRotateTable(rotate_arg);
-    endhead = a;
-    endfirsthead = b;
-    endfoot = c;
-    endlastfoot = d;
-    for (i = 0; i<rows; i++){
-        a = b = c = d = e = f = g = h = 0;
-        fgets(vtmp, sizeof(vtmp), file);
-        sscanf(vtmp, "%d %d %d %d\n",
-               &a, &b, &c, &d);
-        row_info[i].top_line = a;
-        row_info[i].bottom_line = b;
-        row_info[i].is_cont_row = c;
-        row_info[i].newpage = d;
-    }
-    for (i = 0; i<columns; i++){
-        *stmp = 0;
-        *atmp = 0;
-        fgets(vtmp, sizeof(vtmp), file);
-        sscanf(vtmp, "%d %d %d %s %s", &a, &b, &c, stmp, atmp);
-        column_info[i].alignment = static_cast<char>(a);
-        column_info[i].left_line = b;
-        column_info[i].right_line = c;
-        if (*stmp == '"') { /* strip quotes if they exists */
-            *stmp = 0;
-            *atmp = 0;
-            // there are quotes so I have to reread the string correctly
-            // this is only because the old format did not have "
-            // this means also that atmp is ONLY set here!!!
-            if (stmp[1] == '"')
-                sscanf(vtmp, "%*d %*d %*d %*s \"%[^\"]\"", atmp);
-            else // otherwise after the first empty "" read is aborded
-                sscanf(vtmp, "%*d %*d %*d \"%[^\"]\" \"%[^\"]\"", stmp, atmp);
-            column_info[i].p_width = stmp;
-            column_info[i].align_special = atmp;
-        } else if (*stmp)
-            column_info[i].p_width = stmp;
-    }
-    for (i = 0; i < rows; ++i) {
-       for (j = 0; j < columns; ++j) {
-           *stmp = 0;
-           *atmp = 0;
-           a = b = c = d = e = f = g = 0;
-           fgets(vtmp, sizeof(vtmp), file);
-           sscanf(vtmp, "%d %d %d %d %d %d %d %s %s\n",
-                  &a, &b, &c, &d, &e, &f, &g, stmp, atmp);
-           cell_info[i][j].multicolumn = static_cast<char>(a);
-           cell_info[i][j].alignment = static_cast<char>(b);
-           cell_info[i][j].top_line = static_cast<char>(c);
-           cell_info[i][j].bottom_line = static_cast<char>(d);
-           cell_info[i][j].has_cont_row = static_cast<bool>(e);
-           cell_info[i][j].rotate = static_cast<bool>(f);
-           cell_info[i][j].linebreaks = static_cast<bool>(g);
-           // this is only to see if I have an empty string first
-           // this clause should be always TRUE!!!
-           if (*stmp == '"') {
-               *stmp = 0;
-               *atmp = 0;
-               if (stmp[1] == '"')
-                   sscanf(vtmp, "%*d %*d %*d %*d %*d %*d %*d %*s \"%[^\"]\"",
-                          atmp);
-               else // otherwise after the first empty "" read is aborded
-                   sscanf(vtmp, "%*d %*d %*d %*d %*d %*d %*d \"%[^\"]\" \"%[^\"]\"",
-                          stmp, atmp);
-               cell_info[i][j].align_special = stmp;
-               cell_info[i][j].p_width = atmp;
-           } else if (*stmp)
-               cell_info[i][j].align_special = stmp;
-       }
-    }
-    set_row_column_number_info();
 }
 
 
index 9d2a2383d725cbca8fc8bb701cb4d521ad3f2c48..c623d757369050e129d6f23fd6661a93b1d9eed6 100644 (file)
@@ -14,8 +14,6 @@
 #pragma interface
 #endif
 
-#include <cstdio>
-
 #include "lyxlex.h"
 #include "LString.h"
 #include "support/LOstream.h"
@@ -162,7 +160,7 @@ public:
        ///
        void Write(ostream &);
        ///
-       void Read(FILE * file);
+       void Read(istream &);
 
        // cell <0 will tex the preamble
        // returns the number of printed newlines
index 62a0481c886df1230c5b7fd24d1685a7f9825afa..22b318117661d8bf2891ab120a8bd907302daa4f 100644 (file)
 #pragma implementation
 #endif
 
+
+Undo::Undo(undo_kind kind_arg,
+          int number_before_arg, int number_behind_arg,
+          int cursor_par_arg, int cursor_pos_arg,
+          LyXParagraph * par_arg)
+{
+       kind = kind_arg;
+       number_of_before_par = number_before_arg;
+       number_of_behind_par = number_behind_arg;
+       number_of_cursor_par = cursor_par_arg;
+       cursor_pos = cursor_pos_arg;
+       par = par_arg;
+}
+
+
+Undo::~Undo()
+{
+       LyXParagraph * tmppar;
+       while (par) {
+               tmppar = par;
+               par = par->next;
+               delete tmppar;
+       }
+}
+
+
 UndoStack::UndoStack()
        : limit(100) {}
 
@@ -69,3 +95,8 @@ void UndoStack::push(Undo * undo_arg)
                delete tmp;
        }
 }
+
+
+bool UndoStack::empty() const {
+       return stakk.empty();
+}
index bd7e6411bad9e7732d0df00677bd066bb128f586..d7361477aae42e338c8feb24a7aed90b3665dbca 100644 (file)
@@ -51,24 +51,9 @@ public:
        Undo(undo_kind kind_arg,
             int number_before_arg, int number_behind_arg,
             int cursor_par_arg, int cursor_pos_arg,
-            LyXParagraph * par_arg)
-       {
-               kind = kind_arg;
-               number_of_before_par = number_before_arg;
-               number_of_behind_par = number_behind_arg;
-               number_of_cursor_par = cursor_par_arg;
-               cursor_pos = cursor_pos_arg;
-               par = par_arg;
-       }
-       ///
-       ~Undo() {
-               LyXParagraph * tmppar;
-               while (par) {
-                       tmppar = par;
-                       par = par->next;
-                       delete tmppar;
-               }
-       }
+            LyXParagraph * par_arg);
+       ///
+       ~Undo();
 };
 
 
@@ -89,7 +74,7 @@ public:
        ///
        Undo * top();
        ///
-       bool empty() const { return stakk.empty(); }
+       bool empty() const;
        ///
        ~UndoStack();
        ///
index 2a06de412bec9ede5a5e1bc7c8a3688071fc311c..a614b0c282499cb8ad518f93890a19cd3f5df6d0 100644 (file)
@@ -20,7 +20,6 @@
 #include "vspace.h"
 #include "lyxrc.h"
 #include "lyxtext.h"
-#include <cstdio>
 #include <cstring>
 #include "BufferView.h"
 #include "support/lstrings.h"
index 5c61edc10157518e70fb5e271921914393c9f732..8fda0c3f5ed2ffa5e0208b5a37beaa0b9d477290 100644 (file)
@@ -16,7 +16,6 @@
 #pragma interface
 #endif
 
-#include <cstdio>
 #include "LString.h"
 
 ///  LyXLength Class