+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 */
{
/* Dump the file options */
{
ObjHeader H;
- long Size;
unsigned Count;
unsigned I;
/* 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) {
ArgStr = ReadMallocedStr (F);
ArgLen = strlen (ArgStr);
printf (" Data:%*s\"%s\"\n", 24-ArgLen, "", ArgStr);
- Size -= 1 + ArgLen + 1;
xfree (ArgStr);
break;
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:
+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);
+ }
+}
+
+
+
" -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",
+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 */
{
if (What & D_OPTIONS) {
DumpObjOptions (F, 0);
}
+ if (What & D_FILES) {
+ DumpObjFiles (F, 0);
+ }
}
/* Close the file */
{
/* Program long options */
static const LongOpt OptTab[] = {
+ { "--dump-files", 0, OptDumpFiles },
{ "--dump-header", 0, OptDumpHeader },
{ "--dump-options", 0, OptDumpOptions },
{ "--help", 0, OptHelp },