command.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2003 Robert JACOLIN <rjacolin@ifrance.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "command.h"
21#include <iostream.h>
22#include "kdebug.h"
23
24Command::Command()
25{
26 setType(Element::LATEX_COMMAND);
27 _options.setAutoDelete(true);
28 _params.setAutoDelete(true);
29}
30
31Command::Command(const char* name)
32{
33 setType(Element::LATEX_COMMAND);
34 _options.setAutoDelete(true);
35 _params.setAutoDelete(true);
36 _name = name;
37 _name = _name.stripWhiteSpace();
38}
39
40Command::Command(const char* name, TQPtrList<TQPtrList<Element> >* groups)
41{
42 setType(Element::LATEX_COMMAND);
43 _options.setAutoDelete(true);
44 _params.setAutoDelete(true);
45 _name = name;
46 if(groups != NULL)
47 _elements = *groups;
48 _name = _name.stripWhiteSpace();
49}
50
51Command::Command(const char* name, TQPtrList<TQPtrList<Param> >* params,
52 TQPtrList<TQPtrList<Element> >* groups)
53{
54 setType(Element::LATEX_COMMAND);
55 _options.setAutoDelete(true);
56 _params.setAutoDelete(true);
57 _name = name;
58 if(groups != NULL)
59 _elements = *groups;
60 if(params != NULL)
61 _params = *params;
62 _name = _name.stripWhiteSpace();
63}
64
65Command::Command(const char* name, TQPtrList<TQPtrList<Param> >* params, TQPtrList<Param>* options,
66 TQPtrList<TQPtrList<Element> >* groups)
67{
68 setType(Element::LATEX_COMMAND);
69 _options.setAutoDelete(true);
70 _params.setAutoDelete(true);
71 _name = name;
72 if(groups != NULL)
73 _elements = *groups;
74 if(params != NULL)
75 _params = *params;
76 if(options != NULL)
77 _options = *options;
78 _name = name;
79 _name = _name.stripWhiteSpace();
80}
81
82Command::~Command()
83{
84}
85
86void Command::addParam(const char* )
87{
88 /*TQString test = TQString(name);
89 TQString key = test.left(test.find("="));
90 TQString value = test.right(test.find("="));
91 addParam(key, value);*/
92}
93
94void Command::addOption(const char* )
95{
96 /*TQString test = TQString(name);
97 TQString key = test.left(test.find("="));
98 TQString value = test.right(test.find("="));
99 addOption(key, value);*/
100}
101
102void Command::print(int tab)
103{
104 cout << _name.latin1();
105 TQPtrList<Param>* params;
106 for ( params = _params.first(); params; params = _params.next() )
107 {
108 cout << "[";
109 Param* param;
110 for ( param = params->first(); param; param = params->next() )
111 {
112 param->print(tab);
113 if(param != params->getLast())
114 cout << ", ";
115 }
116 cout << "]";
117 }
118 if(_options.count() > 0)
119 {
120 cout << " - [";
121 Param* param;
122 for ( param = _options.first(); param; param = _options.next() )
123 {
124 param->print(tab);
125 if(param != _options.getLast())
126 cout << ", ";
127 }
128 cout << "]";
129 }
130
131 TQPtrList<Element>* group;
132 for(group = _elements.first(); group; group = _elements.next() )
133 {
134 cout << " {";
135 Element* elt;
136 for ( elt = group->first(); elt; elt = group->next() )
137 {
138 elt->print(tab);
139 }
140 cout << "}";
141 }
142 cout << endl;
143}
This class is a element.