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.

82 lines
1.7KB

  1. /*
  2. * JUCE 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. if (char* base2 = strrchr(argv[1], '\\'))
  47. #else
  48. if (char* base2 = strrchr(argv[1], '/'))
  49. #endif
  50. {
  51. strcpy(basename, base2+1);
  52. basename[strrchr(base2, '.')-base2-1] = '\0';
  53. }
  54. else
  55. strcpy(basename, argv[1]);
  56. printf("Generate ttl data for '%s', basename: '%s'\n", argv[1], basename);
  57. ttlFn(basename);
  58. }
  59. else
  60. printf("Failed to find 'lv2_generate_ttl' function\n");
  61. #ifdef TTL_GENERATOR_WINDOWS
  62. FreeLibrary(handle);
  63. #else
  64. dlclose(handle);
  65. #endif
  66. return 0;
  67. }