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