Making buildable under OpenBSD.
[ardour.git] / libs / fst / scanner.cc
1 #define _POSIX_C_SOURCE 200809L
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <vector>
6
7 #include <glib.h>
8
9 #include "pbd/pbd.h"
10 #include "pbd/transmitter.h"
11 #include "pbd/receiver.h"
12
13 #ifdef __MINGW64__
14 #define NO_OLDNAMES // no backwards compat _pid_t, conflict with w64 pthread/sched
15 #endif
16
17 #include "ardour/filesystem_paths.h"
18 #ifdef LXVST_SUPPORT
19 #include "ardour/linux_vst_support.h"
20 #endif
21 #include "ardour/vst_info_file.h"
22
23 /* make stupid waf happy.
24  * waf cannot build multiple variants of .o object files from the same
25  * source using different wscripts.. it mingles e.g.
26  * build/libs/ardour/vst_info_file.cc.1.o for
27  * both lib/ardour/wscript and lib/fst/wscript
28  *
29  * ...but waf does track include dependencies.
30  */
31 #include "../ardour/vst_info_file.cc"
32 #ifdef LXVST_SUPPORT
33 #include "../ardour/linux_vst_support.cc"
34 #endif
35 #ifdef MACVST_SUPPORT
36 #include "../ardour/mac_vst_support.cc"
37 #endif
38 #include "../ardour/filesystem_paths.cc"
39 #include "../ardour/directory_names.cc"
40
41 #include "../ardour/vst_state.cc"
42
43 #ifdef LXVST_SUPPORT
44 void
45 vstfx_destroy_editor (VSTState* /*vstfx*/) { }
46 #endif
47
48 using namespace PBD;
49
50 class DummyReceiver : public Receiver {
51         protected:
52                 void receive (Transmitter::Channel chn, const char * str) {
53                         const char *prefix = "";
54                         switch (chn) {
55                                 case Transmitter::Error:
56                                         prefix = "[ERROR]: ";
57                                         break;
58                                 case Transmitter::Info:
59                                         /* ignore */
60                                         return;
61                                 case Transmitter::Warning:
62                                         prefix = "[WARNING]: ";
63                                         break;
64                                 case Transmitter::Fatal:
65                                         prefix = "[FATAL]: ";
66                                         break;
67                                 case Transmitter::Throw:
68                                         abort ();
69                         }
70
71                         std::cerr << prefix << str << std::endl;
72
73                         if (chn == Transmitter::Fatal) {
74                                 ::exit (1);
75                         }
76                 }
77 };
78
79 DummyReceiver dummy_receiver;
80
81 int main (int argc, char **argv) {
82         char *dllpath = NULL;
83         if (argc == 3 && !strcmp("-f", argv[1])) {
84                 dllpath = argv[2];
85                 const size_t slen = strlen (dllpath);
86                 if (
87                                 (slen > 3 && 0 == g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
88                                 ||
89                                 (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
90                    ) {
91                         vstfx_remove_infofile(dllpath);
92                         vstfx_un_blacklist(dllpath);
93                 }
94
95         }
96         else if (argc != 2) {
97                 fprintf(stderr, "usage: %s [-f] <vst>\n", argv[0]);
98                 return EXIT_FAILURE;
99         } else {
100                 dllpath = argv[1];
101         }
102
103         PBD::init();
104
105         dummy_receiver.listen_to (error);
106         dummy_receiver.listen_to (info);
107         dummy_receiver.listen_to (fatal);
108         dummy_receiver.listen_to (warning);
109
110         std::vector<VSTInfo *> *infos = 0;
111
112         const size_t slen = strlen (dllpath);
113         if (0) { }
114 #ifdef LXVST_SUPPORT
115         else if (slen > 3 && 0 == g_ascii_strcasecmp (&dllpath[slen-3], ".so")) {
116                 infos = vstfx_get_info_lx(dllpath);
117         }
118 #endif
119
120 #ifdef WINDOWS_VST_SUPPORT
121         else if (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".dll")) {
122                 infos = vstfx_get_info_fst(dllpath);
123         }
124 #endif
125
126 #ifdef MACVST_SUPPORT
127         else if (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".vst")) {
128                 infos = vstfx_get_info_mac(dllpath);
129         }
130 #endif
131         else {
132                 fprintf(stderr, "'%s' is not a supported VST plugin.\n", dllpath);
133         }
134
135         PBD::cleanup();
136
137         if (!infos || infos->empty()) {
138                 return EXIT_FAILURE;
139         } else {
140                 return EXIT_SUCCESS;
141         }
142 }