Vuo  2.0.0
VuoFileFormat.h
Go to the documentation of this file.
1 
10 #include <string.h>
11 #include <ctype.h>
12 
13 #ifdef __cplusplus
14 extern "C"
15 {
16 #endif
17 
21 bool VuoFileFormat_isFileOfFormat(const char *path, const char **formats, size_t numFormats)
22 {
24 
25  const char *dot = strrchr(path, '.');
26  if (! dot)
27  return false;
28  const char *rawExtension = dot + 1;
29 
30  size_t extensionLength = strlen(rawExtension);
31  char *extension = (char *)malloc(extensionLength + 1);
32  for (size_t i = 0; i < extensionLength; ++i)
33  extension[i] = tolower(*(rawExtension + i));
34  extension[extensionLength] = 0;
35 
36  bool found = false;
37  for (int i = 0; i < numFormats && ! found; ++i)
38  if (strcmp(extension, formats[i]) == 0)
39  found = true;
40 
41  free(extension);
42 
43  return found;
44 }
45 
49 bool VuoFileFormat_isSupportedAudioFile(const char *path)
50 {
51  const char *formats[] = {"wav", "aif", "aiff", "mp3", "mp2", "aac", "m4a", "ac3", "3gp", "amr"};
52  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
53  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
54 }
55 
59 bool VuoFileFormat_isSupportedImageFile(const char *path)
60 {
61  const char *formats[] = {"png", "jpeg", "jpg", "gif", "bmp", "exr", "hdr", "psd", "raw", "cr2",
62  "dng", "dcr", "nef", "raf", "mos", "kdc", "tif", "tiff", "tga", "targa", "webp", "pct"};
63  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
64  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
65 }
66 
70 bool VuoFileFormat_isSupportedMeshFile(const char *path)
71 {
72  const char *formats[] = {"data"};
73  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
74  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
75 }
76 
80 bool VuoFileFormat_isSupportedMovieFile(const char *path)
81 {
82  const char *formats[] = {"mov", "avi", "dv", "mpeg", "mpg", "mp2", "m4v", "mp4", "ogv", "gif", "qt"};
83  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
84  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
85 }
86 
90 bool VuoFileFormat_isSupportedSceneFile(const char *path)
91 {
92  const char *formats[] = {"3ds", "dae", "obj", "dxf", "ply", "lwo", "lxo", "ac3d", "ms3d", "cob", "scn",
93  "irr", "irrmesh", "mdl", "md2", "md3", "pk3", "mdc", "md5", "m3", "smd", "ter",
94  "raw", "b3d", "q3d", "q3s", "nff", "off", "3dgs", "hmp", "ndo", "fbx", "blend", "stl"};
95  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
96  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
97 }
98 
102 bool VuoFileFormat_isSupportedFeedFile(const char *path)
103 {
104  const char *formats[] = {"rss", "rdf"};
105  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
106  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
107 }
108 
112 bool VuoFileFormat_isSupportedJsonFile(const char *path)
113 {
114  const char *formats[] = {"json"};
115  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
116  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
117 }
118 
122 bool VuoFileFormat_isSupportedXmlFile(const char *path)
123 {
124  const char *formats[] = {"xml"};
125  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
126  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
127 }
128 
133 {
134  const char *formats[] = {"csv", "tsv"};
135  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
136  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
137 }
138 
142 bool VuoFileFormat_isSupportedDataFile(const char *path)
143 {
144  const char *formats[] = {"txt"};
145  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
146  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
147 }
148 
152 bool VuoFileFormat_isSupportedAppFile(const char *path)
153 {
154  const char *formats[] = {"app", "app/"};
155  size_t numFormats = sizeof(formats)/sizeof(formats[0]);
156  return VuoFileFormat_isFileOfFormat(path, formats, numFormats);
157 }
158 
159 #ifdef __cplusplus
160 }
161 #endif