1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-27 19:55:09 +00:00

Added cc65_seginfo_byname.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5190 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-17 15:26:40 +00:00
parent fa6b2e40fd
commit 9724ed5506
2 changed files with 81 additions and 1 deletions

View File

@ -1264,7 +1264,7 @@ static int CompareModInfoByName (const void* L, const void* R)
}
/*****************************************************************************/
/* Scope info */
/*****************************************************************************/
@ -3858,6 +3858,42 @@ static LineInfo* FindLineInfoByLine (Collection* LineInfos, cc65_line Line)
static SegInfo* FindSegInfoByName (Collection* SegInfos, const char* Name)
/* Find the SegInfo for a given segment name. The function returns the segment
* info or NULL if none was found.
*/
{
/* Do a binary search */
int Lo = 0;
int Hi = (int) CollCount (SegInfos) - 1;
while (Lo <= Hi) {
/* Mid of range */
int Cur = (Lo + Hi) / 2;
/* Get item */
SegInfo* CurItem = CollAt (SegInfos, Cur);
/* Compare */
int Res = strcmp (CurItem->Name, Name);
/* Found? */
if (Res < 0) {
Lo = Cur + 1;
} else if (Res > 0) {
Hi = Cur - 1;
} else {
/* Found */
return CurItem;
}
}
/* Not found */
return 0;
}
static int FindSymInfoByName (const Collection* SymInfos, const char* Name,
unsigned* Index)
/* Find the SymInfo for a given file name. The function returns true if the
@ -5197,6 +5233,42 @@ const cc65_segmentinfo* cc65_segmentinfo_byid (cc65_dbginfo Handle, unsigned Id)
const cc65_segmentinfo* cc65_segmentinfo_byname (cc65_dbginfo Handle,
const char* Name)
/* Return information about a segment with a specific name. The function
* returns NULL if no segment with this name exists and otherwise a
* cc65_segmentinfo structure with one entry that contains the requested
* information.
*/
{
DbgInfo* Info;
SegInfo* S;
cc65_segmentinfo* D;
/* Check the parameter */
assert (Handle != 0);
/* The handle is actually a pointer to a debug info struct */
Info = (DbgInfo*) Handle;
/* Search for the segment */
S = FindSegInfoByName (&Info->SegInfoByName, Name);
if (S == 0) {
return 0;
}
/* Allocate memory for the data structure returned to the caller */
D = new_cc65_segmentinfo (1);
/* Fill in the data */
CopySegInfo (D->data, S);
/* Return the result */
return D;
}
void cc65_free_segmentinfo (cc65_dbginfo Handle, const cc65_segmentinfo* Info)
/* Free a segment info record */
{

View File

@ -367,6 +367,14 @@ const cc65_segmentinfo* cc65_segmentinfo_byid (cc65_dbginfo handle, unsigned id)
* structure with one entry that contains the requested segment information.
*/
const cc65_segmentinfo* cc65_segmentinfo_byname (cc65_dbginfo handle,
const char* name);
/* Return information about a segment with a specific name. The function
* returns NULL if no segment with this name exists and otherwise a
* cc65_segmentinfo structure with one entry that contains the requested
* information.
*/
void cc65_free_segmentinfo (cc65_dbginfo handle, const cc65_segmentinfo* info);
/* Free a segment info record */