DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.9KB

  1. /*
  2. * DPF LV2 *.ttl generator
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #ifdef _WIN32
  7. #include <windows.h>
  8. #define TTL_GENERATOR_WINDOWS
  9. #else
  10. #include <dlfcn.h>
  11. #endif
  12. #ifndef nullptr
  13. #define nullptr (0)
  14. #endif
  15. typedef void (*TTL_Generator_Function)(const char* basename);
  16. int main(int argc, char* argv[])
  17. {
  18. if (argc != 2)
  19. {
  20. printf("usage: %s /path/to/plugin-DLL\n", argv[0]);
  21. return 1;
  22. }
  23. #ifdef TTL_GENERATOR_WINDOWS
  24. const HMODULE handle = LoadLibraryA(argv[1]);
  25. #else
  26. void* const handle = dlopen(argv[1], RTLD_LAZY);
  27. #endif
  28. if (! handle)
  29. {
  30. #ifdef TTL_GENERATOR_WINDOWS
  31. printf("Failed to open plugin DLL\n");
  32. #else
  33. printf("Failed to open plugin DLL, error was:\n%s\n", dlerror());
  34. #endif
  35. return 2;
  36. }
  37. #ifdef TTL_GENERATOR_WINDOWS
  38. const TTL_Generator_Function ttlFn = (TTL_Generator_Function)GetProcAddress(handle, "lv2_generate_ttl");
  39. #else
  40. const TTL_Generator_Function ttlFn = (TTL_Generator_Function)dlsym(handle, "lv2_generate_ttl");
  41. #endif
  42. if (ttlFn != NULL)
  43. {
  44. char basename[strlen(argv[1])+1];
  45. #ifdef TTL_GENERATOR_WINDOWS
  46. char* base2 = strrchr(argv[1], '\\');
  47. #else
  48. char* base2 = strrchr(argv[1], '/');
  49. #endif
  50. if (base2 != NULL)
  51. {
  52. strcpy(basename, base2+1);
  53. basename[strrchr(base2, '.')-base2-1] = '\0';
  54. }
  55. else if (argv[1][0] == '.' && argv[1][1] == '/')
  56. {
  57. strcpy(basename, argv[1]+2);
  58. basename[strrchr(basename, '.')-basename] = '\0';
  59. }
  60. else
  61. {
  62. strcpy(basename, argv[1]);
  63. }
  64. printf("Generate ttl data for '%s', basename: '%s'\n", argv[1], basename);
  65. ttlFn(basename);
  66. }
  67. else
  68. printf("Failed to find 'lv2_generate_ttl' function\n");
  69. #ifdef TTL_GENERATOR_WINDOWS
  70. FreeLibrary(handle);
  71. #else
  72. dlclose(handle);
  73. #endif
  74. return 0;
  75. }