#ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #include #include #include "imp_vrml_v1.h" #define VRML_FT_VRML 0x01 #define VRML_FT_INVENTOR 0x02 int plugin_load(const char *filename, G3DModel *model) { FILE *f; yyscan_t scanner; G3DMaterial *material; gchar buffer[128]; guint32 ver_maj, ver_min, filetype; guint32 flex_ver; flex_ver = YY_FLEX_MAJOR_VERSION * 1000000 + YY_FLEX_MINOR_VERSION * 1000 + YY_FLEX_SUBMINOR_VERSION; #if DEBUG > 0 g_print("flex version: %u\n", flex_ver); #endif f = fopen(filename, "r"); if(f == NULL) { g_warning("failed to read '%s'", filename); return EXIT_FAILURE; } memset(buffer, 0, 128); fgets(buffer, 127, f); if(strncmp(buffer, "#VRML", 5) == 0) { filetype = VRML_FT_VRML; } else if(strncmp(buffer, "#Inventor", 9) == 0) { filetype = VRML_FT_INVENTOR; } else { g_warning("file '%s' is not a VRML file", filename); fclose(f); return EXIT_FAILURE; } /* FIXME: more than one space between VRML and Vx.x? */ ver_maj = buffer[7] - '0'; ver_min = buffer[9] - '0'; #if DEBUG > 0 g_print("VRML: version %d.%d\n", ver_maj, ver_min); #endif setlocale(LC_NUMERIC, "C"); if((filetype == VRML_FT_INVENTOR) || (ver_maj == 1)) { /* Inventor / VRML 1.x */ material = g3d_new_G3DMaterial(); material->name = g_strdup("fallback material"); model->materials = g_slist_append(model->materials, material); vrml_v1_yylex_init(&scanner); #if 0 if(flex_ver >= 2005031) yy_init_globals(scanner); #endif vrml_v1_yyset_in(f, scanner); vrml_v1_yyset_extra(model, scanner); vrml_v1_yylex(scanner); vrml_v1_yylex_destroy(scanner); } else if(ver_maj == 2) { g_warning("VRML 2 is not yet supported"); fclose(f); return EXIT_FAILURE; } else { g_warning("unknown VRML version %d.%d", ver_maj, ver_min); } fclose(f); return EXIT_SUCCESS; } char *plugin_description(void) { return g_strdup("import plugin for VRML 2.0+ files\n"); } char **plugin_extensions(void) { return g_strsplit("wrl:vrml:iv", ":", 0); } /* evil hack [tm] */ extern int yywrap(yyscan_t yyscanner); int vrml_v1_yywrap(yyscan_t yyscanner) { return yywrap(yyscanner); } /* VRML specific */