mirror of
https://github.com/holub/mame
synced 2025-04-23 08:49:55 +03:00
[Imgtool] Cleaned up the output of the 'dir' command
This commit is contained in:
parent
2f9ef59017
commit
1b462f7434
@ -177,12 +177,21 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
||||
imgtool::partition::ptr partition;
|
||||
imgtool::directory::ptr imgenum;
|
||||
imgtool_dirent ent;
|
||||
char buf[512];
|
||||
char last_modified[19];
|
||||
const char *path;
|
||||
int partition_index = 0;
|
||||
std::string info;
|
||||
|
||||
// build the separator
|
||||
const int columnwidth_filename = 30;
|
||||
const int columnwidth_filesize = 8;
|
||||
const int columnwidth_attributes = 15;
|
||||
const int columnwidth_lastmodified = 18;
|
||||
std::string separator = std::string(columnwidth_filename, '-') + " "
|
||||
+ std::string(columnwidth_filesize, '-') + " "
|
||||
+ std::string(columnwidth_attributes, '-') + " "
|
||||
+ std::string(columnwidth_lastmodified, '-');
|
||||
|
||||
// attempt to open image
|
||||
err = imgtool::image::open(argv[0], argv[1], OSD_FOPEN_READ, image);
|
||||
if (err)
|
||||
@ -209,14 +218,14 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
||||
info = image->info();
|
||||
if (!info.empty())
|
||||
fprintf(stdout, "%s\n", info.c_str());
|
||||
fprintf(stdout, "------------------------------ -------- --------------- ------------------\n");
|
||||
|
||||
fprintf(stdout, "%s\n", separator.c_str());
|
||||
|
||||
while (((err = imgenum->get_next(ent)) == 0) && !ent.eof)
|
||||
{
|
||||
if (ent.directory)
|
||||
snprintf(buf, sizeof(buf), "<DIR>");
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "%u", (unsigned int) ent.filesize);
|
||||
std::string filesize_string = ent.directory
|
||||
? "<DIR>"
|
||||
: string_format("%u", (unsigned int) ent.filesize);
|
||||
|
||||
if (ent.lastmodified_time != 0)
|
||||
strftime(last_modified, sizeof(last_modified), "%d-%b-%y %H:%M:%S",
|
||||
@ -225,7 +234,11 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
||||
if (ent.hardlink)
|
||||
strcat(ent.filename, " <hl>");
|
||||
|
||||
fprintf(stdout, "%-30s %8s %15s %18s\n", ent.filename, buf, ent.attr, last_modified);
|
||||
fprintf(stdout, "%*s %*s %*s %*s\n",
|
||||
-columnwidth_filename, ent.filename,
|
||||
columnwidth_filesize, filesize_string.c_str(),
|
||||
columnwidth_attributes, ent.attr,
|
||||
columnwidth_lastmodified, last_modified);
|
||||
|
||||
if (ent.softlink && ent.softlink[0] != '\0')
|
||||
fprintf(stdout, "-> %s\n", ent.softlink);
|
||||
@ -244,7 +257,7 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
||||
if (err)
|
||||
goto done;
|
||||
|
||||
fprintf(stdout, "------------------------ ------ ---------------\n");
|
||||
fprintf(stdout, "%s\n", separator.c_str());
|
||||
fprintf(stdout, "%8i File(s) %8i bytes\n", total_count, total_size);
|
||||
if (!freespace_err)
|
||||
fprintf(stdout, " %8u bytes free\n", (unsigned int) freespace);
|
||||
|
Loading…
Reference in New Issue
Block a user