]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
* lily/main.cc (setup_paths): read LILYPOND_RELOCATE_PREFIX
[lilypond.git] / lily / main.cc
1 /*
2   main.cc -- implement main () entrypoint.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "main.hh"
10
11 #include <cassert>
12 #include <clocale>
13 #include <cstring>
14 #include <cerrno>
15 using namespace std;
16
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20
21 #include "config.hh"
22
23 #if HAVE_GRP_H
24 #include <grp.h>
25 #endif
26 #if HAVE_PWD_H
27 #include <pwd.h>
28 #endif
29 #if HAVE_GETTEXT
30 #include <libintl.h>
31 #endif
32
33 #include "all-font-metrics.hh"
34 #include "file-name.hh"
35 #include "freetype.hh"
36 #include "getopt-long.hh"
37 #include "global-ctor.hh"
38 #include "lily-guile.hh"
39 #include "lily-version.hh"
40 #include "misc.hh"
41 #include "output-def.hh"
42 #include "string-convert.hh"
43 #include "version.hh"
44 #include "warn.hh"
45 #include "program-option.hh"
46
47 /*
48  * Global options that can be overridden through command line.
49  */
50
51 /* Names of header fields to be dumped to a separate file. */
52 Array<String> dump_header_fieldnames_global;
53
54 /* Name of initialisation file. */
55 String init_name_global;
56
57 /* Selected output backend
58    One of (gnome, ps [default], eps, scm, svg, tex, texstr)") */
59 String output_backend_global = "ps";
60 /* Output formats to generate.  */
61 String output_format_global = "";
62
63 bool is_pango_format_global;
64 bool is_TeX_format_global;
65
66 /* Current output name. */
67 String output_name_global;
68
69 /* Run in safe mode? */
70 bool be_safe_global = false;
71
72 /* Provide URI links to the original file */
73 bool point_and_click_global = true;
74
75 /* Verbose progress indication? */
76 bool be_verbose_global = false;
77
78 /* Scheme code to execute before parsing, after .scm init.
79    This is where -e arguments are appended to.  */
80 String init_scheme_code_string;
81 String init_scheme_variables;
82
83 /* Generate preview of first system.  */
84 bool make_preview = false;
85
86 /* Generate printed output.  */
87 bool make_print = true;
88
89
90 bool relocate_binary =
91 #ifdef __MINGW32__  
92   true;
93 #else
94   false
95 #endif
96   ;
97
98
99 /*
100  * Miscellaneous global stuff.
101  */
102 File_path global_path;
103
104 /*
105  * File globals.
106  */
107
108 static char const *AUTHORS
109 = "  Han-Wen Nienhuys <hanwen@xs4all.nl>\n"
110   "  Jan Nieuwenhuizen <janneke@gnu.org>\n";
111
112 static char const *PROGRAM_NAME = "lilypond";
113 static char const *PROGRAM_URL = "http://lilypond.org";
114
115 static char const *NOTICE
116 = _i ("This program is free software.  It is covered by the GNU General Public\n"
117       "License and you are welcome to change it and/or distribute copies of it\n"
118       "under certain conditions.  Invoke as `%s --warranty' for more\n"
119       "information.\n");
120
121 static char const *WARRANTY
122 = _i ("    This program is free software; you can redistribute it and/or\n"
123       "modify it under the terms of the GNU General Public License version 2\n"
124       "as published by the Free Software Foundation.\n"
125       "\n"
126       "    This program is distributed in the hope that it will be useful,\n"
127       "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
128       "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
129       "General Public License for more details.\n"
130       "\n"
131       "    You should have received a copy (refer to the file COPYING) of the\n"
132       "GNU General Public License along with this program; if not, write to\n"
133       "the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n"
134       "Boston, MA 02111-1307, USA.\n");
135
136 /* Where the init files live.  Typically:
137    LILYPOND_DATADIR = /usr/share/lilypond
138 */
139 String prefix_directory;
140
141 /* The jail specification: USER,GROUP,JAIL,DIR. */
142 String jail_spec;
143
144 /*  The option parser */
145 static Getopt_long *option_parser = 0;
146
147 /* Internationalisation kludge in two steps:
148  * use _i () to get entry in POT file
149  * call gettext () explicitely for actual "translation"  */
150
151 static Long_option_init options_static[]
152 = {
153   {_i ("BACK"), "backend", 'b', _i ("use backend BACK (gnome, ps,eps,\nscm, svg, tex, texstr)\ndefault: PS")},
154
155   {_i ("SYM=VAL"), "define-default", 'd',
156    _i ("set a Scheme program option. Uses #t if VAL is not specified\n"
157        "Try -dhelp for help.")},
158
159   {_i ("EXPR"), "evaluate", 'e', _i ("evaluate scheme code")},
160   /* Bug in option parser: --output =foe is taken as an abbreviation
161      for --output-format.  */
162   {_i ("FORMATs"), "formats", 'f', _i ("dump FORMAT,...  Also as separate options:")},
163   {0, "dvi", 0, _i ("generate DVI (tex backend only)")},
164   {0, "relocate", 0, _i("relocate using path to binary")},
165   {0, "pdf", 0, _i ("generate PDF (default)")},
166   {0, "png", 0, _i ("generate PNG")},
167   {0, "ps", 0, _i ("generate PostScript")},
168   {0, "tex", 0, _i ("generate TeX (tex backend only)")},
169   {0, "help", 'h',  _i ("print this help")},
170   {_i ("FIELD"), "header", 'H',  _i ("dump a header field to file BASENAME.FIELD")},
171   {_i ("DIR"), "include", 'I',  _i ("add DIR to search path")},
172   {_i ("FILE"), "init", 'i',  _i ("use FILE as init file")},
173   {_i ("FILE"), "output", 'o',  _i ("write output to FILE (suffix will be added)")},
174 #if HAVE_CHROOT
175   {_i ("USER,GROUP,JAIL,DIR"), "jail", 'j', _i ("chroot to JAIL, become USER:GROUP\n"
176                                                 "and cd into DIR")},
177 #endif
178   {0, "no-print", 0, _i ("do not generate printed output")},
179   {0, "preview", 'p',  _i ("generate a preview of the first system")},
180   {0, "safe-mode", 's',  _i ("disallow unsafe Scheme and PostScript operations")},
181   {0, "version", 'v',  _i ("print version number")},
182   {0, "verbose", 'V', _i ("be verbose")},
183   {0, "warranty", 'w',  _i ("show warranty and copyright")},
184   {0, 0, 0, 0}
185 };
186
187 #define LILYPOND_DATADIR PACKAGE_DATADIR "/" TOPLEVEL_VERSION
188
189 static void
190 env_var_info (FILE *out, char const *key)
191 {
192   if (char const *value = getenv (key))
193     fprintf (out, "%s=\"%s\"\n", key, value);
194 }
195
196 static void
197 dir_info (FILE *out)
198 {
199   fputs ("\n", out);
200   fprintf (out, "LILYPOND_DATADIR=\"%s\"\n", LILYPOND_DATADIR);
201   env_var_info (out, "LILYPONDPREFIX");
202   fprintf (out, "LOCALEDIR=\"%s\"\n", LOCALEDIR);
203
204   fprintf (out, "\nEffective prefix: \"%s\"\n", prefix_directory.to_str0 ());
205
206   if (relocate_binary)
207     {
208       env_var_info (out, "FONTCONFIG_FILE");
209       env_var_info (out, "FONTCONFIG_PATH");
210       env_var_info (out, "GS_FONTPATH");
211       env_var_info (out, "GS_LIB");
212       env_var_info (out, "GUILE_LOAD_PATH");
213       env_var_info (out, "PANGO_RC_FILE");
214       env_var_info (out, "PATH");
215     }
216 }
217
218 static void
219 copyright ()
220 {
221   printf (_f ("Copyright (c) %s by\n%s  and others.",
222               "1996--2005",
223               AUTHORS).to_str0 ());
224   printf ("\n");
225 }
226
227 static void
228 identify (FILE *out)
229 {
230   fputs (gnu_lilypond_version_string ().to_str0 (), out);
231   fputs ("\n", out);
232 }
233
234 static void
235 notice ()
236 {
237   identify (stdout);
238   puts (_f (NOTICE, PROGRAM_NAME).to_str0 ());
239   printf ("\n");
240   copyright ();
241 }
242
243 LY_DEFINE (ly_usage, "ly:usage",
244            0, 0, 0, (),
245            "Print usage message.")
246 {
247   /* No version number or newline here.  It confuses help2man.  */
248   printf (_f ("Usage: %s [OPTION]... FILE...", PROGRAM_NAME).to_str0 ());
249   printf ("\n\n");
250   printf (_ ("Typeset music and/or produce MIDI from FILE.").to_str0 ());
251   printf ("\n\n");
252   printf (_ ("LilyPond produces beautiful music notation.").to_str0 ());
253   printf ("\n");
254   printf (_f ("For more information, see %s", PROGRAM_URL).to_str0 ());
255   printf ("\n\n");
256   printf (_ ("Options:").to_str0 ());
257   printf ("\n");
258   printf (Long_option_init::table_string (options_static).to_str0 ());
259   printf ("\n");
260   printf (_f ("Report bugs via %s",
261               "http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs"
262               ).to_str0 ());
263   printf ("\n");
264   printf ("\n");
265   return SCM_UNSPECIFIED;
266 }
267
268 static void
269 warranty ()
270 {
271   identify (stdout);
272   printf ("\n");
273   copyright ();
274   printf ("\n");
275   printf (_ (WARRANTY).to_str0 ());
276 }
277
278 static int
279 sane_putenv (char const *key, String value, bool overwrite = true)
280 {
281   if (overwrite || !getenv (key))
282     {
283       String combine = String (key) + "=" + value;
284       char *s = strdup (combine.to_str0 ());
285       return putenv (s);
286     }
287   return -1;
288 }
289
290 static int
291 set_env_file (char const *key, String value)
292 {
293   if (is_file (value))
294     return sane_putenv (key, value, false);
295   else if (be_verbose_global)
296     warning (_f ("no such file: %s", value));
297   return -1;
298 }
299
300 static int
301 prepend_env_path (char const *key, String value)
302 {
303   if (is_dir (value))
304     {
305       if (be_verbose_global)
306         progress_indication (_f ("%s=%s\n", key, value.to_str0 ())); 
307
308       if (char const *cur = getenv (key))
309         value += to_string (PATHSEP) + cur;
310
311       return sane_putenv (key, value.to_str0 ());
312     }
313   else if (be_verbose_global)
314     warning (_f ("no such directory: %s for %s", value, key));
315   return -1;
316 }
317
318 String
319 dir_name (String const file_name)
320 {
321   String s = file_name;
322   s.substitute ('\\', '/');
323   s = s.left_string (s.index_last ('/'));
324   return s;
325 }
326
327 #ifdef __MINGW32__
328 #include <winbase.h>
329 #endif
330
331 void
332 set_relocation (String bindir, String prefix)
333 {
334   if (be_verbose_global)
335     warning (_f ("Relocation: compile prefix=%s, new prefix=%s",
336                  prefix_directory,
337                  prefix.to_str0 ()));
338   
339   String datadir = prefix + "/share";
340   String libdir = prefix + "/lib";
341   String localedir = datadir + "/locale";
342   String sysconfdir = prefix + "/etc";
343   String lilypond_datadir = datadir + "/lilypond/" TOPLEVEL_VERSION;
344
345   if (is_dir (lilypond_datadir))
346     prefix_directory = lilypond_datadir;
347
348 #if HAVE_GETTEXT
349   if (is_dir (localedir))
350     bindtextdomain ("lilypond", localedir.to_str0 ());
351 #endif
352
353   set_env_file ("FONTCONFIG_FILE", sysconfdir + "/fonts/fonts.conf");
354 #ifdef __MINGW32__
355   char font_dir[PATH_MAX];
356   ExpandEnvironmentStrings ("%windir%/fonts", font_dir, sizeof (font_dir));
357   prepend_env_path ("GS_FONTPATH", font_dir);
358 #endif
359
360   /* FIXME: *cough* 8.15 *cough* */
361   prepend_env_path ("GS_FONTPATH", datadir + "/ghostscript/8.15/fonts");
362   prepend_env_path ("GS_LIB", datadir + "/ghostscript/8.15/Resource");
363   prepend_env_path ("GS_LIB", datadir + "/ghostscript/8.15/lib");
364
365   prepend_env_path ("GS_FONTPATH", datadir + "/gs/fonts");
366   prepend_env_path ("GS_LIB", datadir + "/gs/Resource");
367   prepend_env_path ("GS_LIB", datadir + "/gs/lib");
368
369   /* need otherwise dynamic .so's aren't found.   */
370   prepend_env_path ("DYLD_LIBRARY_PATH", libdir);
371   
372   prepend_env_path ("GUILE_LOAD_PATH", datadir
373                     + to_string ("/guile/%d.%d",
374                                  SCM_MAJOR_VERSION, SCM_MINOR_VERSION));
375   set_env_file ("PANGO_RC_FILE", sysconfdir + "/pango/pangorc");
376   prepend_env_path ("PATH", bindir);
377 }
378
379 String
380 get_working_directory ()
381 {
382   char cwd[PATH_MAX];
383   getcwd (cwd, PATH_MAX);
384
385   return String (cwd);
386 }
387
388 static void
389 setup_paths (char const *argv0)
390 {
391   prefix_directory = LILYPOND_DATADIR;
392
393   if (relocate_binary)
394     {
395       if (getenv ("LILYPOND_VERBOSE"))
396         be_verbose_global = true;
397       
398 #if defined (__CYGWIN__) || defined (__MINGW32__)
399       String s = argv0;
400       s.substitute ('\\', '/');
401       argv0 = s.to_str0 ();
402 #endif /* __CYGWIN__ || __MINGW32__ */
403
404
405       /* if name contains slashes, we should not look in $PATH */
406       String argv0_abs;
407       if (getenv ("LILYPOND_RELOCATE_PREFIX"))
408         argv0_abs = getenv ("LILYPOND_RELOCATE_PREFIX");
409       else if (argv0[0] == '/')
410         argv0_abs = argv0_abs;
411       else if (String (argv0).index ('/') > 0)
412         argv0_abs = get_working_directory () + "/" + String (argv0);
413       else
414         {
415           /* Find absolute ARGV0 name, using PATH.  */
416           File_path path;
417           path.parse_path (getenv ("PATH"));
418
419       
420 #ifndef __MINGW32__
421           String argv0_abs = path.find (argv0);
422 #else /* __MINGW32__ */
423           char const *ext[] = {"exe", "", 0 };
424           String argv0_abs = path.find (argv0, ext);
425 #endif /* __MINGW32__ */
426
427           if (argv0_abs.is_empty ())
428             {
429               File_name name (argv0);
430               /* If NAME contains slashes and its DIR is not absolute, it can
431                  only be referenced from CWD.  */
432               if (name.to_string ().index ('/') >= 0 && name.dir_[0] != '/')
433                 {
434                   argv0_abs =  get_working_directory () + "/" + argv0;
435                 }
436               else
437                 programming_error ("can't find absolute argv0");
438             }
439         }
440       
441       String bindir = dir_name (argv0_abs);
442       String argv0_prefix = dir_name (bindir);
443       if (argv0_prefix != dir_name (dir_name (dir_name (prefix_directory))))
444         set_relocation (bindir, argv0_prefix);
445     }
446   else
447     (void) argv0;
448
449   /* FIXME: use LILYPOND_DATADIR.  */
450   if (char const *env = getenv ("LILYPONDPREFIX"))
451     {
452 #ifdef __MINGW32__
453       /* Normalize file name.  */
454       env = File_name (env).to_string ().get_copy_str0 ();
455 #endif
456       prefix_directory = env;
457     }
458
459   global_path.append ("");
460
461
462   /*
463     When running from build dir, a full LILYPOND_PREFIX is set-up at
464
465         $(OUTBASE)/share/lilypond/TOPLEVEL_VERSION
466
467      This historical hack will allow the shorthand
468
469         LILYPONDPREFIX=out lily/out/lilypond ...
470
471   */
472   
473   struct stat statbuf;
474   String build_prefix = prefix_directory + "/share/lilypond/" TOPLEVEL_VERSION;
475   if (stat (build_prefix.to_str0 (), &statbuf) == 0)
476     prefix_directory = build_prefix;
477
478   
479   /* Adding mf/out make lilypond unchanged source directory, when setting
480      LILYPONDPREFIX to lilypond-x.y.z */
481   char *suffixes[] = {"ly", "ps", "scm", 0 };
482
483   
484   Array<String> dirs;
485   for (char **s = suffixes; *s; s++)
486     {
487       String path = prefix_directory + to_string ('/') + String (*s);
488       dirs.push (path);
489     }
490
491
492   dirs.push (prefix_directory + "/fonts/otf/");
493   dirs.push (prefix_directory + "/fonts/type1/");
494   dirs.push (prefix_directory + "/fonts/svg/");
495   
496   for (int i = 0; i < dirs.size (); i++)
497     global_path.prepend (dirs[i]);
498 }
499
500 static void
501 prepend_load_path (String dir)
502 {
503   String s = "(set! %load-path (cons \"" + dir + "\" %load-path))";
504   scm_c_eval_string (s.to_str0 ());
505 }
506
507 void init_global_tweak_registry ();
508 void init_fontconfig ();
509
510 #if HAVE_CHROOT
511 static void
512 do_chroot_jail ()
513 {
514   /* Now we chroot, setuid/setgrp and chdir.  If something goes wrong,
515      we exit (this is a security-sensitive area).  First we split
516      jail_spec into its components, then we retrieve the user/group id
517      (necessarily *before* chroot'ing) and finally we perform the
518      actual actions.  */
519
520   enum Jail
521     {
522       USER_NAME, GROUP_NAME, JAIL, DIR, JAIL_MAX
523     };
524
525   Array<String> components = String_convert::split (jail_spec, ',');
526   if (components.size () != JAIL_MAX)
527     {
528       error (_f ("expected %d arguments with jail, found: %d", JAIL_MAX,
529                  components.size ()));
530       exit (2);
531     }
532
533   /* Hmm.  */
534   errno = 0;
535
536   int uid;
537   if (passwd * passwd = getpwnam (components[USER_NAME].to_str0 ()))
538     uid = passwd->pw_uid;
539   else
540     {
541       if (errno == 0)
542         error (_f ("no such user: %s", components[USER_NAME]));
543       else
544         error (_f ("can't get user id from user name: %s: %s",
545                    components[USER_NAME],
546                    strerror (errno)));
547       exit (3);
548     }
549
550   /* Hmm.  */
551   errno = 0;
552
553   int gid;
554   if (group * group = getgrnam (components[GROUP_NAME].to_str0 ()))
555     gid = group->gr_gid;
556   else
557     {
558       if (errno == 0)
559         error (_f ("no such group: %s", components[GROUP_NAME]));
560       else
561         error (_f ("can't get group id from group name: %s: %s",
562                    components[GROUP_NAME],
563                    strerror (errno)));
564       exit (3);
565     }
566
567   if (chroot (components[JAIL].to_str0 ()))
568     {
569       error (_f ("can't chroot to: %s: %s", components[JAIL],
570                  strerror (errno)));
571       exit (3);
572     }
573
574   if (setgid (gid))
575     {
576       error (_f ("can't change group id to: %d: %s", gid, strerror (errno)));
577       exit (3);
578     }
579
580   if (setuid (uid))
581     {
582       error (_f ("can't change user id to: %d: %s", uid, strerror (errno)));
583       exit (3);
584     }
585
586   if (chdir (components[DIR].to_str0 ()))
587     {
588       error (_f ("can't change working directory to: %s: %s", components[DIR],
589                  strerror (errno)));
590       exit (3);
591     }
592 }
593 #endif
594
595 static void
596 main_with_guile (void *, int, char **)
597 {
598   /* Engravers use lily.scm contents, need to make Guile find it.
599      Prepend onto GUILE %load-path, very ugh. */
600
601   prepend_load_path (prefix_directory);
602   prepend_load_path (prefix_directory + "/scm");
603
604   if (be_verbose_global)
605     dir_info (stderr);
606   is_TeX_format_global = (output_backend_global == "tex"
607                           || output_backend_global == "texstr");
608
609   is_pango_format_global = !is_TeX_format_global;
610
611   ly_c_init_guile ();
612   call_constructors ();
613   ly_set_option (ly_symbol2scm ("verbose"), scm_from_bool (be_verbose_global));
614
615   init_global_tweak_registry ();
616   init_fontconfig ();
617
618   init_freetype ();
619
620   all_fonts_global = new All_font_metrics (global_path.to_string ());
621
622   if (!init_scheme_variables.is_empty ()
623       || !init_scheme_code_string.is_empty ())
624     {
625       init_scheme_variables = "(map (lambda (x) (ly:set-option (car x) (cdr x))) (list "
626         + init_scheme_variables + "))";
627
628       init_scheme_code_string
629         += "(begin #t "
630         + init_scheme_variables
631         + init_scheme_code_string
632         + ")";
633
634       char const *str0 = init_scheme_code_string.to_str0 ();
635
636       if (be_verbose_global)
637         progress_indication (_f ("Evaluating %s", str0));
638       scm_c_eval_string ((char *) str0);
639     }
640
641   /* We accept multiple independent music files on the command line to
642      reduce compile time when processing lots of small files.
643      Starting the GUILE engine is very time consuming.  */
644
645   SCM files = SCM_EOL;
646   SCM *tail = &files;
647   while (char const *arg = option_parser->get_next_arg ())
648     {
649       *tail = scm_cons (scm_makfrom0str (arg), SCM_EOL);
650       tail = SCM_CDRLOC (*tail);
651     }
652   delete option_parser;
653   option_parser = 0;
654
655 #if HAVE_CHROOT
656   if (!jail_spec.is_empty ())
657     do_chroot_jail ();
658 #endif
659
660   SCM result = scm_call_1 (ly_lily_module_constant ("lilypond-main"), files);
661   (void) result;
662
663   /* Unreachable.  */
664   exit (0);
665 }
666
667 static void
668 setup_localisation ()
669 {
670 #if HAVE_GETTEXT
671   /* Enable locales */
672   setlocale (LC_ALL, "");
673
674   /* FIXME: check if this is still true.
675      Disable localisation of float values.  This breaks TeX output.  */
676   setlocale (LC_NUMERIC, "C");
677
678   String localedir = LOCALEDIR;
679   if (char const *env = getenv ("LILYPOND_LOCALEDIR"))
680     localedir = env;
681
682   bindtextdomain ("lilypond", localedir.to_str0 ());
683   textdomain ("lilypond");
684 #endif
685 }
686
687 static void
688 add_output_format (String format)
689 {
690   if (output_format_global != "")
691     output_format_global += ",";
692   output_format_global += format;
693 }
694
695 static void
696 parse_argv (int argc, char **argv)
697 {
698   bool show_help = false;
699   option_parser = new Getopt_long (argc, argv, options_static);
700   while (Long_option_init const *opt = (*option_parser) ())
701     {
702       switch (opt->shortname_char_)
703         {
704         case 0:
705           if (String (opt->longname_str0_) == "dvi"
706               || String (opt->longname_str0_) == "pdf"
707               || String (opt->longname_str0_) == "png"
708               || String (opt->longname_str0_) == "ps"
709               || String (opt->longname_str0_) == "tex")
710             add_output_format (opt->longname_str0_);
711           else if (String (opt->longname_str0_) == "preview")
712             make_preview = true;
713           else if (String (opt->longname_str0_) == "no-pages")
714             make_print = false;
715           else if (String (opt->longname_str0_) == "relocate")
716             relocate_binary = true;
717           break;
718
719         case 'd':
720           {
721             String arg (option_parser->optional_argument_str0_);
722             int eq = arg.index ('=');
723
724             String key = arg;
725             String val = "#t";
726
727             if (eq >= 0)
728               {
729                 key = arg.left_string (eq);
730                 val = arg.right_string (arg.length () - eq - 1);
731               }
732
733             init_scheme_variables
734               += "(cons \'" + key + "  " + val + ")\n";
735           }
736           break;
737
738         case 'v':
739           notice ();
740           exit (0);
741           break;
742         case 'o':
743           {
744             String s = option_parser->optional_argument_str0_;
745             File_name file_name (s);
746             output_name_global = file_name.to_string ();
747           }
748           break;
749         case 'j':
750           jail_spec = option_parser->optional_argument_str0_;
751           break;
752         case 'e':
753           init_scheme_code_string += option_parser->optional_argument_str0_;
754           break;
755         case 'w':
756           warranty ();
757           exit (0);
758           break;
759
760         case 'b':
761           output_backend_global = option_parser->optional_argument_str0_;
762           break;
763
764         case 'f':
765           output_format_global = option_parser->optional_argument_str0_;
766           break;
767
768         case 'H':
769           dump_header_fieldnames_global
770             .push (option_parser->optional_argument_str0_);
771           break;
772         case 'I':
773           global_path.append (option_parser->optional_argument_str0_);
774           break;
775         case 'i':
776           init_name_global = option_parser->optional_argument_str0_;
777           break;
778         case 'h':
779           show_help = true;
780           break;
781         case 'V':
782           be_verbose_global = true;
783           break;
784         case 's':
785           be_safe_global = true;
786           break;
787         case 'p':
788           make_preview = true;
789           break;
790         default:
791           programming_error (to_string ("unhandled short option: %c",
792                                         opt->shortname_char_));
793           assert (false);
794           break;
795         }
796     }
797
798   if (output_format_global == "")
799     output_format_global = "pdf";
800
801   if (show_help)
802     {
803       identify (stdout);
804       ly_usage ();
805       if (be_verbose_global)
806         dir_info (stdout);
807       exit (0);
808     }
809 }
810
811 void
812 setup_guile_env ()
813 {
814   char *yield = getenv ("LILYPOND_GC_YIELD");
815   bool overwrite = true;
816   if (!yield)
817     {
818       yield = "70";
819       overwrite = false;
820     }
821
822   sane_putenv ("GUILE_MIN_YIELD_1", yield, overwrite);
823   sane_putenv ("GUILE_MIN_YIELD_2", yield, overwrite);
824   sane_putenv ("GUILE_MIN_YIELD_MALLOC", yield, overwrite);
825 }
826
827 int
828 main (int argc, char **argv)
829 {
830   setup_localisation ();
831   parse_argv (argc, argv);
832   if (isatty (STDIN_FILENO))
833     identify (stderr);
834
835   setup_paths (argv[0]);
836   setup_guile_env ();
837   scm_boot_guile (argc, argv, main_with_guile, 0);
838
839   /* Only reachable if GUILE exits.  That is an error.  */
840   return 1;
841 }