Skip to content

Commit eb84617

Browse files
committed
Removed 2nd level grouping in mime types.
1 parent 7ac3f4e commit eb84617

File tree

23 files changed

+91
-153
lines changed

23 files changed

+91
-153
lines changed

include/bu/mime.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ __BEGIN_DECLS
5656
* was found. It is the responsibility of the caller to cast
5757
* the return int to the correct mime_CONTEXT_t type.
5858
*/
59-
BU_EXPORT extern int bu_file_mime(const char *ext, bu_mime_context context);
59+
BU_EXPORT extern int bu_file_mime(const char *ext);
6060

6161

6262
/**
@@ -67,7 +67,7 @@ BU_EXPORT extern int bu_file_mime(const char *ext, bu_mime_context context);
6767
* containing the extensions if a result was found.
6868
* It is the responsibility of the caller to free the returned string.
6969
*/
70-
BU_EXPORT extern const char *bu_file_mime_ext(int t, bu_mime_context context);
70+
BU_EXPORT extern const char *bu_file_mime_ext(int t);
7171

7272

7373
/**
@@ -78,7 +78,7 @@ BU_EXPORT extern const char *bu_file_mime_ext(int t, bu_mime_context context);
7878
* returns NULL if no match was found, or a string if a result was found.
7979
* It is the responsibility of the caller to free the returned string.
8080
*/
81-
BU_EXPORT extern const char *bu_file_mime_str(int t, bu_mime_context context);
81+
BU_EXPORT extern const char *bu_file_mime_str(int t);
8282

8383

8484
/**

include/gcv/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct gcv_filter {
147147
* FIXME: input/output plugins conceivably could be something
148148
* other than geometry (e.g., png input or csv output).
149149
*/
150-
const bu_mime_context_t mime_type;
150+
const bu_mime_t mime_type;
151151

152152
/* For plugins supporting multiple file types, call this to
153153
* process them.

include/icv/io.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ICV_EXPORT extern int icv_destroy(icv_image_t *bif);
8383
* Returns 1 if an image size was identified, zero otherwise.
8484
*
8585
*/
86-
ICV_EXPORT extern int icv_image_size(const char *label, size_t dpi, size_t data_size, bu_mime_context_t type, size_t *widthp, size_t *heightp);
86+
ICV_EXPORT extern int icv_image_size(const char *label, size_t dpi, size_t data_size, bu_mime_t type, size_t *widthp, size_t *heightp);
8787

8888
/**
8989
* Load a file into an ICV struct. For most formats, this will be
@@ -108,7 +108,7 @@ ICV_EXPORT extern int icv_image_size(const char *label, size_t dpi, size_t data_
108108
* program.
109109
* @return A newly allocated struct holding the loaded image info.
110110
*/
111-
ICV_EXPORT extern icv_image_t *icv_read(const char *filename, bu_mime_context_t format, size_t width, size_t height);
111+
ICV_EXPORT extern icv_image_t *icv_read(const char *filename, bu_mime_t format, size_t width, size_t height);
112112

113113
/**
114114
* Saves Image to a file or streams to stdout in respective format
@@ -120,7 +120,7 @@ ICV_EXPORT extern icv_image_t *icv_read(const char *filename, bu_mime_context_t
120120
* @param format Specific format of the file to be written.
121121
* @return on success 0, on failure -1 with log messages.
122122
*/
123-
ICV_EXPORT extern int icv_write(icv_image_t *bif, const char*filename, bu_mime_context_t format);
123+
ICV_EXPORT extern int icv_write(icv_image_t *bif, const char*filename, bu_mime_t format);
124124

