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