]> git.lyx.org Git - features.git/commitdiff
simple argument parsing for FuncRequest;
authorAndré Pönitz <poenitz@gmx.net>
Wed, 26 Feb 2003 18:03:48 +0000 (18:03 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 26 Feb 2003 18:03:48 +0000 (18:03 +0000)
other small stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6288 a592a061-630c-0410-9148-cb99ea01b6c8

src/funcrequest.C
src/funcrequest.h
src/insets/insetgraphics.C
src/lyxlex.C
src/lyxlex.h
src/mathed/formulabase.C

index 75d9cbaab8efc217ad021543d40b12c8df066c24..7b486f199ff1cd453e286a629f37b905ba7fd9ca 100644 (file)
 #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<string> & 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<string> args;
+       split(args, argument);
+       return i < args.size() ? args[i] : string();
+}
index a9afa49ce1a50233c53400536c48e5e2653377d5..a8298708e714e69921d851f8bae969a7f62f936b 100644 (file)
@@ -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_;
index ca8b39175730e33a37ec2c80fbd38387516c555f..c0a30cb2e877e2751d7a7c7683b6add6a0bf4e0f 100644 (file)
@@ -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);
-               }
+       string const justname = OnlyFilename (params().filename);
+       if (!justname.empty()) {
+               msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
+               font_width = font_metrics::width(justname, msgFont);
+       }
 
-               return std::max(50, font_width + 15);
+       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;
                }
        }
        
index bd9e3c4097c07f547ff5057aed770d52022f8438..9df38a2108a0820320f9d5de1f195c558c6609b9 100644 (file)
@@ -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;
 }
 
 
index ad260093c07ef31003f3a6e91b4ba3193bfe5ab3..5f94fc4d6871bef08736a89e9310ee3fcad111f0 100644 (file)
@@ -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.
index 22c0474580a660a1a1ff2b7a87a3d63f7eb1fd49..82b88de5f9b5fd85dabfa30c9282b9c30941dc05 100644 (file)
@@ -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);