[LyX/master] Fix minor annoyance with previous commit.

Richard Kimberly Heck rikiheck at lyx.org
Tue Sep 29 01:41:47 UTC 2020


commit 594401912b5e30397cf258d07a732fccdf481670
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date:   Mon Sep 28 22:07:08 2020 -0400

    Fix minor annoyance with previous commit.
    
    When validating local layout, in particular, we create a dummy text TextClass
    and so are not necessarily modifying previously declared material. Hence, we
    get a spurious (but harmless) "Incomplete argument definition!" warning. This
    suppresses it, but to do that we need to propogate the ReadType.
---
 src/Layout.cpp    |   13 +++++++------
 src/Layout.h      |    6 +++---
 src/TextClass.cpp |   14 +++++++-------
 src/TextClass.h   |    2 +-
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/Layout.cpp b/src/Layout.cpp
index 1f5a898..48328cc 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -194,15 +194,15 @@ Layout::Layout()
 }
 
 
-bool Layout::read(Lexer & lex, TextClass const & tclass)
+bool Layout::read(Lexer & lex, TextClass const & tclass, bool validating)
 {
 	// If this is an empty layout, or if no force local version is set,
 	// we know that we will not discard the stuff to read
 	if (forcelocal == 0)
-		return readIgnoreForcelocal(lex, tclass);
+		return readIgnoreForcelocal(lex, tclass, validating);
 	Layout tmp(*this);
 	tmp.forcelocal = 0;
-	bool const ret = tmp.readIgnoreForcelocal(lex, tclass);
+	bool const ret = tmp.readIgnoreForcelocal(lex, tclass, validating);
 	// Keep the stuff if
 	// - the read version is higher
 	// - both versions are infinity (arbitrary decision)
@@ -214,7 +214,8 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
 }
 
 
-bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
+bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
+								  bool validating)
 {
 	// This table is sorted alphabetically [asierra 30March96]
 	LexerKeyword layoutTags[] = {
@@ -441,7 +442,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
 			break;
 
 		case LT_ARGUMENT:
-			readArgument(lex);
+			readArgument(lex, validating);
 			break;
 
 		case LT_NEED_PROTECT:
@@ -1242,7 +1243,7 @@ void Layout::readArgument(Lexer & lex, bool validating)
 			error = true;
 		}
 	}
-	if (arg.labelstring.empty())
+	if (!validating && arg.labelstring.empty()) {
 		LYXERR0("Incomplete Argument definition!");
 		// remove invalid definition
 		lam.erase(id);
diff --git a/src/Layout.h b/src/Layout.h
index 590c52d..a339021 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -58,7 +58,7 @@ public:
 	void setUnknown(bool unknown) { unknown_ = unknown; }
 	/// Reads a layout definition from file
 	/// \return true on success.
-	bool read(Lexer &, TextClass const &);
+	bool read(Lexer &, TextClass const &, bool validating = false);
 	///
 	void readAlign(Lexer &);
 	///
@@ -74,7 +74,7 @@ public:
 	///
 	void readSpacing(Lexer &);
 	///
-	void readArgument(Lexer &);
+	void readArgument(Lexer &, bool);
 	/// Write a layout definition in utf8 encoding
 	void write(std::ostream &) const;
 	///
@@ -411,7 +411,7 @@ public:
 private:
 	/// Reads a layout definition from file
 	/// \return true on success.
-	bool readIgnoreForcelocal(Lexer &, TextClass const &);
+	bool readIgnoreForcelocal(Lexer &, TextClass const &, bool validating);
 	/// generates the default CSS for this layout
 	void makeDefaultCSS() const;
 	///
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 2c467b6..3628872 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -148,10 +148,10 @@ TextClass::TextClass()
 }
 
 
-bool TextClass::readStyle(Lexer & lexrc, Layout & lay) const
+bool TextClass::readStyle(Lexer & lexrc, Layout & lay, ReadType rt) const
 {
 	LYXERR(Debug::TCLASS, "Reading style " << to_utf8(lay.name()));
-	if (!lay.read(lexrc, *this)) {
+	if (!lay.read(lexrc, *this, rt == VALIDATION)) {
 		LYXERR0("Error parsing style `" << to_utf8(lay.name()) << '\'');
 		return false;
 	}
@@ -515,7 +515,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
 				Layout lay;
 				// Since we couldn't read the name, we just scan the rest
 				// of the style and discard it.
-				error = !readStyle(lexrc, lay);
+				error = !readStyle(lexrc, lay, rt);
 				break;
 			}
 
@@ -526,14 +526,14 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
 			// block.
 			if (have_layout && !providestyle) {
 				Layout & lay = operator[](name);
-				error = !readStyle(lexrc, lay);
+				error = !readStyle(lexrc, lay, rt);
 			}
 			// If the layout does not exist, then we want to create a new
 			// one, but not if we are in a ModifyStyle block.
 			else if (!have_layout && !modifystyle) {
 				Layout layout;
 				layout.setName(name);
-				error = !readStyle(lexrc, layout);
+				error = !readStyle(lexrc, layout, rt);
 				if (!error)
 					layoutlist_.push_back(layout);
 
@@ -551,7 +551,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
 			else {
 				Layout lay;
 				// signal to coverity that we do not care about the result
-				(void)readStyle(lexrc, lay);
+				(void)readStyle(lexrc, lay, rt);
 			}
 			break;
 		}
@@ -1862,7 +1862,7 @@ Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
 	defaultLayout = new Layout;
 	defaultLayout->setUnknown(unknown);
 	defaultLayout->setName(name);
-	if (!readStyle(lex, *defaultLayout)) {
+	if (!readStyle(lex, *defaultLayout, BASECLASS)) {
 		// The only way this happens is because the hardcoded layout above
 		// is wrong.
 		LATTEST(false);
diff --git a/src/TextClass.h b/src/TextClass.h
index bf061ac..11710ed 100644
--- a/src/TextClass.h
+++ b/src/TextClass.h
@@ -389,7 +389,7 @@ private:
 	/// Reads the layout file without running layout2layout.
 	ReturnValues readWithoutConv(support::FileName const & filename, ReadType rt);
 	/// \return true for success.
-	bool readStyle(Lexer &, Layout &) const;
+	bool readStyle(Lexer &, Layout &, ReadType) const;
 	///
 	void readOutputType(Lexer &);
 	///


More information about the lyx-cvs mailing list