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