From 8721e76079100c9238b97b4efdd2637cc2a6790a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 28 Jul 2003 14:40:29 +0000 Subject: [PATCH] more compress support git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7419 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 4 ++++ configure.ac | 3 +++ src/ChangeLog | 18 +++++++++++++++++- src/Makefile.am | 2 +- src/buffer.C | 29 ++++++++++++++++++++--------- src/buffer.h | 2 +- src/buffer_funcs.C | 25 ++++++------------------- src/bufferparams.C | 3 ++- src/bufferparams.h | 2 ++ src/insets/insetgraphics.C | 2 +- src/insets/insettext.C | 4 ++-- src/lyxlex_pimpl.C | 17 ++++++++++------- src/paragraph.C | 4 ++-- src/text.C | 2 +- src/text3.C | 2 +- 15 files changed, 73 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a080ae916..5562248fff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-07-28 Lars Gullik Bjønnes + + * configure.ac: check for zlib. + 2003-07-27 Lars Gullik Bjønnes * configure.ac: new file diff --git a/configure.ac b/configure.ac index a0f114b98f..20ee166268 100644 --- a/configure.ac +++ b/configure.ac @@ -246,6 +246,9 @@ LYX_CHECK_DECL(vsnprintf, stdio.h) LYX_CHECK_DECL(istreambuf_iterator, iterator) LYX_CHECK_DECL(mkstemp,[unistd.h stdlib.h]) +AC_CHECK_HEADERS(zlib.h) +AC_CHECK_LIB(z, gzopen) + dnl This is a slight hack: the tests generated by autoconf 2.52 do not dnl work correctly because of some conflict with stdlib.h with g++ 2.96 dnl We aim to remove this eventually, since we should test as much as diff --git a/src/ChangeLog b/src/ChangeLog index c2073ae59a..dacc8eae5f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,10 +1,26 @@ +2003-07-28 Lars Gullik Bjønnes + + * lyxlex_pimpl.C (setFile): clean up slightly. + + * bufferparams.h: add compressed var + + * buffer_funcs.C (readFile): adjust for LyXLex change + (newFile): ditto + simplify + + * buffer.C (writeFile): handle writing of compressed files + + * buffer.[Ch] (readFile): begin LyXLex here, remove one argument. + Check if the file is compressed and set a bufferparm if so. + + * Makefile.am (lyx_LDADD): remove explicit -lz + 2003-07-28 Jean-Marc Lasgouttes * buffer.C (do_writeFile, makeLaTeXFile, makeLinuxDocFile, makeDocBookFile): put the real LyX version in the first line of the file - * version.h: + * version.h: * version.C.in: remove lyx_docversion * tabular.C (write_attribute): add a template-based version to diff --git a/src/Makefile.am b/src/Makefile.am index 782df6578a..81b9e7f1b7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,7 +31,7 @@ BOOST_LIBS = -lboost_regex -lboost_signals endif lyx_LDADD = $(LYX_CONV_LIBS) $(BOOST_LIBS) $(INTLLIBS) \ - $(AIKSAURUS_LIBS) @LIBS@ -lz + $(AIKSAURUS_LIBS) @LIBS@ lyx_DEPENDENCIES = $(LYX_CONV_LIBS) $(BOOST_LIBS) $(INTLLIBS) diff --git a/src/buffer.C b/src/buffer.C index 6ffdecd056..9ac61660dc 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -440,8 +440,17 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos, } -bool Buffer::readFile(LyXLex & lex, string const & filename) +bool Buffer::readFile(string const & filename) { + // Check if the file is compressed. + string const format = getExtFromContents(filename); + if (format == "gzip" || format == "zip" || format == "compress") { + params.compressed = true; + } + + LyXLex lex(0, 0); + lex.setFile(filename); + bool ret = readFile(lex, filename, paragraphs.begin()); // After we have read a file, we must ensure that the buffer @@ -637,23 +646,25 @@ bool Buffer::writeFile(string const & fname) const return false; } - bool const compressed = (fname.substr(fname.size() - 3, 3) == ".gz"); + bool retval; - if (compressed) { + if (params.compressed) { gz::ogzstream ofs(fname.c_str()); if (!ofs) return false; - return do_writeFile(ofs); + retval = do_writeFile(ofs); - } + } else { + ofstream ofs(fname.c_str()); + if (!ofs) + return false; - ofstream ofs(fname.c_str()); - if (!ofs) - return false; + retval = do_writeFile(ofs); + } - return do_writeFile(ofs); + return retval; } diff --git a/src/buffer.h b/src/buffer.h index 60c98c841b..4c28a12014 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -80,7 +80,7 @@ public: // FIXME: it's very silly to pass a lex in here /// load a new file - bool readFile(LyXLex &, string const &); + bool readFile(string const &); /// read the header, returns number of unknown tokens int readHeader(LyXLex & lex); diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index bf9073fb66..59b1cfc9e4 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -18,7 +18,6 @@ #include "errorlist.h" #include "gettext.h" #include "vc-backend.h" -#include "lyxlex.h" #include "LaTeX.h" #include "ParagraphList.h" #include "paragraph.h" @@ -105,11 +104,7 @@ bool readFile(Buffer * b, string const & s) } } } - // not sure if this is the correct place to begin LyXLex - LyXLex lex(0, 0); - lex.setFile(ts); - - return b->readFile(lex, ts); + return b->readFile(ts); } @@ -166,17 +161,9 @@ Buffer * newFile(string const & filename, string const & templatename, tname = templatename; if (!tname.empty()) { - bool templateok = false; - LyXLex lex(0, 0); - lex.setFile(tname); - if (lex.isOK()) { - if (b->readFile(lex, tname)) { - templateok = true; - } - } - if (!templateok) { + if (!b->readFile(tname)) { string const file = MakeDisplayPath(tname, 50); - string text = bformat(_("The specified document template\n%1$s\n" + string const text = bformat(_("The specified document template\n%1$s\n" "could not be read."), file); Alert::error(_("Could not read template"), text); // no template, start with empty buffer @@ -200,7 +187,7 @@ Buffer * newFile(string const & filename, string const & templatename, } -void bufferErrors(Buffer const & buf, TeXErrors const & terr) +void bufferErrors(Buffer const & buf, TeXErrors const & terr) { TeXErrors::Errors::const_iterator cit = terr.begin(); TeXErrors::Errors::const_iterator end = terr.end(); @@ -219,12 +206,12 @@ void bufferErrors(Buffer const & buf, TeXErrors const & terr) } -void bufferErrors(Buffer const & buf, ErrorList const & el) +void bufferErrors(Buffer const & buf, ErrorList const & el) { ErrorList::const_iterator it = el.begin(); ErrorList::const_iterator end = el.end(); - for (; it != end; ++it) + for (; it != end; ++it) buf.error(*it); } diff --git a/src/bufferparams.C b/src/bufferparams.C index d560eaff6c..02b6b677ed 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -73,6 +73,7 @@ BufferParams::BufferParams() sides = LyXTextClass::OneSide; columns = 1; pagestyle = "default"; + compressed = false; for (int iter = 0; iter < 4; ++iter) { user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter]; temp_bullets[iter] = ITEMIZE_DEFAULTS[iter]; @@ -1004,7 +1005,7 @@ string const BufferParams::dvips_options() const string const paper_option = paperSizeName(); if (paper_option != "letter" || orientation != ORIENTATION_LANDSCAPE) { - // dvips won't accept -t letter -t landscape. + // dvips won't accept -t letter -t landscape. // In all other cases, include the paper size // explicitly. result = lyxrc.print_paper_flag; diff --git a/src/bufferparams.h b/src/bufferparams.h index dc0782d5d1..45bc0fc160 100644 --- a/src/bufferparams.h +++ b/src/bufferparams.h @@ -174,6 +174,8 @@ public: bool tracking_changes; /// Time ago we agreed that this was a buffer property [ale990407] string parentname; + /// + bool compressed; /// map of the file's author IDs to buffer author IDs std::vector author_map; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index afdaa35a9e..c2b4a355f7 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -554,7 +554,7 @@ int InsetGraphics::linuxdoc(Buffer const * buf, ostream & os) const { string const file_name = buf->niceFile ? params().filename.relFilename(buf->filePath()): - params().filename.absFilename(); + params().filename.absFilename(); os << "\n"; os << ""; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 4e0e5ea876..128065ebe6 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -515,7 +515,7 @@ void InsetText::lockInset(BufferView * bv) } -void InsetText::lockInset(BufferView * bv, UpdatableInset * inset) +void InsetText::lockInset(BufferView * /*bv*/, UpdatableInset * inset) { the_locking_inset = inset; inset_x = cix() - top_x + drawTextXOffset; @@ -629,7 +629,7 @@ bool InsetText::updateInsetInInset(BufferView * bv, InsetOld * inset) return false; found = tl_inset->updateInsetInInset(bv, inset); ustat = FULL; - } else { + } else { text_.updateInset(tl_inset); setUpdateStatus(ustat); } diff --git a/src/lyxlex_pimpl.C b/src/lyxlex_pimpl.C index da7d92d9a3..8ad57be9d0 100644 --- a/src/lyxlex_pimpl.C +++ b/src/lyxlex_pimpl.C @@ -113,15 +113,16 @@ void LyXLex::Pimpl::popTable() bool LyXLex::Pimpl::setFile(string const & filename) { - // Is this a compressed file or not? - bool const compressed = (filename.substr(filename.size() - 3, 3) == ".gz"); - // The check only outputs a debug message, because it triggers - // a bug in compaq cxx 6.2, where is_open() returns 'true' for a - // fresh new filebuf. (JMarc) - if (compressed) { + // Check the format of the file. + string const format = getExtFromContents(filename); + + if (format == "gzip" || format == "zip" || format == "compress") { lyxerr << "lyxlex: compressed" << endl; + // The check only outputs a debug message, because it triggers + // a bug in compaq cxx 6.2, where is_open() returns 'true' for + // a fresh new filebuf. (JMarc) if (gz__.is_open() || is.tellg() > 0) lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: " "file or stream already set." << endl; @@ -133,6 +134,9 @@ bool LyXLex::Pimpl::setFile(string const & filename) } else { lyxerr << "lyxlex: UNcompressed" << endl; + // The check only outputs a debug message, because it triggers + // a bug in compaq cxx 6.2, where is_open() returns 'true' for + // a fresh new filebuf. (JMarc) if (fb__.is_open() || is.tellg() > 0) lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: " "file or stream already set." << endl; @@ -142,7 +146,6 @@ bool LyXLex::Pimpl::setFile(string const & filename) lineno = 0; return fb__.is_open() && is.good(); } - } diff --git a/src/paragraph.C b/src/paragraph.C index a15c822019..f6982c75aa 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -404,8 +404,8 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams, } -lyx::pos_type -Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const +lyx::pos_type +Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const { Assert(pos <= size()); diff --git a/src/text.C b/src/text.C index 8cec91518d..d9ae8bdafd 100644 --- a/src/text.C +++ b/src/text.C @@ -1167,7 +1167,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) maxasc = max(maxasc, tmpinset->ascent()); maxdesc = max(maxdesc, tmpinset->descent()); #endif - } + } } else { // Fall-back to normal case maxwidth += singleWidth(pit, pos, c); diff --git a/src/text3.C b/src/text3.C index a5a04b9da4..a4ef8ec0f4 100644 --- a/src/text3.C +++ b/src/text3.C @@ -97,7 +97,7 @@ namespace { // check if the given co-ordinates are inside an inset at the // given cursor, if one exists. If so, the inset is returned, // and the co-ordinates are made relative. Otherwise, 0 is returned. - InsetOld * checkInset(BufferView * bv, LyXText & text, +InsetOld * checkInset(BufferView * /*bv*/, LyXText & text, LyXCursor const & cur, int & x, int & y) { lyx::pos_type const pos = cur.pos(); -- 2.39.5