This commit was generated by cvs2svn to compensate for changes in r2,

which included commits to RCS files with non-trunk default branches.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2000-05-28 13:40:48 +00:00
parent 579491e8a4
commit 53dd513176
847 changed files with 91345 additions and 0 deletions

3
src/ar65/.cvsignore Normal file
View File

@@ -0,0 +1,3 @@
.depend
ar65

83
src/ar65/add.c Normal file
View File

@@ -0,0 +1,83 @@
/*****************************************************************************/
/* */
/* add.c */
/* */
/* Object file adding for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdlib.h>
#include "error.h"
#include "objfile.h"
#include "library.h"
#include "add.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void AddObjFiles (int argc, char* argv [])
/* Add object files to a library */
{
int I;
/* Check the argument count */
if (argc <= 0) {
Error ("No library name given");
}
if (argc <= 1) {
Error ("No object files to add");
}
/* Open the library, read the index */
LibOpen (argv [0], 0, 1);
/* Add the object files */
I = 1;
while (I < argc) {
ObjAdd (argv [I]);
++I;
}
/* Create a new library file and close the old one */
LibClose ();
/* Successful end */
exit (EXIT_SUCCESS);
}

58
src/ar65/add.h Normal file
View File

@@ -0,0 +1,58 @@
/*****************************************************************************/
/* */
/* add.h */
/* */
/* Object file adding for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef ADD_H
#define ADD_H
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void AddObjFiles (int argc, char* argv []);
/* Add object files to a library */
/* End of add.h */
#endif

84
src/ar65/del.c Normal file
View File

@@ -0,0 +1,84 @@
/*****************************************************************************/
/* */
/* del.h */
/* */
/* Object file deleting for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdlib.h>
#include "error.h"
#include "objdata.h"
#include "library.h"
#include "del.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void DelObjFiles (int argc, char* argv [])
/* Delete modules from a library */
{
int I;
/* Check the argument count */
if (argc <= 0) {
Error ("No library name given");
}
if (argc <= 1) {
Error ("No modules to delete");
}
/* Open the library, read the index */
LibOpen (argv [0], 1, 1);
/* Delete the modules */
I = 1;
while (I < argc) {
/* Delete the module from the list */
DelObjData (argv [I]);
++I;
}
/* Create a new library file and close the old one */
LibClose ();
/* Successful end */
exit (EXIT_SUCCESS);
}

58
src/ar65/del.h Normal file
View File

@@ -0,0 +1,58 @@
/*****************************************************************************/
/* */
/* del.h */
/* */
/* Object file deleting for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef DEL_H
#define DEL_H
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void DelObjFiles (int argc, char* argv []);
/* Delete modules from a library */
/* End of del.h */
#endif

106
src/ar65/error.c Normal file
View File

@@ -0,0 +1,106 @@
/*****************************************************************************/
/* */
/* global.c */
/* */
/* Error handling for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "error.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Messages for internal compiler errors */
const char _MsgCheckFailed [] =
"Check failed: `%s' (= %d), file `%s', line %u\n";
const char _MsgPrecondition [] =
"Precondition violated: `%s' (= %d), file `%s', line %u\n";
const char _MsgFail [] =
"%s, file `%s', line %u\n";
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void Warning (const char* Format, ...)
/* Print a warning message */
{
va_list ap;
va_start (ap, Format);
fprintf (stderr, "Warning: ");
vfprintf (stderr, Format, ap);
putc ('\n', stderr);
va_end (ap);
}
void Error (const char* Format, ...)
/* Print an error message and die */
{
va_list ap;
va_start (ap, Format);
fprintf (stderr, "Error: ");
vfprintf (stderr, Format, ap);
putc ('\n', stderr);
va_end (ap);
exit (EXIT_FAILURE);
}
void Internal (const char* Format, ...)
/* Print an internal error message and die */
{
va_list ap;
va_start (ap, Format);
fprintf (stderr, "Internal error: ");
vfprintf (stderr, Format, ap);
putc ('\n', stderr);
va_end (ap);
exit (EXIT_FAILURE);
}

87
src/ar65/error.h Normal file
View File

