Added dump of the file list

git-svn-id: svn://svn.cc65.org/cc65/trunk@238 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2000-07-30 16:15:04 +00:00
parent 697f6e1cfa
commit a63d35278c
3 changed files with 86 additions and 8 deletions

View file

@ -65,6 +65,25 @@ static void DumpObjHeaderSection (const char* Name,
static char* TimeToStr (unsigned long Time)
/* Convert the time into a string and return it */
{
/* Get the time and convert to string */
time_t T = (time_t) Time;
char* S = asctime (localtime (&T));
/* Remove the trailing newline */
unsigned Len = strlen (S);
if (Len > 0 && S[Len-1] == '\n') {
S[Len-1 ] = '\0';
}
/* Return the time string */
return S;
}
void DumpObjHeader (FILE* F, unsigned long Offset)
/* Dump the header of the given object file */
{
@ -119,7 +138,6 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
/* Dump the file options */
{
ObjHeader H;
long Size;
unsigned Count;
unsigned I;
@ -137,7 +155,7 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
/* Read the number of options and print it */
Count = Read16 (F);
printf (" Count: %5u\n", Count);
printf (" Count:%27u\n", Count);
/* Read and print all options */
for (I = 0; I < Count; ++I) {
@ -175,7 +193,6 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
ArgStr = ReadMallocedStr (F);
ArgLen = strlen (ArgStr);
printf (" Data:%*s\"%s\"\n", 24-ArgLen, "", ArgStr);
Size -= 1 + ArgLen + 1;
xfree (ArgStr);
break;
@ -184,11 +201,9 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
printf (" Data:%26lu", ArgNum);
if (Type == OPT_DATETIME) {
/* Print the time as a string */
time_t T = (time_t) ArgNum;
printf (" (%.24s)", asctime (localtime (&T)));
printf (" (%s)", TimeToStr (ArgNum));
}
printf ("\n");
Size -= 1 + 4;
break;
default:
@ -203,3 +218,50 @@ void DumpObjOptions (FILE* F, unsigned long Offset)
void DumpObjFiles (FILE* F, unsigned long Offset)
/* Dump the source files */
{
ObjHeader H;
unsigned Count;
unsigned I;
/* Seek to the header position */
FileSeek (F, Offset);
/* Read the header */
ReadObjHeader (F, &H);
/* Seek to the start of the options */
FileSeek (F, Offset + H.FileOffs);
/* Output a header */
printf (" Files:\n");
/* Read the number of files and print it */
Count = Read8 (F);
printf (" Count:%27u\n", Count);
/* Read and print all options */
for (I = 0; I < Count; ++I) {
/* Read the data for one file */
unsigned long MTime = Read32 (F);
unsigned long Size = Read32 (F);
char* Name = ReadMallocedStr (F);
unsigned Len = strlen (Name);
/* Print the header */
printf (" File %u:\n", I);
/* Print the data */
printf (" Name:%*s\"%s\"\n", 24-Len, "", Name);
printf (" Size:%26lu\n", Size);
printf (" Modification time:%13lu (%s)\n", MTime, TimeToStr (MTime));
/* Free the Name */
xfree (Name);
}
}

View file

@ -54,6 +54,9 @@ void DumpObjHeader (FILE* F, unsigned long Offset);
void DumpObjOptions (FILE* F, unsigned long Offset);
/* Dump the file options */
void DumpObjFiles (FILE* F, unsigned long Offset);
/* Dump the source files */
/* End of dump.h */

View file

@ -77,6 +77,7 @@ static void Usage (void)
" -V\t\t\tPrint the version number and exit\n"
"\n"
"Long options:\n"
" --dump-files\t\tDump the source files\n"
" --dump-header\t\tDump the object file header\n"
" --dump-options\t\tDump object file options\n"
" --help\t\tHelp (this text)\n"
@ -86,6 +87,14 @@ static void Usage (void)
static void OptDumpFiles (const char* Opt, const char* Arg)
/* Dump the source files */
{
What |= D_FILES;
}
static void OptDumpHeader (const char* Opt, const char* Arg)
/* Dump the object file header */
{
@ -158,6 +167,9 @@ static void DumpFile (const char* Name)
if (What & D_OPTIONS) {
DumpObjOptions (F, 0);
}
if (What & D_FILES) {
DumpObjFiles (F, 0);
}
}
/* Close the file */
@ -171,6 +183,7 @@ int main (int argc, char* argv [])
{
/* Program long options */
static const LongOpt OptTab[] = {
{ "--dump-files", 0, OptDumpFiles },
{ "--dump-header", 0, OptDumpHeader },
{ "--dump-options", 0, OptDumpOptions },
{ "--help", 0, OptHelp },