1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "insetcommand.h"
25 InsetCommand::InsetCommand()
29 InsetCommand::InsetCommand(string const & cmd, string const & arg,
31 : cmdname(cmd), options(opt), contents(arg)
35 // In lyxf3 this will be just LaTeX
36 void InsetCommand::Write(Buffer const *, ostream & os) const
38 os << "LatexCommand " << getCommand() << "\n";
42 void InsetCommand::scanCommand(string const & cmd)
44 string tcmdname, toptions, tcontents;
46 if (cmd.empty()) return;
48 enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
50 // Used to handle things like \command[foo[bar]]{foo{bar}}
53 for (string::size_type i = 0; i < cmd.length(); ++i) {
55 if ((state == CMDNAME && c == ' ') ||
56 (state == CMDNAME && c == '[') ||
57 (state == CMDNAME && c == '{')) {
60 if ((state == OPTION && c == ']') ||
61 (state == CONTENT && c == '}')) {
68 if ((state == OPTION && c == '[') ||
69 (state == CONTENT && c == '{')) {
73 case CMDNAME: tcmdname += c; break;
74 case OPTION: toptions += c; break;
75 case CONTENT: tcontents += c; break;
79 } else if (c == '[') {
81 nestdepth = 0; // Just to be sure
82 } else if (c == '{') {
84 nestdepth = 0; // Just to be sure
90 // Don't mess with this.
91 if (!tcmdname.empty()) cmdname = tcmdname;
92 if (!toptions.empty()) options = toptions;
93 if (!tcontents.empty()) setContents(tcontents);
94 // setContents is overloaded in InsetInclude
96 if (lyxerr.debugging(Debug::PARSER))
97 lyxerr << "Command <" << cmd
98 << "> == <" << getCommand()
99 << "> == <" << getCmdName()
100 << '|' << getContents()
101 << '|' << getOptions() << '>' << endl;
105 // This function will not be necessary when lyx3
106 void InsetCommand::Read(Buffer const *, LyXLex & lex)
111 token = lex.GetString();
114 lex.printError("InsetCommand: Parse error: `$$Token'");
117 token = lex.GetString();
118 if (token == "\\end_inset")
121 if (token != "\\end_inset") {
122 lex.printError("Missing \\end_inset at this point. "
128 int InsetCommand::Latex(Buffer const *, ostream & os,
129 bool /*fragile*/, bool/*fs*/) const
136 int InsetCommand::Ascii(Buffer const *, ostream &) const
142 int InsetCommand::Linuxdoc(Buffer const *, ostream &) const
148 int InsetCommand::DocBook(Buffer const *, ostream &) const
154 Inset * InsetCommand::Clone() const
156 return new InsetCommand(cmdname, contents, options);
160 string InsetCommand::getCommand() const
163 if (!cmdname.empty()) s += "\\"+cmdname;
164 if (!options.empty()) s += "["+options+']';
165 s += "{"+contents+'}';