autoexec.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * Contributor(s): Blender Foundation 2013
  19. *
  20. * ***** END GPL LICENSE BLOCK *****
  21. */
  22. /** \file blender/blenkernel/intern/autoexec.c
  23. * \ingroup bke
  24. *
  25. * Currently just checks if a blend file can be trusted to autoexec,
  26. * may add signing here later.
  27. */
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "DNA_userdef_types.h"
  31. #include "BLI_utildefines.h"
  32. #include "BLI_fnmatch.h"
  33. #include "BLI_path_util.h"
  34. #ifdef WIN32
  35. # include "BLI_string.h"
  36. #endif
  37. #include "BKE_autoexec.h" /* own include */
  38. /**
  39. * \param path The path to check against.
  40. * \return Success
  41. */
  42. bool BKE_autoexec_match(const char *path)
  43. {
  44. bPathCompare *path_cmp;
  45. #ifdef WIN32
  46. const int fnmatch_flags = FNM_CASEFOLD;
  47. #else
  48. const int fnmatch_flags = 0;
  49. #endif
  50. BLI_assert((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0);
  51. for (path_cmp = U.autoexec_paths.first; path_cmp; path_cmp = path_cmp->next) {
  52. if (path_cmp->path[0] == '\0') {
  53. /* pass */
  54. }
  55. else if ((path_cmp->flag & USER_PATHCMP_GLOB)) {
  56. if (fnmatch(path_cmp->path, path, fnmatch_flags) == 0) {
  57. return true;
  58. }
  59. }
  60. else if (BLI_path_ncmp(path_cmp->path, path, strlen(path_cmp->path)) == 0) {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }