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