2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* objdata.c */
|
|
|
|
/* */
|
|
|
|
/* Handling object file data for the ar65 archiver */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2011-01-28 11:54:35 +00:00
|
|
|
/* (C) 1998-2011, Ullrich von Bassewitz */
|
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2000-08-01 15:05:48 +00:00
|
|
|
/* common */
|
|
|
|
#include "check.h"
|
|
|
|
#include "xmalloc.h"
|
2000-08-02 13:23:06 +00:00
|
|
|
|
2000-08-01 15:05:48 +00:00
|
|
|
/* ar65 */
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "objdata.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-28 11:54:35 +00:00
|
|
|
/* Collection with object files */
|
|
|
|
Collection ObjPool = STATIC_COLLECTION_INITIALIZER;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjData* NewObjData (void)
|
|
|
|
/* Allocate a new structure on the heap, insert it into the list, return it */
|
|
|
|
{
|
|
|
|
/* Allocate memory */
|
2000-06-14 09:38:07 +00:00
|
|
|
ObjData* O = xmalloc (sizeof (ObjData));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Initialize the data */
|
2003-05-25 17:57:50 +00:00
|
|
|
O->Name = 0;
|
2011-01-28 15:42:32 +00:00
|
|
|
|
2003-05-25 17:57:50 +00:00
|
|
|
O->Flags = 0;
|
|
|
|
O->MTime = 0;
|
|
|
|
O->Start = 0;
|
|
|
|
O->Size = 0;
|
2011-01-28 15:42:32 +00:00
|
|
|
|
|
|
|
O->Strings = EmptyCollection;
|
|
|
|
O->Exports = EmptyCollection;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-01-28 11:54:35 +00:00
|
|
|
/* Add it to the list */
|
|
|
|
CollAppend (&ObjPool, O);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Return the new entry */
|
|
|
|
return O;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FreeObjData (ObjData* O)
|
|
|
|
/* Free a complete struct */
|
|
|
|
{
|
2003-05-25 17:57:50 +00:00
|
|
|
unsigned I;
|
|
|
|
|
2000-06-14 09:38:07 +00:00
|
|
|
xfree (O->Name);
|
2011-01-28 15:42:32 +00:00
|
|
|
for (I = 0; I < CollCount (&O->Strings); ++I) {
|
|
|
|
xfree (CollAt (&O->Strings, I));
|
2003-05-25 17:57:50 +00:00
|
|
|
}
|
2011-01-28 15:42:32 +00:00
|
|
|
DoneCollection (&O->Strings);
|
|
|
|
DoneCollection (&O->Exports);
|
2000-06-14 09:38:07 +00:00
|
|
|
xfree (O);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-28 15:42:32 +00:00
|
|
|
void ClearObjData (ObjData* O)
|
|
|
|
/* Remove any data stored in O */
|
|
|
|
{
|
|
|
|
unsigned I;
|
|
|
|
xfree (O->Name);
|
|
|
|
O->Name = 0;
|
|
|
|
for (I = 0; I < CollCount (&O->Strings); ++I) {
|
|
|
|
xfree (CollAt (&O->Strings, I));
|
|
|
|
}
|
|
|
|
CollDeleteAll (&O->Strings);
|
|
|
|
CollDeleteAll (&O->Exports);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
ObjData* FindObjData (const char* Module)
|
|
|
|
/* Search for the module with the given name and return it. Return NULL if the
|
|
|
|
* module is not in the list.
|
|
|
|
*/
|
|
|
|
{
|
2011-01-28 11:54:35 +00:00
|
|
|
unsigned I;
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Hmm. Maybe we should hash the module names? */
|
2011-01-28 11:54:35 +00:00
|
|
|
for (I = 0; I < CollCount (&ObjPool); ++I) {
|
|
|
|
|
|
|
|
/* Get this object file */
|
|
|
|
ObjData* O = CollAtUnchecked (&ObjPool, I);
|
|
|
|
|
|
|
|
/* Did we find it? */
|
2000-05-28 13:40:48 +00:00
|
|
|
if (strcmp (O->Name, Module) == 0) {
|
|
|
|
return O;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DelObjData (const char* Module)
|
|
|
|
/* Delete the object module from the list */
|
|
|
|
{
|
2011-01-28 11:54:35 +00:00
|
|
|
unsigned I;
|
|
|
|
for (I = 0; I < CollCount (&ObjPool); ++I) {
|
|
|
|
|
|
|
|
/* Get this object file */
|
|
|
|
ObjData* O = CollAtUnchecked (&ObjPool, I);
|
|
|
|
|
|
|
|
/* Did we find it? */
|
|
|
|
if (strcmp (O->Name, Module) == 0) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Free the entry */
|
2011-01-28 11:54:35 +00:00
|
|
|
CollDelete (&ObjPool, I);
|
2000-05-28 13:40:48 +00:00
|
|
|
FreeObjData (O);
|
|
|
|
|
|
|
|
/* Done */
|
|
|
|
return;
|
2011-01-28 11:54:35 +00:00
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Not found! */
|
|
|
|
Warning ("Module `%s' not found in library", Module);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|