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