4 Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 /* ------------------------------------------------------------------- */
32 #endif /* HAVE_CONFIG_H */
42 # define strrchr rindex
46 #ifndef USE_NETBSDGETOPT
49 # include "netbsdgetopt.h"
53 #include "gettext_wrapper.h"
56 /* ------------------------------------------------------------------- */
58 #define PATH_BUF_SIZE 1024
59 #define PLAYER_NAME "rcpplay"
61 /* ------------------------------------------------------------------- */
63 void error_end( char * );
64 static int option_gets( int, char ** );
65 static void usage( void );
66 static void display_version( void );
67 static char *command_name=NULL;
68 static int verbose=FLAG_FALSE;
69 static unsigned char *copyright=NULL;
70 static unsigned char *outfile=NULL;
71 static unsigned char *outdev=NULL;
72 static int is_player = FLAG_FALSE;
73 static int is_send_rtm = FLAG_FALSE;
74 static int is_buffered = FLAG_TRUE;
78 /* ------------------------------------------------------------------- */
80 extern int rcpplay( RCP_DATA *);
82 /* ------------------------------------------------------------------- */
83 int main( int argc, char **argv ) {
86 char *a, buf[PATH_BUF_SIZE];
93 setlocale( LC_ALL, "" );
94 bindtextdomain( PACKAGE, LOCALEDIR );
95 textdomain( PACKAGE );
96 #endif /* ENABLE_NLS */
98 num = option_gets( argc, argv );
99 if ( num == argc-1 ) isonefile=FLAG_TRUE;
100 else isonefile=FLAG_FALSE;
104 while ( num < argc ) {
108 if ( isonefile==FLAG_FALSE ) {
109 if ( (a=strrchr( name, '.' ))==NULL ) continue; /* no extension */
111 if ( strcasecmp( a, ".rcp" )!=0 ) {
112 if ( strcasecmp( a, ".r36" )!=0 ) continue; /* extension not RCP/R36 */
116 rcp = rcp_read_file( argv[num-1] );
118 snprintf( buf, PATH_BUF_SIZE, _("Cannot open file %s.\n"), argv[num-1] );
122 rcp->command_name = command_name;
123 rcp->enable_verbose = verbose;
124 rcp->is_player = is_player;
125 rcp->is_send_rtm = is_send_rtm;
126 rcp->is_buffered = is_buffered;
128 if ( is_player == FLAG_FALSE ) {
130 rcp->copyright = copyright;
131 rcp->enable_converter_notice = FLAG_TRUE;
133 if ( verbose == FLAG_TRUE ) {
134 fprintf( stderr, _("Filename = %s\n"), argv[num-1] );
135 if ( outfile != NULL )
136 fprintf(stderr, _("Output filename = %s\n"), outfile );
137 if ( rcp->copyright != NULL )
138 fprintf( stderr, _("Copyright message = %s\n"), rcp->copyright );
144 fprintf(stderr,_("%s: Cannot convert %s\n"), command_name, argv[num-1]);
147 if ( outfile == NULL )
148 fwrite( smf, 1, rcp->smf_size, stdout );
151 fp = fopen(outfile,"w");
153 fwrite( smf, 1, rcp->smf_size, fp );
156 fprintf(stderr,_("%s: Cannot open file %s\n"), command_name, outfile);
163 if ( verbose == FLAG_TRUE ) {
164 fprintf( stderr, _("Filename = %s\n"), argv[num-1] );
167 if ( outdev != NULL )
168 rcp->output_device = outdev;
170 rcp->output_device = DEFAULT_OUTPUT_DEVICE;
182 /* ------------------------------------------------------------------- */
184 void error_end( char *msg ) {
186 fprintf( stderr, "%s: %s\n", command_name, msg );
190 /* ------------------------------------------------------------------- */
192 static int option_gets( int argc, char **argv ) {
201 (strrchr(argv[0],'/')==NULL)?argv[0]:(strrchr(argv[0],'/')+1);
203 if ( strcasecmp( command_name, PLAYER_NAME ) == 0 ) {
204 is_player = FLAG_TRUE;
207 verbose = FLAG_FALSE;
208 is_send_rtm = FLAG_FALSE;
209 is_buffered = FLAG_TRUE;
212 static struct option long_options[] = {
213 {"no-buffered", 0, 0, 'b'},
214 {"send-seq", 0, 0, 100},
215 {"outdev", 1, 0, 'm'},
216 {"reset-mode", 1, 0, 'r'},
217 {"outfile", 1, 0, 'o'},
218 {"version", 0, 0, 'V'},
219 {"verbose", 0, 0, 'v'},
221 {"copyright", 1, 0, 'c'},
225 c = getopt_long(argc, argv, "Vvbo:m:r:h", long_options, &option_index );
226 if ( c == EOF ) break;
231 is_send_rtm = FLAG_TRUE;
235 is_buffered = FLAG_FALSE;
239 if ( outdev != NULL ) free(outdev);
240 outdev = (unsigned char *)malloc(sizeof(unsigned char)*strlen(optarg)+16);
241 strcpy( outdev, optarg );
245 reset_mode = atoi(optarg);
246 if ( reset_mode < 0 ) reset_mode = 0;
247 if ( reset_mode > 3 ) reset_mode = 0;
256 display_version(); /* version */
264 if ( copyright != NULL ) free(copyright);
265 copyright = (unsigned char *)malloc(sizeof(unsigned char)*strlen(optarg)+16);
266 strcpy( copyright, optarg );
270 if ( outfile != NULL ) free(outfile);
271 outfile = (unsigned char *)malloc(sizeof(unsigned char)*strlen(optarg)+16);
272 strcpy( outfile, optarg );
282 if ( optind >= argc ) {
283 fprintf(stderr, _("%s: No input filename is specified.\n"), command_name);
290 static void usage( void ) {
292 fprintf(stderr, "usage: %s [options] [rcp-filename]\n", command_name );
293 fprintf(stderr, _("Options:\n"));
295 if ( is_player == FLAG_TRUE ) {
296 fprintf(stderr, " -m, --outdev <devname> ");
297 fprintf(stderr, _("Output device name.\n"));
298 fprintf(stderr, " -r, --reset-mode <val> ");
299 fprintf(stderr, _("Send specified reset message after playing. \n"));
300 fprintf(stderr, " 0:GM 1:GS 2:SC88 3:XG\n");
303 if ( is_player == FLAG_FALSE ) {
304 fprintf(stderr, " -o, --outfile <filename> ");
305 fprintf(stderr, _("Output to file as <filename>.\n"));
306 fprintf(stderr, " --copyright <msg> ");
307 fprintf(stderr, _("Set copyright meta event as <msg>.\n"));
310 fprintf(stderr, " -v, --verbose ");
311 fprintf(stderr, _("Be verbose.\n"));
312 fprintf(stderr, " -V, --version ");
313 fprintf(stderr, _("Show version information.\n"));
314 fprintf(stderr, " -h, --help ");
315 fprintf(stderr, _("Show this help message.\n"));
320 static void display_version( void ) {
322 fprintf(stderr, "%s version ", command_name );
323 fprintf(stderr, VERSION_ID "\n");
324 if ( is_player == FLAG_TRUE ) {
325 fprintf(stderr, "tiny RCP player");
326 #ifdef HAVE_STED2_SUPPORT
327 fprintf(stderr, " <STed2 support>");
329 fprintf(stderr,"\n");
332 fprintf(stderr, "RCP to SMF converter\n");
333 fprintf(stderr, "Copyright 1999 by NAGANO Daisuke <breeze.nagano@nifty.ne.jp>\n");
334 fprintf(stderr, "\n");
335 fprintf(stderr, "This is free software; see the source for copying conditions.\n");
336 fprintf(stderr, "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n");
337 fprintf(stderr, "PARTICULAR PURPOSE.\n\n");