]> git.lyx.org Git - lyx.git/blob - src/lyxrc.C
partial fix for '\n' output problem, still needs fixing of output before/after a...
[lyx.git] / src / lyxrc.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation "lyxrc.h"
15 #endif
16
17 #include <fstream>
18 #include <iomanip>
19 #include <iostream>
20
21 #include "debug.h"
22
23 #include "lyxrc.h"
24 #include "kbmap.h"
25 #include "LyXAction.h"
26 #include "lyxserver.h"
27 #include "lyx_main.h"
28 #include "intl.h"
29 #include "tex-strings.h"
30 #include "support/path.h"
31 #include "support/filetools.h"
32 #include "lyxtext.h"
33 #include "converter.h"
34
35 using std::ostream;
36 using std::ofstream;
37 using std::cout;
38 using std::ios;
39 using std::endl;
40
41 // this is crappy... why are those colors command line arguments and
42 // not in lyxrc?? (Matthias) 
43 // Because nobody put them there. (Asger)
44
45 extern bool cursor_follows_scrollbar;
46 extern LyXAction lyxaction;
47 extern kb_keymap * toplevel_keymap;
48
49
50 enum LyXRCTags {
51         RC_FONT_ENCODING = 1,
52         RC_PRINTER,
53         RC_PRINT_COMMAND,
54         RC_PRINTEVENPAGEFLAG,
55         RC_PRINTODDPAGEFLAG,
56         RC_PRINTPAGERANGEFLAG,
57         RC_PRINTCOPIESFLAG,
58         RC_PRINTCOLLCOPIESFLAG,
59         RC_PRINTREVERSEFLAG,
60         RC_PRINTLANDSCAPEFLAG,
61         RC_PRINTTOPRINTER,
62         RC_PRINT_ADAPTOUTPUT,
63         RC_PRINTTOFILE,
64         RC_PRINTFILEEXTENSION,
65         RC_PRINTEXSTRAOPTIONS,
66         RC_PRINTSPOOL_COMMAND,
67         RC_PRINTSPOOL_PRINTERPREFIX,
68         RC_PRINTPAPERFLAG,
69         RC_PRINTPAPERDIMENSIONFLAG,
70         RC_CUSTOM_EXPORT_COMMAND,
71         RC_CUSTOM_EXPORT_FORMAT,
72         RC_LATEX_COMMAND,
73         RC_LITERATE_COMMAND,
74         RC_LITERATE_EXTENSION,
75         RC_LITERATE_ERROR_FILTER,
76         RC_BUILD_COMMAND,
77         RC_BUILD_ERROR_FILTER,
78         RC_SCREEN_DPI,
79         RC_SCREEN_ZOOM,
80         RC_SCREEN_FONT_SIZES,
81         RC_SCREEN_FONT_ROMAN,
82         RC_SCREEN_FONT_SANS,
83         RC_SCREEN_FONT_TYPEWRITER,
84         RC_SCREEN_FONT_MENU,
85         RC_SCREEN_FONT_POPUP,
86         RC_SCREEN_FONT_ENCODING,
87         RC_SCREEN_FONT_ENCODING_MENU,
88         RC_SET_COLOR,
89         RC_AUTOSAVE,
90         RC_DOCUMENTPATH,
91         RC_TEMPLATEPATH,
92         RC_TEMPDIRPATH,
93         RC_USETEMPDIR,
94         RC_LASTFILES,
95         RC_AUTOREGIONDELETE,
96         RC_BIND,
97         RC_OVERRIDE_X_DEADKEYS,
98         RC_SERVERPIPE,
99         RC_INPUT,
100         RC_BINDFILE,
101         RC_UIFILE,
102         RC_KBMAP,
103         RC_KBMAP_PRIMARY,
104         RC_KBMAP_SECONDARY,
105         RC_FAX_COMMAND,
106         RC_PHONEBOOK,
107         RC_FAXPROGRAM,
108         RC_ASCIIROFF_COMMAND,
109         RC_ASCII_LINELEN,
110         RC_NUMLASTFILES,
111         RC_CHECKLASTFILES,
112         RC_VIEWDVI_COMMAND,
113         RC_VIEWDVI_PAPEROPTION,
114         RC_DEFAULT_PAPERSIZE,
115         RC_PS_COMMAND,
116         RC_VIEWPS_COMMAND,
117         RC_VIEWPSPIC_COMMAND,
118         RC_ACCEPT_COMPOUND,
119         RC_SPELL_COMMAND,
120         RC_USE_INP_ENC,
121         RC_USE_ALT_LANG,
122         RC_USE_PERS_DICT,
123         RC_USE_ESC_CHARS,
124         RC_SCREEN_FONT_SCALABLE,
125         RC_ALT_LANG,
126         RC_PERS_DICT,
127         RC_ESC_CHARS,
128         RC_CHKTEX_COMMAND,
129         RC_CURSOR_FOLLOWS_SCROLLBAR,
130         RC_EXIT_CONFIRMATION,
131         RC_DISPLAY_SHORTCUTS,
132         RC_RELYX_COMMAND,
133         RC_HTML_COMMAND,
134         RC_MAKE_BACKUP,
135         RC_BACKUPDIR_PATH,
136         RC_RTL_SUPPORT,
137         RC_AUTO_NUMBER,
138         RC_MARK_FOREIGN_LANGUAGE,
139         RC_LANGUAGE_PACKAGE,
140         RC_LANGUAGE_AUTO_BEGIN,
141         RC_LANGUAGE_AUTO_END,
142         RC_LANGUAGE_COMMAND_BEGIN,
143         RC_LANGUAGE_COMMAND_END,
144         RC_PDFLATEX_COMMAND,
145         RC_PDF_MODE,
146         RC_VIEWPDF_COMMAND,
147         RC_PDF_TO_PS_COMMAND,
148         RC_DVI_TO_PS_COMMAND,
149         RC_DATE_INSERT_FORMAT,
150         RC_SHOW_BANNER,
151         RC_USE_GUI,
152         RC_LINUXDOC_TO_LYX_COMMAND,
153         RC_LINUXDOC_TO_HTML_COMMAND,
154         RC_LINUXDOC_TO_LATEX_COMMAND,
155         RC_DOCBOOK_TO_DVI_COMMAND,
156         RC_DOCBOOK_TO_HTML_COMMAND,
157         RC_DOCBOOK_TO_PDF_COMMAND,
158         RC_WHEEL_JUMP,
159         RC_CONVERTER,
160         RC_VIEWER,
161         RC_NEW_ASK_FILENAME,
162         RC_DEFAULT_LANGUAGE,
163         RC_LAST
164 };
165
166
167 static
168 keyword_item lyxrcTags[] = {
169         { "\\accept_compound", RC_ACCEPT_COMPOUND },
170         { "\\alternate_language", RC_ALT_LANG },
171         { "\\ascii_linelen", RC_ASCII_LINELEN },
172         { "\\ascii_roff_command", RC_ASCIIROFF_COMMAND },
173         { "\\auto_number", RC_AUTO_NUMBER },
174         { "\\auto_region_delete", RC_AUTOREGIONDELETE },
175         { "\\autosave", RC_AUTOSAVE },
176         { "\\backupdir_path", RC_BACKUPDIR_PATH },
177         { "\\bind", RC_BIND },
178         { "\\bind_file", RC_BINDFILE },
179         { "\\build_command", RC_BUILD_COMMAND },
180         { "\\build_error_filter", RC_BUILD_ERROR_FILTER },
181         { "\\check_lastfiles", RC_CHECKLASTFILES },
182         { "\\chktex_command", RC_CHKTEX_COMMAND },
183         { "\\converter", RC_CONVERTER },
184         { "\\cursor_follows_scrollbar", RC_CURSOR_FOLLOWS_SCROLLBAR },
185         { "\\custom_export_command", RC_CUSTOM_EXPORT_COMMAND },
186         { "\\custom_export_format", RC_CUSTOM_EXPORT_FORMAT },
187         { "\\date_insert_format", RC_DATE_INSERT_FORMAT },
188         { "\\default_language", RC_DEFAULT_LANGUAGE },
189         { "\\default_papersize", RC_DEFAULT_PAPERSIZE },
190         { "\\display_shortcuts", RC_DISPLAY_SHORTCUTS },
191         { "\\docbook_to_dvi_command", RC_DOCBOOK_TO_DVI_COMMAND },
192         { "\\docbook_to_html_command", RC_DOCBOOK_TO_HTML_COMMAND },
193         { "\\docbook_to_pdf_command", RC_DOCBOOK_TO_PDF_COMMAND },
194         { "\\document_path", RC_DOCUMENTPATH },
195         { "\\dvi_to_ps_command", RC_DVI_TO_PS_COMMAND },
196         { "\\escape_chars", RC_ESC_CHARS },
197         { "\\exit_confirmation", RC_EXIT_CONFIRMATION },
198         { "\\fax_command", RC_FAX_COMMAND },
199         { "\\fax_program", RC_FAXPROGRAM },
200         { "\\font_encoding", RC_FONT_ENCODING },
201         { "\\html_command", RC_HTML_COMMAND },
202         { "\\input", RC_INPUT },
203         { "\\kbmap", RC_KBMAP },
204         { "\\kbmap_primary", RC_KBMAP_PRIMARY },
205         { "\\kbmap_secondary", RC_KBMAP_SECONDARY },
206         { "\\language_auto_begin", RC_LANGUAGE_AUTO_BEGIN },
207         { "\\language_auto_end", RC_LANGUAGE_AUTO_END },
208         { "\\language_command_begin", RC_LANGUAGE_COMMAND_BEGIN },
209         { "\\language_command_end", RC_LANGUAGE_COMMAND_END },
210         { "\\language_package", RC_LANGUAGE_PACKAGE },
211         { "\\lastfiles", RC_LASTFILES },
212         { "\\latex_command", RC_LATEX_COMMAND },
213         { "\\linuxdoc_to_html_command", RC_LINUXDOC_TO_HTML_COMMAND },
214         { "\\linuxdoc_to_latex_command", RC_LINUXDOC_TO_LATEX_COMMAND },
215         { "\\linuxdoc_to_lyx_command", RC_LINUXDOC_TO_LYX_COMMAND },
216         { "\\literate_command", RC_LITERATE_COMMAND },
217         { "\\literate_error_filter", RC_LITERATE_ERROR_FILTER },
218         { "\\literate_extension", RC_LITERATE_EXTENSION },
219         { "\\make_backup", RC_MAKE_BACKUP },
220         { "\\mark_foreign_language", RC_MARK_FOREIGN_LANGUAGE },
221         { "\\new_ask_filename", RC_NEW_ASK_FILENAME },
222         { "\\num_lastfiles", RC_NUMLASTFILES },
223         { "\\override_x_deadkeys", RC_OVERRIDE_X_DEADKEYS },
224         { "\\pdf_mode", RC_PDF_MODE },
225         { "\\pdf_to_ps_command", RC_PDF_TO_PS_COMMAND },
226         { "\\pdflatex_command", RC_PDFLATEX_COMMAND },
227         { "\\personal_dictionary", RC_PERS_DICT },
228         { "\\phone_book", RC_PHONEBOOK },
229         { "\\print_adapt_output", RC_PRINT_ADAPTOUTPUT },
230         { "\\print_collcopies_flag", RC_PRINTCOLLCOPIESFLAG },
231         { "\\print_command", RC_PRINT_COMMAND },
232         { "\\print_copies_flag", RC_PRINTCOPIESFLAG },
233         { "\\print_evenpage_flag", RC_PRINTEVENPAGEFLAG },
234         { "\\print_extra_options", RC_PRINTEXSTRAOPTIONS },
235         { "\\print_file_extension", RC_PRINTFILEEXTENSION },
236         { "\\print_landscape_flag", RC_PRINTLANDSCAPEFLAG },
237         { "\\print_oddpage_flag", RC_PRINTODDPAGEFLAG },
238         { "\\print_pagerange_flag", RC_PRINTPAGERANGEFLAG },
239         { "\\print_paper_dimension_flag", RC_PRINTPAPERDIMENSIONFLAG },
240         { "\\print_paper_flag", RC_PRINTPAPERFLAG },
241         { "\\print_reverse_flag", RC_PRINTREVERSEFLAG },
242         { "\\print_spool_command", RC_PRINTSPOOL_COMMAND },
243         { "\\print_spool_printerprefix", RC_PRINTSPOOL_PRINTERPREFIX },
244         { "\\print_to_file", RC_PRINTTOFILE },
245         { "\\print_to_printer", RC_PRINTTOPRINTER },
246         { "\\printer", RC_PRINTER },
247         { "\\ps_command", RC_PS_COMMAND },
248         { "\\relyx_command", RC_RELYX_COMMAND },
249         { "\\rtl", RC_RTL_SUPPORT },
250         { "\\screen_dpi", RC_SCREEN_DPI },
251         { "\\screen_font_encoding", RC_SCREEN_FONT_ENCODING },
252         { "\\screen_font_encoding_menu", RC_SCREEN_FONT_ENCODING_MENU },
253         { "\\screen_font_menu", RC_SCREEN_FONT_MENU },
254         { "\\screen_font_popup", RC_SCREEN_FONT_POPUP },
255         { "\\screen_font_roman", RC_SCREEN_FONT_ROMAN },
256         { "\\screen_font_sans", RC_SCREEN_FONT_SANS },
257         { "\\screen_font_scalable", RC_SCREEN_FONT_SCALABLE },
258         { "\\screen_font_sizes", RC_SCREEN_FONT_SIZES },
259         { "\\screen_font_typewriter", RC_SCREEN_FONT_TYPEWRITER },
260         { "\\screen_zoom", RC_SCREEN_ZOOM },
261         { "\\serverpipe", RC_SERVERPIPE },
262         { "\\set_color", RC_SET_COLOR },
263         { "\\show_banner", RC_SHOW_BANNER },
264         { "\\spell_command", RC_SPELL_COMMAND },
265         { "\\tempdir_path", RC_TEMPDIRPATH },
266         { "\\template_path", RC_TEMPLATEPATH },
267         { "\\ui_file", RC_UIFILE },
268         { "\\use_alt_language", RC_USE_ALT_LANG },
269         { "\\use_escape_chars", RC_USE_ESC_CHARS },
270         { "\\use_gui", RC_USE_GUI },
271         { "\\use_input_encoding", RC_USE_INP_ENC },
272         { "\\use_personal_dictionary", RC_USE_PERS_DICT },
273         { "\\use_tempdir", RC_USETEMPDIR },
274         { "\\view_dvi_command", RC_VIEWDVI_COMMAND },
275         { "\\view_dvi_paper_option", RC_VIEWDVI_PAPEROPTION },
276         { "\\view_pdf_command", RC_VIEWPDF_COMMAND },
277         { "\\view_ps_command", RC_VIEWPS_COMMAND },
278         { "\\view_pspic_command", RC_VIEWPSPIC_COMMAND },
279         { "\\viewer" ,RC_VIEWER}, 
280         { "\\wheel_jump", RC_WHEEL_JUMP }
281 };
282
283 /* Let the range depend of the size of lyxrcTags.  Alejandro 240596 */
284 static const int lyxrcCount = sizeof(lyxrcTags) / sizeof(keyword_item);
285
286
287 LyXRC::LyXRC() 
288 {
289         setDefaults();
290 }
291
292
293 void LyXRC::setDefaults() {
294         ui_file = "default";
295         // Get printer from the environment. If fail, use default "",
296         // assuming that everything is set up correctly.
297         printer = GetEnv("PRINTER");
298         print_adapt_output = false;
299         print_command = "dvips";
300         print_evenpage_flag = "-B";
301         print_oddpage_flag = "-A";
302         print_pagerange_flag = "-pp";
303         print_copies_flag = "-c";
304         print_collcopies_flag = "-C";
305         print_reverse_flag = "-r";
306         print_landscape_flag = "-t landscape";
307         print_to_printer = "-P";
308         print_to_file = "-o ";
309         print_file_extension = ".ps";
310         print_paper_flag = "-t";
311         print_paper_dimension_flag = "-T";
312         document_path = GetEnvPath("HOME");
313         tempdir_path = "/tmp";
314         use_tempdir = true;
315         pdf_mode = false;
316         latex_command = "latex";
317         pdflatex_command = "pdflatex";
318         pdf_to_ps_command = "pdf2ps";
319         dvi_to_ps_command = "dvips";
320         literate_command = "none";
321         literate_extension = "none";
322         literate_error_filter = "cat";
323         build_command = "make";
324         build_error_filter = "cat";
325         relyx_command = "reLyX";
326         ps_command = "gs";
327         view_ps_command = "ghostview -swap";
328         view_pspic_command = "ghostview";
329         view_dvi_command = "xdvi";
330         view_dvi_paper_option = "-paper";
331         view_pdf_command = "xpdf";
332         default_papersize = BufferParams::PAPER_USLETTER;
333         custom_export_format = "ps";
334         chktex_command = "chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38";
335         html_command = "tth -t";
336         fontenc = "default";
337         dpi = 75;
338         // Because a screen typically is wider than a piece of paper:
339         zoom = 150;
340         wheel_jump = 100;
341         // Default LaTeX font size:
342         font_sizes[LyXFont::SIZE_TINY] = 5.0;
343         font_sizes[LyXFont::SIZE_SCRIPT] = 7.0;
344         font_sizes[LyXFont::SIZE_FOOTNOTE] = 8.0;
345         font_sizes[LyXFont::SIZE_SMALL] = 9.0;
346         font_sizes[LyXFont::SIZE_NORMAL] = 10.0;
347         font_sizes[LyXFont::SIZE_LARGE] = 12.0;
348         font_sizes[LyXFont::SIZE_LARGER] = 14.4;
349         font_sizes[LyXFont::SIZE_LARGEST] = 17.26;
350         font_sizes[LyXFont::SIZE_HUGE] = 20.74;
351         font_sizes[LyXFont::SIZE_HUGER] = 24.88;
352         use_scalable_fonts = true;
353         roman_font_name = "-*-times";
354         sans_font_name = "-*-helvetica";
355         typewriter_font_name = "-*-courier";
356         menu_font_name = "-*-helvetica-bold-r";
357         popup_font_name = "-*-helvetica-medium-r";
358         font_norm = "iso8859-1";
359         font_norm_type = OTHER_ENCODING;
360         font_norm_menu = "";
361         override_x_deadkeys = true;
362         autosave = 300;
363         auto_region_delete = true;
364         ascii_linelen = 65;
365         num_lastfiles = 4;
366         check_lastfiles = true;
367         make_backup = true;
368         backupdir_path = "";
369         exit_confirmation = true;
370         display_shortcuts = true;
371         // Spellchecker settings:
372         isp_command = "ispell";
373         isp_accept_compound = false;
374         isp_use_input_encoding = false;
375         isp_use_alt_lang = false;
376         isp_use_pers_dict = false;
377         isp_use_esc_chars = false;
378         use_kbmap = false;
379         hasBindFile = false;
380         rtl_support = false;
381         auto_number = true;
382         mark_foreign_language = true;
383         language_package = "\\usepackage{babel}";
384         language_auto_begin = true;
385         language_auto_end = true;
386         language_command_begin = "\\selectlanguage{$$lang}";
387         language_command_end = "\\selectlanguage{$$lang}";
388         default_language = "english";
389         ///
390         new_ask_filename = false;
391
392         ///
393         date_insert_format = "%A, %e %B %Y";
394         show_banner = true;
395         use_gui = true;
396
397         ///
398         linuxdoc_to_latex_command="none";
399         linuxdoc_to_lyx_command="none";
400         linuxdoc_to_html_command="none";
401
402         docbook_to_dvi_command="none";
403         docbook_to_html_command="none";
404         docbook_to_pdf_command="none";
405 }
406
407
408 int LyXRC::ReadBindFile(string const & name)
409 {
410         hasBindFile = true;
411         string tmp = i18nLibFileSearch("bind", name, "bind");
412         lyxerr[Debug::LYXRC] << "Reading bindfile:" << tmp << endl;
413         int result = read(tmp);
414         if (result) {
415                 lyxerr << "Error reading bind file: " << tmp << endl;
416         }
417         return result;
418 }
419
420
421 int LyXRC::read(string const & filename)
422 {
423         // Default bindfile.
424         string bindFile = "cua";
425         
426         LyXLex lexrc(lyxrcTags, lyxrcCount);
427         if (lyxerr.debugging(Debug::PARSER))
428                 lexrc.printTable(lyxerr);
429         
430         lexrc.setFile(filename);
431         if (!lexrc.IsOK()) return -2;
432         
433         lyxerr[Debug::INIT] << "Reading '" << filename << "'..." << endl;
434         
435         while (lexrc.IsOK()) {
436                 // By using two switches we take advantage of the compiler
437                 // telling us if we have missed a LyXRCTags element in
438                 // the second switch.
439                 // Note that this also shows a problem with LyXLex since it
440                 // helps us avoid taking advantage of the strictness of the
441                 // compiler.
442
443                 int le = lexrc.lex();
444                 switch(le) {
445                 case LyXLex::LEX_UNDEF:
446                         lexrc.printError("Unknown tag `$$Token'");
447                         continue; 
448                 case LyXLex::LEX_FEOF:
449                         continue; 
450                 default: break;
451                 }
452                 switch (static_cast<LyXRCTags>(le)) {
453                 case RC_INPUT: // Include file
454                         if (lexrc.next()) {
455                                 string tmp = LibFileSearch(string(),
456                                                            lexrc.GetString()); 
457                                 if (read(tmp)) {
458                                         lexrc.printError("Error reading "
459                                                          "included file: "+tmp);
460                                 }
461                         }
462                         break;
463                 case RC_BINDFILE:                     // RVDK_PATCH_5
464                         if (lexrc.next()) {
465                                 string tmp(lexrc.GetString());
466                                 if (bind_file.empty()) {
467                                         // we only need the name of the first
468                                         // bind file since that (usually)
469                                         // includes several others.
470                                         bind_file = tmp;
471                                 }
472                                 ReadBindFile(tmp);
473                         }
474                         break;
475                         
476                 case RC_UIFILE: 
477                         if (lexrc.next()) {
478                                 ui_file = lexrc.GetString();
479                         }
480                         break;
481                         
482                 case RC_EXIT_CONFIRMATION:
483                         if (lexrc.next())
484                                 exit_confirmation = lexrc.GetBool();
485                         break;
486                         
487                 case RC_DISPLAY_SHORTCUTS:
488                         if (lexrc.next())
489                                 display_shortcuts = lexrc.GetBool();
490                         break;
491                         
492                 case RC_KBMAP:
493                         if (lexrc.next())
494                                 use_kbmap = lexrc.GetBool();
495                         break;
496                         
497                 case RC_KBMAP_PRIMARY:
498                         if (lexrc.next()) {
499                                 string kmap(lexrc.GetString());
500                                 if (kmap.empty()) {
501                                         // nothing
502                                 } else if (!LibFileSearch("kbd", kmap, 
503                                                           "kmap").empty()) 
504                                         primary_kbmap = kmap;
505                                 else 
506                                         lexrc.printError("LyX: Keymap `$$Token' not found");
507                         }
508                         break;
509                         
510                 case RC_KBMAP_SECONDARY:
511                         if (lexrc.next()) {
512                                 string kmap(lexrc.GetString());
513                                 if (kmap.empty()) {
514                                         // nothing
515                                 } else if (!LibFileSearch("kbd", kmap, 
516                                                           "kmap").empty()) 
517                                         secondary_kbmap = kmap;
518                                 else 
519                                         lexrc.printError("LyX: Keymap `$$Token' not found");
520                         }
521                         break;
522                         
523                 case RC_FONT_ENCODING:
524                         if (lexrc.next())
525                                 fontenc = lexrc.GetString();
526                         break;
527                         
528                 case RC_PRINTER:
529                         if (lexrc.next())
530                                 printer = lexrc.GetString();
531                         break;
532                         
533                 case RC_PRINT_COMMAND:
534                         if (lexrc.next())
535                                 print_command = lexrc.GetString();
536                         break;
537                         
538                 case RC_PRINTEVENPAGEFLAG:
539                         if (lexrc.next())
540                                 print_evenpage_flag = lexrc.GetString();
541                         break;
542                         
543                 case RC_PRINTODDPAGEFLAG:
544                         if (lexrc.next())
545                                 print_oddpage_flag = lexrc.GetString();
546                         break;
547                         
548                 case RC_PRINTPAGERANGEFLAG:
549                         if (lexrc.next())
550                                 print_pagerange_flag = lexrc.GetString();
551                         break;
552                         
553                 case RC_PRINTCOPIESFLAG:
554                         if (lexrc.next())
555                                 print_copies_flag = lexrc.GetString();
556                         break;
557                         
558                 case RC_PRINTCOLLCOPIESFLAG:
559                         if (lexrc.next())
560                                 print_collcopies_flag = lexrc.GetString();
561                         break;
562                         
563                 case RC_PRINTREVERSEFLAG:
564                         if (lexrc.next())
565                                 print_reverse_flag = lexrc.GetString();
566                         break;
567                         
568                 case RC_PRINTLANDSCAPEFLAG:
569                         if (lexrc.next())
570                                 print_landscape_flag = lexrc.GetString();
571                         break;
572                         
573                 case RC_PRINTTOPRINTER:
574                         if (lexrc.next())
575                                 print_to_printer = lexrc.GetString();
576                         break;
577                         
578                 case RC_PRINT_ADAPTOUTPUT:
579                         if (lexrc.next())
580                                 print_adapt_output = lexrc.GetBool();
581                         break;
582                         
583                 case RC_PRINTTOFILE:
584                         if (lexrc.next())
585                                 print_to_file = lexrc.GetString();
586                         break;
587                         
588                 case RC_PRINTFILEEXTENSION:
589                         if (lexrc.next())
590                                 print_file_extension = lexrc.GetString();
591                         break;
592                         
593                 case RC_PRINTEXSTRAOPTIONS:
594                         if (lexrc.next())
595                                 print_extra_options = lexrc.GetString();
596                         break;
597                         
598                 case RC_PRINTSPOOL_COMMAND:
599                         if (lexrc.next())
600                                 print_spool_command = lexrc.GetString();
601                         break;
602                         
603                 case RC_PRINTSPOOL_PRINTERPREFIX:
604                         if (lexrc.next())
605                                 print_spool_printerprefix = lexrc.GetString();
606                         break;
607                         
608                 case RC_PRINTPAPERDIMENSIONFLAG:
609                         if (lexrc.next())
610                                 print_paper_dimension_flag = lexrc.GetString();
611                         break;
612                         
613                 case RC_PRINTPAPERFLAG:
614                         if (lexrc.next())
615                                 print_paper_flag = lexrc.GetString();
616                         break;
617                         
618                 case RC_CUSTOM_EXPORT_COMMAND:
619                         if (lexrc.next())
620                                 custom_export_command = lexrc.GetString();
621                         break;
622                         
623                 case RC_CUSTOM_EXPORT_FORMAT:
624                         if (lexrc.next())
625                                 custom_export_format = lexrc.GetString();
626                         break;
627
628                 case RC_PDF_MODE:
629                         if (lexrc.next())
630                                 pdf_mode = lexrc.GetBool();
631                         break;
632                         
633                 case RC_LATEX_COMMAND:
634                         if (lexrc.next())
635                                 latex_command = lexrc.GetString();
636                         break;
637
638                 case RC_PDFLATEX_COMMAND:
639                         if (lexrc.next())
640                                 pdflatex_command = lexrc.GetString();
641                         break;
642
643                 case RC_PDF_TO_PS_COMMAND:
644                         if (lexrc.next())
645                                 pdf_to_ps_command = lexrc.GetString();
646                         break;
647
648                 case RC_DVI_TO_PS_COMMAND:
649                         if (lexrc.next())
650                                 dvi_to_ps_command = lexrc.GetString();
651                         break;
652                         
653                 case RC_LITERATE_COMMAND:
654                         if (lexrc.next())
655                                 literate_command = lexrc.GetString();
656                         break;
657                         
658                 case RC_LITERATE_EXTENSION:
659                         if (lexrc.next())
660                                 literate_extension = lexrc.GetString();
661                         break;
662                         
663                 case RC_LITERATE_ERROR_FILTER:
664                         if (lexrc.next())
665                                 literate_error_filter = lexrc.GetString();
666                         break;
667                         
668                 case RC_BUILD_COMMAND:
669                         if (lexrc.next())
670                                 build_command = lexrc.GetString();
671                         break;
672                         
673                 case RC_BUILD_ERROR_FILTER:
674                         if (lexrc.next())
675                                 build_error_filter = lexrc.GetString();
676                         break;
677                         
678                 case RC_RELYX_COMMAND:
679                         if (lexrc.next())
680                                 relyx_command = lexrc.GetString();
681                         break;
682                         
683                 case RC_DEFAULT_PAPERSIZE:
684                         if (lexrc.next()) {
685                                 string size = lowercase(lexrc.GetString());
686                                 if (size == "usletter")
687                                         default_papersize =
688                                                 BufferParams::PAPER_USLETTER;
689                                 else if (size == "legal")
690                                         default_papersize =
691                                                 BufferParams::PAPER_LEGALPAPER;
692                                 else if (size == "executive")
693                                         default_papersize =
694                                                 BufferParams::PAPER_EXECUTIVEPAPER;
695                                 else if (size == "a3")
696                                         default_papersize =
697                                                 BufferParams::PAPER_A3PAPER;
698                                 else if (size == "a4")
699                                         default_papersize =
700                                                 BufferParams::PAPER_A4PAPER;
701                                 else if (size == "a5")
702                                         default_papersize =
703                                                 BufferParams::PAPER_A5PAPER;
704                                 else if (size == "b5")
705                                         default_papersize =
706                                                 BufferParams::PAPER_B5PAPER;
707                         }
708                         break;
709                 case RC_VIEWDVI_COMMAND:
710                         if (lexrc.next())
711                                 view_dvi_command = lexrc.GetString();
712                         break;
713
714                 case RC_VIEWDVI_PAPEROPTION:
715                         if (lexrc.next())
716                                 view_dvi_paper_option = lexrc.GetString();
717                         else 
718                                 view_dvi_paper_option = "";
719                         break;
720
721                 case RC_VIEWPDF_COMMAND:
722                         if (lexrc.next())
723                                 view_pdf_command = lexrc.GetString();
724                         break;
725                         
726                 case RC_PS_COMMAND:
727                         if (lexrc.next())
728                                 ps_command = lexrc.GetString();
729                         break;
730                         
731                 case RC_VIEWPS_COMMAND:
732                         if (lexrc.next())
733                                 view_ps_command = lexrc.GetString();
734                         break;
735                         
736                 case RC_VIEWPSPIC_COMMAND:
737                         if (lexrc.next())
738                                 view_pspic_command = lexrc.GetString();
739                         break;
740                         
741                 case RC_CHKTEX_COMMAND:
742                         if (lexrc.next())
743                                 chktex_command = lexrc.GetString();
744                         break;
745                         
746                 case RC_HTML_COMMAND:
747                         if (lexrc.next())
748                                 html_command = lexrc.GetString();
749                         break;
750                         
751                 case RC_SCREEN_DPI:
752                         if (lexrc.next())
753                                 dpi = lexrc.GetInteger();
754                         break;
755                         
756                 case RC_SCREEN_ZOOM:
757                         if (lexrc.next())
758                                 zoom = lexrc.GetInteger();
759                         break;
760
761                 case RC_WHEEL_JUMP:
762                         if (lexrc.next())
763                                 wheel_jump = lexrc.GetInteger();
764                         break;
765                         
766                 case RC_SCREEN_FONT_SIZES:
767                         if (lexrc.next())
768                                 font_sizes[LyXFont::SIZE_TINY] =
769                                         lexrc.GetFloat();
770                         if (lexrc.next())
771                                 font_sizes[LyXFont::SIZE_SCRIPT] =
772                                         lexrc.GetFloat();
773                         if (lexrc.next())
774                                 font_sizes[LyXFont::SIZE_FOOTNOTE] =
775                                         lexrc.GetFloat();
776                         if (lexrc.next())
777                                 font_sizes[LyXFont::SIZE_SMALL] =
778                                         lexrc.GetFloat();
779                         if (lexrc.next())
780                                 font_sizes[LyXFont::SIZE_NORMAL] =
781                                         lexrc.GetFloat();
782                         if (lexrc.next())
783                                 font_sizes[LyXFont::SIZE_LARGE] =
784                                         lexrc.GetFloat();
785                         if (lexrc.next())
786                                 font_sizes[LyXFont::SIZE_LARGER] =
787                                         lexrc.GetFloat();
788                         if (lexrc.next())
789                                 font_sizes[LyXFont::SIZE_LARGEST] =
790                                         lexrc.GetFloat();
791                         if (lexrc.next())
792                                 font_sizes[LyXFont::SIZE_HUGE] =
793                                         lexrc.GetFloat();
794                         if (lexrc.next())
795                                 font_sizes[LyXFont::SIZE_HUGER] =
796                                         lexrc.GetFloat();
797                         break;
798                         
799                 case RC_SCREEN_FONT_SCALABLE:
800                         if (lexrc.next())
801                                 use_scalable_fonts = lexrc.GetBool();
802                         break;
803                         
804                 case RC_AUTOSAVE:
805                         if (lexrc.next())
806                                 autosave = lexrc.GetInteger();
807                         break;
808                         
809                 case RC_DOCUMENTPATH:
810                         if (lexrc.next()) {
811                                 document_path = ExpandPath(lexrc.GetString());
812                         }
813                         break;
814                         
815                 case RC_TEMPLATEPATH:
816                         if (lexrc.next())
817                                 template_path = ExpandPath(lexrc.GetString());
818                         break;
819                         
820                 case RC_TEMPDIRPATH:
821                         if (lexrc.next())
822                                 tempdir_path = ExpandPath(lexrc.GetString());
823                         break;
824                         
825                 case RC_USETEMPDIR:
826                         if (lexrc.next())
827                                 use_tempdir = lexrc.GetBool();
828                         break;
829                         
830                 case RC_LASTFILES:
831                         if (lexrc.next())
832                                 lastfiles = ExpandPath(lexrc.GetString());
833                         break;
834                         
835                 case RC_NUMLASTFILES:
836                         if (lexrc.next())
837                                 num_lastfiles = lexrc.GetInteger();
838                         break;
839                         
840                 case RC_CHECKLASTFILES:
841                         if (lexrc.next())
842                                 check_lastfiles = lexrc.GetBool();
843                         break;
844                         
845                 case RC_SCREEN_FONT_ROMAN:
846                         if (lexrc.next())
847                                 roman_font_name = lexrc.GetString();
848                         break;
849                         
850                 case RC_SCREEN_FONT_SANS:
851                         if (lexrc.next())
852                                 sans_font_name = lexrc.GetString();
853                         break;
854                         
855                 case RC_SCREEN_FONT_TYPEWRITER:
856                         if (lexrc.next())
857                                 typewriter_font_name = lexrc.GetString();
858                         break;
859                         
860                 case RC_SCREEN_FONT_MENU:
861                         if (lexrc.next())
862                                 menu_font_name = lexrc.GetString();
863                         break;
864                         
865                 case RC_SCREEN_FONT_POPUP:
866                         if (lexrc.next())
867                                 popup_font_name = lexrc.GetString();
868                         break;
869                         
870                 case RC_SCREEN_FONT_ENCODING:
871                         if (lexrc.next()) {
872                                 font_norm = lexrc.GetString();
873                                 set_font_norm_type();
874                         }
875                         break;
876
877                 case RC_SCREEN_FONT_ENCODING_MENU:
878                         if (lexrc.next())
879                                 font_norm_menu = lexrc.GetString();
880                         break;
881
882                 case RC_SET_COLOR:
883                 {
884                         string lyx_name, x11_name;
885
886                         if (lexrc.next())  {
887                                 lyx_name = lexrc.GetString();
888                         } else {
889                                 lexrc.printError("Missing color tag.");
890                                 break;
891                         }
892                         
893                         if (lexrc.next()) {
894                                 x11_name = lexrc.GetString();
895                         } else {
896                                 lexrc.printError("Missing color name for color : `$$Token'");
897                                 break;
898                         }
899
900                         if (!lcolor.setColor(lyx_name, x11_name))
901                                 lyxerr << "Bad lyxrc set_color for "
902                                         << lyx_name << endl;
903
904                         break;
905                 }
906                 case RC_AUTOREGIONDELETE:
907                         // Auto region delete defaults to true
908                         if (lexrc.next())
909                                 auto_region_delete = lexrc.GetBool();
910                         break;
911                         
912                 case RC_BIND:
913                 {
914                         // we should not do an explicit binding before
915                         // loading a bind file. So, in this case, load
916                         // the default bind file.
917                         if (!hasBindFile) {
918                                 ReadBindFile();
919                                 bind_file = bindFile;
920                         }
921                         // !!!chb, dynamic key binding...
922                         int action, res = 0;
923                         string seq, cmd;
924                         
925                         if (lexrc.lex() == LyXLex::LEX_DATA)  {
926                                 seq = lexrc.GetString();
927                         } else {
928                                 lexrc.printError("Bad key sequence: `$$Token'");
929                                 break;
930                         }
931                         
932                         if (lexrc.lex() == LyXLex::LEX_DATA) {
933                                 cmd = lexrc.GetString();
934                         } else {
935                                 lexrc.printError("Bad command: `$$Token'");
936                                 break;
937                         }
938                         
939                         if ((action = lyxaction.LookupFunc(cmd))>= 0) {
940                                 if (lyxerr.debugging(Debug::KBMAP)) {
941                                         lyxerr << "RC_BIND: Sequence `"
942                                                << seq << "' Command `"
943                                                << cmd << "' Action `"
944                                                << action << '\'' << endl;
945                                 }
946                                 res = toplevel_keymap->bind(seq, action);
947                                 if (res != 0) {
948                                         lexrc.printError(
949                                                 "Invalid key sequence `"
950                                                 + seq + '\''); 
951                                 }
952                         } else {// cmd is the last token read.
953                                 lexrc.printError(
954                                         "Unknown LyX function `$$Token'");
955                         }
956                         break;
957                 }
958                 case RC_OVERRIDE_X_DEADKEYS:
959                         if (lexrc.next())
960                                 override_x_deadkeys = lexrc.GetBool();
961                         break;
962
963                 case RC_SERVERPIPE:
964                         if (lexrc.next())
965                                 lyxpipes = ExpandPath(lexrc.GetString());
966                         break;
967                         
968                 case RC_CURSOR_FOLLOWS_SCROLLBAR:
969                         if (lexrc.next())
970                                 cursor_follows_scrollbar = lexrc.GetBool();
971                         break;
972
973                 case RC_FAX_COMMAND:
974                         if (lexrc.next())
975                                 fax_command = lexrc.GetString();
976                         break;
977                 case RC_FAXPROGRAM:
978                         if (lexrc.next())
979                                 fax_program = lexrc.GetString();
980                         break;
981                 case RC_PHONEBOOK:
982                         if (lexrc.next()) {
983                                 string s = lexrc.GetString();
984                                 if (AbsolutePath(s))
985                                         phone_book = s;
986                                 else
987                                         phone_book = user_lyxdir + s;
988                         }
989                         break;
990                 case RC_ASCIIROFF_COMMAND:
991                         if (lexrc.next())
992                                 ascii_roff_command = lexrc.GetString();
993                         break;
994                 case RC_ASCII_LINELEN:
995                         if (lexrc.next())
996                                 ascii_linelen = lexrc.GetInteger();
997                         break;
998                         // Spellchecker settings:
999                 case RC_SPELL_COMMAND:
1000                         if (lexrc.next())
1001                                 isp_command = lexrc.GetString();
1002                         break;
1003                 case RC_ACCEPT_COMPOUND:
1004                         if (lexrc.next())
1005                                 isp_accept_compound = lexrc.GetBool();
1006                         break;
1007                 case RC_USE_INP_ENC:
1008                         if (lexrc.next())
1009                                 isp_use_input_encoding = lexrc.GetBool();
1010                         break;
1011                 case RC_USE_ALT_LANG:
1012                         if (lexrc.next())
1013                                 isp_use_alt_lang = lexrc.GetBool();
1014                         break;
1015                 case RC_USE_PERS_DICT:
1016                         if (lexrc.next())
1017                                 isp_use_pers_dict = lexrc.GetBool();
1018                         break;
1019                 case RC_USE_ESC_CHARS:
1020                         if (lexrc.next())
1021                                 isp_use_esc_chars = lexrc.GetBool();
1022                         break;
1023                 case RC_ALT_LANG:
1024                         if (lexrc.next())
1025                                 isp_alt_lang = lexrc.GetString();
1026                         break;
1027                 case RC_PERS_DICT:
1028                         if (lexrc.next())
1029                                 isp_pers_dict = lexrc.GetString();
1030                         break;
1031                 case RC_ESC_CHARS:
1032                         if (lexrc.next())
1033                                 isp_esc_chars = lexrc.GetString();
1034                         break;
1035                 case RC_MAKE_BACKUP:
1036                         if (lexrc.next())
1037                                 make_backup = lexrc.GetBool();
1038                         break;
1039                 case RC_BACKUPDIR_PATH:
1040                         if (lexrc.next())
1041                                 backupdir_path = ExpandPath(lexrc.GetString());
1042                         break;
1043                 case RC_DATE_INSERT_FORMAT:
1044                         if (lexrc.next())
1045                                 date_insert_format = lexrc.GetString();
1046                         break;
1047                 case RC_LANGUAGE_PACKAGE:
1048                         if (lexrc.next())
1049                                 language_package = lexrc.GetString();
1050                         break;
1051                 case RC_LANGUAGE_AUTO_BEGIN:
1052                         if (lexrc.next())
1053                                 language_auto_begin = lexrc.GetBool();
1054                         break;
1055                 case RC_LANGUAGE_AUTO_END:
1056                         if (lexrc.next())
1057                                 language_auto_end = lexrc.GetBool();
1058                         break;
1059                 case RC_LANGUAGE_COMMAND_BEGIN:
1060                         if (lexrc.next())
1061                                 language_command_begin = lexrc.GetString();
1062                         break;
1063                 case RC_LANGUAGE_COMMAND_END:
1064                         if (lexrc.next())
1065                                 language_command_end = lexrc.GetString();
1066                         break;
1067                 case RC_RTL_SUPPORT:
1068                         if (lexrc.next())
1069                                 rtl_support = lexrc.GetBool();
1070                         break;
1071                 case RC_AUTO_NUMBER:
1072                         if (lexrc.next())
1073                                 auto_number = lexrc.GetBool();
1074                         break;
1075                 case RC_MARK_FOREIGN_LANGUAGE:
1076                         if (lexrc.next())
1077                                 mark_foreign_language = lexrc.GetBool();
1078                         break;
1079                 case RC_SHOW_BANNER:
1080                         if (lexrc.next())
1081                                 show_banner = lexrc.GetBool();
1082                         break;
1083                 case RC_USE_GUI:
1084                         if (lexrc.next())
1085                                 use_gui = lexrc.GetBool();
1086                         break;
1087                 case RC_LINUXDOC_TO_LYX_COMMAND:
1088                         if ( lexrc.next())
1089                                 linuxdoc_to_lyx_command = lexrc.GetString();
1090                         break;
1091                 case RC_LINUXDOC_TO_HTML_COMMAND:
1092                         if ( lexrc.next())
1093                                 linuxdoc_to_html_command = lexrc.GetString();
1094                         break;
1095                 case RC_LINUXDOC_TO_LATEX_COMMAND:
1096                         if ( lexrc.next())
1097                                 linuxdoc_to_latex_command = lexrc.GetString();
1098                         break;
1099                 case RC_DOCBOOK_TO_DVI_COMMAND:
1100                         if ( lexrc.next())
1101                                 docbook_to_dvi_command = lexrc.GetString();
1102                         break;
1103                 case RC_DOCBOOK_TO_HTML_COMMAND:
1104                         if ( lexrc.next())
1105                                 docbook_to_html_command = lexrc.GetString();
1106                         break;
1107                 case RC_DOCBOOK_TO_PDF_COMMAND:
1108                         if ( lexrc.next())
1109                                 docbook_to_pdf_command = lexrc.GetString();
1110                         break;
1111                         
1112                 case RC_NEW_ASK_FILENAME:
1113                         if ( lexrc.next())
1114                                 new_ask_filename = lexrc.GetBool();
1115                         break;
1116                 case RC_CONVERTER:
1117                 {
1118                         string from, to, command, flags;
1119                         if (lexrc.next())
1120                                 from = lexrc.GetString();
1121                         if (lexrc.next())
1122                                 to = lexrc.GetString();
1123                         if (lexrc.next())
1124                                 command = lexrc.GetString();
1125                         if (lexrc.next())
1126                                 flags = lexrc.GetString();
1127                         Converter::Add(from, to, command, flags);
1128                         break;
1129                 }
1130                 case RC_VIEWER:
1131                 {
1132                         string format, command;
1133                         if (lexrc.next())
1134                                 format = lexrc.GetString();
1135                         if (lexrc.next())
1136                                 command = lexrc.GetString();
1137                         Formats::SetViewer(format, command);
1138                         break;
1139                 }
1140                 case RC_DEFAULT_LANGUAGE:
1141                         if ( lexrc.next())
1142                                 default_language = lexrc.GetString();
1143                         break;
1144
1145                 case RC_LAST: break; // this is just a dummy
1146                 }
1147         }
1148
1149         return 0;
1150 }
1151
1152
1153 void LyXRC::write(string const & filename) const
1154 {
1155         ofstream ofs(filename.c_str());
1156         if (ofs)
1157                 output(ofs);
1158 }
1159
1160
1161 void LyXRC::print() const
1162 {
1163         if (lyxerr.debugging())
1164                 output(lyxerr);
1165         else
1166                 output(cout);
1167 }
1168
1169
1170 void LyXRC::output(ostream & os) const
1171 {
1172         os << "### This file is part of\n"
1173            << "### ========================================================\n"
1174            << "###          LyX, The Document Processor\n"
1175            << "###\n"
1176            << "###          Copyright 1995 Matthias Ettrich\n"
1177            << "###          Copyright 1995-2000 The LyX Team.\n"
1178            << "###\n"
1179            << "### ========================================================\n"
1180            << "\n"
1181            << "# This file is written by LyX, if you want to make your own\n"
1182            << "# modifications you should do them from inside LyX and save\n"
1183            << "\n";
1184         
1185         // Why the switch you might ask. It is a trick to ensure that all
1186         // the elements in the LyXRCTags enum is handled. As you can see
1187         // there are no breaks at all. So it is just a huge fall-through.
1188         // The nice thing is that we will get a warning from the compiler
1189         // if we forget an element.
1190         LyXRCTags tag = RC_LAST;
1191         switch(tag) {
1192         case RC_LAST:
1193         case RC_INPUT:
1194                 // input/include files are not done here
1195         case RC_BIND:
1196                 // bindings is not written to the preferences file.
1197         case RC_BINDFILE:
1198                 os << "\\bind_file " << bind_file << "\n";
1199
1200                 //
1201                 // Misc Section
1202                 //
1203                 os << "\n#\n"
1204                    << "# MISC SECTION ######################################\n"
1205                    << "#\n\n";
1206                 
1207         case RC_SHOW_BANNER:
1208                 os << "# Set to false to inhibit the startup banner.\n"
1209                    << "\\show_banner " << tostr(show_banner) << "\n";
1210
1211                 // bind files are not done here.
1212         case RC_UIFILE:
1213                 os << "\\ui_file \"" << ui_file << "\"\n";
1214         case RC_AUTOREGIONDELETE:
1215                 os << "# Set to false to inhibit automatic replacement of\n"
1216                    << "# the current selection.\n"
1217                    << "\\auto_region_delete " << tostr(auto_region_delete)
1218                    << "\n";
1219         case RC_AUTOSAVE:
1220                 os << "# The time interval between auto-saves in seconds.\n"
1221                    << "\\autosave " << autosave << "\n";
1222         case RC_EXIT_CONFIRMATION:
1223                 os << "# Ask for confirmation before exit if there are\n"
1224                    << "# unsaved changed documents.\n"
1225                    << "\\exit_confirmation " << tostr(exit_confirmation)
1226                    << "\n";
1227         case RC_DISPLAY_SHORTCUTS:
1228                 os << "# Display name of the last command executed, with a\n"
1229                    << "# list of short-cuts in the minibuffer.\n" 
1230                    << "\\display_shortcuts " << tostr(display_shortcuts)
1231                    << "\n";
1232         case RC_VIEWDVI_COMMAND:
1233                 os << "# Program used to view dvi files.\n"
1234                    << "\\view_dvi_command \"" << view_dvi_command << "\"\n";
1235         case RC_VIEWDVI_PAPEROPTION:
1236                 os << "# Options used to specify paper size to the\n"
1237                    << "# view_dvi_command\n"
1238                    << "\\view_dvi_paper_option \""
1239                    << view_dvi_paper_option << "\"\n";
1240         case RC_DEFAULT_PAPERSIZE:
1241                 os << "# The default papersize to use.\n"
1242                    << "\\default_papersize \"";
1243                 switch (default_papersize) {
1244                 case BufferParams::PAPER_USLETTER:
1245                         os << "usletter"; break;
1246                 case BufferParams::PAPER_LEGALPAPER:
1247                         os << "legal"; break;
1248                 case BufferParams::PAPER_EXECUTIVEPAPER:
1249                         os << "executive"; break;
1250                 case BufferParams::PAPER_A3PAPER:
1251                         os << "a3"; break;
1252                 case BufferParams::PAPER_A4PAPER:
1253                         os << "a4"; break;
1254                 case BufferParams::PAPER_A5PAPER:
1255                         os << "a5"; break;
1256                 case BufferParams::PAPER_B5PAPER:
1257                         os << "b5"; break;
1258                 case BufferParams::PAPER_DEFAULT: break;
1259                 }
1260                 os << "\"\n";
1261         case RC_VIEWPDF_COMMAND:
1262                 os << "# Command used to view PDF files.\n"
1263                    << "\\view_pdf_command \"" << view_pdf_command << "\"\n";
1264         case RC_VIEWPS_COMMAND:
1265                 os << "# Command used to view PostScript files.\n"
1266                    << "\\view_ps_command \"" << view_ps_command << "\"\n";
1267         case RC_VIEWPSPIC_COMMAND:
1268                 os << "# Command used to view full screen included PS\n"
1269                    << "# pictures.\n"
1270                    << "\\view_pspic_command \"" << view_pspic_command
1271                    << "\"\n";
1272         case RC_PS_COMMAND:
1273                 os << "# Program used for interpreting postscript.\n"
1274                    << "\\ps_command \"" << ps_command << "\"\n";
1275         case RC_CHKTEX_COMMAND:
1276                 os << "\\chktex_command \"" << chktex_command << "\"\n";
1277         case RC_HTML_COMMAND:
1278                 os << "\\html_command \"" << html_command << "\"\n";
1279         case RC_KBMAP:
1280                 os << "\\kbmap " << tostr(use_kbmap) << "\n";
1281         case RC_KBMAP_PRIMARY:
1282                 os << "\\kbmap_primary \"" << primary_kbmap << "\"\n";
1283         case RC_KBMAP_SECONDARY:
1284                 os << "\\kbmap_secondary \"" << secondary_kbmap << "\"\n";
1285         case RC_SERVERPIPE:
1286                 os << "\\serverpipe \"" << lyxpipes << "\"\n";
1287         case RC_RELYX_COMMAND:
1288                 os << "\\relyx_command \"" << relyx_command << "\"\n";
1289         case RC_DATE_INSERT_FORMAT:
1290                 os << "\\date_insert_format \"" << date_insert_format
1291                    << "\"\n";
1292
1293                 
1294                 os << "\n#\n"
1295                    << "# SCREEN & FONTS SECTION ############################\n"
1296                    << "#\n\n";
1297                 
1298         case RC_SCREEN_DPI:
1299                 os << "\\screen_dpi " << dpi << "\n";
1300         case RC_SCREEN_ZOOM:
1301                 os << "\\screen_zoom " << zoom << "\n";
1302         case RC_WHEEL_JUMP:
1303                 os << "\\wheel_jump " << wheel_jump << "\n";
1304         case RC_CURSOR_FOLLOWS_SCROLLBAR:
1305                 os << "\\cursor_follows_scrollbar "
1306                    << tostr(cursor_follows_scrollbar) << "\n";
1307         case RC_SCREEN_FONT_ROMAN:
1308                 os << "\\screen_font_roman \"" << roman_font_name << "\"\n";
1309         case RC_SCREEN_FONT_SANS:
1310                 os << "\\screen_font_sans \"" << sans_font_name << "\"\n";
1311         case RC_SCREEN_FONT_TYPEWRITER:
1312                 os << "\\screen_font_typewriter \""
1313                    << typewriter_font_name << "\"\n";
1314         case RC_SCREEN_FONT_SCALABLE:
1315                 os << "\\screen_font_scalable " << tostr(use_scalable_fonts)
1316                    << "\n";
1317         case RC_SCREEN_FONT_ENCODING:
1318                 os << "\\screen_font_encoding \"" << font_norm << "\"\n";
1319         case RC_SCREEN_FONT_POPUP:
1320                 os << "\\screen_font_popup \"" << popup_font_name << "\"\n";
1321         case RC_SCREEN_FONT_MENU:
1322                 os << "\\screen_font_menu \"" << menu_font_name << "\"\n";
1323         case RC_SCREEN_FONT_SIZES:
1324                 os.setf(ios::fixed);
1325                 os.precision(2);
1326                 os << "\\screen_font_sizes";
1327                 os << " " << font_sizes[LyXFont::SIZE_TINY];
1328                 os << " " << font_sizes[LyXFont::SIZE_SCRIPT];
1329                 os << " " << font_sizes[LyXFont::SIZE_FOOTNOTE];
1330                 os << " " << font_sizes[LyXFont::SIZE_SMALL];
1331                 os << " " << font_sizes[LyXFont::SIZE_NORMAL];
1332                 os << " " << font_sizes[LyXFont::SIZE_LARGE];
1333                 os << " " << font_sizes[LyXFont::SIZE_LARGER];
1334                 os << " " << font_sizes[LyXFont::SIZE_LARGEST];
1335                 os << " " << font_sizes[LyXFont::SIZE_HUGE];
1336                 os << " " << font_sizes[LyXFont::SIZE_HUGER];
1337                 os << "\n";
1338         //case RC_SET_COLOR:
1339                 // color bindings not written to preference file.
1340                 // And we want to be warned about that. (Lgb)
1341                 
1342                 os << "\n#\n"
1343                    << "# PRINTER SECTION ###################################\n"
1344                    << "#\n\n";
1345                 
1346         case RC_PRINTER:
1347                 os << "\\printer \"" << printer << "\"\n";
1348         case RC_PRINT_ADAPTOUTPUT:
1349                 os << "\\print_adapt_output " << tostr(print_adapt_output)
1350                    << "\n";
1351         case RC_PRINT_COMMAND:
1352                 os << "\\print_command \"" << print_command << "\"\n";
1353         case RC_PRINTEXSTRAOPTIONS:
1354                 os << "\\print_extra_options \"" << print_extra_options
1355                    << "\"\n";
1356         case RC_PRINTSPOOL_COMMAND:
1357                 os << "\\print_spool_command \"" << print_spool_command
1358                    << "\"\n";
1359         case RC_PRINTSPOOL_PRINTERPREFIX:
1360                 os << "\\print_spool_printerprefix \""
1361                    << print_spool_printerprefix << "\"\n";
1362         case RC_PRINTEVENPAGEFLAG:
1363                 os << "\\print_evenpage_flag \"" << print_evenpage_flag
1364                    << "\"\n";
1365         case RC_PRINTODDPAGEFLAG:
1366                 os << "\\print_oddpage_flag \"" << print_oddpage_flag
1367                    << "\"\n";
1368         case RC_PRINTREVERSEFLAG:
1369                 os << "\\print_reverse_flag \"" << print_reverse_flag
1370                    << "\"\n";
1371         case RC_PRINTLANDSCAPEFLAG:
1372                 os << "\\print_landscape_flag \"" << print_landscape_flag
1373                    << "\"\n";
1374         case RC_PRINTPAGERANGEFLAG:
1375                 os << "\\print_pagerange_flag \"" << print_pagerange_flag
1376                    << "\"\n";
1377         case RC_PRINTCOPIESFLAG:
1378                 os << "\\print_copies_flag \"" << print_copies_flag << "\"\n";
1379         case RC_PRINTCOLLCOPIESFLAG:
1380                 os << "\\print_collcopies_flag \"" << print_collcopies_flag
1381                    << "\"\n";
1382         case RC_PRINTPAPERFLAG:
1383                 os << "\\print_paper_flag \"" << print_paper_flag << "\"\n";
1384         case RC_PRINTPAPERDIMENSIONFLAG:
1385                 os << "\\print_paper_dimension_flag \""
1386                    << print_paper_dimension_flag << "\"\n";
1387         case RC_PRINTTOPRINTER:
1388                 os << "\\print_to_printer \"" << print_to_printer << "\"\n";
1389         case RC_PRINTTOFILE:
1390                 os << "\\print_to_file \"" << print_to_file << "\"\n";
1391         case RC_PRINTFILEEXTENSION:
1392                 os << "\\print_file_extension \"" << print_file_extension
1393                    << "\"\n";
1394
1395                 os << "\n#\n"
1396                    << "# EXPORT SECTION ####################################\n"
1397                    << "#\n\n";
1398                 
1399         case RC_CUSTOM_EXPORT_COMMAND:
1400                 os << "\\custom_export_command \"" << custom_export_command
1401                    << "\"\n";
1402         case RC_CUSTOM_EXPORT_FORMAT:
1403                 os << "\\custom_export_format \"" << custom_export_format
1404                    << "\"\n";
1405
1406                 os << "\n#\n"
1407                    << "# TEX SECTION #######################################\n"
1408                    << "#\n\n";
1409                 
1410         case RC_LATEX_COMMAND:
1411                 os << "\\latex_command \"" << latex_command << "\"\n";
1412         case RC_PDFLATEX_COMMAND:
1413                 os << "\\pdflatex_command \"" << pdflatex_command << "\"\n";
1414         case RC_PDF_MODE:
1415                 os << "\\pdf_mode " << tostr(pdf_mode) << "\n";
1416         case RC_FONT_ENCODING:
1417                 os << "\\font_encoding \"" << fontenc << "\"\n";
1418
1419                 os << "\n#\n"
1420                    << "# LINUXDOC SECTION ##################################\n"
1421                    << "#\n\n";
1422
1423         case RC_LINUXDOC_TO_LATEX_COMMAND:
1424                 os << "\\linuxdoc_to_latex_command \"" << linuxdoc_to_latex_command
1425                    << "\"\n";
1426         case RC_LINUXDOC_TO_HTML_COMMAND:
1427                 os << "\\linuxdoc_to_html_command \"" << linuxdoc_to_html_command
1428                    << "\"\n";
1429         case RC_LINUXDOC_TO_LYX_COMMAND:
1430                 os << "\\linuxdoc_to_lyx_command \"" << linuxdoc_to_lyx_command
1431                    << "\"\n";
1432                 
1433                 os << "\n#\n"
1434                    << "# DOCBOOK SECTION ###################################\n"
1435                    << "#\n\n";
1436
1437         case RC_DOCBOOK_TO_DVI_COMMAND:
1438                 os << "\\docbook_to_dvi_command \"" << docbook_to_dvi_command
1439                    << "\"\n";
1440         case RC_DOCBOOK_TO_HTML_COMMAND:
1441                 os << "\\docbook_to_html_command \"" << docbook_to_html_command
1442                    << "\"\n";
1443         case RC_DOCBOOK_TO_PDF_COMMAND:
1444                 os << "\\docbook_to_pdf_command \"" << docbook_to_pdf_command
1445                    << "\"\n";
1446
1447                 os << "\n#\n"
1448                    << "# FILE SECTION ######################################\n"
1449                    << "#\n\n";
1450
1451         case RC_DOCUMENTPATH:
1452                 os << "\\document_path \"" << document_path << "\"\n";
1453         case RC_LASTFILES:
1454                 os << "\\lastfiles \"" << lastfiles << "\"\n";
1455         case RC_NUMLASTFILES:
1456                 os << "\\num_lastfiles " << num_lastfiles << "\n";
1457         case RC_CHECKLASTFILES:
1458                 os << "\\check_lastfiles " << tostr(check_lastfiles) << "\n";
1459         case RC_TEMPLATEPATH:
1460                 os << "\\template_path \"" << template_path << "\"\n";
1461         case RC_TEMPDIRPATH:
1462                 os << "\\tempdir_path \"" << tempdir_path << "\"\n";
1463         case RC_USETEMPDIR:
1464                 os << "\\use_tempdir " << tostr(use_tempdir) << "\n";
1465         case RC_ASCII_LINELEN:
1466                 os << "\\ascii_linelen " << ascii_linelen << "\n";
1467         case RC_MAKE_BACKUP:
1468                 os << "\\make_backup " << tostr(make_backup) << "\n";
1469         case RC_BACKUPDIR_PATH:
1470                 os << "\\backupdir_path \"" << backupdir_path << "\"\n";
1471
1472                 os << "\n#\n"
1473                    << "# FAX SECTION #######################################\n"
1474                    << "#\n\n";
1475                 
1476         case RC_FAX_COMMAND:
1477                 os << "\\fax_command \"" << fax_command << "\"\n";
1478         case RC_PHONEBOOK:
1479                 os << "\\phone_book \"" << phone_book << "\"\n";
1480         case RC_FAXPROGRAM:
1481                 os << "\\fax_program \"" << fax_program << "\"\n";
1482
1483                 os << "\n#\n"
1484                    << "# ASCII EXPORT SECTION ##############################\n"
1485                    << "#\n\n";
1486
1487         case RC_ASCIIROFF_COMMAND:
1488                 os << "\\ascii_roff_command \"" << ascii_roff_command
1489                    << "\"\n";
1490
1491                 os << "\n#\n"
1492                    << "# SPELLCHECKER SECTION ##############################\n"
1493                    << "#\n\n";
1494
1495         case RC_SPELL_COMMAND:
1496                 os << "\\spell_command \"" << isp_command << "\"\n";
1497         case RC_ACCEPT_COMPOUND:
1498                 os << "\\accept_compound " << tostr(isp_accept_compound)
1499                    << "\n";
1500         case RC_USE_ALT_LANG:
1501                 os << "\\use_alt_language " << tostr(isp_use_alt_lang) << "\n";
1502         case RC_ALT_LANG:
1503                 os << "\\alternate_language \"" << isp_alt_lang << "\"\n";
1504         case RC_USE_ESC_CHARS:
1505                 os << "\\use_escape_chars " << tostr(isp_use_esc_chars)
1506                    << "\n";
1507         case RC_ESC_CHARS:
1508                 os << "\\escape_chars \"" << isp_esc_chars << "\"\n";
1509         case RC_USE_PERS_DICT:
1510                 os << "\\use_personal_dictionary " << tostr(isp_use_pers_dict)
1511                    << "\n";
1512         case RC_PERS_DICT:
1513                 os << "\\personal_dictionary \"" << isp_pers_dict << "\"\n";
1514         case RC_USE_INP_ENC:
1515                 os << "\\use_input_encoding " << tostr(isp_use_input_encoding)
1516                    << "\n";
1517
1518                 os << "\n#\n"
1519                    << "# LANGUAGE SUPPORT SECTION ##########################\n"
1520                    << "#\n\n";
1521
1522         case RC_RTL_SUPPORT:
1523                 os << "\\rtl " << tostr(rtl_support) << "\n";
1524         case RC_LANGUAGE_PACKAGE:
1525                 os << "\\language_package \"" << language_package << "\"\n";
1526         case RC_LANGUAGE_COMMAND_BEGIN:
1527                 os << "\\language_command_begin \"" << language_command_begin
1528                    << "\"\n";
1529         case RC_LANGUAGE_COMMAND_END:
1530                 os << "\\language_command_end \"" << language_command_end
1531                    << "\"\n";
1532         case RC_LANGUAGE_AUTO_BEGIN:
1533                 os << "\\language_auto_begin " 
1534                    << tostr(language_auto_begin) << "\n";
1535         case RC_LANGUAGE_AUTO_END:
1536                 os << "\\language_auto_end " 
1537                    << tostr(language_auto_end) << "\n";
1538         case RC_MARK_FOREIGN_LANGUAGE:
1539                 os << "\\mark_foreign_language " << 
1540                         tostr(mark_foreign_language) << "\n";
1541
1542                 os << "\n#\n"
1543                    << "# 2nd MISC SUPPORT SECTION ##########################\n"
1544                    << "#\n\n";
1545
1546         case RC_PDF_TO_PS_COMMAND:
1547                 os << "\\pdf_to_ps_command \"" << pdf_to_ps_command << "\"\n";
1548         case RC_DVI_TO_PS_COMMAND:
1549                 os << "\\dvi_to_ps_command \"" << dvi_to_ps_command << "\"\n";
1550         case RC_LITERATE_COMMAND:
1551                 os << "\\literate_command \"" << literate_command << "\"\n";
1552         case RC_LITERATE_EXTENSION:
1553                 os << "\\literate_extension \"" << literate_extension
1554                    << "\"\n";
1555         case RC_LITERATE_ERROR_FILTER:
1556                 os << "\\literate_error_filter \"" << literate_error_filter
1557                    << "\"\n";
1558         case RC_BUILD_COMMAND:
1559                 os << "\\build_command \"" << build_command << "\"\n";
1560         case RC_BUILD_ERROR_FILTER:
1561                 os << "\\build_error_filter \"" << build_error_filter
1562                    << "\"\n";
1563         case RC_OVERRIDE_X_DEADKEYS:
1564                 os << "\\override_x_deadkeys " 
1565                    << tostr(override_x_deadkeys) << "\n";
1566         case RC_SCREEN_FONT_ENCODING_MENU:
1567                 os << "\\screen_font_encoding_menu \"" << font_norm_menu
1568                    << "\"\n";
1569         case RC_AUTO_NUMBER:
1570                 os << "\\auto_number " << tostr(auto_number) << "\n";
1571         case RC_USE_GUI:
1572                 os << "\\use_gui " << tostr(use_gui) << "\n";
1573         case RC_NEW_ASK_FILENAME:
1574                 os << "\\new_ask_filename " << tostr(new_ask_filename) << "\n";
1575         case RC_DEFAULT_LANGUAGE:
1576                 os << "\\default_language " << default_language << "\n";
1577         }
1578         os.flush();
1579 }
1580
1581 void LyXRC::set_font_norm_type()
1582 {
1583         if (font_norm == "iso10646-1")
1584                 font_norm_type = ISO_10646_1;
1585         else if (font_norm == "iso8859-6.8x")
1586                 font_norm_type = ISO_8859_6_8;
1587         else
1588                 font_norm_type = OTHER_ENCODING;
1589 }
1590
1591 // The global instance
1592 LyXRC lyxrc;
1593
1594 // The global copy of the system lyxrc entries (everything except preferences)
1595 //LyXRC system_lyxrc;