summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
author npwoods <npwoods@mess.org>2022-10-16 14:04:19 -0400
committer GitHub <noreply@github.com>2022-10-16 20:04:19 +0200
commitc831208d8cb363ecffb278e3b2f4a4218cbb04de (patch)
tree59d1e64208956bad011b5e79f0691cab139f165a /src/tools
parent7a864debcc9a8c1d67ca9a281aa6c3587892416d (diff)
Added support for specifying volume attributes in 'floptool flopcreate' (#9590)
An example command line: flopcreate vdk coco_rawdsk_os9_35 newdisk.vdk -name mycooldisk -creation_date "1999-02-28 13:23:47" Attributes are identified on the command line prefixed with '-'; if this is not the preferred syntax this can be changed. Implementing this also forced a change to fs::meta_value where the various as_*() calls can now be called without respect to which type the fs::meta_value is; this is necessary so that floptool code doesn't need to "own" parsing of the various types of fs::meta_value. And with this change, fs::meta_value::to_string() is now replaced by fs::meta_value::as_string()
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/floptool.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/tools/floptool.cpp b/src/tools/floptool.cpp
index eaf43d0861e..d680118944d 100644
--- a/src/tools/floptool.cpp
+++ b/src/tools/floptool.cpp
@@ -227,8 +227,39 @@ static int flopconvert(int argc, char *argv[])
return 0;
}
+static fs::meta_data extract_meta_data(int &argc, char *argv[])
+{
+ fs::meta_data result;
+
+ int new_argc = 0;
+ for (int i = 0; i < argc; i++)
+ {
+ std::optional<fs::meta_name> attrname;
+ if (argv[i][0] == '-' && i < argc - 1)
+ attrname = fs::meta_data::from_entry_name(&argv[i][1]);
+
+ if (attrname)
+ {
+ // we found a metadata variable; set it
+ result.set(*attrname, argv[i + 1]);
+ i++;
+ }
+ else
+ {
+ // we didn't; update argv
+ argv[new_argc++] = argv[i];
+ }
+ }
+
+ // we're done; update the argument count
+ argc = new_argc;
+ return result;
+}
+
static int flopcreate(int argc, char *argv[])
{
+ fs::meta_data meta = extract_meta_data(argc, argv);
+
if(argc!=5) {
fprintf(stderr, "Incorrect number of arguments.\n\n");
display_usage(argv[0]);
@@ -255,7 +286,6 @@ static int flopcreate(int argc, char *argv[])
return 1;
}
- fs::meta_data meta;
image_handler ih;
ih.set_on_disk_path(argv[4]);
@@ -281,7 +311,7 @@ static void dir_scan(fs::filesystem_t *fs, u32 depth, const std::vector<std::str
if(!c.m_meta.has(m.m_name))
continue;
size_t slot = nmap.find(m.m_name)->second;
- std::string val = c.m_meta.get(m.m_name).to_string();
+ std::string val = c.m_meta.get(m.m_name).as_string();
if(slot == 0)
val = head + "dir " + val;
entries[id][slot] = val;
@@ -296,7 +326,7 @@ static void dir_scan(fs::filesystem_t *fs, u32 depth, const std::vector<std::str
if(!c.m_meta.has(m.m_name))
continue;
size_t slot = nmap.find(m.m_name)->second;
- std::string val = c.m_meta.get(m.m_name).to_string();
+ std::string val = c.m_meta.get(m.m_name).as_string();
if(slot == 0)
val = head + "file " + val;
entries[id][slot] = val;
@@ -318,7 +348,7 @@ static int generic_dir(image_handler &ih)
if(!vmeta.empty()) {
std::string vinf = "Volume:";
for(const auto &e : vmetad)
- vinf += util::string_format(" %s=%s", fs::meta_data::entry_name(e.m_name), vmeta.get(e.m_name).to_string());
+ vinf += util::string_format(" %s=%s", fs::meta_data::entry_name(e.m_name), vmeta.get(e.m_name).as_string());
printf("%s\n\n", vinf.c_str());
}