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