From: uz Date: Mon, 5 Mar 2012 19:28:22 +0000 (+0000) Subject: Fix FindInputFormat. X-Git-Tag: V2.14~486 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=15a8a51aa253792da5ea6440609d5c373ea09f4f;p=cc65 Fix FindInputFormat. git-svn-id: svn://svn.cc65.org/cc65/trunk@5577 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/sp65/input.c b/src/sp65/input.c index 735e4920c..a34e527e7 100644 --- a/src/sp65/input.c +++ b/src/sp65/input.c @@ -33,6 +33,8 @@ +#include + /* common */ #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) /* Find an input format by name. The function returns a value less than zero * if Name is not a known input format. */ { - /* Search for the entry in the table */ - const FileId* F = GetFileId (Name, FormatTable, - sizeof (FormatTable) / sizeof (FormatTable[0])); + /* Search for the entry in the table. */ + const FileId* F = bsearch (Name, + FormatTable, + sizeof (FormatTable) / sizeof (FormatTable[0]), + sizeof (FormatTable[0]), + Compare); + + /* Return the id or an error code */ return (F == 0)? -1 : F->Id; } diff --git a/src/sp65/main.c b/src/sp65/main.c index cd159a1b3..a49b69fbe 100644 --- a/src/sp65/main.c +++ b/src/sp65/main.c @@ -118,7 +118,7 @@ static void OptRead (const char* Opt, const char* Arg) const char* Format = GetAttrVal (C, "format"); if (Format != 0) { IF = FindInputFormat (Format); - if (IF <= 0) { + if (IF < 0) { Error ("Unknown input format `%s'", Format); } }