-
Notifications
You must be signed in to change notification settings - Fork 1
/
list-machine.cpp
70 lines (60 loc) · 1.77 KB
/
list-machine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2013-2019 amded workers, All rights reserved.
* Terms for redistribution and use can be found in LICENCE.
*/
/**
* @file list-machine.cpp
* @brief Tag reader frontend for machines
*/
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <b64/encode.h>
#include <fileref.h>
#include <tpropertymap.h>
#include "list-machine.h"
#include "list.h"
#include "setup.h"
#include "value.h"
/** ascii start-of-text character code */
#define ASCII_STX ((char)0x02)
/** ascii end-of-text character code */
#define ASCII_ETX ((char)0x03)
static void
print_iter(std::pair< const std::string, Value > &iter)
{
std::cout << ASCII_ETX << iter.first << ASCII_STX;
if (iter.second.get_type() == TAG_INTEGER) {
std::cout << iter.second.get_int();
} else if (iter.second.get_type() == TAG_BOOLEAN) {
std::cout << (iter.second.get_bool() ? "true" : "false");
} else if (iter.second.get_type() == TAG_STRING) {
if (get_opt(AMDED_MACHINE_DONT_USE_BASE64)) {
std::cout << iter.second.get_str().toCString(true);
} else {
base64::encoder enc;
std::istringstream in {iter.second.get_str().to8Bit(true)};
std::ostringstream out;
enc.encode(in, out);
std::cout << out.str();
}
}
}
void
amded_list_machine(const struct amded_file &file)
{
std::cout << "file-name" << ASCII_STX << file.name;
std::map< std::string, Value > data = amded_list_amded(file);
for (auto &iter : data) {
print_iter(iter);
}
data = amded_list_tags(file);
for (auto &iter : data) {
print_iter(iter);
}
data = amded_list_audioprops(file.fh->audioProperties());
for (auto &iter : data) {
print_iter(iter);
}
}