/* ROMorg (C)2001 B Y T E THE BIG O N E * * This program examines the "listinfo.txt" file (generated by Mame) and * outputs a custom tab-delimited file that can be loaded into Excel. * Rom files are sorted alphabetically, then sorted again by certain * criteria and then grouped with clones. * * * Written June 7, 2001 * By Darryl P. Hirschler * Ver 0.91 - Beta release. * Ver 1.0 - Initial release after bug fixes found through Mame version 057 * * Need to add these features: * - Make use of config file * * ROMorg c:\mame36 [options] */ #define BYTE unsigned char #define WORD unsigned int /*flags */ #define GAME 0x01 #define ORIGINAL 0x02 #define SORTNAME 0x04 #define SORTYEAR 0x10 #define SORTSIZE 0x20 // flag |= GAME; /* turn flag on */ // flag &= ~GAME; /* turn flag off */ #include #include #include #include #include #include #include void helpme(void); /* help screen */ void wr(int, BYTE[]); /* writes data to a file */ void dit(BYTE[]); /* do it */ void filereaderror(BYTE[]); int getachar(BYTE *); /* gets a char from a 4k buffer or from disk */ int getline(BYTE *); void perr(BYTE[]); /* print error message */ int match(BYTE[], BYTE[]); // string matching long int filesize(BYTE[]); // returns the filesize int join(BYTE *, BYTE *, BYTE *, BYTE *, BYTE *); // joins 4 strings, returns length BYTE *readkey(BYTE *, BYTE, BYTE); /* reads what is between keyopen and keyclos */ int keyfits(BYTE *, BYTE *, BYTE *); /* checks line against key */ int subkeyfits(BYTE *, BYTE *, BYTE *); /* looks for subkey in line*/ // these functions not used // int str_count_to(BYTE *, BYTE); /* counts characters in line until character c occurs */ // int strfind(BYTE *, BYTE *); // finds a string within a line int ii=4096; // 4k buffer index int fh_read; // file handle for read file BYTE flag=0x00; // flag byte BYTE keyopen='['; BYTE keyclos=']'; struct { BYTE dir[9]; BYTE name[256]; BYTE cloneof[9]; BYTE romof[9]; BYTE sampleof[9]; BYTE year[5]; BYTE manufacturer[256]; BYTE sample; BYTE screen; BYTE orientation; BYTE xresolution[5]; BYTE yresolution[5]; BYTE colors[33]; BYTE control[64]; long int romsize; long int samplesize; long int artworksize; } game[10000]; void main(BYTE argc, BYTE *argv[]) { int a; //counter if(argc<2 || argc>3) helpme(); if(argc==3) { /* checking for optional argument */ if (match(strupr(argv[2]),"-N")) flag |= SORTNAME; else if(match(strupr(argv[2]),"-Y")) flag |= SORTYEAR; else if(match(strupr(argv[2]),"-S")) flag |= SORTSIZE; else if(match(strupr(argv[2]),"-?")) helpme(); else helpme(); } else flag |= SORTNAME; printf("ROMorg...\n"); printf("args: "); for(a=1; allen) return(0); } subkey[c]=0; } if(line[a] == key[b]) { b++; // a match } else { b=0; c=0; } } return(strlen(subkey)); } int keyfits(BYTE *line, BYTE *key, BYTE *string) /* checks line against key */ { int llen; // length of line int klen; // length of key int slen; // length of subkey int a; int b=0; int c=0; int d=0; BYTE subkey[2048]=""; llen=strlen(line); klen=strlen(key); strset(string,0); for(a=0; allen) return(0); } string[c]=0; } if(line[a] == key[b]) b++; // still a match else return(0); } if(strlen(subkey)) { subkeyfits(line, subkey, string); } return(strlen(string)); } BYTE *readkey(BYTE *cline, BYTE keyop, BYTE keycl) /* reads what is between keyopen and keyclos */ { BYTE key[2048]=""; int clen; int a; int b=0; int kread=0; //cline="[ name %s]"; // for testing clen=strlen(cline); for(a=0; a0) { strcpy(line,temp); free(temp); } else bdata=0; } else { temp[count++] = bdata; temp[count]=0; if(g==0) return(0); if(count == 2048) perr("getline failed: line too long"); } } return(count); } int getachar(BYTE *p) /* Loads data in 4k blocks and returns one byte at a time. This speeds up disk reads a lot. */ { static char buf[4096]; static int count; if(ii==4096) { // printf("-"); if((count= read(fh_read, buf, 4096))== -1) return(-1); ii=0; } if(ii == count) return(0); *p=buf[ii++]; return(1); } void wr(int fh_write, BYTE stuff[]) { /* printf("%s\n", stuff); */ _write(fh_write,stuff, strlen(stuff)); _write(fh_write,"\n",1); } void filereaderror(BYTE rfilename[]) { printf("file read error: %s", rfilename); exit(1); } void perr(BYTE er[]) { printf("%s\n",er); exit(1); } void helpme(void) { printf("Usage: ROMorg mamepath [option]\n" "where:\n" " mamepath=the path where...\n" " listinfo.txt is stored,\n" " roms, samples, and artwork folders are\n" "\n" " option=\n" " -N Sort by game name(full name)\n" " -Y Sort by year\n" " -S Sort by size (rom+sample+artwork)\n" "\n" "Warning! ROMorg will die after 10,000 games. Email dphirschler@hotmail.com\n" "for an update or for the C source code.\n"); exit(0); }