]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 0.1.61
[lilypond.git] / lily / main.cc
1 /*
2   main.cc -- implement main: entrypoints
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include <stdlib.h>
10 #include <iostream.h>
11 #include <assert.h>
12 #include "proto.hh"
13 #include "plist.hh"
14 #include "lgetopt.hh"
15 #include "misc.hh"
16 #include "string.hh"
17 #include "main.hh"
18 #include "file-path.hh"
19 #include "config.hh"
20 #include "file-results.hh"
21 #include "debug.hh"
22
23
24 bool version_ignore_global_b = false;
25 bool no_paper_global_b = false;
26 bool no_timestamps_global_b = false;
27 String default_outname_base_global =  "lelie";
28 int default_count_global;
29
30 bool experimental_features_global_b = false;
31 bool dependency_global_b = false;
32
33 int exit_status_i_;
34
35 void destill_inname (String &name_str_r);
36
37 Long_option_init theopts[] = {
38   {1, "output", 'o'},
39   {0, "warranty", 'w'},
40   {0, "help", 'h'},
41   {0, "test", 't'},
42   {0, "debug", 'D'},
43   {1, "init", 'i'},
44   {1, "include", 'I'},
45   {0, "no-paper", 'M'},
46   {0, "dependencies", 'd'},
47   {0, "no-timestamps", 'T'},
48   {0, "ignore-version", 'V'},
49   {0,0,0}
50 };
51
52 void
53 usage ()
54 {
55   cout <<
56     _("Usage: lilypond [options] [mudela-files]\n"
57     "Typeset and or produce midi output from mudela-file or stdin\n"
58     "\n"
59     "Options:\n"
60     "  -D, --debug            enable debugging output\n"
61     "  -d, --dependencies     write dependency files for every output\n"
62     "  -I, --include=DIR      add DIR to search path\n"
63     "  -i, --init=FILE        use FILE as init file\n"
64     "  -h, --help             this help\n"
65     "  -w, --warranty         show warranty and copyright\n"
66     "  -o, --output=FILE      set FILE as default output\n"
67     "  -t, --test             switch on experimental features\n"
68     "  -M, --no-paper         produce midi output only\n"
69     "  -V, --ignore-version   ignore mudela version\n"
70
71     "  -T, --no-timestamps    don't timestamp the output\n"
72     "\n"
73     "GNU LilyPond was compiled with the following settings:\n")
74 #ifdef NDEBUG
75     "NDEBUG "
76 #endif
77 #ifdef NPRINT
78     "NPRINT "
79 #endif
80 #ifdef STRING_UTILS_INLINED
81     "STRING_UTILS_INLINED "
82 #endif
83         "datadir= " DIR_DATADIR
84
85     "\n";
86
87   ;
88
89
90 }
91
92 void
93 notice ()
94 {
95   cout <<
96     _("\n"
97     "GNU LilyPond -- The GNU Project music typesetter.\n"
98     "Copyright 1996, 97, 98 by\n"
99     "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
100     "  Jan Nieuwenhuizen <jan@digicash.com>\n"
101     "\n"
102     "    This program is free software; you can redistribute it and/or\n"
103     "modify it under the terms of the GNU General Public License version 2\n"
104     "as published by the Free Software Foundation.\n"
105     "\n"
106     "    This program is distributed in the hope that it will be useful,\n"
107     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
108     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
109     "General Public License for more details.\n"
110     "\n"
111     "    You should have received a copy (refer to the file COPYING) of the\n"
112     "GNU General Public License along with this program; if not, write to\n"
113     "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
114     "USA.\n");
115 }
116
117
118  File_path path;
119
120
121 void
122 identify ()
123 {
124   cout << get_version_str () << endl;
125 }
126
127 int
128 main (int argc, char **argv)
129 {
130   identify ();
131   call_constructors ();
132   debug_init ();                // should be first
133
134
135   
136   path.add ("");
137   // must override (come before) "/usr/local/share/lilypond"!
138   char const *env_sz = getenv ("LILYINCLUDE");
139   if (env_sz)
140     path.parse_path (env_sz);
141
142   path.add (String (DIR_DATADIR) + "/init/");
143
144   path.push (DIR_DATADIR);
145
146   Getopt_long oparser (argc, argv,theopts);
147   String init_str ("lily-init.ly");
148
149   while (Long_option_init const * opt = oparser ())
150     {
151       switch (opt->shortname)
152         {
153         case 't':
154           experimental_features_global_b = true;
155           break;
156         case 'o':
157           default_outname_base_global = oparser.optional_argument_ch_C_;
158           break;
159         case 'w':
160           notice ();
161           exit (0);
162           break;
163         case 'I':
164           path.push (oparser.optional_argument_ch_C_);
165           break;
166         case 'i':
167           init_str = oparser.optional_argument_ch_C_;
168           break;
169         case 'h':
170           usage ();
171           exit (0);
172           break;
173         case 'V':
174           version_ignore_global_b = true;
175           break;
176         case 'd':
177           dependency_global_b = true;
178           break; 
179         case 'D':
180           set_debug (true);
181           break;
182         case 'M':
183           no_paper_global_b = true;
184           break;
185         case 'T':
186           no_timestamps_global_b = true;
187           break;
188         default:
189           assert (false);
190           break;
191         }
192     }
193
194   int p=0;
195   const char *arg ;
196   while ((arg= oparser.get_next_arg ()))
197     {
198       String f (arg);
199       destill_inname (f);
200       do_one_file (init_str,f);
201       p++;
202     }
203   if (!p)
204     {
205       do_one_file (init_str, "");
206     }
207
208   return exit_status_i_;
209 }
210
211 /// make input file name: add default extension. "" is stdin.
212 void
213 destill_inname (String &name_str_r)
214 {
215   if (name_str_r.length_i ())
216     {
217       if (name_str_r[ 0 ] != '-')
218         {
219           String a,b,c,d;
220           split_path (name_str_r,a,b,c,d);
221
222           // add extension if not present.
223           if (d.empty_b ())
224             d = ".ly";
225           name_str_r = a+b+c+d;
226         }
227     }
228   else name_str_r = "";
229 }