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()
30 InsetCommand::InsetCommand(string const & cmd, string const & arg,
32 : cmdname(cmd), options(opt), contents(arg)
37 // In lyxf3 this will be just LaTeX
38 void InsetCommand::Write(Buffer const *, ostream & os) const
40 os << "LatexCommand " << getCommand() << "\n";
44 void InsetCommand::scanCommand(string const & cmd)
46 string tcmdname, toptions, tcontents;
48 if (cmd.empty()) return;
50 enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
52 // Used to handle things like \command[foo[bar]]{foo{bar}}
55 for (string::size_type i = 0; i < cmd.length(); ++i) {
57 if ((state == CMDNAME && c == ' ') ||
58 (state == CMDNAME && c == '[') ||
59 (state == CMDNAME && c == '{')) {
62 if ((state == OPTION && c == ']') ||
63 (state == CONTENT && c == '}')) {
70 if ((state == OPTION && c == '[') ||
71 (state == CONTENT && c == '{')) {
75 case CMDNAME: tcmdname += c; break;
76 case OPTION: toptions += c; break;
77 case CONTENT: tcontents += c; break;
81 } else if (c == '[') {
83 nestdepth = 0; // Just to be sure
84 } else if (c == '{') {
86 nestdepth = 0; // Just to be sure
92 // Don't mess with this.
93 if (!tcmdname.empty()) cmdname = tcmdname;
94 if (!toptions.empty()) options = toptions;
95 if (!tcontents.empty()) setContents(tcontents);
96 // setContents is overloaded in InsetInclude
98 if (lyxerr.debugging(Debug::PARSER))
99 lyxerr << "Command <" << cmd
100 << "> == <" << getCommand()
101 << "> == <" << getCmdName()
102 << '|' << getContents()
103 << '|' << getOptions() << '>' << endl;
107 // This function will not be necessary when lyx3
108 void InsetCommand::Read(Buffer const *, LyXLex & lex)
111 string t = lex.GetString();
114 lex.printError("InsetCommand: Parse error: `$$Token'");
118 int InsetCommand::Latex(Buffer const *, ostream & os, bool /*fragile*/, bool/*fs*/) const
125 int InsetCommand::Ascii(Buffer const *, ostream &) const
131 int InsetCommand::Linuxdoc(Buffer const *, ostream &) const
137 int InsetCommand::DocBook(Buffer const *, ostream &) const
143 Inset * InsetCommand::Clone() const
145 return new InsetCommand(cmdname, contents, options);
149 string InsetCommand::getCommand() const
152 if (!cmdname.empty()) s += "\\"+cmdname;
153 if (!options.empty()) s += "["+options+']';
154 s += "{"+contents+'}';