@@ -0,0 +1,87 @@
/*****************************************************************************/
/* */
/* global.h */
/* */
/* Error handling for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef ERROR_H
#define ERROR_H
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Messages for internal compiler errors */
extern const char _MsgCheckFailed [];
extern const char _MsgPrecondition [];
extern const char _MsgFail [];
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void Warning (const char* Format, ...);
/* Print a warning message */
void Error (const char* Format, ...);
/* Print an error message and die */
void Internal (const char* Format, ...);
/* Print an internal error message and die */
#define CHECK(c) \
if (!(c)) \
Internal (_MsgCheckFailed, #c, c, __FILE__, __LINE__)
#define PRECONDITION(c) \
if (!(c)) \
Internal (_MsgPrecondition, #c, c, __FILE__, __LINE__)
#define FAIL(s) \
Internal (_MsgFail, s, __FILE__, __LINE__)
/* End of error.h */
#endif

149
src/ar65/exports.c Normal file
View File

@@ -0,0 +1,149 @@
/*****************************************************************************/
/* */
/* exports.c */
/* */
/* Duplicate export checking for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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>
#include "../common/hashstr.h"
#include "mem.h"
#include "error.h"
#include "objdata.h"
#include "exports.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* A hash table entry */
typedef struct HashEntry_ HashEntry;
struct HashEntry_ {
HashEntry* Next; /* Next in list */
unsigned Module; /* Module index */
char Name [1]; /* Name of identifier */
};
/* Hash table */
#define HASHTAB_SIZE 4783
static HashEntry* HashTab [HASHTAB_SIZE];
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static HashEntry* NewHashEntry (const char* Name, unsigned Module)
/* Create and return a new hash entry */
{
/* Get the length of the name */
unsigned Len = strlen (Name);
/* Get memory for the struct */
HashEntry* H = Xmalloc (sizeof (HashEntry) + Len);
/* Initialize the fields and return it */
H->Next = 0;
H->Module = Module;
memcpy (H->Name, Name, Len);
H->Name [Len] = '\0';
return H;
}
void ExpInsert (const char* Name, unsigned Module)
/* Insert an exported identifier and check if it's already in the list */
{
HashEntry* L;
/* Create a hash value for the given name */
unsigned HashVal = HashStr (Name) % HASHTAB_SIZE;
/* Create a new hash entry */
HashEntry* H = NewHashEntry (Name, Module);
/* Search through the list in that slot and print matching duplicates */
if (HashTab [HashVal] == 0) {
/* The slot is empty */
HashTab [HashVal] = H;
return;
}
L = HashTab [HashVal];
while (1) {
if (strcmp (L->Name, Name) == 0) {
/* Duplicate entry */
Warning ("External symbol `%s' in module `%s' is duplicated in "
"module `%s'",
Name, GetObjName (L->Module), GetObjName (Module));
}
if (L->Next == 0) {
break;
} else {
L = L->Next;
}
}
L->Next = H;
}
int ExpFind (const char* Name)
/* Check for an identifier in the list. Return -1 if not found, otherwise
* return the number of the module, that exports the identifer.
*/
{
/* Get a pointer to the list with the symbols hash value */
HashEntry* L = HashTab [HashStr (Name) % HASHTAB_SIZE];
while (L) {
/* Search through the list in that slot */
if (strcmp (L->Name, Name) == 0) {
/* Entry found */
return L->Module;
}
L = L->Next;
}
/* Not found */
return -1;
}

62
src/ar65/exports.h Normal file
View File

@@ -0,0 +1,62 @@
/*****************************************************************************/
/* */
/* exports.h */
/* */
/* Duplicate export checking for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef EXPORTS_H
#define EXPORTS_H
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void ExpInsert (const char* Name, unsigned Module);
/* Insert an exported identifier and check if it's already in the list */
int ExpFind (const char* Name);
/* Check for an identifier in the list. Return -1 if not found, otherwise
* return the number of the module, that exports the identifer.
*/
/* End of exports.h */
#endif

83
src/ar65/extract.c Normal file
View File

@@ -0,0 +1,83 @@
/*****************************************************************************/
/* */
/* extract.c */
/* */
/* Object file extraction for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdlib.h>
#include "mem.h"
#include "error.h"
#include "objfile.h"
#include "library.h"
#include "extract.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void ExtractObjFiles (int argc, char* argv [])
/* Extract object files from a library */
{
int I;
/* Check the argument count */
if (argc <= 0) {
Error ("No library name given");
}
if (argc <= 1) {
Error ("No object files to add");
}
/* Open the library, read the index */
LibOpen (argv [0], 1, 0);
/* Extract the object files */
I = 1;
while (I < argc) {
ObjExtract (argv [I]);
++I;
}
/* Create a new library file and close the old one */
LibClose ();
/* Successful end */
exit (EXIT_SUCCESS);
}

58
src/ar65/extract.h Normal file
View File

@@ -0,0 +1,58 @@
/*****************************************************************************/
/* */
/* extract.h */
/* */
/* Object file extraction for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef EXTRACT_H
#define EXTRACT_H
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void ExtractObjFiles (int argc, char* argv []);
/* Extract object files from a library */
/* End of extract.h */
#endif

210
src/ar65/fileio.c Normal file
View File

@@ -0,0 +1,210 @@
/*****************************************************************************/
/* */
/* fileio.c */
/* */
/* File I/O for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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>
#include "error.h"
#include "mem.h"
#include "fileio.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void Write8 (FILE* F, unsigned char Val)
/* Write an 8 bit value to the file */
{
if (putc (Val, F) == EOF) {
Error ("Write error (disk full?)");
}
}
void Write16 (FILE* F, unsigned Val)
/* Write a 16 bit value to the file */
{
Write8 (F, (unsigned char) Val);
Write8 (F, (unsigned char) (Val >> 8));
}
void Write32 (FILE* F, unsigned long Val)
/* Write a 32 bit value to the file */
{
Write8 (F, (unsigned char) Val);
Write8 (F, (unsigned char) (Val >> 8));
Write8 (F, (unsigned char) (Val >> 16));
Write8 (F, (unsigned char) (Val >> 24));
}
void WriteStr (FILE* F, const char* S)
/* Write a string to the file */
{
unsigned Len = strlen (S);
if (Len > 255) {
Internal ("String too long");
}
Write8 (F, (unsigned char) Len);
WriteData (F, S, Len);
}
void WriteData (FILE* F, const void* Data, unsigned Size)
/* Write data to the file */
{
if (fwrite (Data, 1, Size, F) != Size) {
Error ("Write error (disk full?)");
}
}
unsigned Read8 (FILE* F)
/* Read an 8 bit value from the file */
{
int C = getc (F);
if (C == EOF) {
Error ("Read error (file corrupt?)");
}
return C;
}
unsigned Read16 (FILE* F)
/* Read a 16 bit value from the file */
{
unsigned Lo = Read8 (F);
unsigned Hi = Read8 (F);
return (Hi << 8) | Lo;
}
unsigned long Read32 (FILE* F)
/* Read a 32 bit value from the file */
{
unsigned long Lo = Read16 (F);
unsigned long Hi = Read16 (F);
return (Hi << 16) | Lo;
}
char* ReadStr (FILE* F)
/* Read a string from the file (the memory will be malloc'ed) */
{
/* Read the length byte */
unsigned Len = Read8 (F);
/* Allocate memory and read the string itself */
char* S = Xmalloc (Len + 1);
ReadData (F, S, Len);
/* Terminate the string and return it */
S [Len] = '\0';
return S;
}
void* ReadData (FILE* F, void* Data, unsigned Size)
/* Read data from the file */
{
if (fread (Data, 1, Size, F) != Size) {
Error ("Read error (file corrupt?)");
}
return Data;
}

88
src/ar65/fileio.h Normal file
View File

@@ -0,0 +1,88 @@
/*****************************************************************************/
/* */
/* fileio.h */
/* */
/* File I/O for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef FILEIO_H
#define FILEIO_H
#include <stdio.h>
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void Write8 (FILE* F, unsigned char Val);
/* Write an 8 bit value to the file */
void Write16 (FILE* F, unsigned Val);
/* Write a 16 bit value to the file */
void Write32 (FILE* F, unsigned long Val);
/* Write a 32 bit value to the file */
void WriteStr (FILE* F, const char* S);
/* Write a string to the file */
void WriteData (FILE* F, const void* Data, unsigned Size);
/* Write data to the file */
unsigned Read8 (FILE* F);
/* Read an 8 bit value from the file */
unsigned Read16 (FILE* F);
/* Read a 16 bit value from the file */
unsigned long Read32 (FILE* F);
/* Read a 32 bit value from the file */
char* ReadStr (FILE* F);
/* Read a string from the file (the memory will be malloc'ed) */
void* ReadData (FILE* F, void* Data, unsigned Size);
/* Read data from the file */
/* End of fileio.h */
#endif

51
src/ar65/global.c Normal file
View File

@@ -0,0 +1,51 @@
/*****************************************************************************/
/* */
/* global.c */
/* */
/* Global variables for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 "global.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
const char* ProgName = "ar65"; /* Program name */
int Verbose = 0; /* Verbose operation flag */

58
src/ar65/global.h Normal file
View File

@@ -0,0 +1,58 @@
/*****************************************************************************/
/* */
/* global.h */
/* */
/* Global variables for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef GLOBAL_H
#define GLOBAL_H
/*****************************************************************************/
/* Data */
/*****************************************************************************/
extern const char* ProgName; /* Program name */
extern int Verbose; /* Verbose operation flag */
/* End of global.h */
#endif

470
src/ar65/library.c Normal file
View File

@@ -0,0 +1,470 @@
/*****************************************************************************/
/* */
/* library.c */
/* */
/* Library data structures and helpers for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdio.h>
#include <string.h>
#include <errno.h>
#include "../common/libdefs.h"
#include "../common/symdefs.h"
#include "../common/exprdefs.h"
#include "../common/filepos.h"
#include "../common/bitops.h"
#include "mem.h"
#include "error.h"
#include "global.h"
#include "fileio.h"
#include "objdata.h"
#include "exports.h"
#include "library.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* File descriptor for the library file */
FILE* NewLib = 0;
static FILE* Lib = 0;
static const char* LibName = 0;
/* The library header */
static LibHeader Header = {
LIB_MAGIC,
LIB_VERSION
};
/*****************************************************************************/
/* Writing file data structures */
/*****************************************************************************/
static void ReadHeader (void)
/* Read the header of a library file */
{
/* Seek to position zero */
fseek (Lib, 0, SEEK_SET);
/* Read the header fields, checking magic and version */
Header.Magic = Read32 (Lib);
if (Header.Magic != LIB_MAGIC) {
Error ("`%s' is not a valid library file", LibName);
}
Header.Version = Read16 (Lib);
if (Header.Version != LIB_VERSION) {
Error ("Wrong data version in `%s'", LibName);
}
Header.Flags = Read16 (Lib);
Header.IndexOffs = Read32 (Lib);
}
static void ReadIndexEntry (void)
/* Read one entry in the index */
{
/* Create a new entry and insert it into the list */
ObjData* O = NewObjData ();
/* Module name/flags/MTime/Start/Size */
O->Name = ReadStr (Lib);
O->Flags = Read16 (Lib);
O->MTime = Read32 (Lib);
O->Start = Read32 (Lib);
O->Size = Read32 (Lib);
/* Exports */
O->ExportSize = Read16 (Lib);
O->Exports = Xmalloc (O->ExportSize);
ReadData (Lib, O->Exports, O->ExportSize);
/* Imports */
O->ImportSize = Read16 (Lib);
O->Imports = Xmalloc (O->ImportSize);
ReadData (Lib, O->Imports, O->ImportSize);
}
static void ReadIndex (void)
/* Read the index of a library file */
{
unsigned Count;
/* Seek to the start of the index */
fseek (Lib, Header.IndexOffs, SEEK_SET);
/* Read the object file count and calculate the cross ref size */
Count = Read16 (Lib);
/* Read all entries in the index */
while (Count--) {
ReadIndexEntry ();
}
}
/*****************************************************************************/
/* Writing file data structures */
/*****************************************************************************/
static void WriteHeader (void)
/* Write the header to the library file */
{
/* Seek to position zero */
fseek (NewLib, 0, SEEK_SET);
/* Write the header fields */
Write32 (NewLib, Header.Magic);
Write16 (NewLib, Header.Version);
Write16 (NewLib, Header.Flags);
Write32 (NewLib, Header.IndexOffs);
}
static void WriteIndexEntry (ObjData* O)
/* Write one index entry */
{
/* Module name/flags/MTime/start/size */
WriteStr (NewLib, O->Name);
Write16 (NewLib, O->Flags & ~OBJ_HAVEDATA);
Write32 (NewLib, O->MTime);
Write32 (NewLib, O->Start);
Write32 (NewLib, O->Size);
/* Exports */
Write16 (NewLib, O->ExportSize);
WriteData (NewLib, O->Exports, O->ExportSize);
/* Imports */
Write16 (NewLib, O->ImportSize);
WriteData (NewLib, O->Imports, O->ImportSize);
}
static void WriteIndex (void)
/* Write the index of a library file */
{
ObjData* O;
/* Sync I/O in case the last operation was a read */
fseek (NewLib, 0, SEEK_CUR);
/* Remember the current offset in the header */
Header.IndexOffs = ftell (NewLib);
/* Write the object file count */
Write16 (NewLib, ObjCount);
/* Write the object files */
O = ObjRoot;
while (O) {
WriteIndexEntry (O);
O = O->Next;
}
}
/*****************************************************************************/
/* High level stuff */
/*****************************************************************************/
void LibOpen (const char* Name, int MustExist, int NeedTemp)
/* Open an existing library and a temporary copy. If MustExist is true, the
* old library is expected to exist. If NeedTemp is true, a temporary library
* is created.
*/
{
/* Remember the name */
LibName = StrDup (Name);
/* Open the existing library for reading */
Lib = fopen (Name, "rb");
if (Lib == 0) {
/* File does not exist */
if (MustExist) {
Error ("Library `%s' does not exist", Name);
} else {
Warning ("Library `%s' not found - will be created", Name);
}
} else {
/* We have an existing file: Read the header */
ReadHeader ();
/* Now read the existing index */
ReadIndex ();
}
if (NeedTemp) {
/* Create the temporary library */
NewLib = tmpfile ();
if (NewLib == 0) {
Error ("Cannot create temporary file: %s", strerror (errno));
}
/* Write a dummy header to the temp file */
WriteHeader ();
}
}
unsigned long LibCopyTo (FILE* F, unsigned long Bytes)
/* Copy data from F to the temp library file, return the start position in
* the temporary library file.
*/
{
unsigned char Buf [4096];
/* Remember the position */
unsigned long Pos = ftell (NewLib);
/* Copy loop */
while (Bytes) {
unsigned Count = (Bytes > sizeof (Buf))? sizeof (Buf) : Bytes;
ReadData (F, Buf, Count);
WriteData (NewLib, Buf, Count);
Bytes -= Count;
}
/* Return the start position */
return Pos;
}
void LibCopyFrom (unsigned long Pos, unsigned long Bytes, FILE* F)
/* Copy data from the library file into another file */
{
unsigned char Buf [4096];
/* Seek to the correct position */
fseek (Lib, Pos, SEEK_SET);
/* Copy loop */
while (Bytes) {
unsigned Count = (Bytes > sizeof (Buf))? sizeof (Buf) : Bytes;
ReadData (Lib, Buf, Count);
WriteData (F, Buf, Count);
Bytes -= Count;
}
}
static void SkipExpr (unsigned char** Buf)
/* Skip an expression in Buf */
{
/* Get the operation and skip it */
unsigned char Op = **Buf;
++(*Buf);
/* Filter leaf nodes */
switch (Op) {
case EXPR_NULL:
return;
case EXPR_LITERAL:
/* 32 bit literal value */
*Buf += 4;
return;
case EXPR_SYMBOL:
/* 16 bit symbol index */
*Buf += 2;
return;
case EXPR_SEGMENT:
/* 8 bit segment number */
*Buf += 1;
return;
}
/* What's left are unary and binary nodes */
SkipExpr (Buf); /* Skip left */
SkipExpr (Buf); /* Skip right */
}
static void LibCheckExports (ObjData* O)
/* Insert all exports from the given object file into the global list
* checking for duplicates.
*/
{
char Name [256];
/* Get a pointer to the buffer */
unsigned char* Exports = O->Exports;
/* First two bytes are export count */
unsigned Lo = *Exports++;
unsigned Hi = *Exports++;
unsigned Count = (Hi << 8) + Lo;
/* Read the exports */
if (Verbose > 1) {
printf ("Module `%s' (%u exports):\n", O->Name, Count);
}
while (Count--) {
unsigned char Len;
/* Get the export tag */
unsigned char Tag = *Exports++;
/* Next thing is name of symbol */
Len = *Exports++;
memcpy (Name, Exports, Len);
Name [Len] = '\0';
Exports += Len;
/* Skip value of symbol */
if (Tag & EXP_EXPR) {
/* Expression tree */
SkipExpr (&Exports);
} else {
/* Constant 32 bit value */
Exports += 4;
}
/* Skip the position */
Exports += POS_SIZE;
/* Insert the name into the hash table */
if (Verbose > 1) {
printf (" %s\n", Name);
}
ExpInsert (Name, O->Index);
}
}
void LibClose (void)
/* Write remaining data, close both files and copy the temp file to the old
* filename
*/
{
/* Do we have a temporary library? */
if (NewLib) {
unsigned I;
unsigned char Buf [4096];
size_t Count;
/* Index the object files and make an array containing the objects */
MakeObjPool ();
/* Walk through the object file list, inserting exports into the
* export list checking for duplicates. Copy any data that is still
* in the old library into the new one.
*/
for (I = 0; I < ObjCount; ++I) {
/* Get a pointer to the object */
ObjData* O = ObjPool [I];
/* Check exports, make global export table */
LibCheckExports (O);
/* Copy data if needed */
if ((O->Flags & OBJ_HAVEDATA) == 0) {
/* Data is still in the old library */
fseek (Lib, O->Start, SEEK_SET);
O->Start = ftell (NewLib);
LibCopyTo (Lib, O->Size);
O->Flags |= OBJ_HAVEDATA;
}
}
/* Write the index */
WriteIndex ();
/* Write the updated header */
WriteHeader ();
/* Close the file */
if (Lib && fclose (Lib) != 0) {
Error ("Error closing library: %s", strerror (errno));
}
/* Reopen the library and truncate it */
Lib = fopen (LibName, "wb");
if (Lib == 0) {
Error ("Cannot open library `%s' for writing: %s",
LibName, strerror (errno));
}
/* Copy the new library to the new one */
fseek (NewLib, 0, SEEK_SET);
while ((Count = fread (Buf, 1, sizeof (Buf), NewLib)) != 0) {
if (fwrite (Buf, 1, Count, Lib) != Count) {
Error ("Cannot write to `%s': %s", LibName, strerror (errno));
}
}
}
/* Close both files */
if (Lib && fclose (Lib) != 0) {
Error ("Problem closing `%s': %s", LibName, strerror (errno));
}
if (NewLib && fclose (NewLib) != 0) {
Error ("Problem closing temporary library file: %s", strerror (errno));
}
}

88
src/ar65/library.h Normal file
View File

@@ -0,0 +1,88 @@
/*****************************************************************************/
/* */
/* library.h */
/* */
/* Library data structures and helpers for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef LIBRARY_H
#define LIBRARY_H
#include <stdio.h>
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* File descriptor for the new library file */
extern FILE* NewLib;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void LibOpen (const char* Name, int MustExist, int NeedTemp);
/* Open an existing library and a temporary copy. If MustExist is true, the
* old library is expected to exist. If NeedTemp is true, a temporary library
* is created.
*/
unsigned long LibCopyTo (FILE* F, unsigned long Bytes);
/* Copy data from F to the temp library file, return the start position in
* the temporary library file.
*/
void LibCopyFrom (unsigned long Pos, unsigned long Bytes, FILE* F);
/* Copy data from the library file into another file */
void LibClose (void);
/* Write remaining data, close both files and copy the temp file to the old
* filename
*/
/* End of library.h */
#endif

83
src/ar65/list.c Normal file
View File

@@ -0,0 +1,83 @@
/*****************************************************************************/
/* */
/* list.c */
/* */
/* Module listing for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdio.h>
#include <stdlib.h>
#include "error.h"
#include "objdata.h"
#include "library.h"
#include "list.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void ListObjFiles (int argc, char* argv [])
/* List modules in a library */
{
ObjData* O;
/* Check the argument count */
if (argc <= 0) {
Error ("No library name given");
}
if (argc > 2) {
Error ("Too many arguments");
}
/* Open the library, read the index */
LibOpen (argv [0], 1, 0);
/* List the modules */
O = ObjRoot;
while (O) {
printf ("%s\n", O->Name);
O = O->Next;
}
/* Create a new library file and close the old one */
LibClose ();
/* Successful end */
exit (EXIT_SUCCESS);
}

58
src/ar65/list.h Normal file
View File

@@ -0,0 +1,58 @@
/*****************************************************************************/
/* */
/* list.h */
/* */
/* Module listing for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef LIST_H
#define LIST_H
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void ListObjFiles (int argc, char* argv []);
/* List modules in a library */
/* End of list.h */
#endif

140
src/ar65/main.c Normal file
View File

@@ -0,0 +1,140 @@
/*****************************************************************************/
/* */
/* main.c */
/* */
/* Main program for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../common/version.h"
#include "global.h"
#include "error.h"
#include "mem.h"
#include "add.h"
#include "del.h"
#include "list.h"
#include "extract.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static void Usage (void)
/* Print usage information and exit */
{
fprintf (stderr,
"Usage: %s <operation> lib file|module ...\n"
"Operation is one of:\n"
"\ta\tAdd modules\n"
"\td\tDelete modules\n"
"\tl\tList library contents\n"
"\tx\tExtract modules\n"
"\tV\tPrint the archiver version\n",
ProgName);
exit (EXIT_FAILURE);
}
int main (int argc, char* argv [])
/* Assembler main program */
{
int I;
/* We must have a file name */
if (argc < 2) {
Usage ();
}
/* Check the parameters */
I = 1;
while (I < argc) {
/* Get the argument */
const char* Arg = argv [I];
/* Check for an option */
if (strlen (Arg) != 1) {
Usage ();
}
switch (Arg [0]) {
case 'a':
AddObjFiles (argc - I - 1, &argv [I+1]);
break;
case 'd':
DelObjFiles (argc - I - 1, &argv [I+1]);
break;
case 'l':
ListObjFiles (argc - I - 1, &argv [I+1]);
break;
case 'v':
++Verbose;
break;
case 'x':
ExtractObjFiles (argc - I - 1, &argv [I+1]);
break;
case 'V':
fprintf (stderr,
"ar65 V%u.%u.%u - (C) Copyright 1998-1999 Ullrich von Bassewitz\n",
VER_MAJOR, VER_MINOR, VER_PATCH);
break;
default:
fprintf (stderr, "Unknown option: %s\n", Arg);
Usage ();
}
/* Next argument */
++I;
}
/* Return an apropriate exit code */
return EXIT_SUCCESS;
}

56
src/ar65/make/gcc.mak Normal file
View File

@@ -0,0 +1,56 @@
#
# gcc Makefile for ar65
#
CFLAGS = -g -O2 -Wall
CC = gcc
LDFLAGS =
OBJS = add.o \
del.o \
error.o \
exports.o \
extract.o \
fileio.o \
global.o \
library.o \
list.o \
main.o \
mem.o \
objdata.o \
objfile.o
LIBS = ../common/common.a
EXECS = ar65
.PHONY: all
ifeq (.depend,$(wildcard .depend))
all : $(EXECS)
include .depend
else
all: depend
@$(MAKE) -f make/gcc.mak all
endif
ar65: $(OBJS) $(LIBS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
rm -f *~ core
zap: clean
rm -f *.o $(EXECS) .depend
# ------------------------------------------------------------------------------
# Make the dependencies
.PHONY: depend dep
depend dep: $(OBJS:.o=.c)
@echo "Creating dependency information"
$(CC) -MM $^ > .depend

123
src/ar65/make/watcom.mak Normal file
View File

@@ -0,0 +1,123 @@
#
# ar65 Makefile for the Watcom compiler
#
# ------------------------------------------------------------------------------
# Generic stuff
.AUTODEPEND
.SUFFIXES .ASM .C .CC .CPP
.SWAP
AR = WLIB
LD = WLINK
!if !$d(TARGET)
!if $d(__OS2__)
TARGET = OS2
!else
TARGET = NT
!endif
!endif
# target specific macros.
!if $(TARGET)==OS2
# --------------------- OS2 ---------------------
SYSTEM = os2v2
CC = WCC386
CCCFG = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
!elif $(TARGET)==DOS32
# -------------------- DOS4G --------------------
SYSTEM = dos4g
CC = WCC386
CCCFG = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
!elif $(TARGET)==DOS
# --------------------- DOS ---------------------
SYSTEM = dos
CC = WCC
CCCFG = -bt=$(TARGET) -d1 -onatx -zp2 -2 -ml -zq -w2
!elif $(TARGET)==NT
# --------------------- NT ----------------------
SYSTEM = nt
CC = WCC386
CCCFG = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
!else
!error
!endif
# ------------------------------------------------------------------------------
# Implicit rules
.c.obj:
$(CC) $(CCCFG) $<
# ------------------------------------------------------------------------------
# All library OBJ files
OBJS = add.obj \
del.obj \
error.obj \
exports.obj \
extract.obj \
fileio.obj \
global.obj \
library.obj \
list.obj \
main.obj \
mem.obj \
objdata.obj \
objfile.obj
LIBS = ..\common\common.lib
# ------------------------------------------------------------------------------
# Main targets
all: ar65
ar65: ar65.exe
# ------------------------------------------------------------------------------
# Other targets
ar65.exe: $(OBJS) $(LIBS)
$(LD) system $(SYSTEM) @&&|
DEBUG ALL
OPTION QUIET
NAME $<
FILE add.obj
FILE del.obj
FILE error.obj
FILE exports.obj
FILE extract.obj
FILE fileio.obj
FILE global.obj
FILE library.obj
FILE list.obj
FILE main.obj
FILE mem.obj
FILE objdata.obj
FILE objfile.obj
LIBRARY ..\common\common.lib
|
clean:
@if exist *.obj del *.obj
@if exist ar65.exe del ar65.exe
strip:
@-wstrip ar65.exe

84
src/ar65/mem.c Normal file
View File

@@ -0,0 +1,84 @@
/*****************************************************************************/
/* */
/* mem.c */
/* */
/* Memory allocation for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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 <stdlib.h>
#include <string.h>
#include "error.h"
#include "mem.h"
/*****************************************************************************/
/* code */
/*****************************************************************************/
void* Xmalloc (size_t size)
/* Allocate memory, check for out of memory condition. Do some debugging */
{
void* p;
p = malloc (size);
if (p == 0 && size != 0) {
Error ("Out of memory");
}
/* Return a pointer to the block */
return p;
}
void Xfree (const void* block)
/* Free the block, do some debugging */
{
free ((void*) block);
}
char* StrDup (const char* s)
/* Duplicate a string on the heap. The function checks for out of memory */
{
unsigned len;
len = strlen (s) + 1;
return memcpy (Xmalloc (len), s, len);
}

67
src/ar65/mem.h Normal file
View File

@@ -0,0 +1,67 @@
/*****************************************************************************/
/* */
/* mem.h */
/* */
/* Memory allocation for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef MEM_H
#define MEM_H
#include <stddef.h>
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void* Xmalloc (size_t size);
/* Allocate memory, check for out of memory condition. Do some debugging */
void Xfree (const void* block);
/* Free the block, do some debugging */
char* StrDup (const char* s);
/* Duplicate a string on the heap. The function checks for out of memory */
/* End of mem.h */
#endif

207
src/ar65/objdata.c Normal file
View File

@@ -0,0 +1,207 @@
/*****************************************************************************/
/* */
/* objdata.c */
/* */
/* Handling object file data for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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>
#include "mem.h"
#include "error.h"
#include "objdata.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Object data list management */
unsigned ObjCount = 0; /* Count of object files in the list */
ObjData* ObjRoot = 0; /* List of object files */
ObjData* ObjLast = 0; /* Last entry in list */
ObjData** ObjPool = 0; /* Object files as array */
/*****************************************************************************/
/* Code */
/*****************************************************************************/
ObjData* NewObjData (void)
/* Allocate a new structure on the heap, insert it into the list, return it */
{
/* Allocate memory */
ObjData* O = Xmalloc (sizeof (ObjData));
/* Initialize the data */
O->Next = 0;
O->Name = 0;
O->Index = ~0;
O->Flags = 0;
O->MTime = 0;
O->Start = 0;
O->Size = 0;
O->ImportSize = 0;
O->Imports = 0;
O->ExportSize = 0;
O->Exports = 0;
/* Link it into the list */
if (ObjLast) {
ObjLast->Next = O;
ObjLast = O;
} else {
/* First entry */
ObjRoot = ObjLast = O;
}
/* One object file more now */
++ObjCount;
/* Return the new entry */
return O;
}
void FreeObjData (ObjData* O)
/* Free a complete struct */
{
Xfree (O->Name);
Xfree (O->Imports);
Xfree (O->Exports);
Xfree (O);
}
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.
*/
{
/* Hmm. Maybe we should hash the module names? */
ObjData* O = ObjRoot;
while (O) {
if (strcmp (O->Name, Module) == 0) {
return O;
}
O = O->Next;
}
return 0;
}
void DelObjData (const char* Module)
/* Delete the object module from the list */
{
ObjData* O = ObjRoot;
ObjData* Last = 0;
while (O) {
if (strcmp (O->Name, Module) == 0) {
/* Found the module, remove it from the list */
if (Last == 0) {
/* This was the first entry in the list */
ObjRoot = O->Next;
} else {
Last->Next = O->Next;
}
if (ObjLast == O) {
/* O was the last object in the list */
ObjLast = Last;
}
--ObjCount;
/* Free the entry */
FreeObjData (O);
/* Done */
return;
}
Last = O;
O = O->Next;
}
/* Not found! */
Warning ("Module `%s' not found in library", Module);
}
void MakeObjPool (void)
/* Allocate memory, index the entries and make the ObjPool valid */
{
ObjData* O;
unsigned Index;
/* Allocate memory for the pool */
ObjPool = Xmalloc (ObjCount * sizeof (ObjData*));
/* Setup the pointers and index the objects */
Index = 0;
O = ObjRoot;
while (O) {
/* Safety */
CHECK (Index < ObjCount);
/* Set the Index */
O->Index = Index;
/* Set the pool pointer */
ObjPool [Index] = O;
/* Next object */
++Index;
O = O->Next;
}
}
const char* GetObjName (unsigned Index)
/* Get the name of a module by index */
{
PRECONDITION (ObjPool != 0 && Index < ObjCount && ObjPool [Index] != 0);
return ObjPool [Index]->Name;
}

111
src/ar65/objdata.h Normal file
View File

@@ -0,0 +1,111 @@
/*****************************************************************************/
/* */
/* objdata.h */
/* */
/* Handling object file data for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef OBJDATA_H
#define OBJDATA_H
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Values for the Flags field */
#define OBJ_HAVEDATA 0x0001 /* The object data is in the tmp file */
#define OBJ_MARKED 0x0002 /* Generic marker bit */
/* Internal structure holding object file data */
typedef struct ObjData_ ObjData;
struct ObjData_ {
ObjData* Next; /* Linked list of all objects */
char* Name; /* Module name */
unsigned Index; /* Module index */
unsigned Flags;
unsigned long MTime; /* Modifiation time of object file */
unsigned long Start; /* Start offset of data in library */
unsigned long Size; /* Size of data in library */
unsigned long ImportSize; /* Size of imports */
void* Imports; /* Imports as raw data */
unsigned long ExportSize; /* Size of exports */
void* Exports; /* Exports as raw data */
};
/* Object data list management */
extern unsigned ObjCount; /* Count of files in the list */
extern ObjData* ObjRoot; /* List of object files */
extern ObjData* ObjLast; /* Last entry in list */
extern ObjData** ObjPool; /* Object files as array */
/*****************************************************************************/
/* Code */
/*****************************************************************************/
ObjData* NewObjData (void);
/* Allocate a new structure on the heap, insert it into the list, return it */
void FreeObjData (ObjData* O);
/* Free a complete struct */
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.
*/
void DelObjData (const char* Module);
/* Delete the object module from the list */
void MakeObjPool (void);
/* Allocate memory, index the entries and make the ObjPool valid */
const char* GetObjName (unsigned Index);
/* Get the name of a module by index */
/* End of objdata.h */
#endif

288
src/ar65/objfile.c Normal file
View File

@@ -0,0 +1,288 @@
/*****************************************************************************/
/* */
/* objfile.c */
/* */
/* Object file handling for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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>
#include <errno.h>
#ifdef __WATCOMC__
/* Watcom has the file in the wrong directory */
# include <sys/utime.h>
#else
# include <sys/types.h> /* FreeBSD needs this */
# include <utime.h>
#endif
#include <time.h>
#include <sys/stat.h>
#include "error.h"
#include "mem.h"
#include "objdata.h"
#include "fileio.h"
#include "library.h"
#include "objfile.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static const char* GetModule (const char* Name)
/* Get a module name from the file name */
{
/* Make a module name from the file name */
const char* Module = Name + strlen (Name);
while (Module > Name) {
--Module;
if (*Module == '/' || *Module == '\\') {
++Module;
break;
}
}
if (*Module == 0) {
Error ("Cannot make module name from `%s'", Name);
}
return Module;
}
void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name)
/* Read the header of the object file checking the signature */
{
H->Magic = Read32 (Obj);
if (H->Magic != OBJ_MAGIC) {
Error ("`%s' is not an object file", Name);
}
H->Version = Read16 (Obj);
if (H->Version != OBJ_VERSION) {
Error ("Object file `%s' has wrong version", Name);
}
H->Flags = Read16 (Obj);
H->OptionOffs = Read32 (Obj);
H->OptionSize = Read32 (Obj);
H->FileOffs = Read32 (Obj);
H->FileSize = Read32 (Obj);
H->SegOffs = Read32 (Obj);
H->SegSize = Read32 (Obj);
H->ImportOffs = Read32 (Obj);
H->ImportSize = Read32 (Obj);
H->ExportOffs = Read32 (Obj);
H->ExportSize = Read32 (Obj);
H->DbgSymOffs = Read32 (Obj);
H->DbgSymSize = Read32 (Obj);
}
void ObjWriteHeader (FILE* Obj, ObjHeader* H)
/* Write the header of the object file */
{
Write32 (Obj, H->Magic);
Write16 (Obj, H->Version);
Write16 (Obj, H->Flags);
Write32 (Obj, H->OptionOffs);
Write32 (Obj, H->OptionSize);
Write32 (Obj, H->FileOffs);
Write32 (Obj, H->FileSize);
Write32 (Obj, H->SegOffs);
Write32 (Obj, H->SegSize);
Write32 (Obj, H->ImportOffs);
Write32 (Obj, H->ImportSize);
Write32 (Obj, H->ExportOffs);
Write32 (Obj, H->ExportSize);
Write32 (Obj, H->DbgSymOffs);
Write32 (Obj, H->DbgSymSize);
}
void ObjAdd (const char* Name)
/* Add an object file to the library */
{
struct stat StatBuf;
const char* Module;
ObjHeader H;
ObjData* O;
/* Open the object file */
FILE* Obj = fopen (Name, "rb");
if (Obj == 0) {
Error ("Could not open `%s': %s", Name, strerror (errno));
}
/* Get the modification time of the object file */
if (fstat (fileno (Obj), &StatBuf) != 0) {
Error ("Cannot stat object file `%s': %s", Name, strerror (errno));
}
/* Read and check the header */
ObjReadHeader (Obj, &H, Name);
/* Make a module name from the file name */
Module = GetModule (Name);
/* Check if we already have a module with this name */
O = FindObjData (Module);
if (O == 0) {
/* Not found, create a new entry */
O = NewObjData ();
} else {
/* Found - check the file modification times of the internal copy
* and the external one.
*/
if (difftime ((time_t)O->MTime, StatBuf.st_mtime) > 0.0) {
Warning ("Replacing module `%s' by older version", O->Name);
}
}
/* Initialize the object module data structure */
O->Name = StrDup (Module);
O->Flags = OBJ_HAVEDATA;
O->MTime = StatBuf.st_mtime;
O->ImportSize = H.ImportSize;
O->Imports = Xmalloc (O->ImportSize);
O->ExportSize = H.ExportSize;
O->Exports = Xmalloc (O->ExportSize);
/* Read imports and exports */
fseek (Obj, H.ImportOffs, SEEK_SET);
ReadData (Obj, O->Imports, O->ImportSize);
fseek (Obj, H.ExportOffs, SEEK_SET);
ReadData (Obj, O->Exports, O->ExportSize);
/* Skip the object file header */
O->Start = ftell (NewLib);
fseek (NewLib, OBJ_HDR_SIZE, SEEK_CUR);
/* Copy the remaining sections */
fseek (Obj, H.DbgSymOffs, SEEK_SET);
H.DbgSymOffs = LibCopyTo (Obj, H.DbgSymSize) - O->Start;
fseek (Obj, H.OptionOffs, SEEK_SET);
H.OptionOffs = LibCopyTo (Obj, H.OptionSize) - O->Start;
fseek (Obj, H.SegOffs, SEEK_SET);
H.SegOffs = LibCopyTo (Obj, H.SegSize) - O->Start;
fseek (Obj, H.FileOffs, SEEK_SET);
H.FileOffs = LibCopyTo (Obj, H.FileSize) - O->Start;
/* Calculate the amount of data written */
O->Size = ftell (NewLib) - O->Start;
/* Clear the remaining header fields */
H.ImportOffs = H.ImportSize = 0;
H.ExportOffs = H.ExportSize = 0;
/* Seek back and write the updated header */
fseek (NewLib, O->Start, SEEK_SET);
ObjWriteHeader (NewLib, &H);
/* Now seek again to end of file */
fseek (NewLib, 0, SEEK_END);
/* Done, close the file (we read it only, so no error check) */
fclose (Obj);
}
void ObjExtract (const char* Name)
/* Extract a module from the library */
{
unsigned long ImportStart;
unsigned long ExportStart;
struct utimbuf U;
ObjHeader H;
FILE* Obj;
/* Make a module name from the file name */
const char* Module = GetModule (Name);
/* Try to find the module in the library */
ObjData* O = FindObjData (Module);
/* Bail out if the module does not exist */
if (O == 0) {
Error ("Module `%s' not found in library", Module);
}
/* Open the output file */
Obj = fopen (Name, "w+b");
if (Obj == 0) {
Error ("Cannot open target file `%s': %s", Name, strerror (errno));
}
/* Copy the first four segments including the header to the new file */
LibCopyFrom (O->Start, O->Size, Obj);
/* Write imports and exports */
ImportStart = ftell (Obj);
WriteData (Obj, O->Imports, O->ImportSize);
ExportStart = ftell (Obj);
WriteData (Obj, O->Exports, O->ExportSize);
/* Seek back and read the header */
fseek (Obj, 0, SEEK_SET);
ObjReadHeader (Obj, &H, Name);
/* Update the header fields */
H.ImportOffs = ImportStart;
H.ImportSize = O->ImportSize;
H.ExportOffs = ExportStart;
H.ExportSize = O->ExportSize;
/* Write the changed header */
fseek (Obj, 0, SEEK_SET);
ObjWriteHeader (Obj, &H);
/* Close the file */
if (fclose (Obj) != 0) {
Error ("Problem closing object file `%s': %s", Name, strerror (errno));
}
/* Set access and modification time */
U.actime = O->MTime;
U.modtime = O->MTime;
if (utime (Name, &U) != 0) {
Error ("Cannot set mod time on `%s': %s", Name, strerror (errno));
}
}

72
src/ar65/objfile.h Normal file
View File

@@ -0,0 +1,72 @@
/*****************************************************************************/
/* */
/* objfile.h */
/* */
/* Object file handling for the ar65 archiver */
/* */
/* */
/* */
/* (C) 1998 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef OBJFILE_H
#define OBJFILE_H
#include <stdio.h>
#include "../common/objdefs.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void ObjReadHeader (FILE* Obj, ObjHeader* H, const char* Name);
/* Read the header of the object file checking the signature */
void ObjWriteHeader (FILE* Obj, ObjHeader* H);
/* Write the header of the object file */
void ObjAdd (const char* Name);
/* Add an object file to the library */
void ObjExtract (const char* Name);
/* Extract a module from the library */
/* End of objfile.h */
#endif