]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
* GNUmakefile.in: add dir argument for find command.
[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   false
93 #else
94   true;
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 (char const *cur = getenv (key))
306         value += to_string (PATHSEP) + cur;
307       return sane_putenv (key, value.to_str0 ());
308     }
309   else if (be_verbose_global)
310     warning (_f ("no such directory: %s", value));
311   return -1;
312 }
313
314 String
315 dir_name (String const file_name)
316 {
317   String s = file_name;
318   s.substitute ('\\', '/');
319   s = s.left_string (s.index_last ('/'));
320   return s;
321 }
322
323 #ifdef __MINGW32__
324 #include <winbase.h>
325 #endif
326
327 void
328 set_relocation (String bindir, String prefix)
329 {
330   if (be_verbose_global)
331     warning (_f ("argv0 relocation: prefix=%s, new prefix=%s",
332                  prefix_directory,
333                  prefix.to_str0 ()));
334   
335   String datadir = prefix + "/share";
336   String libdir = prefix + "/lib";
337   String localedir = datadir + "/locale";
338   String sysconfdir = prefix + "/etc";
339   String lilypond_datadir = datadir + "/lilypond/" TOPLEVEL_VERSION;
340
341   if (is_dir (lilypond_datadir))
342     prefix_directory = lilypond_datadir;
343
344 #if HAVE_GETTEXT
345   if (is_dir (localedir))
346     bindtextdomain ("lilypond", localedir.to_str0 ());
347 #endif
348
349   set_env_file ("FONTCONFIG_FILE", sysconfdir + "/fonts/fonts.conf");
350 #ifdef __MINGW32__
351   char font_dir[PATH_MAX];
352   ExpandEnvironmentStrings ("%windir%/fonts", font_dir, sizeof (font_dir));
353   prepend_env_path ("GS_FONTPATH", font_dir);
354 #endif
355
356   /* FIXME: *cough* 8.15 *cough* */
357   prepend_env_path ("GS_FONTPATH", datadir + "/ghostscript/8.15/fonts");
358   prepend_env_path ("GS_LIB", datadir + "/ghostscript/8.15/Resource");
359   prepend_env_path ("GS_LIB", datadir + "/ghostscript/8.15/lib");
360
361   prepend_env_path ("GS_FONTPATH", datadir + "/gs/fonts");
362   prepend_env_path ("GS_LIB", datadir + "/gs/Resource");
363   prepend_env_path ("GS_LIB", datadir + "/gs/lib");
364
365   prepend_env_path ("GUILE_LOAD_PATH", datadir
366                     + to_string ("/guile/%d.%d",
367                                  SCM_MAJOR_VERSION, SCM_MINOR_VERSION));
368   set_env_file ("PANGO_RC_FILE", sysconfdir + "/pango/pangorc");
369   prepend_env_path ("PATH", bindir);
370 }
371
372
373 static void
374 setup_paths (char const *argv0)
375 {
376   prefix_directory = LILYPOND_DATADIR;
377
378   if (relocate_binary)
379     {
380       if (getenv ("LILYPOND_VERBOSE"))
381         be_verbose_global = true;
382
383       /* Find absolute ARGV0 name, using PATH.  */
384       File_path path;
385       path.parse_path (getenv ("PATH"));
386
387 #if defined (__CYGWIN__) || defined (__MINGW32__)
388       String s = argv0;
389       s.substitute ('\\', '/');
390       argv0 = s.to_str0 ();
391 #endif /* __CYGWIN__ || __MINGW32__ */
392
393 #ifndef __MINGW32__
394       String argv0_abs = path.find (argv0);
395 #else /* __MINGW32__ */
396       char const *ext[] = {"exe", "", 0 };
397       String argv0_abs = path.find (argv0, ext);
398 #endif /* __MINGW32__ */
399
400       if (argv0_abs.is_empty ())
401         {
402           File_name name (argv0);
403           /* If NAME contains slashes and its DIR is not absolute, it can
404              only be referenced from CWD.  */
405           if (name.to_string ().index ('/') >= 0 && name.dir_[0] != '/')
406             {
407               char cwd[PATH_MAX];
408               getcwd (cwd, PATH_MAX);
409               argv0_abs = String (cwd) + "/" + argv0;
410             }
411           else
412             programming_error ("can't find absolute argv0");
413         }
414     
415       String bindir = dir_name (argv0_abs);
416       String argv0_prefix = dir_name (bindir);
417       if (argv0_prefix != dir_name (dir_name (dir_name (prefix_directory))))
418         set_relocation (bindir, argv0_prefix);
419     }
420   else
421     (void) argv0;
422
423   /* FIXME: use LILYPOND_DATADIR.  */
424   if (char const *env = getenv ("LILYPONDPREFIX"))
425     {
426 #ifdef __MINGW32__
427       /* Normalize file name.  */
428       env = File_name (env).to_string ().get_copy_str0 ();
429 #endif
430       prefix_directory = env;
431     }
432
433   global_path.append ("");
434
435
436   /*
437     When running from build dir, a full LILYPOND_PREFIX is set-up at
438
439         $(OUTBASE)/share/lilypond/TOPLEVEL_VERSION
440
441      This historical hack will allow the shorthand
442
443         LILYPONDPREFIX=out lily/out/lilypond ...
444
445   */
446   
447   struct stat statbuf;
448   String build_prefix = prefix_directory + "/share/lilypond/" TOPLEVEL_VERSION;
449   if (stat (build_prefix.to_str0 (), &statbuf) == 0)
450     prefix_directory = build_prefix;
451
452   
453   /* Adding mf/out make lilypond unchanged source directory, when setting
454      LILYPONDPREFIX to lilypond-x.y.z */
455   char *suffixes[] = {"ly", "ps", "scm", 0 };
456
457   
458   Array<String> dirs;
459   for (char **s = suffixes; *s; s++)
460     {
461       String path = prefix_directory + to_string ('/') + String (*s);
462       dirs.push (path);
463     }
464
465
466   dirs.push (prefix_directory + "/fonts/otf/");
467   dirs.push (prefix_directory + "/fonts/type1/");
468   dirs.push (prefix_directory + "/fonts/svg/");
469   
470   for (int i = 0; i < dirs.size (); i++)
471     global_path.prepend (dirs[i]);
472 }
473
474 static void
475 prepend_load_path (String dir)
476 {
477   String s = "(set! %load-path (cons \"" + dir + "\" %load-path))";
478   scm_c_eval_string (s.to_str0 ());
479 }
480
481 void init_global_tweak_registry ();
482 void init_fontconfig ();
483
484 #if HAVE_CHROOT
485 static void
486 do_chroot_jail ()
487 {
488   /* Now we chroot, setuid/setgrp and chdir.  If something goes wrong,
489      we exit (this is a security-sensitive area).  First we split
490      jail_spec into its components, then we retrieve the user/group id
491      (necessarily *before* chroot'ing) and finally we perform the
492      actual actions.  */
493
494   enum Jail
495     {
496       USER_NAME, GROUP_NAME, JAIL, DIR, JAIL_MAX
497     };
498
499   Array<String> components = String_convert::split (jail_spec, ',');
500   if (components.size () != JAIL_MAX)
501     {
502       error (_f ("expected %d arguments with jail, found: %d", JAIL_MAX,
503                  components.size ()));
504       exit (2);
505     }
506
507   /* Hmm.  */
508   errno = 0;
509
510   int uid;
511   if (passwd * passwd = getpwnam (components[USER_NAME].to_str0 ()))
512     uid = passwd->pw_uid;
513   else
514     {
515       if (errno == 0)
516         error (_f ("no such user: %s", components[USER_NAME]));
517       else
518         error (_f ("can't get user id from user name: %s: %s",
519                    components[USER_NAME],
520                    strerror (errno)));
521       exit (3);
522     }
523
524   /* Hmm.  */
525   errno = 0;
526
527   int gid;
528   if (group * group = getgrnam (components[GROUP_NAME].to_str0 ()))
529     gid = group->gr_gid;
530   else
531     {
532       if (errno == 0)
533         error (_f ("no such group: %s", components[GROUP_NAME]));
534       else
535         error (_f ("can't get group id from group name: %s: %s",
536                    components[GROUP_NAME],
537                    strerror (errno)));
538       exit (3);
539     }
540
541   if (chroot (components[JAIL].to_str0 ()))
542     {
543       error (_f ("can't chroot to: %s: %s", components[JAIL],
544                  strerror (errno)));
545       exit (3);
546     }
547
548   if (setgid (gid))
549     {
550       error (_f ("can't change group id to: %d: %s", gid, strerror (errno)));
551       exit (3);
552     }
553
554   if (setuid (uid))
555     {
556       error (_f ("can't change user id to: %d: %s", uid, strerror (errno)));
557       exit (3);
558     }
559
560   if (chdir (components[DIR].to_str0 ()))
561     {
562       error (_f ("can't change working directory to: %s: %s", components[DIR],
563                  strerror (errno)));
564       exit (3);
565     }
566 }
567 #endif
568
569 static void
570 main_with_guile (void *, int, char **)
571 {
572   /* Engravers use lily.scm contents, need to make Guile find it.
573      Prepend onto GUILE %load-path, very ugh. */
574
575   prepend_load_path (prefix_directory);
576   prepend_load_path (prefix_directory + "/scm");
577
578   if (be_verbose_global)
579     dir_info (stderr);
580   is_TeX_format_global = (output_backend_global == "tex"
581                           || output_backend_global == "texstr");
582
583   is_pango_format_global = !is_TeX_format_global;
584
585   ly_c_init_guile ();
586   call_constructors ();
587   ly_set_option (ly_symbol2scm ("verbose"), scm_from_bool (be_verbose_global));
588
589   init_global_tweak_registry ();
590   init_fontconfig ();
591
592   init_freetype ();
593
594   all_fonts_global = new All_font_metrics (global_path.to_string ());
595
596   if (!init_scheme_variables.is_empty ()
597       || !init_scheme_code_string.is_empty ())
598     {
599       init_scheme_variables = "(map (lambda (x) (ly:set-option (car x) (cdr x))) (list "
600         + init_scheme_variables + "))";
601
602       init_scheme_code_string
603         += "(begin #t "
604         + init_scheme_variables
605         + init_scheme_code_string
606         + ")";
607
608       char const *str0 = init_scheme_code_string.to_str0 ();
609
610       if (be_verbose_global)
611         progress_indication (_f ("Evaluating %s", str0));
612       scm_c_eval_string ((char *) str0);
613     }
614
615   /* We accept multiple independent music files on the command line to
616      reduce compile time when processing lots of small files.
617      Starting the GUILE engine is very time consuming.  */
618
619   SCM files = SCM_EOL;
620   SCM *tail = &files;
621   while (char const *arg = option_parser->get_next_arg ())
622     {
623       *tail = scm_cons (scm_makfrom0str (arg), SCM_EOL);
624       tail = SCM_CDRLOC (*tail);
625     }
626   delete option_parser;
627   option_parser = 0;
628
629 #if HAVE_CHROOT
630   if (!jail_spec.is_empty ())
631     do_chroot_jail ();
632 #endif
633
634   SCM result = scm_call_1 (ly_lily_module_constant ("lilypond-main"), files);
635   (void) result;
636
637   /* Unreachable.  */
638   exit (0);
639 }
640
641 static void
642 setup_localisation ()
643 {
644 #if HAVE_GETTEXT
645   /* Enable locales */
646   setlocale (LC_ALL, "");
647
648   /* FIXME: check if this is still true.
649      Disable localisation of float values.  This breaks TeX output.  */
650   setlocale (LC_NUMERIC, "C");
651
652   String localedir = LOCALEDIR;
653   if (char const *env = getenv ("LILYPOND_LOCALEDIR"))
654     localedir = env;
655
656   bindtextdomain ("lilypond", localedir.to_str0 ());
657   textdomain ("lilypond");
658 #endif
659 }
660
661 static void
662 add_output_format (String format)
663 {
664   if (output_format_global != "")
665     output_format_global += ",";
666   output_format_global += format;
667 }
668
669 static void
670 parse_argv (int argc, char **argv)
671 {
672   bool show_help = false;
673   option_parser = new Getopt_long (argc, argv, options_static);
674   while (Long_option_init const *opt = (*option_parser) ())
675     {
676       switch (opt->shortname_char_)
677         {
678         case 0:
679           if (String (opt->longname_str0_) == "dvi"
680               || String (opt->longname_str0_) == "pdf"
681               || String (opt->longname_str0_) == "png"
682               || String (opt->longname_str0_) == "ps"
683               || String (opt->longname_str0_) == "tex")
684             add_output_format (opt->longname_str0_);
685           else if (String (opt->longname_str0_) == "preview")
686             make_preview = true;
687           else if (String (opt->longname_str0_) == "no-pages")
688             make_print = false;
689           else if (String (opt->longname_str0_) == "relocate")
690             relocate_binary = true;
691           break;
692
693         case 'd':
694           {
695             String arg (option_parser->optional_argument_str0_);
696             int eq = arg.index ('=');
697
698             String key = arg;
699             String val = "#t";
700
701             if (eq >= 0)
702               {
703                 key = arg.left_string (eq);
704                 val = arg.right_string (arg.length () - eq - 1);
705               }
706
707             init_scheme_variables
708               += "(cons \'" + key + "  " + val + ")\n";
709           }
710           break;
711
712         case 'v':
713           notice ();
714           exit (0);
715           break;
716         case 'o':
717           {
718             String s = option_parser->optional_argument_str0_;
719             File_name file_name (s);
720             output_name_global = file_name.to_string ();
721           }
722           break;
723         case 'j':
724           jail_spec = option_parser->optional_argument_str0_;
725           break;
726         case 'e':
727           init_scheme_code_string += option_parser->optional_argument_str0_;
728           break;
729         case 'w':
730           warranty ();
731           exit (0);
732           break;
733
734         case 'b':
735           output_backend_global = option_parser->optional_argument_str0_;
736           break;
737
738         case 'f':
739           output_format_global = option_parser->optional_argument_str0_;
740           break;
741
742         case 'H':
743           dump_header_fieldnames_global
744             .push (option_parser->optional_argument_str0_);
745           break;
746         case 'I':
747           global_path.append (option_parser->optional_argument_str0_);
748           break;
749         case 'i':
750           init_name_global = option_parser->optional_argument_str0_;
751           break;
752         case 'h':
753           show_help = true;
754           break;
755         case 'V':
756           be_verbose_global = true;
757           break;
758         case 's':
759           be_safe_global = true;
760           break;
761         case 'p':
762           make_preview = true;
763           break;
764         default:
765           programming_error (to_string ("unhandled short option: %c",
766                                         opt->shortname_char_));
767           assert (false);
768           break;
769         }
770     }
771
772   if (output_format_global == "")
773     output_format_global = "pdf";
774
775   if (show_help)
776     {
777       identify (stdout);
778       ly_usage ();
779       if (be_verbose_global)
780         dir_info (stdout);
781       exit (0);
782     }
783 }
784
785 void
786 setup_guile_env ()
787 {
788   char *yield = getenv ("LILYPOND_GC_YIELD");
789   bool overwrite = true;
790   if (!yield)
791     {
792       yield = "70";
793       overwrite = false;
794     }
795
796   sane_putenv ("GUILE_MIN_YIELD_1", yield, overwrite);
797   sane_putenv ("GUILE_MIN_YIELD_2", yield, overwrite);
798   sane_putenv ("GUILE_MIN_YIELD_MALLOC", yield, overwrite);
799 }
800
801 int
802 main (int argc, char **argv)
803 {
804   setup_localisation ();
805   parse_argv (argc, argv);
806   if (isatty (STDIN_FILENO))
807     identify (stderr);
808
809   setup_paths (argv[0]);
810   setup_guile_env ();
811   scm_boot_guile (argc, argv, main_with_guile, 0);
812
813   /* Only reachable if GUILE exits.  That is an error.  */
814   return 1;
815 }