# HG changeset patch # User Matti Hamalainen # Date 1411602564 -10800 # Node ID 16cfbdf20eaf61cd3229372a21760b5f6858478c # Parent 8052423cf15151e989ee568849cae813240f1c80 Handle multiple files. diff -r 8052423cf151 -r 16cfbdf20eaf sidinfo.c --- a/sidinfo.c Thu Sep 25 02:35:31 2014 +0300 +++ b/sidinfo.c Thu Sep 25 02:49:24 2014 +0300 @@ -70,11 +70,11 @@ /* Options */ -char * optInFilename = NULL; BOOL optParsable = FALSE, optNoNamePrefix = FALSE, optHexadecimal = FALSE; uint32_t optFields = PSF_ALL; +int optNFiles = 0; /* Arguments @@ -222,20 +222,6 @@ } -BOOL argHandleFile(char *currArg) -{ - if (!optInFilename) - optInFilename = currArg; - else - { - THERR("Filename already specified on commandline!\n"); - return FALSE; - } - - return TRUE; -} - - typedef struct { char magic[PSID_MAGIC_LEN + 1]; // "PSID" / "RSID" magic identifier @@ -477,12 +463,36 @@ } +BOOL argHandleFile(char *filename) +{ + static PSIDHeader psid; + static FILE *inFile = NULL; + optNFiles++; + + if ((inFile = fopen(filename, "rb")) == NULL) + { + THERR("Could not open file '%s'.\n", filename); + return FALSE; + } + + // Read PSID data + if (siReadPSIDFile(inFile, &psid) != 0) + goto error; + + // Output + siPrintPSIDInformation(stdout, optParsable, optHexadecimal, optFields, filename, &psid); + + // Shutdown +error: + if (inFile != NULL) + fclose(inFile); + + return TRUE; +} + + int main(int argc, char *argv[]) { - FILE *inFile = NULL; - int ret = -1; - PSIDHeader psid; - // Initialize th_init("SIDInfo", "PSID/RSID information displayer", "0.2", NULL, NULL); th_verbosityLevel = 0; @@ -492,33 +502,11 @@ argHandleOpt, argHandleFile, FALSE)) return -1; - if (optInFilename == NULL) + if (optNFiles == 0) { argShowHelp(); - THERR("No filename specified.\n"); - goto error; - } - - // Try to open the file - if ((inFile = fopen(optInFilename, "rb")) == NULL) - { - THERR("Could not open file '%s'.\n", optInFilename); - goto error; + THERR("No filename(s) specified.\n"); } - // Read PSID data - if ((ret = siReadPSIDFile(inFile, &psid)) != 0) - goto error; - - // Output - siPrintPSIDInformation(stdout, optParsable, optHexadecimal, optFields, optInFilename, &psid); - - ret = 0; - - // Shutdown -error: - if (inFile != NULL) - fclose(inFile); - - return ret; + return 0; }