]> git.donarmstrong.com Git - lilypond.git/blob - lily/main.cc
release: 0.1.62
[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 bool find_quarts_global_b = false;
28 String default_outname_base_global =  "lelie";
29 int default_count_global;
30
31 bool experimental_features_global_b = false;
32 bool dependency_global_b = false;
33
34 int exit_status_i_;
35
36 void destill_inname (String &name_str_r);
37
38 Long_option_init theopts[] = {
39   {1, "output", 'o'},
40   {0, "warranty", 'w'},
41   {0, "help", 'h'},
42   {0, "test", 't'},
43   {0, "debug", 'D'},
44   {1, "init", 'i'},
45   {1, "include", 'I'},
46   {0, "no-paper", 'M'},
47   {0, "dependencies", 'd'},
48   {0, "no-timestamps", 'T'},
49   {0, "find-quarts", 'Q'},
50   {0, "ignore-version", 'V'},
51   {0,0,0}
52 };
53
54 void
55 usage ()
56 {
57   cout <<
58     _("Usage: lilypond [options] [mudela-files]\n"
59     "Typeset and or produce midi output from mudela-file or stdin\n"
60     "\n"
61     "Options:\n"
62     "  -D, --debug            enable debugging output\n"
63     "  -d, --dependencies     write Makefile dependencies for every input file\n"
64     "  -Q, --find-quarts      show all intervals bigger than a quart\n"
65     "  -I, --include=DIR      add DIR to search path\n"
66     "  -i, --init=FILE        use FILE as init file\n"
67     "  -h, --help             this help\n"
68     "  -M, --no-paper         produce midi output only\n"
69     "  -o, --output=FILE      set FILE as default output\n"
70     "  -t, --test             switch on experimental features\n"
71     "  -T, --no-timestamps    don't timestamp the output\n"
72     "  -V, --ignore-version   ignore mudela version\n"
73     "  -w, --warranty         show warranty and copyright\n"
74     "\n"
75     "GNU LilyPond was compiled with the following settings:\n")
76 #ifdef NDEBUG
77     "NDEBUG "
78 #endif
79 #ifdef NPRINT
80     "NPRINT "
81 #endif
82 #ifdef STRING_UTILS_INLINED
83     "STRING_UTILS_INLINED "
84 #endif
85         "datadir= " DIR_DATADIR
86
87     "\n";
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 'Q':
164           find_quarts_global_b = true;
165           break;
166         case 'I':
167           path.push (oparser.optional_argument_ch_C_);
168           break;
169         case 'i':
170           init_str = oparser.optional_argument_ch_C_;
171           break;
172         case 'h':
173           usage ();
174           exit (0);
175           break;
176         case 'V':
177           version_ignore_global_b = true;
178           break;
179         case 'd':
180           dependency_global_b = true;
181           break; 
182         case 'D':
183           set_debug (true);
184           break;
185         case 'M':
186           no_paper_global_b = true;
187           break;
188         case 'T':
189           no_timestamps_global_b = true;
190           break;
191         default:
192           assert (false);
193           break;
194         }
195     }
196
197   int p=0;
198   const char *arg ;
199   while ((arg= oparser.get_next_arg ()))
200     {
201       String f (arg);
202       destill_inname (f);
203       do_one_file (init_str,f);
204       p++;
205     }
206   if (!p)
207     {
208       do_one_file (init_str, "");
209     }
210
211   return exit_status_i_;
212 }
213
214 /// make input file name: add default extension. "" is stdin.
215 void
216 destill_inname (String &name_str_r)
217 {
218   if (name_str_r.length_i ())
219     {
220       if (name_str_r[ 0 ] != '-')
221         {
222           String a,b,c,d;
223           split_path (name_str_r,a,b,c,d);
224
225           // add extension if not present.
226           if (d.empty_b ())
227             d = ".ly";
228           name_str_r = a+b+c+d;
229         }
230     }
231   else name_str_r = "";
232 }