125125
/**
126126
* Write an image line to the data of ICV struct. Can handle unsigned

src/conv/3dm/3dm-g.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535

3636

3737
static const struct gcv_filter *
38-
find_filter(enum gcv_filter_type filter_type, bu_mime_context_t mime_type, const char *data)
38+
find_filter(enum gcv_filter_type filter_type, bu_mime_t mime_type, const char *data)
3939
{
4040
const struct gcv_filter * const *entry;
4141
const struct bu_ptbl * const filters = gcv_list_filters();
4242

4343
for (BU_PTBL_FOR(entry, (const struct gcv_filter * const *), filters)) {
44-
bu_mime_context_t emt = (*entry)->mime_type;
44+
bu_mime_t emt = (*entry)->mime_type;
4545
if ((*entry)->filter_type != filter_type) continue;
4646
if ( (emt != BU_MIME_MODEL_AUTO) && (emt == mime_type)) return *entry;
4747
if ( (emt == BU_MIME_MODEL_AUTO) && ((*entry)->data_supported && data && (*(*entry)->data_supported)(data)) ) return *entry;

src/conv/gcv/gcv.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static int
186186
parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt, const char *input)
187187
{
188188
int type_int = 0;
189-
bu_mime_context_t type = BU_MIME_MODEL_UNKNOWN;
189+
bu_mime_t type = BU_MIME_MODEL_UNKNOWN;
190190

191191
struct bu_vls format_cpy = BU_VLS_INIT_ZERO;
192192
struct bu_vls path = BU_VLS_INIT_ZERO;
@@ -206,8 +206,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt,
206206

207207
/* If we have an explicit option, that overrides any other format specifiers */
208208
if (opt) {
209-
type_int = bu_file_mime(opt, BU_MIME_AUTO);
210-
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
209+
type_int = bu_file_mime(opt);
210+
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_t)type_int;
211211
if (type == BU_MIME_MODEL_UNKNOWN) {
212212
/* Have prefix, but doesn't result in a known format - that's an error */
213213
if (slog)
@@ -223,8 +223,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt,
223223
* find out if it maps to a valid type */
224224
if (type == BU_MIME_MODEL_UNKNOWN && format) {
225225
/* Yes - see if the prefix specifies a model format */
226-
type_int = bu_file_mime(bu_vls_addr(format), BU_MIME_AUTO);
227-
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
226+
type_int = bu_file_mime(bu_vls_addr(format));
227+
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_t)type_int;
228228
if (type == BU_MIME_MODEL_UNKNOWN) {
229229
/* Have prefix, but doesn't result in a known format - that's an error */
230230
if (slog)
@@ -238,8 +238,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt,
238238
/* If we don't already have a type and we were passed a format string, give it a try */
239239
if (type == BU_MIME_MODEL_UNKNOWN && format && bu_vls_strlen(&format_cpy) > 0) {
240240
bu_vls_sprintf(format, "%s", bu_vls_addr(&format_cpy));
241-
type_int = bu_file_mime(bu_vls_addr(&format_cpy), BU_MIME_AUTO);
242-
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
241+
type_int = bu_file_mime(bu_vls_addr(&format_cpy));
242+
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_t)type_int;
243243
if (type == BU_MIME_MODEL_UNKNOWN) {
244244
/* Have prefix, but doesn't result in a known format - that's an error */
245245
if (slog)
@@ -252,8 +252,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt,
252252
/* If we have no prefix or the prefix didn't map to a model type, try file extension */
253253
if (type == BU_MIME_MODEL_UNKNOWN && extract_path(&path, input)) {
254254
if (bu_path_component(format, bu_vls_addr(&path), BU_PATH_EXT)) {
255-
type_int = bu_file_mime(bu_vls_addr(format), BU_MIME_AUTO);
256-
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
255+
type_int = bu_file_mime(bu_vls_addr(format));
256+
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_t)type_int;
257257
if (type == BU_MIME_MODEL_UNKNOWN) {
258258
/* Have file extension, but doesn't result in a known format - that's an error */
259259
if (slog)
@@ -315,13 +315,13 @@ static int
315315
model_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime)
316316
{
317317
int type_int;
318-
bu_mime_context_t type = BU_MIME_MODEL_UNKNOWN;
319-
bu_mime_context_t *set_type = (bu_mime_context_t *)set_mime;
318+
bu_mime_t type = BU_MIME_MODEL_UNKNOWN;
319+
bu_mime_t *set_type = (bu_mime_t *)set_mime;
320320

321321
BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format");
322322

323-
type_int = bu_file_mime(argv[0], BU_MIME_AUTO);
324-
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
323+
type_int = bu_file_mime(argv[0]);
324+
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_t)type_int;
325325
if (type == BU_MIME_MODEL_UNKNOWN) {
326326
if (msg) {
327327
bu_vls_sprintf(msg, "Error - unknown geometry file type: %s \n", argv[0]);
@@ -361,8 +361,8 @@ help(struct bu_vls *UNUSED(msg), size_t argc, const char **argv, void *set_var)
361361
static int
362362
do_conversion(
363363
struct bu_vls *messages,
364-
const char *in_path, bu_mime_context_t in_type,
365-
const char *out_path, bu_mime_context_t out_type,
364+
const char *in_path, bu_mime_t in_type,
365+
const char *out_path, bu_mime_t out_type,
366366
size_t in_argc, const char **in_argv,
367367
size_t out_argc, const char **out_argv)
368368
{
@@ -372,7 +372,7 @@ do_conversion(
372372
struct gcv_context context;
373373

374374
for (BU_PTBL_FOR(entry, (const struct gcv_filter * const *), filters)) {
375-
bu_mime_context_t emt = (*entry)->mime_type;
375+
bu_mime_t emt = (*entry)->mime_type;
376376
if ((*entry)->filter_type == GCV_FILTER_READ) {
377377
if (!in_filter && (emt != BU_MIME_MODEL_AUTO) && (emt == in_type))
378378
in_filter = *entry;
@@ -385,16 +385,16 @@ do_conversion(
385385
if (!out_filter && (emt != BU_MIME_MODEL_AUTO) && (emt == out_type))
386386
out_filter = *entry;
387387
if (!out_filter && (emt == BU_MIME_MODEL_AUTO) &&
388-
((*entry)->data_supported && (*(*entry)->data_supported)(bu_file_mime_str(out_type, BU_MIME_AUTO)))) {
388+
((*entry)->data_supported && (*(*entry)->data_supported)(bu_file_mime_str(out_type)))) {
389389
out_filter = *entry;
390390
}
391391
}
392392
}
393393

394394
if (!in_filter)
395-
bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(in_type, BU_MIME_AUTO));
395+
bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(in_type));
396396
if (!out_filter)
397-
bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(out_type, BU_MIME_AUTO));
397+
bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(out_type));
398398
if (!in_filter || !out_filter)
399399
return 0;
400400

@@ -435,8 +435,8 @@ main(int ac, const char **av)
435435
int fmt = 0;
436436
int ret = 0;
437437

438-
static bu_mime_context_t in_type = BU_MIME_MODEL_UNKNOWN;
439-
static bu_mime_context_t out_type = BU_MIME_MODEL_UNKNOWN;
438+
static bu_mime_t in_type = BU_MIME_MODEL_UNKNOWN;
439+
static bu_mime_t out_type = BU_MIME_MODEL_UNKNOWN;
440440

441441
static struct fmt_opts in_only_opts;
442442
static struct fmt_opts out_only_opts;
@@ -630,13 +630,13 @@ main(int ac, const char **av)
630630
/* Find out what input file type we are dealing with */
631631
if (in_type == BU_MIME_MODEL_UNKNOWN) {
632632
fmt = parse_model_string(&in_format, &slog, in_fmt, bu_vls_addr(&in_path_raw));
633-
in_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)fmt;
633+
in_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_t)fmt;
634634
in_fmt = NULL;
635635
}
636636
/* Identify output file type */
637637
if (out_type == BU_MIME_MODEL_UNKNOWN) {
638638
fmt = parse_model_string(&out_format, &slog, out_fmt, bu_vls_addr(&out_path_raw));
639-
out_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)fmt;
639+
out_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_t)fmt;
640640
out_fmt = NULL;
641641
}
642642

@@ -663,8 +663,8 @@ main(int ac, const char **av)
663663
/* If we've gotten this far, we know enough to try to convert. Until we
664664
* hook in conversion calls to libgcv, print a summary of the option
665665
* parsing results for debugging. */
666-
in_fmt = bu_file_mime_str((int)in_type, BU_MIME_AUTO);
667-
out_fmt = bu_file_mime_str((int)out_type, BU_MIME_AUTO);
666+
in_fmt = bu_file_mime_str((int)in_type);
667+
out_fmt = bu_file_mime_str((int)out_type);
668668
if (in_fmt) {
669669
bu_log("Input file format: %s\n", in_fmt);
670670
} else {

src/libbu/mime.cmake

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,6 @@ endforeach(line ${TYPES})
124124

125125
# HEADER with typedefs
126126

127-
list(GET ACTIVE_TYPES 0 FIRST_TYPE)
128-
set(mcstr "typedef enum {")
129-
set(last_type "")
130-
foreach(context ${ACTIVE_TYPES})
131-
string(TOUPPER "${context}" c)
132-
if("${context}" STREQUAL "${FIRST_TYPE}")
133-
set(mcstr "${mcstr}\n BU_MIME_${c} = 0,")
134-
else("${context}" STREQUAL "${FIRST_TYPE}")
135-
set(mcstr "${mcstr}\n BU_MIME_${c},")
136-
endif("${context}" STREQUAL "${FIRST_TYPE}")
137-
set(last_type "BU_MIME_${c}")
138-
endforeach(context ${ACTIVE_TYPES})
139-
set(mcstr "${mcstr}\n BU_MIME_UNKNOWN,")
140-
set(mcstr "${mcstr}\n BU_MIME_AUTO")
141-
set(mcstr "${mcstr}\n} bu_mime_context;\n\n")
142-
set(h_contents "${h_contents}\n${mcstr}")
143-
144127
set(enum_str "typedef enum {")
145128
list(GET ACTIVE_TYPES 0 FIRST_ACTIVE_TYPE)
146129
foreach(c ${ACTIVE_TYPES})
@@ -158,7 +141,7 @@ foreach(c ${ACTIVE_TYPES})
158141
set(enum_str "${enum_str}\n BU_MIME_${c_u}_UNKNOWN,")
159142
endif("${c_u}" STREQUAL "${FIRST_TYPE}")
160143
endforeach(c ${ACTIVE_TYPES})
161-
set(enum_str "${enum_str}\n} bu_mime_context_t;\n\n")
144+
set(enum_str "${enum_str}\n} bu_mime_t;\n\n")
162145
set(h_contents "${h_contents}\n${enum_str}")
163146
set(h_contents "${h_contents}\n__END_DECLS\n")
164147
set(h_contents "${h_contents}\n#endif /*BU_MIME_TYPES_H*/\n")
@@ -177,26 +160,12 @@ foreach(c ${ACTIVE_TYPES})
177160
endforeach(c ${ACTIVE_TYPES})
178161

179162
# Public C mapping function - extension to type
180-
set(mcstr "\nint\nbu_file_mime(const char *ext, bu_mime_context context)\n{")
181-
set(mcstr "${mcstr}\n switch (context) {\n")
182-
foreach(context ${ACTIVE_TYPES})
183-
string(TOUPPER "${context}" c)
184-
set(mcstr "${mcstr} case BU_MIME_${c}:\n")
185-
set(mcstr "${mcstr} return mime_${context}(ext);\n")
186-
set(mcstr "${mcstr} break;\n")
187-
endforeach(context ${ACTIVE_TYPES})
188-
set(mcstr "${mcstr} case BU_MIME_AUTO:\n")
163+
set(mcstr "\nint\nbu_file_mime(const char *ext)\n{")
189164
foreach(context ${ACTIVE_TYPES})
190-
string(TOUPPER "${context}" c)
191-
set(mcstr "${mcstr} if (mime_${context}(ext) != -1){\n")
192-
set(mcstr "${mcstr} return mime_${context}(ext);\n")
193-
set(mcstr "${mcstr} }\n")
165+
set(mcstr "${mcstr} if (mime_${context}(ext) != -1){\n")
166+
set(mcstr "${mcstr} return mime_${context}(ext);\n")
167+
set(mcstr "${mcstr} }\n")
194168
endforeach(context ${ACTIVE_TYPES})
195-
set(mcstr "${mcstr} break;\n")
196-
set(mcstr "${mcstr} default:\n")
197-
set(mcstr "${mcstr} return -1;\n")
198-
set(mcstr "${mcstr} break;\n")
199-
set(mcstr "${mcstr} }\n")
200169
set(mcstr "${mcstr} return -1;\n")
201170
set(mcstr "${mcstr}}\n")
202171
set(c_contents "${c_contents}\n${mcstr}")
@@ -217,26 +186,13 @@ foreach(c ${ACTIVE_TYPES})
217186
endforeach(c ${ACTIVE_TYPES})
218187

219188
# Public C mapping function - type to string
220-
set(mcstr "\nconst char *\nbu_file_mime_str(int t, bu_mime_context context)\n{")
221-
set(mcstr "${mcstr}\n switch (context) {\n")
222-
foreach(context ${ACTIVE_TYPES})
223-
string(TOUPPER "${context}" c)
224-
set(mcstr "${mcstr} case BU_MIME_${c}:\n")
225-
set(mcstr "${mcstr} return mime_str_${context}(t);\n")
226-
set(mcstr "${mcstr} break;\n")
227-
endforeach(context ${ACTIVE_TYPES})
228-
set(mcstr "${mcstr} case BU_MIME_AUTO:\n")
189+
set(mcstr "\nconst char *\nbu_file_mime_str(int t)\n{")
229190
foreach(context ${ACTIVE_TYPES})
230191
string(TOUPPER "${context}" c)
231-
set(mcstr "${mcstr} if (mime_str_${context}(t) != NULL && !BU_STR_EQUIV(\"BU_MIME_${c}_UNKNOWN\", mime_str_${context}(t))){\n")
232-
set(mcstr "${mcstr} return mime_str_${context}(t);\n")
233-
set(mcstr "${mcstr} }\n")
192+
set(mcstr "${mcstr} if (mime_str_${context}(t) != NULL && !BU_STR_EQUIV(\"BU_MIME_${c}_UNKNOWN\", mime_str_${context}(t))){\n")
193+
set(mcstr "${mcstr} return mime_str_${context}(t);\n")
194+
set(mcstr "${mcstr} }\n")
234195
endforeach(context ${ACTIVE_TYPES})
235-
set(mcstr "${mcstr} break;\n")
236-
set(mcstr "${mcstr} default:\n")
237-
set(mcstr "${mcstr} return NULL;\n")
238-
set(mcstr "${mcstr} break;\n")
239-
set(mcstr "${mcstr} }\n")
240196
set(mcstr "${mcstr} return NULL;\n")
241197
set(mcstr "${mcstr}}\n")
242198
set(c_contents "${c_contents}\n${mcstr}")
@@ -271,26 +227,13 @@ foreach(c ${ACTIVE_TYPES})
271227
endforeach(c ${ACTIVE_TYPES})
272228

273229
# Public C mapping function - type to string
274-
set(mcstr "\nconst char *\nbu_file_mime_ext(int t, bu_mime_context context)\n{")
275-
set(mcstr "${mcstr}\n switch (context) {\n")
276-
foreach(context ${ACTIVE_TYPES})
277-
string(TOUPPER "${context}" c)
278-
set(mcstr "${mcstr} case BU_MIME_${c}:\n")
279-
set(mcstr "${mcstr} return mime_ext_${context}(t);\n")
280-
set(mcstr "${mcstr} break;\n")
281-
endforeach(context ${ACTIVE_TYPES})
282-
set(mcstr "${mcstr} case BU_MIME_AUTO:\n")
230+
set(mcstr "\nconst char *\nbu_file_mime_ext(int t)\n{")
283231
foreach(context ${ACTIVE_TYPES})
284232
string(TOUPPER "${context}" c)
285-
set(mcstr "${mcstr} if (mime_ext_${context}(t) != NULL){\n")
286-
set(mcstr "${mcstr} return mime_ext_${context}(t);\n")
287-
set(mcstr "${mcstr} }\n")
233+
set(mcstr "${mcstr} if (mime_ext_${context}(t) != NULL){\n")
234+
set(mcstr "${mcstr} return mime_ext_${context}(t);\n")
235+
set(mcstr "${mcstr} }\n")
288236
endforeach(context ${ACTIVE_TYPES})
289-
set(mcstr "${mcstr} break;\n")
290-
set(mcstr "${mcstr} default:\n")
291-
set(mcstr "${mcstr} return NULL;\n")
292-
set(mcstr "${mcstr} break;\n")
293-
set(mcstr "${mcstr} }\n")
294237
set(mcstr "${mcstr} return NULL;\n")
295238
set(mcstr "${mcstr}}\n")
296239
set(c_contents "${c_contents}\n${mcstr}")

src/libbu/tests/file_mime.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include "bu.h"
2727

2828
int
29-
test_ext(const char *str, bu_mime_context context, int expected)
29+
test_ext(const char *str, int expected)
3030
{
3131
int status = 0;
32-
int type = bu_file_mime(str, context);
32+
int type = bu_file_mime(str);
3333

3434
if (type == expected) {
3535
bu_log("%s -> %d [PASS]\n", str, type);
@@ -45,21 +45,16 @@ test_ext(const char *str, bu_mime_context context, int expected)
4545
int
4646
main(int ac, char *av[])
4747
{
48-
int context = 0;
4948
int expected = 0;
5049

5150
bu_setprogname(av[0]);
5251

53-
if (ac != 4)
54-
bu_exit(1, "Usage: %s {extension} {context} {expected}\n", av[0]);
52+
if (ac != 3)
53+
bu_exit(1, "Usage: %s {extension} {expected}\n", av[0]);
5554

56-
sscanf(av[2], "%d", &context);
57-
sscanf(av[3], "%d", &expected);
55+
sscanf(av[2], "%d", &expected);
5856

59-
if (context >= BU_MIME_UNKNOWN)
60-
return -1;
61-
62-
return test_ext(av[1], (bu_mime_context)context, expected);
57+
return test_ext(av[1], expected);
6358
}
6459

6560

0 commit comments

Comments
 (0)