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