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.

132 lines
3.2KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #ifdef _WIN32
  20. #include <windows.h>
  21. #define TTL_GENERATOR_WINDOWS
  22. #else
  23. #include <dlfcn.h>
  24. #endif
  25. #ifndef nullptr
  26. #define nullptr (0)
  27. #endif
  28. typedef void (*TTL_Generator_Function)(const char* basename);
  29. static int isPathSeparator(char c);
  30. static char* makeNormalPath(const char* path);
  31. int main(int argc, char* argv[])
  32. {
  33. if (argc != 2)
  34. {
  35. printf("usage: %s /path/to/plugin-DLL\n", argv[0]);
  36. return 1;
  37. }
  38. const char* path = argv[1];
  39. #ifdef TTL_GENERATOR_WINDOWS
  40. const HMODULE handle = LoadLibraryA(path);
  41. #else
  42. void* const handle = dlopen(path, RTLD_LAZY);
  43. #endif
  44. if (! handle)
  45. {
  46. #ifdef TTL_GENERATOR_WINDOWS
  47. printf("Failed to open plugin DLL\n");
  48. #else
  49. printf("Failed to open plugin DLL, error was:\n%s\n", dlerror());
  50. #endif
  51. return 2;
  52. }
  53. #ifdef TTL_GENERATOR_WINDOWS
  54. const TTL_Generator_Function ttlFn = (TTL_Generator_Function)GetProcAddress(handle, "lv2_generate_ttl");
  55. #else
  56. const TTL_Generator_Function ttlFn = (TTL_Generator_Function)dlsym(handle, "lv2_generate_ttl");
  57. #endif
  58. if (ttlFn != NULL)
  59. {
  60. char* normalPath = makeNormalPath(path);
  61. path = normalPath;
  62. while (path[0] == '.' && path[1] == '/')
  63. path += 2;
  64. char* basename = strrchr(path, '/');
  65. if (basename != NULL)
  66. basename += 1;
  67. else
  68. basename = (char*)path;
  69. char* dotPos = strrchr(basename, '.');
  70. if (dotPos)
  71. *dotPos = '\0';
  72. printf("Generate ttl data for '%s', basename: '%s'\n", path, basename);
  73. ttlFn(basename);
  74. free(normalPath);
  75. }
  76. else
  77. printf("Failed to find 'lv2_generate_ttl' function\n");
  78. #ifdef TTL_GENERATOR_WINDOWS
  79. FreeLibrary(handle);
  80. #else
  81. dlclose(handle);
  82. #endif
  83. return 0;
  84. }
  85. static int isPathSeparator(char c)
  86. {
  87. #ifdef TTL_GENERATOR_WINDOWS
  88. return c == '/' || c == '\\';
  89. #else
  90. return c == '/';
  91. #endif
  92. }
  93. static char* makeNormalPath(const char* path)
  94. {
  95. size_t i, j;
  96. size_t len = strlen(path);
  97. char* result = (char*)malloc(len + 1);
  98. int isSep, wasSep = 0;
  99. for (i = 0, j = 0; i < len; ++i)
  100. {
  101. isSep = isPathSeparator(path[i]);
  102. if (!isSep)
  103. result[j++] = path[i];
  104. else if (!wasSep)
  105. result[j++] = '/';
  106. wasSep = isSep;
  107. }
  108. result[j] = '\0';
  109. return result;
  110. }