parse.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. //-----------------------------------------------------------------------------
  24. #include "os/osFile.h"
  25. #include "os/osPrint.h"
  26. #include "util/utilStr.h"
  27. #include "util/utilString.h"
  28. #include "util/utilArray.h"
  29. #include "util/utilMap.h"
  30. #include "util/utilSort.h"
  31. using namespace Torque;
  32. #include <stdio.h>
  33. #include <dirent.h>
  34. //-----------------------------------------------------------------------------
  35. const char* OrderTable[] =
  36. {
  37. // Extension list as of 8.25.2005
  38. // http://oss.sgi.com/projects/ogl-sample/registry/
  39. // Core
  40. "GL_VERSION_1_1",
  41. "GL_VERSION_1_2",
  42. "GL_VERSION_1_3",
  43. "GL_VERSION_1_4",
  44. "GL_VERSION_1_5",
  45. // X Windows
  46. "GLX_VERSION_1_1",
  47. "GLX_VERSION_1_2",
  48. "GLX_VERSION_1_3",
  49. "GLX_VERSION_1_4",
  50. "GLX_VERSION_1_5",
  51. // Arb extension
  52. "GL_ARB_multitexture",
  53. "GLX_ARB_get_proc_address",
  54. "GL_ARB_transpose_matrix",
  55. "WGL_ARB_buffer_region",
  56. "GL_ARB_multisample",
  57. "GL_ARB_texture_env_add",
  58. "GL_ARB_texture_cube_map",
  59. "WGL_ARB_extensions_string",
  60. "WGL_ARB_pixel_format",
  61. "WGL_ARB_make_current_read",
  62. "WGL_ARB_pbuffer",
  63. "GL_ARB_texture_compression",
  64. "GL_ARB_texture_border_clamp",
  65. "GL_ARB_point_parameters",
  66. "GL_ARB_vertex_blend",
  67. "GL_ARB_matrix_palette",
  68. "GL_ARB_texture_env_combine",
  69. "GL_ARB_texture_env_crossbar",
  70. "GL_ARB_texture_env_dot3",
  71. "WGL_ARB_render_texture",
  72. "GL_ARB_texture_mirrored_repeat",
  73. "GL_ARB_depth_texture",
  74. "GL_ARB_shadow",
  75. "GL_ARB_shadow_ambient",
  76. "GL_ARB_window_pos",
  77. "GL_ARB_vertex_program",
  78. "GL_ARB_fragment_program",
  79. "GL_ARB_vertex_buffer_object",
  80. "GL_ARB_occlusion_query",
  81. "GL_ARB_shader_objects",
  82. "GL_ARB_vertex_shader",
  83. "GL_ARB_fragment_shader",
  84. "GL_ARB_shading_language_100",
  85. "GL_ARB_texture_non_power_of_two",
  86. "GL_ARB_point_sprite",
  87. "GL_ARB_fragment_program_shadow",
  88. "GL_ARB_draw_buffers",
  89. "GL_ARB_texture_rectangle",
  90. "GL_ARB_color_buffer_float",
  91. "GL_ARB_half_float_pixel",
  92. "GL_ARB_texture_float",
  93. "GL_ARB_pixel_buffer_object",
  94. // Misc extensions
  95. "GL_EXT_abgr",
  96. "GL_EXT_blend_color",
  97. "GL_EXT_polygon_offset",
  98. "GL_EXT_texture",
  99. "GL_EXT_texture3D",
  100. "GL_SGIS_texture_filter4",
  101. "GL_EXT_subtexture",
  102. "GL_EXT_copy_texture",
  103. "GL_EXT_histogram",
  104. "GL_EXT_convolution",
  105. "GL_SGI_color_matrix",
  106. "GL_SGI_color_table",
  107. "GL_SGIS_pixel_texture",
  108. "GL_SGIX_pixel_texture",
  109. "GL_SGIS_texture4D",
  110. "GL_SGI_texture_color_table",
  111. "GL_EXT_cmyka",
  112. "GL_EXT_texture_object",
  113. "GL_SGIS_detail_texture",
  114. "GL_SGIS_sharpen_texture",
  115. "GL_EXT_packed_pixels",
  116. "GL_SGIS_texture_lod",
  117. "GL_SGIS_multisample",
  118. "GL_EXT_rescale_normal",
  119. "GLX_EXT_visual_info",
  120. "GL_EXT_vertex_array",
  121. "GL_EXT_misc_attribute",
  122. "GL_SGIS_generate_mipmap",
  123. "GL_SGIX_clipmap",
  124. "GL_SGIX_shadow",
  125. "GL_SGIS_texture_edge_clamp",
  126. "GL_SGIS_texture_border_clamp",
  127. "GL_EXT_blend_minmax",
  128. "GL_EXT_blend_subtract",
  129. "GL_EXT_blend_logic_op",
  130. "GLX_SGI_swap_control",
  131. "GLX_SGI_video_sync",
  132. "GLX_SGI_make_current_read",
  133. "GLX_SGIX_video_source",
  134. "GLX_EXT_visual_rating",
  135. "GL_SGIX_interlace",
  136. "GLX_EXT_import_context",
  137. "GLX_SGIX_fbconfig",
  138. "GLX_SGIX_pbuffer",
  139. "GL_SGIS_texture_select",
  140. "GL_SGIX_sprite",
  141. "GL_SGIX_texture_multi_buffer",
  142. "GL_EXT_point_parameters",
  143. "GL_SGIX_instruments",
  144. "GL_SGIX_texture_scale_bias",
  145. "GL_SGIX_framezoom",
  146. "GL_SGIX_tag_sample_buffer",
  147. "GL_SGIX_reference_plane",
  148. "GL_SGIX_flush_raster",
  149. "GLX_SGI_cushion",
  150. "GL_SGIX_depth_texture",
  151. "GL_SGIS_fog_function",
  152. "GL_SGIX_fog_offset",
  153. "GL_HP_image_transform",
  154. "GL_HP_convolution_border_modes",
  155. "GL_SGIX_texture_add_env",
  156. "GL_EXT_color_subtable",
  157. "GLU_EXT_object_space_tess",
  158. "GL_PGI_vertex_hints",
  159. "GL_PGI_misc_hints",
  160. "GL_EXT_paletted_texture",
  161. "GL_EXT_clip_volume_hint",
  162. "GL_SGIX_list_priority",
  163. "GL_SGIX_ir_instrument1",
  164. "GLX_SGIX_video_resize",
  165. "GL_SGIX_texture_lod_bias",
  166. "GLU_SGI_filter4_parameters",
  167. "GLX_SGIX_dm_buffer",
  168. "GL_SGIX_shadow_ambient",
  169. "GLX_SGIX_swap_group",
  170. "GLX_SGIX_swap_barrier",
  171. "GL_EXT_index_texture",
  172. "GL_EXT_index_material",
  173. "GL_EXT_index_func",
  174. "GL_EXT_index_array_formats",
  175. "GL_EXT_compiled_vertex_array",
  176. "GL_EXT_cull_vertex",
  177. "GLU_EXT_nurbs_tessellator",
  178. "GL_SGIX_ycrcb",
  179. "GL_EXT_fragment_lighting",
  180. "GL_IBM_rasterpos_clip",
  181. "GL_HP_texture_lighting",
  182. "GL_EXT_draw_range_elements",
  183. "GL_WIN_phong_shading",
  184. "GL_WIN_specular_fog",
  185. "GLX_SGIS_color_range",
  186. "GL_EXT_light_texture",
  187. "GL_SGIX_blend_alpha_minmax",
  188. "GL_EXT_scene_marker",
  189. "GL_SGIX_pixel_texture_bits",
  190. "GL_EXT_bgra",
  191. "GL_SGIX_async",
  192. "GL_SGIX_async_pixel",
  193. "GL_SGIX_async_histogram",
  194. "GL_INTEL_texture_scissor",
  195. "GL_INTEL_parallel_arrays",
  196. "GL_HP_occlusion_test",
  197. "GL_EXT_pixel_transform",
  198. "GL_EXT_pixel_transform_color_table",
  199. "GL_EXT_shared_texture_palette",
  200. "GLX_SGIS_blended_overlay",
  201. "GL_EXT_separate_specular_color",
  202. "GL_EXT_secondary_color",
  203. "GL_EXT_texture_env",
  204. "GL_EXT_texture_perturb_normal",
  205. "GL_EXT_multi_draw_arrays",
  206. "GL_EXT_fog_coord",
  207. "GL_REND_screen_coordinates",
  208. "GL_EXT_coordinate_frame",
  209. "GL_EXT_texture_env_combine",
  210. "GL_APPLE_specular_vector",
  211. "GL_APPLE_transform_hint",
  212. "GL_SUNX_constant_data",
  213. "GL_SUN_global_alpha",
  214. "GL_SUN_triangle_list",
  215. "GL_SUN_vertex",
  216. "WGL_EXT_display_color_table",
  217. "WGL_EXT_extensions_string",
  218. "WGL_EXT_make_current_read",
  219. "WGL_EXT_pixel_format",
  220. "WGL_EXT_pbuffer",
  221. "WGL_EXT_swap_control",
  222. "GL_EXT_blend_func_separate",
  223. "GL_INGR_color_clamp",
  224. "GL_INGR_interlace_read",
  225. "GL_EXT_stencil_wrap",
  226. "WGL_EXT_depth_float",
  227. "GL_EXT_422_pixels",
  228. "GL_NV_texgen_reflection",
  229. "GL_SGIX_texture_range",
  230. "GL_SUN_convolution_border_modes",
  231. "GLX_SUN_get_transparent_index",
  232. "GL_EXT_texture_env_add",
  233. "GL_EXT_texture_lod_bias",
  234. "GL_EXT_texture_filter_anisotropic",
  235. "GL_EXT_vertex_weighting",
  236. "GL_NV_light_max_exponent",
  237. "GL_NV_vertex_array_range",
  238. "GL_NV_register_combiners",
  239. "GL_NV_fog_distance",
  240. "GL_NV_texgen_emboss",
  241. "GL_NV_blend_square",
  242. "GL_NV_texture_env_combine4",
  243. "GL_MESA_resize_buffers",
  244. "GL_MESA_window_pos",
  245. "GL_EXT_texture_compression_s3tc",
  246. "GL_IBM_cull_vertex",
  247. "GL_IBM_multimode_draw_arrays",
  248. "GL_IBM_vertex_array_lists",
  249. "GL_3DFX_texture_compression_FXT1",
  250. "GL_3DFX_multisample",
  251. "GL_3DFX_tbuffer",
  252. "WGL_EXT_multisample",
  253. "GL_SGIX_vertex_preclip",
  254. "GL_SGIX_resample",
  255. "GL_SGIS_texture_color_mask",
  256. "GLX_MESA_copy_sub_buffer",
  257. "GLX_MESA_pixmap_colormap",
  258. "GLX_MESA_release_buffers",
  259. "GLX_MESA_set_3dfx_mode",
  260. "GL_EXT_texture_env_dot3",
  261. "GL_ATI_texture_mirror_once",
  262. "GL_NV_fence",
  263. "GL_IBM_static_data",
  264. "GL_IBM_texture_mirrored_repeat",
  265. "GL_NV_evaluators",
  266. "GL_NV_packed_depth_stencil",
  267. "GL_NV_register_combiners2",
  268. "GL_NV_texture_compression_vtc",
  269. "GL_NV_texture_rectangle",
  270. "GL_NV_texture_shader",
  271. "GL_NV_texture_shader2",
  272. "GL_NV_vertex_array_range2",
  273. "GL_NV_vertex_program",
  274. "GLX_SGIX_visual_select_group",
  275. "GL_SGIX_texture_coordinate_clamp",
  276. "GLX_OML_swap_method",
  277. "GLX_OML_sync_control",
  278. "GL_OML_interlace",
  279. "GL_OML_subsample",
  280. "GL_OML_resample",
  281. "WGL_OML_sync_control",
  282. "GL_NV_copy_depth_to_color",
  283. "GL_ATI_envmap_bumpmap",
  284. "GL_ATI_fragment_shader",
  285. "GL_ATI_pn_triangles",
  286. "GL_ATI_vertex_array_object",
  287. "GL_EXT_vertex_shader",
  288. "GL_ATI_vertex_streams",
  289. "WGL_I3D_digital_video_control",
  290. "WGL_I3D_gamma",
  291. "WGL_I3D_genlock",
  292. "WGL_I3D_image_buffer",
  293. "WGL_I3D_swap_frame_lock",
  294. "WGL_I3D_swap_frame_usage",
  295. "GL_ATI_element_array",
  296. "GL_SUN_mesh_array",
  297. "GL_SUN_slice_accum",
  298. "GL_NV_multisample_filter_hint",
  299. "GL_NV_depth_clamp",
  300. "GL_NV_occlusion_query",
  301. "GL_NV_point_sprite",
  302. "WGL_NV_render_depth_texture",
  303. "WGL_NV_render_texture_rectangle",
  304. "GL_NV_texture_shader3",
  305. "GL_NV_vertex_program1_1",
  306. "GL_EXT_shadow_funcs",
  307. "GL_EXT_stencil_two_side",
  308. "GL_ATI_text_fragment_shader",
  309. "GL_APPLE_client_storage",
  310. "GL_APPLE_element_array",
  311. "GL_APPLE_fence",
  312. "GL_APPLE_vertex_array_object",
  313. "GL_APPLE_vertex_array_range",
  314. "GL_APPLE_ycbcr_422",
  315. "GL_S3_s3tc",
  316. "GL_ATI_draw_buffers",
  317. "WGL_ATI_pixel_format_float",
  318. "GL_ATI_texture_env_combine3",
  319. "GL_ATI_texture_float",
  320. "GL_NV_float_buffer",
  321. "GL_NV_fragment_program",
  322. "GL_NV_half_float",
  323. "GL_NV_pixel_data_range",
  324. "GL_NV_primitive_restart",
  325. "GL_NV_texture_expand_normal",
  326. "GL_NV_vertex_program2",
  327. "GL_ATI_map_object_buffer",
  328. "GL_ATI_separate_stencil",
  329. "GL_ATI_vertex_attrib_array_object",
  330. "GL_OES_byte_coordinates",
  331. "GL_OES_fixed_point",
  332. "GL_OES_single_precision",
  333. "GL_OES_compressed_paletted_texture",
  334. "GL_OES_read_format",
  335. "GL_OES_query_matrix",
  336. "GL_EXT_depth_bounds_test",
  337. "GL_EXT_texture_mirror_clamp",
  338. "GL_EXT_blend_equation_separate",
  339. "GL_MESA_pack_invert",
  340. "GL_MESA_ycbcr_texture",
  341. "GL_EXT_pixel_buffer_object",
  342. "GL_NV_fragment_program_option",
  343. "GL_NV_fragment_program2",
  344. "GL_NV_vertex_program2_option",
  345. "GL_NV_vertex_program3",
  346. "GLX_SGIX_hyperpipe",
  347. "GLX_MESA_agp_offset",
  348. "GL_EXT_texture_compression_dxt1",
  349. "GL_EXT_framebuffer_object",
  350. "GL_GREMEDY_string_marker",
  351. };
  352. Map<String,int> OutputOrder;
  353. //-----------------------------------------------------------------------------
  354. String trim(const char* str)
  355. {
  356. String ts = "";
  357. if (str) {
  358. int s = 0, e = strLength(str);
  359. for (; s != e; s++) {
  360. C8 c = str[s];
  361. if (c != ' ' && c != '\t' && c != '\n')
  362. break;
  363. }
  364. while (s != e) {
  365. C8 c = str[--e];
  366. if (c != ' ' && c != '\t' && c != '\n')
  367. break;
  368. }
  369. if (s != e)
  370. ts.insert(0,str + s,e-s+1);
  371. }
  372. return ts;
  373. }
  374. //-----------------------------------------------------------------------------
  375. struct Group
  376. {
  377. String name;
  378. String link;
  379. Array<String> defines;
  380. Array<String> functions;
  381. Array<String> types;
  382. int order;
  383. };
  384. typedef Array<Group> GroupList;
  385. static inline int weight(const String& str)
  386. {
  387. if (str.find("GL_VERSION") != String::NPos)
  388. return 0;
  389. String prefix = str.substr(0,3);
  390. if (prefix == "GL_")
  391. return 1;
  392. if (prefix == "GLU")
  393. return 2;
  394. if (prefix == "GLX")
  395. return 3;
  396. if (prefix == "WGL")
  397. return 4;
  398. return 5;
  399. }
  400. bool operator<(const Group& a,const Group& b)
  401. {
  402. int wa = weight(a.name);
  403. int wb = weight(b.name);
  404. return (wa == wb)? a.name < b.name: wa < wb;
  405. // return a.order < b.order;
  406. }
  407. bool loadFile(Group& group,String name)
  408. {
  409. FILE* file = fopen(name.c_str(),"r");
  410. if (!file) {
  411. Print("Could not open file " + name);
  412. return false;
  413. }
  414. char buf[512];
  415. group.name = trim(fgets(buf,sizeof(buf),file));
  416. Map<String,int>::Iterator entry = OutputOrder.find(group.name);
  417. if (entry == OutputOrder.end()) {
  418. Print ("[" + group.name + "]");
  419. }
  420. group.order = (entry != OutputOrder.end())? entry->value: 2000;
  421. while (!feof(file)) {
  422. String str = trim(fgets(buf,sizeof(buf),file));
  423. if (!str.length())
  424. continue;
  425. if (str.find("http:") != String::NPos) {
  426. group.link = trim(str);
  427. continue;
  428. }
  429. if (str.find("typedef") != String::NPos) {
  430. group.types.pushBack(str);
  431. continue;
  432. }
  433. if (str.find("DECLARE") != String::NPos) {
  434. group.types.pushBack(str);
  435. continue;
  436. }
  437. if (str.find("(") != String::NPos) {
  438. group.functions.pushBack(str);
  439. continue;
  440. }
  441. group.defines.pushBack(str);
  442. }
  443. fclose( file );
  444. return true;
  445. }
  446. void loadDir(GroupList& groups,String name,const char* filter)
  447. {
  448. DIR *dir = opendir(name);
  449. if (!dir) {
  450. Print("Could not open file " + name);
  451. return;
  452. }
  453. struct dirent *fEntry;
  454. while ((fEntry = readdir(dir)) != 0) {
  455. if (fEntry->d_name[0] == '.')
  456. continue;
  457. String file = name + "/" + String(fEntry->d_name);
  458. if (filter[0] != '*' && file.find(filter) == String::NPos)
  459. continue;
  460. //Print("Loading " + file);
  461. groups.pushBack(Group());
  462. if (!loadFile(groups.last(),file))
  463. groups.popBack();
  464. }
  465. quickSort(groups.begin(),groups.end());
  466. }
  467. //-----------------------------------------------------------------------------
  468. void write(FILE* file,String line)
  469. {
  470. fwrite(line,1,line.length(),file);
  471. }
  472. void outputHeader(GroupList& groups, String name)
  473. {
  474. FILE* file = fopen(name.c_str(),"w");
  475. if (!file)
  476. Print("Could not open file " + name);
  477. // Output all the group name together at the top
  478. for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++)
  479. write(file,"#define " + grp->name + "\n");
  480. #if 0 // Types now with the group
  481. // Output all the types for all the extensions
  482. for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++)
  483. for (Array<String>::Iterator itr = grp->types.begin();
  484. itr != grp->types.end(); itr++)
  485. write(file,*itr + ";\n");
  486. #endif
  487. // Output the defines for each group
  488. for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++) {
  489. if (!grp->name)
  490. continue;
  491. write(file,"\n#ifdef " + grp->name + "\n");
  492. for (Array<String>::Iterator itr = grp->types.begin();
  493. itr != grp->types.end(); itr++)
  494. write(file,*itr + ";\n");
  495. for (Array<String>::Iterator itr = grp->defines.begin();
  496. itr != grp->defines.end(); itr++) {
  497. write(file,"#define " + *itr + "\n");
  498. }
  499. for (Array<String>::Iterator itr = grp->functions.begin();
  500. itr != grp->functions.end(); itr++) {
  501. String& str = *itr;
  502. // Parse function "return name (args)". Start at the back because
  503. // args is enclosed in (), the name has no spaces, and the return type
  504. // can be several tokens, such as "void *" or "const char *"
  505. int b = str.length();
  506. int a = b - 1;
  507. while (str[a] != '(')
  508. a--;
  509. while (str[--a] == ' ')
  510. ;
  511. b = a;
  512. while (str[a] != ' ')
  513. a--;
  514. String name = str.substr(a+1,b - a);
  515. //
  516. write(file,"#define "+name+" XGL_FUNCPTR("+name+")\n");
  517. }
  518. write(file,"#endif\n");
  519. }
  520. fclose(file);
  521. }
  522. void outputFunctions(GroupList& groups, String name)
  523. {
  524. FILE* file = fopen(name.c_str(),"w");
  525. if (!file)
  526. Print("Could not open file " + name);
  527. // Output the functions for each group
  528. for (GroupList::Iterator grp = groups.begin(); grp != groups.end(); grp++) {
  529. if (!grp->name)
  530. continue;
  531. if (grp->name == "GL_ARB_imaging")
  532. // Imaging is include as part of 1.4...
  533. write(file,"\n#if defined(GL_ARB_imaging) && !defined(GL_VERSION_1_4)\n");
  534. else
  535. write(file,"\n#ifdef " + grp->name + "\n");
  536. write(file,"GL_GROUP_BEGIN(" + grp->name + ")\n");
  537. for (Array<String>::Iterator itr = grp->functions.begin();
  538. itr != grp->functions.end(); itr++) {
  539. String& str = *itr;
  540. // Parse function "return name (args)". Start at the back because
  541. // args is enclosed in (), the name has no spaces, and the return type
  542. // can be several tokens, such as "void *" or "const char *"
  543. int b = str.length();
  544. int a = b - 1;
  545. while (str[a] != '(')
  546. a--;
  547. String args = str.substr(a,b - a);
  548. while (str[--a] == ' ')
  549. ;
  550. b = a;
  551. while (str[a] != ' ')
  552. a--;
  553. String name = str.substr(a+1,b - a);
  554. while (str[a] == ' ')
  555. a--;
  556. String rtype = str.substr(0,a+1);
  557. //
  558. write(file,"GL_FUNCTION("+name+","+rtype+","+args+")\n");
  559. }
  560. write(file,"GL_GROUP_END()\n#endif\n");
  561. }
  562. fclose(file);
  563. }
  564. //-----------------------------------------------------------------------------
  565. int main(int argc, char* argv[])
  566. {
  567. Kernel::installDefaultPrint();
  568. // Build a name -> order map for faster lookups.
  569. for (int i = 0; i < sizeof(OrderTable) / sizeof(const char*); i++)
  570. OutputOrder.insert(String(OrderTable[i]),i+1);
  571. GroupList extensions;
  572. extensions.reserve(800);
  573. loadDir(extensions,"core","VERSION");
  574. loadDir(extensions,"extensions","*");
  575. outputHeader(extensions,"glext.h");
  576. outputFunctions(extensions,"glfnext.h");
  577. return 0;
  578. }