From: Lars Gullik Bjønnes Date: Thu, 6 Jan 2000 02:44:26 +0000 (+0000) Subject: my changes during the holidyas...i expect some compilers to have some problems, but... X-Git-Tag: 1.6.10~22445 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8dccec5c46a1689fe3ea37144252e952771e1e1c;p=lyx.git my changes during the holidyas...i expect some compilers to have some problems, but I think that can be solved. Ok these are the main changes: use iostreams for everything, a TextCache to store the text variable in git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@403 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index d0319e8247..d31dc98696 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2000-01-06 Lars Gullik Bjønnes + + * src/BufferView.C: first go at a TextCache to speed up switching + between documents. + 2000-01-05 Jean-Marc Lasgouttes * lib/examples/ItemizeBullets.lyx: update from Tino Meinen. @@ -34,6 +39,60 @@ know when a user has cancelled input. Fixes annoying problems with inserting labels and version control. +1999-12-29 Lars Gullik Bjønnes + + * src/support/lstrings.C (tostr): rewritten to use strstream and + stringstream + +1999-12-28 Lars Gullik Bjønnes + + * 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 * src/buffer.C (Dispatch): remove an extraneous break statement. diff --git a/Makefile.am b/Makefile.am index 5da61745cf..dfa8b9cb32 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/autogen.sh b/autogen.sh index 997cb75362..ffbf543bcd 100755 --- a/autogen.sh +++ b/autogen.sh @@ -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 diff --git a/config/ltconfig b/config/ltconfig index 65ec6f65d0..03e18f5299 100755 --- a/config/ltconfig +++ b/config/ltconfig @@ -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" diff --git a/configure.in b/configure.in index 1a73c4124a..6b97c2f2f3 100644 --- a/configure.in +++ b/configure.in @@ -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. diff --git a/src/BufferView.C b/src/BufferView.C index c6ab81144b..96b13d6251 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -11,6 +11,7 @@ #include +#include #include #include @@ -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 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(); + } + } +} diff --git a/src/BufferView.h b/src/BufferView.h index 2ec4f88575..ba4b2f5733 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -50,6 +50,8 @@ public: /// void update(signed char f); /// + void smallUpdate(signed char f); + /// void updateScrollbar(); /// void redoCurrentBuffer(); diff --git a/src/FontInfo.C b/src/FontInfo.C index 95f44c8f2e..cfc7143588 100644 --- a/src/FontInfo.C +++ b/src/FontInfo.C @@ -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) == '-') { diff --git a/src/Makefile.am b/src/Makefile.am index efb3142a71..b4b61f54ee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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++ diff --git a/src/Spacing.C b/src/Spacing.C index 6e5cd60292..4ec657432c 100644 --- a/src/Spacing.C +++ b/src/Spacing.C @@ -1,6 +1,5 @@ #include -#include #include "Spacing.h" using std::ios; diff --git a/src/Spacing.h b/src/Spacing.h index 50ecc64daa..bf593a19f5 100644 --- a/src/Spacing.h +++ b/src/Spacing.h @@ -12,9 +12,13 @@ #ifndef SPACING_H #define SPACING_H -#include -#include "support/LOstream.h" +#ifdef HAVE_SSTREAM +#include +#else +#include +#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); } /// diff --git a/src/buffer.C b/src/buffer.C index 4a7e081b18..dfa419d17b 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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(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 pp = + pair 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 << ""; /* 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 << ""; // closes the tag os << ""; // 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 << "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; diff --git a/src/debug.C b/src/debug.C index bb260cd308..abee30ac35 100644 --- a/src/debug.C +++ b/src/debug.C @@ -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(); } - - - diff --git a/src/debug.h b/src/debug.h index be866a258d..c7fcb43fa8 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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); diff --git a/src/filedlg.C b/src/filedlg.C index 388318e3c3..80dc5fd49c 100644 --- a/src/filedlg.C +++ b/src/filedlg.C @@ -12,7 +12,6 @@ #include #include -#include #include #include #include diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index cb0e3b132f..46a10ba968 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -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 \ diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 4e4bea58d2..dcc77e1532 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -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; diff --git a/src/kbmap.C b/src/kbmap.C index 3a491f334d..b95f8aeaee 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -10,7 +10,6 @@ #include #include -#include #include "support/lstrings.h" #include "gettext.h" diff --git a/src/layout.C b/src/layout.C index d54b8c1c06..c8a55e8aa2 100644 --- a/src/layout.C +++ b/src/layout.C @@ -1208,7 +1208,7 @@ void LyXTextClass::load() ////////////////////////////////////////// // Gets textclass number from name -pair +pair 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 -LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::size_type textclass, string const & name) const +pair +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()) { diff --git a/src/layout.h b/src/layout.h index 3926f99bbe..58cb39ce3b 100644 --- a/src/layout.h +++ b/src/layout.h @@ -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 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 - NumberOfLayout(ClassList::size_type textclass, + pair + 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 + pair 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; diff --git a/src/lyx_cb.C b/src/lyx_cb.C index b81d045c74..263f6707ea 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -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 diff --git a/src/lyxfunc.C b/src/lyxfunc.C index d226829be0..d355691697 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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 = diff --git a/src/lyxlex.C b/src/lyxlex.C index c35caaca7b..bb55e8b971 100644 --- a/src/lyxlex.C +++ b/src/lyxlex.C @@ -17,10 +17,9 @@ #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." <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(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(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(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(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(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(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(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(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; } diff --git a/src/lyxlex.h b/src/lyxlex.h index b581a7bb36..74a8054d9c 100644 --- a/src/lyxlex.h +++ b/src/lyxlex.h @@ -11,7 +11,7 @@ #pragma interface #endif -#include +#include #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) diff --git a/src/lyxparagraph.h b/src/lyxparagraph.h index e8162459e8..5b6adafb76 100644 --- a/src/lyxparagraph.h +++ b/src/lyxparagraph.h @@ -136,9 +136,9 @@ public: /// void read(); - + /// - void readSimpleWholeFile(FILE *); + void readSimpleWholeFile(istream &); /// LyXParagraph * TeXOnePar(string & file, TexRow & texrow, diff --git a/src/lyxserver.C b/src/lyxserver.C index 58e1af3497..8449f9a420 100644 --- a/src/lyxserver.C +++ b/src/lyxserver.C @@ -38,7 +38,6 @@ #include #include -#include #include #include #include diff --git a/src/lyxtext.h b/src/lyxtext.h index f46b05edbe..ee644335c4 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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 */ diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 791fe931cc..b43390441c 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -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 \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index d59847f686..82565a5298 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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 } diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index abc12fe4a4..773bd83d95 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -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(&tmacro)); + istream & is = lex.getStream(); + mathed_parser_file(is, lex.GetLineNo()); + mathed_parse(0, 0, reinterpret_cast(&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; } diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index 669de5783c..74317388e8 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -24,13 +24,11 @@ #pragma interface #endif -#include #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(); /// diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 19ff2b7a62..90b623d4f2 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -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 -#include + #include #include diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 959e784ffd..536e83458d 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -26,7 +26,6 @@ #pragma interface #endif -#include #include "math_defs.h" #include "symbol_def.h" #include "LString.h" diff --git a/src/mathed/math_panel.C b/src/mathed/math_panel.C index 40067b44f4..250de2aa6a 100644 --- a/src/mathed/math_panel.C +++ b/src/mathed/math_panel.C @@ -15,7 +15,6 @@ #include #include FORMS_H_LOCATION -#include #include #include "lyx_gui_misc.h" diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 3b10d551f2..5bb466ed6d 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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(); diff --git a/src/mathed/math_root.h b/src/mathed/math_root.h index 0429aadff9..b9e5569a53 100644 --- a/src/mathed/math_root.h +++ b/src/mathed/math_root.h @@ -19,7 +19,6 @@ #pragma interface #endif -#include #include "math_defs.h" #include "math_inset.h" #include "symbol_def.h" diff --git a/src/mathed/math_symbols.C b/src/mathed/math_symbols.C index 3b86cbc7ad..8d268a9a93 100644 --- a/src/mathed/math_symbols.C +++ b/src/mathed/math_symbols.C @@ -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 *); diff --git a/src/mathed/math_utils.C b/src/mathed/math_utils.C index cb6da98baf..89f758519d 100644 --- a/src/mathed/math_utils.C +++ b/src/mathed/math_utils.C @@ -11,7 +11,8 @@ #include -#include +#include + #include "math_defs.h" #include "symbol_def.h" diff --git a/src/mathed/math_write.C b/src/mathed/math_write.C index 82a8b1e3df..959a5bcb7f 100644 --- a/src/mathed/math_write.C +++ b/src/mathed/math_write.C @@ -16,6 +16,7 @@ */ #include + #include "LString.h" #include "math_inset.h" #include "math_iter.h" diff --git a/src/paragraph.C b/src/paragraph.C index 0c39863afe..49439cd261 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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); + }; } diff --git a/src/support/DebugStream.C b/src/support/DebugStream.C index ad610636ff..ea6bbab231 100644 --- a/src/support/DebugStream.C +++ b/src/support/DebugStream.C @@ -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; diff --git a/src/support/filetools.C b/src/support/filetools.C index d511683bc5..53120ecd86 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -17,6 +17,7 @@ #include #include +#include #include 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((new string(envstr))->c_str())); + // Actually we don't have to leak...calling putenv like this + // should be enough: + int retval = putenv(const_cast(envstr.c_str())); + //int retval = putenv(const_cast((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); diff --git a/src/support/filetools.h b/src/support/filetools.h index 72752f1a15..f171e94d8e 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -11,111 +11,14 @@ #pragma interface #endif -#include #include #include #include + #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()); diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 06875d2159..27f398dd4a 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -1,16 +1,27 @@ #include #include +#ifdef __GLIBCPP__ +#include +#else #include -#include +#endif #include +#ifdef HAVE_SSTREAM +#include +#else +#include +#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(); } diff --git a/src/support/syscall.C b/src/support/syscall.C index f9264cd96f..c12e755aa5 100644 --- a/src/support/syscall.C +++ b/src/support/syscall.C @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "debug.h" #include "syscall.h" diff --git a/src/table.C b/src/table.C index ac5b6487d3..ef46bb9a27 100644 --- a/src/table.C +++ b/src/table.C @@ -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> 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> a >> b >> c; + char ch; // skip '"' + is >> ch; + getline(is, s1, '"'); + is >> ch; // skip '"' + getline(is, s2, '"'); + column_info[i].alignment = static_cast(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(a); + cell_info[i][j].alignment = static_cast(b); + cell_info[i][j].top_line = static_cast(c); + cell_info[i][j].bottom_line = static_cast(d); + cell_info[i][j].has_cont_row = static_cast(e); + cell_info[i][j].rotate = static_cast(f); + cell_info[i][j].linebreaks = static_cast(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(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(a); - cell_info[i][j].alignment = static_cast(b); - cell_info[i][j].top_line = static_cast(c); - cell_info[i][j].bottom_line = static_cast(d); - cell_info[i][j].has_cont_row = static_cast(e); - cell_info[i][j].rotate = static_cast(f); - cell_info[i][j].linebreaks = static_cast(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(); } diff --git a/src/table.h b/src/table.h index 9d2a2383d7..c623d75736 100644 --- a/src/table.h +++ b/src/table.h @@ -14,8 +14,6 @@ #pragma interface #endif -#include - #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 diff --git a/src/undo.C b/src/undo.C index 62a0481c88..22b3181176 100644 --- a/src/undo.C +++ b/src/undo.C @@ -16,6 +16,32 @@ #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(); +} diff --git a/src/undo.h b/src/undo.h index bd7e6411ba..d7361477aa 100644 --- a/src/undo.h +++ b/src/undo.h @@ -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(); /// diff --git a/src/vspace.C b/src/vspace.C index 2a06de412b..a614b0c282 100644 --- a/src/vspace.C +++ b/src/vspace.C @@ -20,7 +20,6 @@ #include "vspace.h" #include "lyxrc.h" #include "lyxtext.h" -#include #include #include "BufferView.h" #include "support/lstrings.h" diff --git a/src/vspace.h b/src/vspace.h index 5c61edc101..8fda0c3f5e 100644 --- a/src/vspace.h +++ b/src/vspace.h @@ -16,7 +16,6 @@ #pragma interface #endif -#include #include "LString.h" /// LyXLength Class