summaryrefslogtreecommitdiff
path: root/lily/main.cc
blob: d14272f41b2d500755d4613104ca64e81ed0c7ad (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
  main.cc -- implement main: entrypoints

  source file of the LilyPond music typesetter

  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
*/

#include <iostream.h>
#include <assert.h>
#include "proto.hh"
#include "plist.hh"
#include "lgetopt.hh"
#include "misc.hh"
#include "string.hh"
#include "main.hh"
#include "path.hh"
#include "config.hh"
#include "source.hh"
#include "my-lily-parser.hh"

Sources* source_l_g = 0;
bool only_midi = false;
bool version_ignore_b_ = false;

void destill_inname( String &name_str_r);

Long_option_init theopts[] = {
    {1, "output", 'o'},
    {0, "warranty", 'w'},
    {0, "help", 'h'},
    {0, "debug", 'd'},
    {1, "init", 'i'},
    {1, "include", 'I'},
    {0, "midi", 'M'},
    {0, "ignore-version", 'V'},
    {0,0,0}
};

void
usage()
{
    cout <<
    	"Usage: lilypond [options] [mudela-file]\n"
	"Typeset and or produce midi output from mudela-file or stdin\n"
	"\n"
	"Options:\n"
	"  -d, --debug            enable debugging output\n"
        "  -I, --include=DIR      add DIR to search path\n"
	"  -i, --init=FILE        use FILE as init file\n"
	"  -h, --help             this help\n"
	"  -w, --warranty         show warranty and copyright\n"
	"  -o, --output=FILE      set FILE as default output\n"
	"  -M, --midi             produce midi output only\n"
	"  -V, --ignore-version   ignore mudela version\n"
	"\n"
	"LilyPond was compiled with the following settings:\n"
#ifdef NDEBUG
	"NDEBUG "	
#endif
#ifdef NPRINT
	"NPRINT "
#endif
#ifdef STRING_UTILS_INLINED
	"STRING_UTILS_INLINED "
#endif
	"datadir= " DIR_DATADIR "\n" 
	;
    
    
}

void 
notice()
{
    cout <<
	"\n"
	"LilyPond, a music typesetter.\n"
	"Copyright (C) 1996,97 by\n"
	"  Han-Wen Nienhuys <hanwen@stack.nl>\n"
	"  Jan Nieuwenhuizen <jan@digicash.com>\n"
	"Contributors\n"
	"  Mats Bengtsson <matsb@s3.kth.se>\n"
	"\n"
	"    This program is free software; you can redistribute it and/or\n"
	"modify it under the terms of the GNU General Public License version 2\n"
	"as published by the Free Software Foundation.\n"
	"\n"
	"    This program is distributed in the hope that it will be useful,\n"
	"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
	"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
	"General Public License for more details.\n"
	"\n"
	"    You should have received a copy (refer to the file COPYING) of the\n"
	"GNU General Public License along with this program; if not, write to\n"
	"the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
	"USA.\n";
}

static File_path * path_l =0;

void
do_one_file(String init_str, String file_str)
{
    Sources sources;
    source_l_g = &sources; 
    source_l_g->set_path(path_l);
    {
	My_lily_parser parser(source_l_g);
	parser.set_version_check(version_ignore_b_);
	parser.parse_file(init_str, file_str);
    }
    do_scores();
    source_l_g = 0;
}

int
main (int argc, char **argv)
{    
    debug_init();		// should be first
    File_path path(String(DIR_DATADIR)+"/init/") ;
    path_l = & path;
    path_l->push(DIR_DATADIR );

    char const * env_l=getenv("LILYINCLUDE");
    if (env_l) {
	path.add(env_l);
    }
    
    Getopt_long oparser(argc, argv,theopts);
    cout << get_version_str() << endl;
    String init_str("symbol.ini");
    
    while (Long_option_init * opt = oparser()) {
	switch ( opt->shortname){
	case 'o':
	    set_default_output(oparser.optarg);
	    break;
	case 'w':
	    notice();
	    exit(0);
	    break;
	case 'I':
	    path.push(oparser.optarg);
	    break;
	case 'i':
	    init_str = oparser.optarg;
	    break;
	case 'h':
	    usage();
	    exit(0);
	    break;
	case 'V':
	    version_ignore_b_ = false;
	    break;
	case 'd':
	    set_debug(true);
	    break;
	case 'M':
	    only_midi = true;
	    break;
	default:
	    assert(false);
	    break;
	}
    }

    int p=0;
    char *arg ;
    while ( (arg= oparser.get_next_arg()) ) {
	String f(arg);
	destill_inname(f);
	do_one_file(init_str,f);
	p++;
    }
    if (!p) {
	do_one_file(init_str, "");	
    }

    return 0;
}

/// make input file name: add default extension. "" is stdin.
void
destill_inname( String &name_str_r)
{
    if ( name_str_r.length_i() )
        {
        if( name_str_r[ 0 ] != '-' ) 
	    {
	    String a,b,c,d;
	    split_path(name_str_r,a,b,c,d);

	    // add extension if not present.
	    if (d == "") 
		d = ".ly";
	    name_str_r = a+b+c+d;
	    }
	} else name_str_r = "";   
}