mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
separate insetcommand.[Ch] into two files
we should be ble to use this later to reduce include dependencies git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4530 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
22695610d6
commit
f849bc4a62
@ -1,3 +1,10 @@
|
||||
|
||||
2002-07-04 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* insetcommandparams.[Ch]: new files
|
||||
|
||||
* insetcommand.[Ch]: move code to insetcommandparams.[Ch]
|
||||
|
||||
2002-06-15 Herbert Voss <voss@perce.de>
|
||||
|
||||
* insetgraphics.C (prepareFile): bugfix; return always
|
||||
|
@ -29,6 +29,8 @@ libinsets_la_SOURCES = \
|
||||
insetcollapsable.h \
|
||||
insetcommand.C \
|
||||
insetcommand.h \
|
||||
insetcommandparams.C \
|
||||
insetcommandparams.h \
|
||||
inseterror.C \
|
||||
inseterror.h \
|
||||
insetert.C \
|
||||
|
@ -17,169 +17,11 @@
|
||||
#include "insetcommand.h"
|
||||
#include "debug.h"
|
||||
#include "frontends/Painter.h"
|
||||
#include "lyxlex.h"
|
||||
|
||||
using std::ostream;
|
||||
using std::endl;
|
||||
|
||||
|
||||
InsetCommandParams::InsetCommandParams()
|
||||
{}
|
||||
|
||||
|
||||
InsetCommandParams::InsetCommandParams(string const & n,
|
||||
string const & c,
|
||||
string const & o)
|
||||
: cmdname(n), contents(c), options(o)
|
||||
{}
|
||||
|
||||
|
||||
string const InsetCommandParams::getAsString() const
|
||||
{
|
||||
return cmdname + "|++|" + contents + "|++|" + options;
|
||||
}
|
||||
|
||||
|
||||
void InsetCommandParams::setFromString(string const & b)
|
||||
{
|
||||
string::size_type idx = b.find("|++|");
|
||||
if (idx == string::npos) {
|
||||
cmdname = b;
|
||||
contents = "";
|
||||
options = "";
|
||||
return;
|
||||
}
|
||||
|
||||
cmdname = b.substr(0, idx);
|
||||
string tmp = b.substr(idx+4);
|
||||
|
||||
idx = tmp.find("|++|");
|
||||
if (idx == string::npos) {
|
||||
contents = tmp;
|
||||
options = "";
|
||||
} else {
|
||||
contents = tmp.substr(0, idx);
|
||||
options = tmp.substr(idx+4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool InsetCommandParams::operator==(InsetCommandParams const & o) const
|
||||
{
|
||||
return cmdname == o.cmdname && contents == o.contents
|
||||
&& options == o.options;
|
||||
}
|
||||
|
||||
|
||||
bool InsetCommandParams::operator!=(InsetCommandParams const & o) const
|
||||
{
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
|
||||
void InsetCommandParams::scanCommand(string const & cmd)
|
||||
{
|
||||
string tcmdname, toptions, tcontents;
|
||||
|
||||
if (cmd.empty()) return;
|
||||
|
||||
enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
|
||||
|
||||
// Used to handle things like \command[foo[bar]]{foo{bar}}
|
||||
int nestdepth = 0;
|
||||
|
||||
for (string::size_type i = 0; i < cmd.length(); ++i) {
|
||||
char c = cmd[i];
|
||||
if ((state == CMDNAME && c == ' ') ||
|
||||
(state == CMDNAME && c == '[') ||
|
||||
(state == CMDNAME && c == '{')) {
|
||||
state = WS;
|
||||
}
|
||||
if ((state == OPTION && c == ']') ||
|
||||
(state == CONTENT && c == '}')) {
|
||||
if (nestdepth == 0) {
|
||||
state = WS;
|
||||
} else {
|
||||
--nestdepth;
|
||||
}
|
||||
}
|
||||
if ((state == OPTION && c == '[') ||
|
||||
(state == CONTENT && c == '{')) {
|
||||
++nestdepth;
|
||||
}
|
||||
switch (state) {
|
||||
case CMDNAME: tcmdname += c; break;
|
||||
case OPTION: toptions += c; break;
|
||||
case CONTENT: tcontents += c; break;
|
||||
case WS:
|
||||
if (c == '\\') {
|
||||
state = CMDNAME;
|
||||
} else if (c == '[') {
|
||||
state = OPTION;
|
||||
nestdepth = 0; // Just to be sure
|
||||
} else if (c == '{') {
|
||||
state = CONTENT;
|
||||
nestdepth = 0; // Just to be sure
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't mess with this.
|
||||
if (!tcmdname.empty()) setCmdName(tcmdname);
|
||||
if (!toptions.empty()) setOptions(toptions);
|
||||
if (!tcontents.empty()) setContents(tcontents);
|
||||
|
||||
if (lyxerr.debugging(Debug::PARSER))
|
||||
lyxerr << "Command <" << cmd
|
||||
<< "> == <" << getCommand()
|
||||
<< "> == <" << getCmdName()
|
||||
<< '|' << getContents()
|
||||
<< '|' << getOptions() << '>' << endl;
|
||||
}
|
||||
|
||||
|
||||
// This function will not be necessary when lyx3
|
||||
void InsetCommandParams::read(LyXLex & lex)
|
||||
{
|
||||
string token;
|
||||
|
||||
if (lex.eatLine()) {
|
||||
token = lex.getString();
|
||||
scanCommand(token);
|
||||
} else {
|
||||
lex.printError("InsetCommand: Parse error: `$$Token'");
|
||||
}
|
||||
|
||||
while (lex.isOK()) {
|
||||
lex.nextToken();
|
||||
token = lex.getString();
|
||||
if (token == "\\end_inset")
|
||||
break;
|
||||
}
|
||||
if (token != "\\end_inset") {
|
||||
lex.printError("Missing \\end_inset at this point. "
|
||||
"Read: `$$Token'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetCommandParams::write(ostream & os) const
|
||||
{
|
||||
os << "LatexCommand " << getCommand() << "\n";
|
||||
}
|
||||
|
||||
|
||||
string const InsetCommandParams::getCommand() const
|
||||
{
|
||||
string s;
|
||||
if (!getCmdName().empty()) s += "\\"+getCmdName();
|
||||
if (!getOptions().empty()) s += "["+getOptions()+']';
|
||||
s += "{"+getContents()+'}';
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
|
||||
: p_(p.getCmdName(), p.getContents(), p.getOptions())
|
||||
{}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#endif
|
||||
|
||||
#include "insetbutton.h"
|
||||
#include "insetcommandparams.h"
|
||||
#include <boost/signals/signal0.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
@ -26,52 +27,6 @@
|
||||
* Similar to InsetLaTeX but having control of the basic structure of a
|
||||
* LaTeX command: \name[options]{contents}.
|
||||
*/
|
||||
class InsetCommandParams {
|
||||
public:
|
||||
///
|
||||
InsetCommandParams();
|
||||
///
|
||||
explicit
|
||||
InsetCommandParams(string const & n,
|
||||
string const & c = string(),
|
||||
string const & o = string());
|
||||
///
|
||||
bool operator==(InsetCommandParams const &) const;
|
||||
///
|
||||
bool operator!=(InsetCommandParams const &) const;
|
||||
///
|
||||
void read(LyXLex &);
|
||||
/// Parse the command
|
||||
void scanCommand(string const &);
|
||||
///
|
||||
void write(std::ostream &) const;
|
||||
/// Build the complete LaTeX command
|
||||
string const getCommand() const;
|
||||
///
|
||||
string const & getCmdName() const { return cmdname; }
|
||||
///
|
||||
string const & getOptions() const { return options; }
|
||||
///
|
||||
string const & getContents() const { return contents; }
|
||||
///
|
||||
void setCmdName(string const & n) { cmdname = n; }
|
||||
///
|
||||
void setOptions(string const & o) { options = o; }
|
||||
///
|
||||
void setContents(string const & c) { contents = c; }
|
||||
///
|
||||
string const getAsString() const;
|
||||
///
|
||||
void setFromString(string const &);
|
||||
private:
|
||||
///
|
||||
string cmdname;
|
||||
///
|
||||
string contents;
|
||||
///
|
||||
string options;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
class InsetCommand : public InsetButton, boost::noncopyable {
|
||||
|
174
src/insets/insetcommandparams.C
Normal file
174
src/insets/insetcommandparams.C
Normal file
@ -0,0 +1,174 @@
|
||||
/* This file is part of
|
||||
* ======================================================
|
||||
*
|
||||
* LyX, The Document Processor
|
||||
*
|
||||
* Copyright 2002-2002 The LyX Team.
|
||||
*
|
||||
* ====================================================== */
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "insetcommandparams.h"
|
||||
#include "lyxlex.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
InsetCommandParams::InsetCommandParams()
|
||||
{}
|
||||
|
||||
|
||||
InsetCommandParams::InsetCommandParams(string const & n,
|
||||
string const & c,
|
||||
string const & o)
|
||||
: cmdname(n), contents(c), options(o)
|
||||
{}
|
||||
|
||||
|
||||
string const InsetCommandParams::getAsString() const
|
||||
{
|
||||
return cmdname + "|++|" + contents + "|++|" + options;
|
||||
}
|
||||
|
||||
|
||||
void InsetCommandParams::setFromString(string const & b)
|
||||
{
|
||||
string::size_type idx = b.find("|++|");
|
||||
if (idx == string::npos) {
|
||||
cmdname = b;
|
||||
contents = "";
|
||||
options = "";
|
||||
return;
|
||||
}
|
||||
|
||||
cmdname = b.substr(0, idx);
|
||||
string tmp = b.substr(idx+4);
|
||||
|
||||
idx = tmp.find("|++|");
|
||||
if (idx == string::npos) {
|
||||
contents = tmp;
|
||||
options = "";
|
||||
} else {
|
||||
contents = tmp.substr(0, idx);
|
||||
options = tmp.substr(idx+4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool InsetCommandParams::operator==(InsetCommandParams const & o) const
|
||||
{
|
||||
return cmdname == o.cmdname && contents == o.contents
|
||||
&& options == o.options;
|
||||
}
|
||||
|
||||
|
||||
bool InsetCommandParams::operator!=(InsetCommandParams const & o) const
|
||||
{
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
|
||||
void InsetCommandParams::scanCommand(string const & cmd)
|
||||
{
|
||||
string tcmdname, toptions, tcontents;
|
||||
|
||||
if (cmd.empty()) return;
|
||||
|
||||
enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
|
||||
|
||||
// Used to handle things like \command[foo[bar]]{foo{bar}}
|
||||
int nestdepth = 0;
|
||||
|
||||
for (string::size_type i = 0; i < cmd.length(); ++i) {
|
||||
char c = cmd[i];
|
||||
if ((state == CMDNAME && c == ' ') ||
|
||||
(state == CMDNAME && c == '[') ||
|
||||
(state == CMDNAME && c == '{')) {
|
||||
state = WS;
|
||||
}
|
||||
if ((state == OPTION && c == ']') ||
|
||||
(state == CONTENT && c == '}')) {
|
||||
if (nestdepth == 0) {
|
||||
state = WS;
|
||||
} else {
|
||||
--nestdepth;
|
||||
}
|
||||
}
|
||||
if ((state == OPTION && c == '[') ||
|
||||
(state == CONTENT && c == '{')) {
|
||||
++nestdepth;
|
||||
}
|
||||
switch (state) {
|
||||
case CMDNAME: tcmdname += c; break;
|
||||
case OPTION: toptions += c; break;
|
||||
case CONTENT: tcontents += c; break;
|
||||
case WS:
|
||||
if (c == '\\') {
|
||||
state = CMDNAME;
|
||||
} else if (c == '[') {
|
||||
state = OPTION;
|
||||
nestdepth = 0; // Just to be sure
|
||||
} else if (c == '{') {
|
||||
state = CONTENT;
|
||||
nestdepth = 0; // Just to be sure
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't mess with this.
|
||||
if (!tcmdname.empty()) setCmdName(tcmdname);
|
||||
if (!toptions.empty()) setOptions(toptions);
|
||||
if (!tcontents.empty()) setContents(tcontents);
|
||||
|
||||
if (lyxerr.debugging(Debug::PARSER))
|
||||
lyxerr << "Command <" << cmd
|
||||
<< "> == <" << getCommand()
|
||||
<< "> == <" << getCmdName()
|
||||
<< '|' << getContents()
|
||||
<< '|' << getOptions() << '>' << endl;
|
||||
}
|
||||
|
||||
|
||||
void InsetCommandParams::read(LyXLex & lex)
|
||||
{
|
||||
string token;
|
||||
|
||||
if (lex.eatLine()) {
|
||||
token = lex.getString();
|
||||
scanCommand(token);
|
||||
} else {
|
||||
lex.printError("InsetCommand: Parse error: `$$Token'");
|
||||
}
|
||||
|
||||
while (lex.isOK()) {
|
||||
lex.nextToken();
|
||||
token = lex.getString();
|
||||
if (token == "\\end_inset")
|
||||
break;
|
||||
}
|
||||
if (token != "\\end_inset") {
|
||||
lex.printError("Missing \\end_inset at this point. "
|
||||
"Read: `$$Token'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetCommandParams::write(ostream & os) const
|
||||
{
|
||||
os << "LatexCommand " << getCommand() << "\n";
|
||||
}
|
||||
|
||||
|
||||
string const InsetCommandParams::getCommand() const
|
||||
{
|
||||
string s;
|
||||
if (!getCmdName().empty()) s += "\\"+getCmdName();
|
||||
if (!getOptions().empty()) s += "["+getOptions()+']';
|
||||
s += "{"+getContents()+'}';
|
||||
return s;
|
||||
}
|
||||
|
73
src/insets/insetcommandparams.h
Normal file
73
src/insets/insetcommandparams.h
Normal file
@ -0,0 +1,73 @@
|
||||
// -*- C++ -*-
|
||||
/* This file is part of*
|
||||
* ======================================================
|
||||
*
|
||||
* LyX, The Document Processor
|
||||
*
|
||||
* Copyright 2002-2001 The LyX Team.
|
||||
*
|
||||
* ====================================================== */
|
||||
|
||||
#ifndef INSETCOMMANDPARAMS_H
|
||||
#define INSETCOMMANDPARAMS_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "LString.h"
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class LyXLex;
|
||||
|
||||
class InsetCommandParams {
|
||||
public:
|
||||
///
|
||||
InsetCommandParams();
|
||||
///
|
||||
explicit
|
||||
InsetCommandParams(string const & n,
|
||||
string const & c = string(),
|
||||
string const & o = string());
|
||||
///
|
||||
bool operator==(InsetCommandParams const &) const;
|
||||
///
|
||||
bool operator!=(InsetCommandParams const &) const;
|
||||
///
|
||||
void read(LyXLex &);
|
||||
/// Parse the command
|
||||
void scanCommand(string const &);
|
||||
///
|
||||
void write(std::ostream &) const;
|
||||
/// Build the complete LaTeX command
|
||||
string const getCommand() const;
|
||||
///
|
||||
string const & getCmdName() const { return cmdname; }
|
||||
///
|
||||
string const & getOptions() const { return options; }
|
||||
///
|
||||
string const & getContents() const { return contents; }
|
||||
///
|
||||
void setCmdName(string const & n) { cmdname = n; }
|
||||
///
|
||||
void setOptions(string const & o) { options = o; }
|
||||
///
|
||||
void setContents(string const & c) { contents = c; }
|
||||
///
|
||||
string const getAsString() const;
|
||||
///
|
||||
void setFromString(string const &);
|
||||
private:
|
||||
///
|
||||
string cmdname;
|
||||
///
|
||||
string contents;
|
||||
///
|
||||
string options;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user