From c6c5eb530cf6c2b818e69dd55bc273286ff8513d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 26 Feb 2003 18:03:48 +0000 Subject: [PATCH] simple argument parsing for FuncRequest; other small stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6288 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/funcrequest.C | 31 ++++++++++++ src/funcrequest.h | 3 ++ src/insets/insetgraphics.C | 97 ++++++++++++++++++-------------------- src/lyxlex.C | 14 ++---- src/lyxlex.h | 2 +- src/mathed/formulabase.C | 2 +- 6 files changed, 88 insertions(+), 61 deletions(-) diff --git a/src/funcrequest.C b/src/funcrequest.C index 75d9cbaab8..7b486f199f 100644 --- a/src/funcrequest.C +++ b/src/funcrequest.C @@ -13,6 +13,11 @@ #include "lyxfunc.h" // only for setMessage() #include "frontends/LyXView.h" #include "debug.h" +#include "Lsstream.h" + + +using std::vector; +using std::getline; FuncRequest::FuncRequest() @@ -98,3 +103,29 @@ void FuncRequest::errorMessage(string const & msg) const else lyxerr << "Dropping error message '" << msg << "'\n"; } + + +void split(vector & args, string str) +{ + istringstream is(str); + while (is) { + char c; + string s; + is >> c; + if (c == '"') + getline(is, s, '"'); + else { + is.putback(c); + is >> s; + } + args.push_back(s); + } +} + + +string FuncRequest::getArg(int i) const +{ + vector args; + split(args, argument); + return i < args.size() ? args[i] : string(); +} diff --git a/src/funcrequest.h b/src/funcrequest.h index a9afa49ce1..a8298708e7 100644 --- a/src/funcrequest.h +++ b/src/funcrequest.h @@ -53,6 +53,9 @@ public: /// output an error message void errorMessage(string const & msg) const; + /// argument parsing, extract argument i as string + string getArg(int i) const; + private: /// the BufferView we are talking to BufferView * view_; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index ca8b391757..c0a30cb2e8 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -219,29 +219,31 @@ InsetGraphics::~InsetGraphics() string const InsetGraphics::statusMessage() const { + using namespace grfx; + switch (cache_->loader.status()) { - case grfx::WaitingToLoad: - return _("Not shown."); - case grfx::Loading: - return _("Loading..."); - case grfx::Converting: - return _("Converting to loadable format..."); - case grfx::Loaded: - return _("Loaded into memory. Must now generate pixmap."); - case grfx::ScalingEtc: - return _("Scaling etc..."); - case grfx::Ready: - return _("Ready to display"); - case grfx::ErrorNoFile: - return _("No file found!"); - case grfx::ErrorConverting: - return _("Error converting to loadable format"); - case grfx::ErrorLoading: - return _("Error loading file into memory"); - case grfx::ErrorGeneratingPixmap: - return _("Error generating the pixmap"); - case grfx::ErrorUnknown: - return _("No image"); + case WaitingToLoad: + return _("Not shown."); + case Loading: + return _("Loading..."); + case Converting: + return _("Converting to loadable format..."); + case Loaded: + return _("Loaded into memory. Must now generate pixmap."); + case ScalingEtc: + return _("Scaling etc..."); + case Ready: + return _("Ready to display"); + case ErrorNoFile: + return _("No file found!"); + case ErrorConverting: + return _("Error converting to loadable format"); + case ErrorLoading: + return _("Error loading file into memory"); + case ErrorGeneratingPixmap: + return _("Error generating the pixmap"); + case ErrorUnknown: + return _("No image"); } return string(); } @@ -275,27 +277,26 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const { if (imageIsDrawable()) return cache_->loader.image()->getWidth() + 2 * TEXT_TO_INSET_OFFSET; - else { - int font_width = 0; - LyXFont msgFont(font); - msgFont.setFamily(LyXFont::SANS_FAMILY); + int font_width = 0; - string const justname = OnlyFilename (params().filename); - if (!justname.empty()) { - msgFont.setSize(LyXFont::SIZE_FOOTNOTE); - font_width = font_metrics::width(justname, msgFont); - } + LyXFont msgFont(font); + msgFont.setFamily(LyXFont::SANS_FAMILY); - string const msg = statusMessage(); - if (!msg.empty()) { - msgFont.setSize(LyXFont::SIZE_TINY); - int const msg_width = font_metrics::width(msg, msgFont); - font_width = std::max(font_width, msg_width); - } - - return std::max(50, font_width + 15); + string const justname = OnlyFilename (params().filename); + if (!justname.empty()) { + msgFont.setSize(LyXFont::SIZE_FOOTNOTE); + font_width = font_metrics::width(justname, msgFont); } + + string const msg = statusMessage(); + if (!msg.empty()) { + msgFont.setSize(LyXFont::SIZE_TINY); + int const msg_width = font_metrics::width(msg, msgFont); + font_width = std::max(font_width, msg_width); + } + + return std::max(50, font_width + 15); } @@ -326,9 +327,8 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, // This is not a nice thing to do and should be fixed properly somehow. // But I still don't know the best way to go. So let's do this like this // for now (Jug 20020311) - if (lascent != oasc) { + if (lascent != oasc) return; - } // Make sure now that x is updated upon exit from this routine int old_x = int(x); @@ -336,8 +336,8 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, grfx::Params const & gparams = params().as_grfxParams(); - if (gparams.display != grfx::NoDisplay - && cache_->loader.status() == grfx::WaitingToLoad) + if (gparams.display != grfx::NoDisplay && + cache_->loader.status() == grfx::WaitingToLoad) cache_->loader.startLoading(); if (!cache_->loader.monitoring()) @@ -551,7 +551,7 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const // temp_file will contain the file for LaTeX to act on if, for example, // we move it to a temp dir or uncompress it. - string temp_file(orig_file); + string temp_file = orig_file; if (zipped) { // Uncompress the file if necessary. @@ -585,11 +585,9 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const // No conversion is needed. LaTeX can handle the // graphic file as is. // This is true even if the orig_file is compressed. - if (formats.getFormat(to)->extension() == GetExtension(orig_file)) { + if (formats.getFormat(to)->extension() == GetExtension(orig_file)) return RemoveExtension(orig_file_with_path); - } else { - return orig_file_with_path; - } + return orig_file_with_path; } // We're going to be running the exported buffer through the LaTeX @@ -638,8 +636,7 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const // graphic file as is. if (formats.getFormat(to)->extension() == GetExtension(orig_file)) return RemoveExtension(temp_file); - else - return temp_file; + return temp_file; } } diff --git a/src/lyxlex.C b/src/lyxlex.C index bd9e3c4097..9df38a2108 100644 --- a/src/lyxlex.C +++ b/src/lyxlex.C @@ -113,12 +113,10 @@ int LyXLex::lex() int LyXLex::getInteger() const { - if (isStrInt(pimpl_->getString())) { + if (isStrInt(pimpl_->getString())) return strToInt(pimpl_->getString()); - } else { - pimpl_->printError("Bad integer `$$Token'"); - return -1; - } + pimpl_->printError("Bad integer `$$Token'"); + return -1; } @@ -130,10 +128,8 @@ float LyXLex::getFloat() const string str = subst(pimpl_->getString(), ",", "."); if (isStrDbl(str)) return strToDbl(str); - else { - pimpl_->printError("Bad float `$$Token'"); - return -1; - } + pimpl_->printError("Bad float `$$Token'"); + return -1; } diff --git a/src/lyxlex.h b/src/lyxlex.h index ad260093c0..5f94fc4d68 100644 --- a/src/lyxlex.h +++ b/src/lyxlex.h @@ -49,7 +49,7 @@ public: /// return true if able to open file, else false bool setFile(string const & filename); /// - void setStream(std::istream & i); + void setStream(std::istream & is); /// std::istream & getStream(); /// Danger! Don't use it unless you know what you are doing. diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 22c0474580..82b88de5f9 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -675,7 +675,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd) //bv->owner()->message(_("math text mode toggled")); break; - case LFUN_MATH_SIZE: + case LFUN_MATH_SIZE: #if 0 if (!arg.empty()) { bv->lockedInsetStoreUndo(Undo::EDIT);