9 #define RITEBIN_EXT ".mrb"
30 usage(
const char *name)
32 static const char *
const usage_msg[] = {
34 "-c check syntax only",
35 "-o<outfile> place the output into <outfile>",
36 "-v print version number, then turn on verbose mode",
37 "-g produce debugging information",
38 "-B<symbol> binary <symbol> output in C language format",
39 "--verbose run at verbose mode",
40 "--version print the version",
41 "--copyright print the copyright",
44 const char *
const *p = usage_msg;
46 printf(
"Usage: %s [switches] programfile\n", name);
48 printf(
" %s\n", *p++);
59 infilelen = strlen(infile);
61 outfile = (
char*)
mrb_malloc(mrb, infilelen + extlen + 1);
62 memcpy(outfile, infile, infilelen + 1);
64 if ((p = strrchr(outfile,
'.')) == NULL)
65 p = outfile + infilelen;
66 memcpy(p, ext, extlen + 1);
76 static const struct mrbc_args args_zero = { 0 };
84 for (i=1; i<
argc; i++) {
85 if (argv[i][0] ==
'-') {
86 switch ((argv[i])[1]) {
89 fprintf(stderr,
"%s: an output file is already specified. (%s)\n",
93 if (argv[i][2] ==
'\0' && argv[i+1]) {
95 args->
outfile = get_outfilename(mrb, argv[i],
"");
98 args->
outfile = get_outfilename(mrb, argv[i] + 2,
"");
102 if (argv[i][2] ==
'\0' && argv[i+1]) {
110 fprintf(stderr,
"%s: function name is not specified.\n", args->
prog);
127 if (argv[i][1] ==
'\n') {
130 if (strcmp(argv[i] + 2,
"version") == 0) {
134 else if (strcmp(argv[i] + 2,
"verbose") == 0) {
138 else if (strcmp(argv[i] + 2,
"copyright") == 0) {
169 if (p->f) fclose(p->f);
175 p->f = fopen(fn,
"r");
177 fprintf(stderr,
"%s: cannot open program file. (%s)\n", args->
prog, fn);
189 char *input = args->
argv[args->
idx];
196 if (input[0] ==
'-' && input[1] ==
'\0') {
199 else if ((infile = fopen(input,
"r")) == NULL) {
200 fprintf(stderr,
"%s: cannot open program file. (%s)\n", args->
prog, input);
209 result = mrb_load_file_cxt(mrb, infile, c);
226 fprintf(stderr,
"%s: invalid C language symbol name\n", args->
initname);
230 n = mrb_dump_irep_binary(mrb, 0, args->
debug_info, wfp);
233 fprintf(stderr,
"%s: error in mrb dump (%s) %d\n", args->
prog, outfile, n);
247 fputs(
"Invalid mrb_state, exiting mrbc\n", stderr);
251 n = parse_args(mrb, argc, argv, &args);
258 fprintf(stderr,
"%s: no program file given\n", args.
prog);
266 fprintf(stderr,
"%s: output file should be specified to compile multiple files\n", args.
prog);
272 if (load_file(mrb, &args) == EXIT_FAILURE) {
277 printf(
"%s:%s:Syntax OK", args.
prog, argv[n]);
286 if (strcmp(
"-", args.
outfile) == 0) {
289 else if ((wfp = fopen(args.
outfile,
"wb")) == NULL) {
290 fprintf(stderr,
"%s: cannot open output file:(%s)\n", args.
prog, args.
outfile);
295 fprintf(stderr,
"Output file is required\n");
298 result = dump_file(mrb, wfp, args.
outfile, &args);