]> git.lyx.org Git - lyx.git/blob - src/lyx_main.C
2eca5c1a3954fc6e4e5810a2fa301e291fac094b
[lyx.git] / src / lyx_main.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 #include <cstdlib>
14 #include <csignal>
15
16 #include "version.h"
17 #include "lyx_main.h"
18 #include "lyx_gui.h"
19 #include "LyXView.h"
20 #include "lyxfunc.h"
21 #include "lyx_gui_misc.h"
22 #include "lyxrc.h"
23 #include "support/path.h"
24 #include "support/filetools.h"
25 #include "bufferlist.h"
26 #include "debug.h"
27 #include "support/FileInfo.h"
28 #include "lastfiles.h"
29 #include "intl.h"
30 #include "lyxserver.h"
31 #include "layout.h"
32 #include "gettext.h"
33 #include "kbmap.h"
34
35 using std::endl;
36
37 extern void LoadLyXFile(string const &);
38
39 string system_lyxdir;
40 string build_lyxdir;
41 string system_tempdir;
42 string user_lyxdir;     // Default $HOME/.lyx
43
44 // Should this be kept global? Asger says Yes.
45 DebugStream lyxerr;
46
47 LastFiles * lastfiles;
48
49 // This is the global bufferlist object
50 BufferList bufferlist;
51
52 LyXServer * lyxserver = 0;
53 // this should be static, but I need it in buffer.C
54 bool finished = false;  // flag, that we are quitting the program
55
56 // convenient to have it here.
57 kb_keymap * toplevel_keymap;
58
59
60 LyX::LyX(int * argc, char * argv[])
61 {
62         // Prevent crash with --help
63         lyxGUI = 0;
64         lastfiles = 0;
65
66         // Here we need to parse the command line. At least
67         // we need to parse for "-dbg" and "-help"
68         bool gui = easyParse(argc, argv);
69
70         // Global bindings (this must be done as early as possible.) (Lgb)
71         toplevel_keymap = new kb_keymap;
72         defaultKeyBindings(toplevel_keymap);
73         
74         // Make the GUI object, and let it take care of the
75         // command line arguments that concerns it.
76         lyxerr[Debug::INIT] << "Initializing LyXGUI..." << endl;
77         lyxGUI = new LyXGUI(this, argc, argv, gui);
78         lyxerr[Debug::INIT] << "Initializing LyXGUI...done" << endl;
79
80         // Initialization of LyX (reads lyxrc and more)
81         lyxerr[Debug::INIT] << "Initializing LyX::init..." << endl;
82         init(argc, argv, gui);
83         lyxerr[Debug::INIT] << "Initializing LyX::init...done" << endl;
84
85         lyxGUI->init();
86
87         // Load the files specified in the command line.
88         // Now the GUI and LyX have taken care of their arguments, so
89         // the only thing left on the command line should be
90         // filenames.
91         if ((*argc) == 2) 
92                 lyxerr[Debug::INFO] << "Opening document..." << endl;
93         else if ((*argc) > 2)
94                 lyxerr[Debug::INFO] << "Opening documents..." << endl;
95
96         Buffer * last_loaded = 0;
97
98         for (int argi = (*argc) - 1; argi >= 1; --argi) {
99                 Buffer * loadb = bufferlist.loadLyXFile(argv[argi]);
100                 if (loadb != 0) {
101                         last_loaded = loadb;
102                 }
103         }
104
105         if (first_start) {
106                 string splash = i18nLibFileSearch("examples", "splash.lyx");
107                 lyxerr.debug() << "Opening splash document "
108                                << splash << "..." << endl;
109                 Buffer * loadb = bufferlist.loadLyXFile(splash);
110                 if (loadb != 0) {
111                         last_loaded = loadb;
112                 }
113         }
114
115         if (last_loaded != 0) {
116                 lyxerr.debug() << "Yes we loaded some files." << endl;
117                 if (lyxrc.use_gui)
118                         lyxGUI->regBuf(last_loaded);
119         }
120
121         // Execute batch commands if available
122         if (!batch_command.empty()) {
123                 lyxerr << "About to handle -x '" << batch_command << "'" << endl;
124
125                 // no buffer loaded, create one
126                 if (!last_loaded)
127                         last_loaded = bufferlist.newFile("tmpfile", string());
128
129                 // try to dispatch to last loaded buffer first
130                 bool dispatched = last_loaded->Dispatch(batch_command);
131
132                 // if this was successful, return. 
133                 // Maybe we could do something more clever than aborting...
134                 if (dispatched) {
135                         lyxerr << "We are done!" << endl;
136                         return;
137                 }
138
139                 // otherwise, let the GUI handle the batch command
140                 lyxGUI->regBuf(last_loaded);
141                 lyxGUI->getLyXView()->getLyXFunc()->Dispatch(batch_command);
142
143                 // fall through...
144         }
145         
146         // Let the ball begin...
147         lyxGUI->runTime();
148 }
149
150
151 // A destructor is always necessary  (asierra-970604)
152 LyX::~LyX()
153 {
154         delete lastfiles;
155         delete lyxGUI;
156 }
157
158
159 extern "C" void error_handler(int err_sig);
160
161 void LyX::init(int */*argc*/, char **argv, bool gui)
162 {
163         // Install the signal handlers
164         signal(SIGHUP, error_handler);
165         signal(SIGFPE, error_handler);
166         signal(SIGSEGV, error_handler);
167         signal(SIGINT, error_handler);
168         signal(SIGTERM, error_handler);
169
170         //
171         // Determine path of binary
172         //
173
174         string fullbinpath;
175         string binpath = subst(argv[0], '\\', '/');
176         string binname = OnlyFilename(argv[0]);
177         // Sorry for system specific code. (SMiyata)
178         if (suffixIs(binname, ".exe")) 
179                 binname.erase(binname.length()-4, string::npos);
180         
181         binpath = ExpandPath(binpath); // This expands ./ and ~/
182         
183         if (!AbsolutePath(binpath)) {
184                 string binsearchpath = GetEnvPath("PATH");
185                 // This will make "src/lyx" work always :-)
186                 binsearchpath += ";."; 
187                 binpath = FileOpenSearch(binsearchpath, argv[0]);
188         }
189
190         fullbinpath = binpath;
191         binpath = MakeAbsPath(OnlyPath(binpath));
192
193         // In case we are running in place and compiled with shared libraries
194         if (suffixIs(binpath, "/.libs/"))
195                 binpath.erase(binpath.length()-6, string::npos);
196
197         if (binpath.empty()) {
198                 lyxerr << _("Warning: could not determine path of binary.")
199                        << "\n"
200                        << _("If you have problems, try starting LyX with an absolute path.")
201                        << endl;
202         }
203         lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
204
205         //
206         // Determine system directory.
207         //
208
209         // Directories are searched in this order:
210         // 1) -sysdir command line parameter
211         // 2) LYX_DIR_11x environment variable
212         // 3) Maybe <path of binary>/TOP_SRCDIR/lib
213         // 4) <path of binary>/../share/<name of binary>/
214         // 4a) repeat 4 after following the Symlink if <path of
215         //     binary> is a symbolic link.
216         // 5) hardcoded lyx_dir
217         // The directory is checked for the presence of the file
218         // "chkconfig.ltx", and if that is present, the directory
219         // is accepted as the system directory.
220         // If no chkconfig.ltx file is found, a warning is given,
221         // and the hardcoded lyx_dir is used.
222
223         // If we had a command line switch, system_lyxdir is already set
224         string searchpath;
225         if (!system_lyxdir.empty())
226                 searchpath= MakeAbsPath(system_lyxdir) + ';';
227
228         // LYX_DIR_11x environment variable
229         string lyxdir = GetEnvPath("LYX_DIR_11x");
230         
231         if (!lyxdir.empty()) {
232                 lyxerr[Debug::INIT] << "LYX_DIR_11x: " << lyxdir << endl;
233                 searchpath += lyxdir + ';';
234         }
235
236         // <path of binary>/TOP_SRCDIR/lib
237         build_lyxdir = MakeAbsPath("../lib", binpath);
238         if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
239                 searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
240                                           binpath) + ';';
241                 lyxerr[Debug::INIT] << "Checking whether LyX is run in "
242                         "place... yes" << endl;
243         } else {
244                 lyxerr[Debug::INIT]
245                         << "Checking whether LyX is run in place... no"
246                         << endl;
247                 build_lyxdir.erase();
248         }
249
250         bool FollowLink;
251         do {
252           // Path of binary/../share/name of binary/
253                 searchpath += NormalizePath(AddPath(binpath, "../share/") + 
254                       OnlyFilename(binname)) + ';';
255
256           // Follow Symlinks
257                 FileInfo file(fullbinpath, true);
258                 FollowLink = file.isLink();
259                 if (FollowLink) {
260                         string Link;
261                         if (LyXReadLink(fullbinpath, Link)) {
262                                 fullbinpath = Link;
263                                 binpath = MakeAbsPath(OnlyPath(fullbinpath));
264                         }
265                         else {
266                                 FollowLink = false;
267                         }
268                 }
269         } while (FollowLink);
270
271         // Hardcoded dir
272         searchpath += LYX_DIR;
273
274         // If debugging, show complete search path
275         lyxerr[Debug::INIT] << "System directory search path: "
276                             << searchpath << endl;
277
278         string const filename = "chkconfig.ltx";
279         string temp = FileOpenSearch(searchpath, filename, string());
280         system_lyxdir = OnlyPath(temp);
281
282         // Reduce "path/../path" stuff out of system directory
283         system_lyxdir = NormalizePath(system_lyxdir);
284
285         bool path_shown = false;
286
287         // Warn if environment variable is set, but unusable
288         if (!lyxdir.empty()) {
289                 if (system_lyxdir != NormalizePath(lyxdir)) {
290                         lyxerr <<_("LYX_DIR_11x environment variable no good.")
291                                << '\n'
292                                << _("System directory set to: ") 
293                                << system_lyxdir << endl;
294                         path_shown = true;
295                 }
296         }
297
298         // Warn the user if we couldn't find "chkconfig.ltx"
299         if (system_lyxdir == "./") {
300                 lyxerr <<_("LyX Warning! Couldn't determine system directory.")
301                        <<_("Try the '-sysdir' command line parameter or")
302                        <<_("set the environment variable LYX_DIR_11x to the "
303                            "LyX system directory")
304                        << _("containing the file `chkconfig.ltx'.") << endl;
305                 if (!path_shown)
306                         lyxerr << _("Using built-in default ") 
307                                << LYX_DIR << _(" but expect problems.")
308                                << endl;
309                 else
310                         lyxerr << _("Expect problems.") << endl;
311                 system_lyxdir = LYX_DIR;
312                 path_shown = true;
313         }
314
315         // Report the system directory if debugging is on
316         if (!path_shown)
317                 lyxerr[Debug::INIT] << "System directory: '"
318                                     << system_lyxdir << '\'' << endl; 
319
320         //
321         // Determine user lyx-dir
322         //
323         
324         user_lyxdir = AddPath(GetEnvPath("HOME"), string(".") + PACKAGE);
325         lyxerr[Debug::INIT] << "User LyX directory: '" 
326                             <<  user_lyxdir << '\'' << endl;
327
328         // Check that user LyX directory is ok.
329         queryUserLyXDir();
330
331         //
332         // Load the layouts first
333         //
334
335         lyxerr[Debug::INIT] << "Reading layouts..." << endl;
336         LyXSetStyle();
337
338         //
339         // Shine up lyxrc defaults
340         //
341
342         // Default template path: system_dir/templates
343         if (lyxrc.template_path.empty()){
344                 lyxrc.template_path = AddPath(system_lyxdir, "templates");
345         }
346    
347         // Default lastfiles file: $HOME/.lyx/lastfiles
348         if (lyxrc.lastfiles.empty()){
349                 lyxrc.lastfiles = AddName(user_lyxdir, "lastfiles");
350         }
351
352         // Disable gui when either lyxrc or easyparse says so
353         if (!gui)
354                 lyxrc.use_gui = false;
355  
356         // Calculate screen dpi as average of x-DPI and y-DPI:
357         if (lyxrc.use_gui) {
358                 lyxrc.dpi = getScreenDPI();
359                 lyxerr[Debug::INFO] << "DPI setting detected to be "
360                                                 << lyxrc.dpi + 0.5 << endl;
361         } else {
362                 lyxrc.dpi = 1; // I hope this is safe
363         }
364
365         //
366         // Read configuration files
367         //
368
369         ReadRcFile("lyxrc.defaults");
370         ReadRcFile("lyxrc");
371
372         // Ensure that we have really read a bind file, so that LyX is
373         // usable.
374         if (!lyxrc.hasBindFile)
375                 lyxrc.ReadBindFile();
376
377
378         // Bind the X dead keys to the corresponding LyX functions if
379         // necessary. 
380         if (lyxrc.override_x_deadkeys)
381                 deadKeyBindings(toplevel_keymap);
382
383         if (lyxerr.debugging(Debug::LYXRC)) {
384                 lyxrc.print();
385         }
386
387         // Create temp directory        
388         system_tempdir = CreateLyXTmpDir(lyxrc.tempdir_path);
389         if (lyxerr.debugging(Debug::INIT)) {
390                 lyxerr << "LyX tmp dir: `" << system_tempdir << '\'' << endl;
391         }
392
393         // load the lastfiles mini-database
394         lyxerr[Debug::INIT] << "Reading lastfiles `"
395                             << lyxrc.lastfiles << "'..." << endl; 
396         lastfiles = new LastFiles(lyxrc.lastfiles, 
397                                   lyxrc.check_lastfiles,
398                                   lyxrc.num_lastfiles);
399
400         // start up the lyxserver. (is this a bit early?) (Lgb)
401         // 0.12 this will be way to early, we need the GUI to be initialized
402         // first, so move it for now.
403         // lyxserver = new LyXServer;
404 }
405
406 // These are the default bindings known to LyX
407 void LyX::defaultKeyBindings(kb_keymap  * kbmap)
408 {
409         kbmap->bind("Right", LFUN_RIGHT);
410         kbmap->bind("Left", LFUN_LEFT);
411         kbmap->bind("Up", LFUN_UP);
412         kbmap->bind("Down", LFUN_DOWN);
413         
414         kbmap->bind("Tab", LFUN_TAB);
415         
416         kbmap->bind("Home", LFUN_HOME);
417         kbmap->bind("End", LFUN_END);
418         kbmap->bind("Prior", LFUN_PRIOR);
419         kbmap->bind("Next", LFUN_NEXT);
420         
421         kbmap->bind("Return", LFUN_BREAKPARAGRAPH);
422         kbmap->bind("~C-~S-~M-nobreakspace", LFUN_PROTECTEDSPACE);
423         
424         kbmap->bind("Delete", LFUN_DELETE);
425         kbmap->bind("BackSpace", LFUN_BACKSPACE);
426         
427         // kbmap->bindings to enable the use of the numeric keypad
428         // e.g. Num Lock set
429         kbmap->bind("KP_0", LFUN_SELFINSERT);
430         kbmap->bind("KP_Decimal", LFUN_SELFINSERT);
431         kbmap->bind("KP_Enter", LFUN_SELFINSERT);
432         kbmap->bind("KP_1", LFUN_SELFINSERT);
433         kbmap->bind("KP_2", LFUN_SELFINSERT);
434         kbmap->bind("KP_3", LFUN_SELFINSERT);
435         kbmap->bind("KP_4", LFUN_SELFINSERT);
436         kbmap->bind("KP_5", LFUN_SELFINSERT);
437         kbmap->bind("KP_6", LFUN_SELFINSERT);
438         kbmap->bind("KP_Add", LFUN_SELFINSERT);
439         kbmap->bind("KP_7", LFUN_SELFINSERT);
440         kbmap->bind("KP_8", LFUN_SELFINSERT);
441         kbmap->bind("KP_9", LFUN_SELFINSERT);
442         kbmap->bind("KP_Divide", LFUN_SELFINSERT);
443         kbmap->bind("KP_Multiply", LFUN_SELFINSERT);
444         kbmap->bind("KP_Subtract", LFUN_SELFINSERT);
445         
446         /* Most self-insert keys are handled in the 'default:' section of
447          * WorkAreaKeyPress - so we don't have to define them all.
448          * However keys explicit decleared as self-insert are
449          * handled seperatly (LFUN_SELFINSERT.) Lgb. */
450         
451         kbmap->bind("C-Tab", LFUN_TABINSERT);  // ale970515
452 }
453
454 // LyX can optionally take over the handling of deadkeys
455 void LyX::deadKeyBindings(kb_keymap * kbmap)
456 {
457         // bindKeyings for transparent handling of deadkeys
458         // The keysyms are gotten from XFree86 X11R6
459         kbmap->bind("~C-~S-~M-dead_acute", LFUN_ACUTE);
460         kbmap->bind("~C-~S-~M-dead_breve", LFUN_BREVE);
461         kbmap->bind("~C-~S-~M-dead_caron", LFUN_CARON);
462         kbmap->bind("~C-~S-~M-dead_cedilla", LFUN_CEDILLA);
463         kbmap->bind("~C-~S-~M-dead_abovering", LFUN_CIRCLE);
464         kbmap->bind("~C-~S-~M-dead_circumflex", LFUN_CIRCUMFLEX);
465         kbmap->bind("~C-~S-~M-dead_abovedot", LFUN_DOT);
466         kbmap->bind("~C-~S-~M-dead_grave", LFUN_GRAVE);
467         kbmap->bind("~C-~S-~M-dead_doubleacute", LFUN_HUNG_UMLAUT);
468         kbmap->bind("~C-~S-~M-dead_macron", LFUN_MACRON);
469         // nothing with this name
470         // kbmap->bind("~C-~S-~M-dead_special_caron", LFUN_SPECIAL_CARON);
471         kbmap->bind("~C-~S-~M-dead_tilde", LFUN_TILDE);
472         kbmap->bind("~C-~S-~M-dead_diaeresis", LFUN_UMLAUT);
473         // nothing with this name either...
474         //kbmap->bind("~C-~S-~M-dead_underbar", LFUN_UNDERBAR);
475         kbmap->bind("~C-~S-~M-dead_belowdot", LFUN_UNDERDOT);
476         kbmap->bind("~C-~S-~M-dead_tie", LFUN_TIE);
477         kbmap->bind("~C-~S-~M-dead_ogonek", LFUN_OGONEK);
478 }
479
480
481
482 // This one is not allowed to use anything on the main form, since that
483 // one does not exist yet. (Asger)
484 void LyX::queryUserLyXDir()
485 {
486         // Does user directory exist?
487         FileInfo fileInfo(user_lyxdir);
488         if (fileInfo.isOK() && fileInfo.isDir()) {
489                 first_start = false;
490                 return;
491         } else {
492                 first_start = true;
493         }
494         
495         // Nope
496         if (!AskQuestion(_("You don't have a personal LyX directory."),
497                          _("It is needed to keep your own configuration."),
498                          _("Should I try to set it up for you (recommended)?"))) {
499                 lyxerr << _("Running without personal LyX directory.") << endl;
500                 // No, let's use $HOME instead.
501                 user_lyxdir = GetEnvPath("HOME");
502                 return;
503         }
504
505         // Tell the user what is going on
506         lyxerr << _("LyX: Creating directory ") << user_lyxdir
507                << _(" and running configure...") << endl;
508
509         // Create directory structure
510         if (!createDirectory(user_lyxdir, 0755)) {
511                 // Failed, let's use $HOME instead.
512                 user_lyxdir = GetEnvPath("HOME");
513                 lyxerr << _("Failed. Will use ") << user_lyxdir
514                        << _(" instead.") << endl;
515                 return;
516         }
517
518         // Run configure in user lyx directory
519         Path p(user_lyxdir);
520         system(AddName(system_lyxdir, "configure").c_str());
521         lyxerr << "LyX: " << _("Done!") << endl;
522 }
523
524
525 // Read the rc file `name'
526 void LyX::ReadRcFile(string const & name)
527 {
528         lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
529         
530         string lyxrc_path = LibFileSearch(string(), name);
531         if (!lyxrc_path.empty()){
532                 lyxerr[Debug::INIT] << "Found " << name
533                                     << " in " << lyxrc_path << endl;
534                 if (lyxrc.read(lyxrc_path) < 0) { 
535                         WriteAlert(_("LyX Warning!"), 
536                                    _("Error while reading ")+lyxrc_path+".",
537                                    _("Using built-in defaults."));
538                 }
539         } else
540                 lyxerr[Debug::INIT] << "Could not find " << name << endl;
541 }
542
543
544 // Set debugging level and report result to user
545 void setDebuggingLevel(string const & dbgLevel)
546 {
547         lyxerr << _("Setting debug level to ") <<  dbgLevel << endl;
548         lyxerr.level(Debug::value(dbgLevel));
549         Debug::showLevel(lyxerr, lyxerr.level());
550 }
551
552
553 // Give command line help
554 void commandLineHelp()
555 {
556         lyxerr << "LyX " LYX_VERSION << " of " LYX_RELEASE << endl;
557         lyxerr <<
558                 _("Usage: lyx [ command line switches ] [ name.lyx ... ]\n"
559                   "Command line switches (case sensitive):\n"
560                   "\t-help           summarize LyX usage\n"
561                   "\t-sysdir x       try to set system directory to x\n"
562                   "\t-width x        set the width of the main window\n"
563                   "\t-height y       set the height of the main window\n"
564                   "\t-xpos x         set the x position of the main window\n"
565                   "\t-ypos y         set the y position of the main window\n"
566                   "\t-dbg feature[,feature]...\n"
567                   "                  select the features to debug.\n"
568                   "                  Type `lyx -dbg' to see the list of features\n"
569                   "Check the LyX man page for more options.") << endl;
570 }
571
572
573 bool LyX::easyParse(int * argc, char * argv[])
574 {
575         bool gui = true;
576         for(int i = 1; i < *argc; ++i) {
577                 string arg = argv[i];
578
579                 // Check for -dbg int
580                 if (arg == "-dbg") {
581                         if (i + 1 < *argc) {
582                                 setDebuggingLevel(argv[i + 1]);
583
584                                 // Now, remove these two arguments by shifting
585                                 // the following two places down.
586                                 (*argc) -= 2;
587                                 for (int j = i; j < (*argc); ++j)
588                                         argv[j] = argv[j + 2];
589                                 --i; // After shift, check this number again.
590                         } else {
591                                 lyxerr << _("List of supported debug flags:")
592                                        << endl;
593                                 Debug::showTags(lyxerr);
594                                 exit(0);
595                         }
596                 } 
597                 // Check for "-sysdir"
598                 else if (arg == "-sysdir") {
599                         if (i + 1 < *argc) {
600                                 system_lyxdir = argv[i + 1];
601
602                                 // Now, remove these two arguments by shifting
603                                 // the following two places down.
604                                 (*argc) -= 2;
605                                 for (int j= i; j < (*argc); ++j)
606                                         argv[j] = argv[j + 2];
607                                 --i; // After shift, check this number again.
608                         } else
609                                 lyxerr << _("Missing directory for -sysdir switch!")
610                                        << endl;
611                 // Check for --help or -help
612                 } else if (arg == "--help" || arg == "-help") {
613                         commandLineHelp();
614                         exit(0);
615                 } 
616                 // Check for "-nw": No XWindows as for emacs this should
617                 // give a LyX that could be used in a terminal window.
618                 //else if (arg == "-nw") {
619                 //      gui = false;
620                 //}
621
622                 // Check for "-x": Execute commands
623                 else if (arg == "-x" || arg == "--execute") {
624                         if (i + 1 < *argc) {
625                                 batch_command = string(argv[i + 1]);
626
627                                 // Now, remove these two arguments by shifting
628                                 // the following two places down.
629                                 (*argc) -= 2;
630                                 for (int j = i; j < (*argc); ++j)
631                                         argv[j] = argv[j + 2];
632                                 --i; // After shift, check this number again.
633
634                         }
635                         else
636                                 lyxerr << _("Missing command string after  -x switch!") << endl;
637
638                         // Argh. Setting gui to false segfaults..
639                         //gui = false;
640                 }
641
642                 else if (arg == "-e" || arg == "--export") {
643                         if (i + 1 < *argc) {
644                                 string type(argv[i+1]);
645
646                                 (*argc) -= 2;
647                                 for (int j = i; j < (*argc); ++j)
648                                         argv[j] = argv[j + 2];
649                                 --i; // After shift, check this number again.
650
651                                 if (type == "tex")
652                                         type = "latex";
653                                 else if (type == "ps")
654                                         type = "postscript";
655                                 else if (type == "text" || type == "txt")
656                                         type = "ascii";
657
658                                 if (type == "latex" || type == "postscript"
659                                     || type == "ascii" || type == "html") 
660                                         batch_command = "buffer-export " + type;
661                                 else
662                                         lyxerr << _("Unknown file type '")
663                                                << type << _("' after ")
664                                                << arg << _(" switch!") << endl;
665                         } else
666                                 lyxerr << _("Missing file type [eg latex, "
667                                             "ps...] after ")
668                                        << arg << _(" switch!") << endl;
669                 }
670
671                 else if (arg == "--import") {
672                         if (i + 1 < *argc) {
673                                 string type(argv[i+1]);
674                                 string file(argv[i+2]);
675
676                                 (*argc) -= 3;
677                                 for (int j = i; j < (*argc); ++j)
678                                         argv[j] = argv[j + 3];
679                                 --i; // After shift, check this number again.
680         
681                                 batch_command = "buffer-import " + type + " " + file;
682                                 lyxerr << "batch_command: "
683                                        << batch_command << endl;
684
685                         } else
686                                 lyxerr << _("Missing type [eg latex, "
687                                             "ps...] after ")
688                                        << arg << _(" switch!") << endl;
689                 }
690         }
691
692         return gui;
693 }
694
695
696 extern "C"
697 void error_handler(int err_sig)
698 {
699         switch (err_sig) {
700         case SIGHUP:
701                 lyxerr << "\nlyx: SIGHUP signal caught" << endl;
702                 break;
703         case SIGINT:
704                 // no comments
705                 break;
706         case SIGFPE:
707                 lyxerr << "\nlyx: SIGFPE signal caught" << endl;
708                 break;
709         case SIGSEGV:
710                 lyxerr << "\nlyx: SIGSEGV signal caught" << endl;
711                 lyxerr <<
712                         "Sorry, you have found a bug in LyX."
713                         " If possible, please read 'Known bugs'\n"
714                         "under the Help menu and then send us "
715                         "a full bug report. Thanks!" << endl;
716                 break;
717         case SIGTERM:
718                 // no comments
719                 break;
720         }
721    
722         // Deinstall the signal handlers
723         signal(SIGHUP, SIG_DFL);
724         signal(SIGINT, SIG_DFL);
725         signal(SIGFPE, SIG_DFL);
726         signal(SIGSEGV, SIG_DFL);
727         signal(SIGTERM, SIG_DFL);
728
729         bufferlist.emergencyWriteAll();
730
731         lyxerr << "Bye." << endl;
732         if(err_sig!= SIGHUP && (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
733                 lyx::abort();
734         exit(0);
735 }