mirror of
https://github.com/cc65/cc65.git
synced 2025-08-08 06:25:17 +00:00
Encode option strings in the string pool
git-svn-id: svn://svn.cc65.org/cc65/trunk@2170 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "spool.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ static unsigned OptCount = 0;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static Option* NewOption (unsigned char Type)
|
static Option* NewOption (unsigned char Type, unsigned long Val)
|
||||||
/* Create a new option, insert it into the list and return it */
|
/* Create a new option, insert it into the list and return it */
|
||||||
{
|
{
|
||||||
Option* Opt;
|
Option* Opt;
|
||||||
@@ -76,7 +77,7 @@ static Option* NewOption (unsigned char Type)
|
|||||||
/* Initialize fields */
|
/* Initialize fields */
|
||||||
Opt->Next = 0;
|
Opt->Next = 0;
|
||||||
Opt->Type = Type;
|
Opt->Type = Type;
|
||||||
Opt->V.Str = 0;
|
Opt->Val = Val;
|
||||||
|
|
||||||
/* Insert it into the list */
|
/* Insert it into the list */
|
||||||
if (OptRoot == 0) {
|
if (OptRoot == 0) {
|
||||||
@@ -98,14 +99,7 @@ static Option* NewOption (unsigned char Type)
|
|||||||
void OptStr (unsigned char Type, const char* Text)
|
void OptStr (unsigned char Type, const char* Text)
|
||||||
/* Add a string option */
|
/* Add a string option */
|
||||||
{
|
{
|
||||||
Option* O;
|
NewOption (Type, GetStringId (Text));
|
||||||
|
|
||||||
/* String must have less than 255 bytes */
|
|
||||||
if (strlen (Text) > 255) {
|
|
||||||
Fatal (FAT_STRING_TOO_LONG);
|
|
||||||
}
|
|
||||||
O = NewOption (Type);
|
|
||||||
O->V.Str = xstrdup (Text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -113,7 +107,7 @@ void OptStr (unsigned char Type, const char* Text)
|
|||||||
void OptComment (const char* Comment)
|
void OptComment (const char* Comment)
|
||||||
/* Add a comment */
|
/* Add a comment */
|
||||||
{
|
{
|
||||||
OptStr (OPT_COMMENT, Comment);
|
NewOption (OPT_COMMENT, GetStringId (Comment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +115,7 @@ void OptComment (const char* Comment)
|
|||||||
void OptAuthor (const char* Author)
|
void OptAuthor (const char* Author)
|
||||||
/* Add an author statement */
|
/* Add an author statement */
|
||||||
{
|
{
|
||||||
OptStr (OPT_AUTHOR, Author);
|
NewOption (OPT_AUTHOR, GetStringId (Author));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,7 +123,7 @@ void OptAuthor (const char* Author)
|
|||||||
void OptTranslator (const char* Translator)
|
void OptTranslator (const char* Translator)
|
||||||
/* Add a translator option */
|
/* Add a translator option */
|
||||||
{
|
{
|
||||||
OptStr (OPT_TRANSLATOR, Translator);
|
NewOption (OPT_TRANSLATOR, GetStringId (Translator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -137,7 +131,7 @@ void OptTranslator (const char* Translator)
|
|||||||
void OptCompiler (const char* Compiler)
|
void OptCompiler (const char* Compiler)
|
||||||
/* Add a compiler option */
|
/* Add a compiler option */
|
||||||
{
|
{
|
||||||
OptStr (OPT_COMPILER, Compiler);
|
NewOption (OPT_COMPILER, GetStringId (Compiler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -145,7 +139,7 @@ void OptCompiler (const char* Compiler)
|
|||||||
void OptOS (const char* OS)
|
void OptOS (const char* OS)
|
||||||
/* Add an operating system option */
|
/* Add an operating system option */
|
||||||
{
|
{
|
||||||
OptStr (OPT_OS, OS);
|
NewOption (OPT_OS, GetStringId (OS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -153,8 +147,7 @@ void OptOS (const char* OS)
|
|||||||
void OptDateTime (unsigned long DateTime)
|
void OptDateTime (unsigned long DateTime)
|
||||||
/* Add a date/time option */
|
/* Add a date/time option */
|
||||||
{
|
{
|
||||||
Option* O = NewOption (OPT_DATETIME);
|
NewOption (OPT_DATETIME, DateTime);
|
||||||
O->V.Val = DateTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -174,24 +167,9 @@ void WriteOptions (void)
|
|||||||
O = OptRoot;
|
O = OptRoot;
|
||||||
while (O) {
|
while (O) {
|
||||||
|
|
||||||
/* Write the type of the option */
|
/* Write the type of the option, then the value */
|
||||||
ObjWrite8 (O->Type);
|
ObjWrite8 (O->Type);
|
||||||
|
ObjWriteVar (O->Val);
|
||||||
/* Write the argument */
|
|
||||||
switch (O->Type & OPT_ARGMASK) {
|
|
||||||
|
|
||||||
case OPT_ARGSTR:
|
|
||||||
ObjWriteStr (O->V.Str);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OPT_ARGNUM:
|
|
||||||
ObjWrite32 (O->V.Val);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Internal ("Invalid option type: $%02X", O->Type & 0xFF);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Next option */
|
/* Next option */
|
||||||
O = O->Next;
|
O = O->Next;
|
||||||
|
@@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998 Ullrich von Bassewitz */
|
/* (C) 1998-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@musoftware.de */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@@ -60,14 +60,11 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Structure to encode options */
|
/* Structure to encode options */
|
||||||
typedef struct Option_ Option;
|
typedef struct Option Option;
|
||||||
struct Option_ {
|
struct Option {
|
||||||
Option* Next; /* For list of options */
|
Option* Next; /* For list of options */
|
||||||
unsigned char Type; /* Type of option */
|
unsigned char Type; /* Type of option */
|
||||||
union {
|
unsigned long Val; /* Value attribute or string index */
|
||||||
const char* Str; /* String attribute */
|
|
||||||
unsigned long Val; /* Value attribute */
|
|
||||||
} V;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -370,49 +370,47 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
|
|||||||
/* Read and print all options */
|
/* Read and print all options */
|
||||||
for (I = 0; I < Count; ++I) {
|
for (I = 0; I < Count; ++I) {
|
||||||
|
|
||||||
unsigned long ArgNum;
|
const char* ArgStr;
|
||||||
char* ArgStr;
|
unsigned ArgLen;
|
||||||
unsigned ArgLen;
|
|
||||||
|
|
||||||
/* Read the type of the option */
|
/* Read the type of the option and the value */
|
||||||
unsigned char Type = Read8 (F);
|
unsigned char Type = Read8 (F);
|
||||||
|
unsigned long Val = ReadVar (F);
|
||||||
|
|
||||||
/* Get the type of the argument */
|
/* Get the type of the argument */
|
||||||
unsigned char ArgType = Type & OPT_ARGMASK;
|
unsigned char ArgType = Type & OPT_ARGMASK;
|
||||||
|
|
||||||
/* Determine which option follows */
|
/* Determine which option follows */
|
||||||
const char* TypeDesc;
|
const char* TypeDesc;
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
case OPT_COMMENT: TypeDesc = "OPT_COMMENT"; break;
|
case OPT_COMMENT: TypeDesc = "OPT_COMMENT"; break;
|
||||||
case OPT_AUTHOR: TypeDesc = "OPT_AUTHOR"; break;
|
case OPT_AUTHOR: TypeDesc = "OPT_AUTHOR"; break;
|
||||||
case OPT_TRANSLATOR:TypeDesc = "OPT_TRANSLATOR"; break;
|
case OPT_TRANSLATOR:TypeDesc = "OPT_TRANSLATOR"; break;
|
||||||
case OPT_COMPILER: TypeDesc = "OPT_COMPILER"; break;
|
case OPT_COMPILER: TypeDesc = "OPT_COMPILER"; break;
|
||||||
case OPT_OS: TypeDesc = "OPT_OS"; break;
|
case OPT_OS: TypeDesc = "OPT_OS"; break;
|
||||||
case OPT_DATETIME: TypeDesc = "OPT_DATETIME"; break;
|
case OPT_DATETIME: TypeDesc = "OPT_DATETIME"; break;
|
||||||
default: TypeDesc = "OPT_UNKNOWN"; break;
|
default: TypeDesc = "OPT_UNKNOWN"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the header */
|
/* Print the header */
|
||||||
printf (" Index:%27u\n", I);
|
printf (" Index:%27u\n", I);
|
||||||
|
|
||||||
/* Print the data */
|
/* Print the data */
|
||||||
printf (" Type:%22s0x%02X (%s)\n", "", Type, TypeDesc);
|
printf (" Type:%22s0x%02X (%s)\n", "", Type, TypeDesc);
|
||||||
switch (ArgType) {
|
switch (ArgType) {
|
||||||
|
|
||||||
case OPT_ARGSTR:
|
case OPT_ARGSTR:
|
||||||
ArgStr = ReadStr (F);
|
ArgStr = GetString (&StrPool, Val);
|
||||||
ArgLen = strlen (ArgStr);
|
ArgLen = strlen (ArgStr);
|
||||||
printf (" Data:%*s\"%s\"\n", 24-ArgLen, "", ArgStr);
|
printf (" Data:%*s\"%s\"\n", 24-ArgLen, "", ArgStr);
|
||||||
xfree (ArgStr);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case OPT_ARGNUM:
|
case OPT_ARGNUM:
|
||||||
ArgNum = Read32 (F);
|
printf (" Data:%26lu", Val);
|
||||||
printf (" Data:%26lu", ArgNum);
|
if (Type == OPT_DATETIME) {
|
||||||
if (Type == OPT_DATETIME) {
|
/* Print the time as a string */
|
||||||
/* Print the time as a string */
|
printf (" (%s)", TimeToStr (Val));
|
||||||
printf (" (%s)", TimeToStr (ArgNum));
|
}
|
||||||
}
|
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -513,7 +511,7 @@ void DumpObjSegments (FILE* F, unsigned long Offset)
|
|||||||
|
|
||||||
/* Read and print all segments */
|
/* Read and print all segments */
|
||||||
for (I = 0; I < Count; ++I) {
|
for (I = 0; I < Count; ++I) {
|
||||||
|
|
||||||
/* Read the data for one segments */
|
/* Read the data for one segments */
|
||||||
char* Name = ReadStr (F);
|
char* Name = ReadStr (F);
|
||||||
unsigned Len = strlen (Name);
|
unsigned Len = strlen (Name);
|
||||||
|
Reference in New Issue
Block a user