From a63d35278cbfa7d3b1df34d2fb329e758e8cddc4 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 30 Jul 2000 16:15:04 +0000 Subject: [PATCH] Added dump of the file list git-svn-id: svn://svn.cc65.org/cc65/trunk@238 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/od65/dump.c | 74 +++++++++++++++++++++++++++++++++++++++++++++---- src/od65/dump.h | 5 +++- src/od65/main.c | 15 +++++++++- 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/src/od65/dump.c b/src/od65/dump.c index 0eaa18d4b..e14fb5e66 100644 --- a/src/od65/dump.c +++ b/src/od65/dump.c @@ -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); + } +} + + + diff --git a/src/od65/dump.h b/src/od65/dump.h index 42ac38aae..6bc425550 100644 --- a/src/od65/dump.h +++ b/src/od65/dump.h @@ -50,10 +50,13 @@ void DumpObjHeader (FILE* F, unsigned long Offset); /* Dump the header of the given object file */ - + 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 */ diff --git a/src/od65/main.c b/src/od65/main.c index 81a4c5ad2..34ed9ae0b 100644 --- a/src/od65/main.c +++ b/src/od65/main.c @@ -77,7 +77,8 @@ static void Usage (void) " -V\t\t\tPrint the version number and exit\n" "\n" "Long options:\n" - " --dump-header\t\tDump the object file header\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" " --version\t\tPrint the version number and exit\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 }, -- 2.39.5