-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget-version.cpp
More file actions
164 lines (136 loc) · 4.72 KB
/
get-version.cpp
File metadata and controls
164 lines (136 loc) · 4.72 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Copyright (c) 2020 Queen Mary, University of London
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the names of the Centre for
Digital Music and Queen Mary, University of London shall not be
used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization.
*/
#include <vamp-hostsdk/PluginHostAdapter.h>
// Undocumented internal API
#include <vamp-hostsdk/../src/vamp-hostsdk/Files.h>
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#include <io.h>
#else
#include <unistd.h>
#endif
#include <fcntl.h>
#include <iostream>
#include <string>
using namespace std;
void usage(const char *me)
{
cerr << endl;
cerr << "Usage: " << me << " <soname>" << endl;
cerr << endl;
cerr << "Loads the Vamp plugin library found in <soname> and lists\n"
<< "the plugin versions found therein. Plugins are listed one per\n"
<< "line, with the plugin id and version number separated by a colon."
<< endl;
cerr << endl;
cerr << "Note that <soname> must be the path to a plugin library, not\n"
<< "merely the name of the library. That is, no search path is used.\n"
<< "The file path should be UTF-8 encoded (on all platforms)."
<< endl;
cerr << endl;
cerr << "The return code is 0 if the plugin library was successfully\n"
<< "loaded, otherwise 1. An error message may be printed to stderr\n"
<< "in the latter case." << endl;
cerr << endl;
exit(2);
}
// We write our output to stdout, but want to ensure that the plugin
// doesn't write anything itself. To do this we open a null file
// descriptor and dup2() it into place of stdout in the gaps between
// our own output activity.
static int normalFd = -1;
static int suspendedFd = -1;
static void initFds()
{
#ifdef _WIN32
normalFd = _dup(1);
suspendedFd = _open("NUL", _O_WRONLY);
#else
normalFd = dup(1);
suspendedFd = open("/dev/null", O_WRONLY);
#endif
if (normalFd < 0 || suspendedFd < 0) {
throw std::runtime_error
("Failed to initialise fds for stdio suspend/resume");
}
}
static void suspendOutput()
{
#ifdef _WIN32
_dup2(suspendedFd, 1);
#else
dup2(suspendedFd, 1);
#endif
}
static void resumeOutput()
{
fflush(stdout);
#ifdef _WIN32
_dup2(normalFd, 1);
#else
dup2(normalFd, 1);
#endif
}
int main(int argc, char **argv)
{
char *scooter = argv[0];
char *name = 0;
while (scooter && *scooter) {
if (*scooter == '/' || *scooter == '\\') name = ++scooter;
else ++scooter;
}
if (!name || !*name) name = argv[0];
if (argc != 2) usage(name);
if (string(argv[1]) == string("-?")) usage(name);
initFds();
suspendOutput();
string libraryPath(argv[1]);
void *handle = Files::loadLibrary(libraryPath);
if (!handle) {
cerr << "Unable to load library " << libraryPath << endl;
return 1;
}
VampGetPluginDescriptorFunction fn =
(VampGetPluginDescriptorFunction)Files::lookupInLibrary
(handle, "vampGetPluginDescriptor");
if (!fn) {
cerr << "No vampGetPluginDescriptor function found in library \""
<< libraryPath << "\"" << endl;
Files::unloadLibrary(handle);
return 1;
}
int index = 0;
const VampPluginDescriptor *descriptor = 0;
while ((descriptor = fn(VAMP_API_VERSION, index))) {
resumeOutput();
cout << descriptor->identifier << ":"
<< descriptor->pluginVersion << endl;
suspendOutput();
++index;
}
Files::unloadLibrary(handle);
return 0;
}