1
///////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1997, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
6
// Author: Henk van de Zandschulp (henkz@cs.utwente.nl).
8
// TCM is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 2 of the License, or
11
// (at your option) any later version.
13
// TCM is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
18
// You should have received a copy of the GNU General Public License
19
// along with TCM; if not, write to the Free Software
20
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22
////////////////////////////////////////////////////////////////////////////////
26
#include "inputfile.h"
31
const char Config::SYS_CONFIG[] = CONFIG_FILE;
32
const char Config::USER_CONFIG[] = ".tcmrc";
34
Config::Config(const char *s) {
38
ifile = new InputFile();
40
addPointSizes = new List <string *>;
42
// get user configuration file.
43
(void)System::GetHome(&ufile);
46
// get default and system configuration file.
48
char toolkit_conf[MAXNAME];
49
System::GetToolkitConfig(toolkit_conf);
54
// start with setting (reasonable) built-in defaults.
57
// load system config file.
58
if (System::FileExists(sfile.getstr())) {
60
// error("Warning: can't load system config file %s, "
61
// "using built-in defaults\n", SYS_CONFIG);
66
// override with user config file (when this exists).
67
if (System::FileExists(ufile.getstr())) {
69
error("Warning: can't load user config file %s, "
70
"using built-in defaults\n", ufile.getstr());
75
// PRINTER environment variable used when no printerName is set.
77
if (System::GetPrinter(&p)) {
78
if (printerName == "lp")
83
CheckPrinterQueueCommand();
84
CheckPrinterRemoveCommand();
85
CheckPreviewCommand();
86
CheckPSFilterCommand();
87
CheckText2PSCommand();
88
CheckFig2DevCommand();
96
bool Config::Load(const string *file) {
97
// open file for reading.
103
// look if it is not a directory etc.
104
if (!System::FileRegular(file->getstr())) {
115
bool Config::LoadEntries() {
119
while ((c = ifile->ReadChar()) == '{') {
120
if (ifile->ReadWord(&option)) {
121
if (!ifile->ReadWord(&value)) {
122
error("%s, line %d: illegal value for option %s\n",
123
ifile->GetFileName()->getstr(),
124
ifile->LineNumber(), option.getstr());
125
// try to continue with other options.
128
if (option %= "Version")
129
; // ignore (not used anymore).
130
else if (option %= "EncapsulatedPostScript")
131
; // ignore (not used anymore)
132
else if (option %= "NumberOfCopies")
133
; // ignore not used anymore
134
else if (option %= "ExportFormat")
135
exportFormat = value;
136
else if (option %= "PrinterName")
138
else if (option %= "PrintCommand")
139
printCommand = value;
140
else if (option %= "PrinterRemoveCommand")
141
printerRemoveCommand = value;
142
else if (option %= "PrinterQueueCommand")
143
printerQueueCommand = value;
144
else if (option %= "PreviewCommand")
145
previewCommand = value;
146
else if (option %= "Fig2DevCommand")
147
fig2devCommand = value;
148
else if (option %= "PostScriptFilterCommand")
149
postScriptFilterCommand = value;
150
else if (option %= "Text2PSFilterCommand")
151
text2PSFilterCommand = value;
152
else if (option %= "PrintColors")
153
printColors = (value %= "True");
154
else if (option %= "PrintDuplexPages")
155
printDuplexPages = (value %= "True");
156
else if (option %= "PrintTumbledPages")
157
printTumbledPages = (value %= "True");
158
else if (option %= "CharacterEncoding") {
159
if (value %= "Standard")
160
characterEncoding = STANDARD;
161
else if (value %= "ISO_8859_1")
162
characterEncoding = ISO_8859_1;
164
else if (option %= "BannerPage") {
165
if (value %= "Default")
166
bannerPage = DEF_BANNER;
167
else if (value %= "None")
168
bannerPage = NO_BANNER;
169
else if (value %= "TCM_Banner")
170
bannerPage = TCM_BANNER;
172
else if (option %= "TmpFile")
174
else if (option %= "SendEmailOnCrash")
175
sendEmailOnCrash = (value %= "True");
176
else if (option %= "SendEmailOnStartup")
177
sendEmailOnStartup = (value %= "True");
178
else if (option %= "EmailAddress")
179
emailAddress = value;
181
else if (option %= "AutoResizing")
182
autoResizing = (value %= "True");
183
else if (option %= "InlineEditor")
184
inlineEditor = (value %= "True");
185
else if (option %= "AskBeforeQuit")
186
askBeforeQuit = (value %= "True");
188
else if (option %= "ScaleFactor")
189
scaleFactor = value.todouble();
191
else if (option %= "ShowGrid")
192
showGrid = (value %= "True");
193
else if (option %= "GridSize")
194
gridSize = value.toint();
195
else if (option %= "PointSnapping")
196
pointSnapping = (value %= "True");
197
else if (option %= "PointDistance")
198
pointDistance = value.toint();
199
else if (option %= "TextSelectDistance")
200
textSelectDistance = value.toint();
201
else if (option %= "LineSelectDistance")
202
lineSelectDistance = value.toint();
204
else if (option %= "PageOrientation") {
205
if (value %= "Portrait")
206
pageOrientation = PORTRAIT;
207
else if (value %= "Landscape")
208
pageOrientation = LANDSCAPE;
210
else if (option %= "ShowPageBoundary")
211
showPageBoundary = (value %= "True");
212
else if (option %= "PageSize")
213
pageSize = PageSize::String2Type(&value);
214
else if (option %= "IncludePageNumbers")
215
includePageNumbers = (value %= "True");
216
else if (option %= "IncludeDocumentInfo") {
217
showDocumentInfoAsHeader = (value %= "Header");
218
showDocumentInfoAsFooter = (value %= "Footer");
221
else if (option %= "FontFamily") {
222
if (value %= "Helvetica")
223
fontFamily = AFont::HELVETICA;
224
else if (value %= "Times")
225
fontFamily = AFont::TIMESROMAN;
226
else if (value %= "Courier")
227
fontFamily = AFont::COURIER;
228
else if (value %= "NewCenturySchoolbook")
229
fontFamily = AFont::NEWCENTURYSCHLBK;
230
else if (value %= "Symbol")
231
fontFamily = AFont::SYMBOL;
233
else if (option %= "FontStyle") {
234
if (value %= "Roman")
235
fontStyle = AFont::PLAIN;
236
else if (value %= "Italic")
237
fontStyle = AFont::ITALIC;
238
else if (value %= "Bold")
239
fontStyle = AFont::BOLD;
240
else if (value %= "BoldItalic")
241
fontStyle = AFont::BOLD+AFont::ITALIC;
243
else if (option %= "PointSize")
244
pointSize = value.toint();
245
else if (option %= "FontFoundry")
247
else if (option %= "ScalableFonts")
248
scalableFonts = (value %= "True");
249
else if (option %= "Underlined")
250
underlined = (value %= "True");
252
else if (option %= "AddPointSize") {
253
if (value.toint() > 0)
254
addPointSizes->add(new string(value));
257
else if (option %= "LineWidth")
258
lineWidth = value.toint();
259
else if (option %= "LineStyle")
260
lineStyle = LineStyle::String2Type(&value);
261
else if (option %= "LineColor") {
263
// no spaces in word.
264
lineColor.replace('_', ' ');
265
lineColor.downcase();
267
else if (option %= "TextColor") {
269
textColor.replace('_', ' ');
270
textColor.downcase();
272
else if (option %= "FillColor") {
274
fillColor.replace('_', ' ');
275
fillColor.downcase();
278
else if (option %= "Alignment")
279
textAlignment = TextAlign::String2Type(&value);
280
else if (option %= "TextAlignment")
281
textAlignment = TextAlign::String2Type(&value);
283
else if (option %= "DrawingScrollWidth")
284
drawingScrollWidth = value.toint();
285
else if (option %= "DrawingScrollHeight")
286
drawingScrollHeight = value.toint();
287
else if (option %= "DrawingWidth")
288
drawingWidth = value.toint();
289
else if (option %= "DrawingHeight")
290
drawingHeight = value.toint();
291
else if (option %= "DrawingMaxWidth")
292
drawingMaxWidth = value.toint();
293
else if (option %= "DrawingMaxHeight")
294
drawingMaxHeight = value.toint();
295
else if (option %= "DrawingBackground")
296
drawingBackground = value;
297
else if (option %= "DrawingForeground")
298
drawingForeground = value;
300
// GUI style view mode option
301
else if (option %= "GUIstyle")
302
classicGUIstyle = (value %= "Classic");
303
else if (option %= "PrivateColormap")
304
privateColormap = (value %= "True");
306
// startup window view mode option
307
else if (option %= "StartupWindowSmall")
308
startupSmall = (value %= "True");
311
else if (option %= "TableMarginWidth")
312
tableMarginWidth = value.toint();
313
else if (option %= "TableMarginHeight")
314
tableMarginHeight = value.toint();
315
else if (option %= "ColumnAlignment")
317
TextAlign::String2Type(&value);
318
else if (option %= "RowAlignment")
319
rowAlignment = TextAlign::String2Type(&value);
320
else if (option %= "MinimalRowHeight")
321
defaultRowHeight = value.toint();
322
else if (option %= "DefaultRowHeight")
323
defaultRowHeight = value.toint();
324
else if (option %= "MinimalColumnWidth")
325
defaultColumnWidth = value.toint();
326
else if (option %= "DefaultColumnWidth")
327
defaultColumnWidth = value.toint();
328
else if (option %= "ShowRowColumnLabels")
329
showRowColumnLabels = (value %= "True");
330
else if (option %= "PrintRowColumnLabels")
331
printRowColumnLabels = (value %= "True");
332
else if (option %= "NumberOfColumns")
333
numberOfColumns = value.toint();
334
else if (option %= "NumberOfRows")
335
numberOfRows = value.toint();
336
else if (option %= "TableTopLeft") {
337
int x = value.toint();
338
if (ifile->ReadWord(&value)) {
339
int y = value.toint();
340
tableTopLeft = Point(x, y);
343
error("%s, line %d: missing value "
345
ifile->GetFileName()->getstr(),
346
ifile->LineNumber(), option.getstr());
350
else if (option %= "FETcolumnWidth")
351
fetColumnWidth = value.toint();
352
else if (option %= "TUTcolumnWidth")
353
tutColumnWidth = value.toint();
354
else if (option %= "TUTnumberOfColumns")
355
tutNumberOfColumns = value.toint();
357
error("%s, line %d: warning: unknown "
359
ifile->GetFileName()->getstr(),
360
ifile->LineNumber(), option.getstr());
361
// ignore this option then.
365
error("%s, line %d: option expected\n",
366
ifile->GetFileName()->getstr(),
367
ifile->LineNumber());
370
if (!ifile->LookupChar('}'))
376
bool Config::Save() {
377
return True; // not implemented yet.
380
void Config::CheckPrintCommand() {
381
if (!System::FileExecutable(printCommand.getstr())) {
382
DefaultPrintCommand();
385
std::cout << "printing with " << printCommand << std::endl;
389
void Config::CheckPrinterQueueCommand() {
390
if (!System::FileExecutable(printerQueueCommand.getstr())) {
391
DefaultPrinterQueueCommand();
394
std::cout << "show printer queue with " << printerQueueCommand << std::endl;
398
void Config::CheckPrinterRemoveCommand() {
399
if(!System::FileExecutable(printerRemoveCommand.getstr())) {
400
DefaultPrinterRemoveCommand();
403
std::cout << "remove from queue with " << printerRemoveCommand << std::endl;
407
void Config::CheckPreviewCommand() {
408
if(!System::FileExecutable(previewCommand.getstr())) {
409
DefaultPreviewCommand();
412
std::cout << "preview ps with " << previewCommand << std::endl;
416
void Config::CheckFig2DevCommand() {
417
if(!System::FileExecutable(fig2devCommand.getstr())) {
418
DefaultFig2DevCommand();
421
std::cout << "fig2dev with " << fig2devCommand << std::endl;
425
void Config::CheckPSFilterCommand() {
426
if(!System::FileExecutable(postScriptFilterCommand.getstr())) {
427
DefaultPSFilterCommand();
430
std::cout << "PostScript filter (psf) with " <<
431
postScriptFilterCommand << std::endl;
435
void Config::CheckText2PSCommand() {
437
strcpy(file, text2PSFilterCommand.getstr());
438
char *p = strchr(file, ' ');
441
if(!System::FileExecutable(file)) {
442
DefaultText2PSCommand();
445
std::cout << "Text to ps with " << text2PSFilterCommand << std::endl;
449
void Config::DefaultPrintCommand() {
450
if (!(System::FindProgram(&printCommand, "lpr") ||
451
System::FindProgram(&printCommand, "lp")))
452
printCommand = "lpr";
455
void Config::DefaultPrinterQueueCommand() {
456
if (!(System::FindProgram(&printerQueueCommand, "lpstat") ||
457
System::FindProgram(&printerQueueCommand, "lpq")))
458
printerQueueCommand = "lpq";
461
void Config::DefaultPrinterRemoveCommand() {
462
if (!(System::FindProgram(&printerRemoveCommand, "cancel") ||
463
System::FindProgram(&printerRemoveCommand, "lprm")))
464
printerRemoveCommand = "lprm";
467
void Config::DefaultPreviewCommand() {
468
if (!(System::FindProgram(&previewCommand, "gv") ||
469
System::FindProgram(&previewCommand, "xpsview") ||
470
System::FindProgram(&previewCommand, "pageview") ||
471
System::FindProgram(&previewCommand, "ghostview") ||
472
System::FindProgram(&previewCommand, "gs")))
473
previewCommand = "ghostview";
476
void Config::DefaultFig2DevCommand() {
477
if (!System::FindProgram(&fig2devCommand, "fig2dev"))
478
fig2devCommand = "fig2dev";
481
void Config::DefaultPSFilterCommand() {
482
if (!System::FindProgram(&postScriptFilterCommand, "psf"))
483
postScriptFilterCommand = "psf";
486
void Config::DefaultText2PSCommand() {
487
if (System::FindProgram(&text2PSFilterCommand, "text2ps"))
488
text2PSFilterCommand += " -f Helvetica ";
490
text2PSFilterCommand = "a2ps";
493
void Config::SetDefault() {
494
DefaultPrintCommand();
495
DefaultPrinterQueueCommand();
496
DefaultPrinterRemoveCommand();
497
DefaultPreviewCommand();
498
DefaultFig2DevCommand();
499
DefaultPSFilterCommand();
500
DefaultText2PSCommand();
502
exportFormat = "PostScript";
505
printDuplexPages = True;
506
printTumbledPages = False;
507
characterEncoding = STANDARD;
508
bannerPage = DEF_BANNER;
510
tmpFile = "/tmp/tcmXXXXXX";
511
sendEmailOnCrash = False;
512
sendEmailOnStartup = False;
513
emailAddress = "tcm@cs.utwente.nl";
516
askBeforeQuit = True;
521
pointSnapping = True;
524
textSelectDistance = 2;
525
lineSelectDistance = 12;
527
pageOrientation = PORTRAIT;
528
showPageBoundary = True;
529
pageSize = PageSize::A4;
530
includePageNumbers = False;
531
showDocumentInfoAsHeader = False;
532
showDocumentInfoAsFooter = False;
534
fontFoundry = "Adobe";
535
fontFamily = AFont::PLAIN;
536
fontStyle = AFont::HELVETICA;
538
textAlignment = TextAlign::CENTER;
539
scalableFonts = True;
542
lineStyle = LineStyle::SOLID;
547
drawingScrollWidth = 820;
548
drawingScrollHeight= 680;
550
drawingHeight = 1330;
551
drawingMaxWidth = 10000;
552
drawingMaxHeight = 10000;
553
drawingBackground = "White";
554
drawingForeground = "Black";
555
classicGUIstyle = False;
556
privateColormap = False;
558
tableMarginWidth = 5;
559
tableMarginHeight = 5;
560
columnAlignment= TextAlign::LEFT;
561
rowAlignment = TextAlign::CENTER;
562
defaultRowHeight = 26;
563
defaultColumnWidth = 65;
566
showRowColumnLabels = True;
567
printRowColumnLabels = False;
568
tableTopLeft = Point(20, 80);
572
tutNumberOfColumns = 5;