1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-15 21:27:43 +00:00

Fix FindInputFormat.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5577 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2012-03-05 19:28:22 +00:00
parent 3cef75b26c
commit 15a8a51aa2
2 changed files with 19 additions and 4 deletions

View File

@@ -33,6 +33,8 @@
#include <stdlib.h>
/* common */ /* common */
#include "fileid.h" #include "fileid.h"
@@ -78,14 +80,27 @@ static const FileId FormatTable[] = {
static int Compare (const void* Key, const void* Id)
/* Compare function for bsearch */
{
return strcmp (Key, ((const FileId*) Id)->Ext);
}
int FindInputFormat (const char* Name) int FindInputFormat (const char* Name)
/* Find an input format by name. The function returns a value less than zero /* Find an input format by name. The function returns a value less than zero
* if Name is not a known input format. * if Name is not a known input format.
*/ */
{ {
/* Search for the entry in the table */ /* Search for the entry in the table. */
const FileId* F = GetFileId (Name, FormatTable, const FileId* F = bsearch (Name,
sizeof (FormatTable) / sizeof (FormatTable[0])); FormatTable,
sizeof (FormatTable) / sizeof (FormatTable[0]),
sizeof (FormatTable[0]),
Compare);
/* Return the id or an error code */
return (F == 0)? -1 : F->Id; return (F == 0)? -1 : F->Id;
} }

View File

@@ -118,7 +118,7 @@ static void OptRead (const char* Opt, const char* Arg)
const char* Format = GetAttrVal (C, "format"); const char* Format = GetAttrVal (C, "format");
if (Format != 0) { if (Format != 0) {
IF = FindInputFormat (Format); IF = FindInputFormat (Format);
if (IF <= 0) { if (IF < 0) {
Error ("Unknown input format `%s'", Format); Error ("Unknown input format `%s'", Format);
} }
} }