2828#include "rom.h"
2929#include "utils.h"
3030#include "version.h"
31+ #include "json.h"
3132
3233int trace = 0 ;
3334int verbose = 0 ;
@@ -40,31 +41,33 @@ void print_version() {
4041void print_usage () {
4142 printf (PROJECT_NAME " v%s [%s] (%s)\n" , PROJECT_VER , BUILD_REF , BUILD_DATE );
4243 printf ("Usage:\n" );
43- printf (" orca [-vlzoOaA ] <recipe.xml>\n" );
44- printf ("\nConvert ROM recipes to a single file for usage with arcade cores.\nOptionally creates the associated support files.\n\n" );
44+ printf (" orca [-vlzoOaAJ ] <recipe.xml>\n" );
45+ printf ("\nConvert ROM recipes to a single file for usage with arcade cores.\nOptionally creates the associated metadata files.\n\n" );
4546 printf ("Options:\n" );
4647 printf (" -h\t\tthis help.\n" );
4748 printf (" -v\t\twhen it is the only parameter, display version information and exit. Otherwise, set Verbose on (default: off).\n" );
4849 printf (" -l\t\tlist recipe content instead of creating the ROM file.\n" );
4950 printf (" -z directory\tadd directory to include zip files. Directories added with -z have priority over the current dir.\n" );
5051 printf (" -o filename\tset the output ROM file name. Overrides the internal generation of the filename.\n" );
51- printf (" -O directory\tset the output directory. By default, ROM and ARC files are created in the current directory.\n" );
52- printf (" -a filename\tset the output ARC file name. Overrides the internal generation of the filename.\n" );
52+ printf (" -O directory\tset the output directory. By default, ROM and metadata files are created in the current directory.\n" );
53+ printf (" -a filename\tset the output metadata file name. Overrides the internal generation of the filename.\n" );
5354 printf (" -A\t\tcreate ARC file. This is done in addition to creating the ROM file.\n" );
54- printf (" -s\t\tskip ROM creation. This is useful if only the ARC file is required.\n" );
55+ printf (" -J\t\tcreate JSON file. This is done in addition to creating the ROM file.\n" );
56+ printf (" -s\t\tskip ROM creation. This is useful if only the metadata file is required.\n" );
5557}
5658
5759int main (int argc , char * * argv ) {
5860 char * rom_filename = NULL ;
5961 char * arc_filename = NULL ;
60- char * output_dir = NULL ;
62+ char * output_dir = NULL ;
6163 char * mra_filename ;
6264 char * mra_basename ;
6365 t_string_list * dirs = string_list_new (NULL );
6466 int i , res ;
65- int dump_mra = 0 ;
66- int dump_rom = -1 ;
67+ int dump_mra = 0 ;
68+ int dump_rom = -1 ;
6769 int create_arc = 0 ;
70+ int create_json = 0 ;
6871
6972 if (trace > 0 ) {
7073 for (i = 0 ; i < argc ; i ++ ) {
@@ -83,24 +86,21 @@ int main(int argc, char **argv) {
8386 // put ':' in the starting of the
8487 // string so that program can
8588 // distinguish between '?' and ':'
86- while ((opt = getopt (argc , argv , ":vlhAo :a:O:z:s" )) != -1 ) {
89+ while ((opt = getopt (argc , argv , ":vlhAJo :a:O:z:s" )) != -1 ) {
8790 switch (opt ) {
8891 case 'v' : verbose = -1 ; break ;
8992 case 'l' : dump_mra = -1 ; break ;
9093 case 'A' : create_arc = -1 ; break ;
94+ case 'J' : create_json = -1 ; break ;
9195 case 'z' : string_list_add (dirs , replace_backslash (optarg )); break ;
9296 case 'O' : output_dir = replace_backslash (strndup (optarg , 1024 )); break ;
9397 case 'o' : rom_filename = replace_backslash (strndup (optarg , 1024 )); break ;
9498 case 'a' : arc_filename = replace_backslash (strndup (optarg , 1024 )); break ;
9599 case 's' : dump_rom = 0 ; break ;
96100 case 'h' : print_usage (); exit (0 );
97- case ':' :
98- printf ("option needs a value\n" );
99- case '?' :
100- printf ("unknown option: %c\n" , optopt );
101- default :
102- print_usage ();
103- exit (-1 );
101+ case ':' : printf ("option needs a value\n" );
102+ case '?' : printf ("unknown option: %c\n" , optopt );
103+ default : print_usage (); exit (-1 );
104104 }
105105 }
106106
@@ -174,7 +174,6 @@ int main(int argc, char **argv) {
174174 if (trace > 0 ) {
175175 printf ("create_arc set...\n" );
176176 }
177-
178177 if (arc_filename ) {
179178 if (output_dir ) {
180179 arc_filename = get_filename (output_dir , get_basename (arc_filename , 1 ), "arc" );
@@ -195,6 +194,30 @@ int main(int argc, char **argv) {
195194 exit (EXIT_FAILURE );
196195 }
197196 arc_filename = NULL ;
197+
198+ }
199+
200+ if (create_json ) {
201+ if (trace > 0 ) {
202+ printf ("create_json set...\n" );
203+ }
204+
205+ char * arc_mra_filename = strdup (mra .name ? mra .name : mra_basename );
206+ make_fat32_compatible (arc_mra_filename , 1 );
207+ arc_filename = get_filename (output_dir ? output_dir : "." , arc_mra_filename , "json" );
208+ free (arc_mra_filename );
209+
210+ if (verbose ) {
211+ printf ("Creating JSON file %s\n" , arc_filename );
212+ }
213+ res = write_json (& mra , arc_filename );
214+ if (res != 0 ) {
215+ printf ("Writing JSON file failed with error code: %d\n. Retry without -J if you still want to create the ROM file.\n" , res );
216+ exit (EXIT_FAILURE );
217+ }
218+ arc_filename = NULL ;
219+
220+
198221 }
199222 if (dump_rom ) {
200223 if (trace > 0 ) {
0 commit comments