Audio plugin host https://kx.studio/carla
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.

dispatch.c 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "rtosc.h"
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. static bool rtosc_match_number(const char **pattern, const char **msg)
  5. {
  6. //Verify both hold digits
  7. if(!isdigit(**pattern) || !isdigit(**msg))
  8. return false;
  9. //Read in both numeric values
  10. unsigned max = atoi(*pattern);
  11. unsigned val = atoi(*msg);
  12. ////Advance pointers
  13. while(isdigit(**pattern))++*pattern;
  14. while(isdigit(**msg))++*msg;
  15. //Match iff msg number is strictly less than pattern
  16. return val < max;
  17. }
  18. const char *rtosc_match_path(const char *pattern, const char *msg)
  19. {
  20. while(1) {
  21. //Check for special characters
  22. if(*pattern == ':' && !*msg)
  23. return pattern;
  24. else if(*pattern == '/' && *msg == '/')
  25. return ++pattern;
  26. else if(*pattern == '#') {
  27. ++pattern;
  28. if(!rtosc_match_number(&pattern, &msg))
  29. return NULL;
  30. } else if((*pattern == *msg)) { //verbatim compare
  31. if(*msg)
  32. ++pattern, ++msg;
  33. else
  34. return pattern;
  35. } else
  36. return NULL;
  37. }
  38. }
  39. //Match the arg string or fail
  40. static bool rtosc_match_args(const char *pattern, const char *msg)
  41. {
  42. //match anything if now arg restriction is present (ie the ':')
  43. if(*pattern++ != ':')
  44. return true;
  45. const char *arg_str = rtosc_argument_string(msg);
  46. bool arg_match = *pattern || *pattern == *arg_str;
  47. while(*pattern && *pattern != ':')
  48. arg_match &= (*pattern++==*arg_str++);
  49. if(*pattern==':') {
  50. if(arg_match && !*arg_str)
  51. return true;
  52. else
  53. return rtosc_match_args(pattern, msg); //retry
  54. }
  55. return arg_match;
  56. }
  57. bool rtosc_match(const char *pattern, const char *msg)
  58. {
  59. const char *arg_pattern = rtosc_match_path(pattern, msg);
  60. if(!arg_pattern)
  61. return false;
  62. else if(*arg_pattern == ':')
  63. return rtosc_match_args(arg_pattern, msg);
  64. return true;
  65. }