# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.

import sys,os;
import cPickle;
import types;
import string;
import re;

import stub_common;

parsed_file = open( "../glapi_parser/gl_header.parsed", "rb" )
gl_mapping = cPickle.load( parsed_file )

keys = gl_mapping.keys()
keys.sort();

stub_common.CopyrightC()

print """
/* DO NOT EDIT - THIS FILE GENERATED BY THE getprocaddress.py SCRIPT */
#include "cr_glwrapper.h"
#include "api_templates.h"
#include "cr_applications.h"
#include "cr_string.h"
#include "cr_error.h"

#include <stdio.h>

#ifdef WINDOWS
#pragma warning( disable: 4055 )
#endif
"""

for func_name in stub_common.AllSpecials( "getprocaddress" ):
	( return_type, arg_names, arg_types ) = gl_mapping[func_name];
	print 'extern %s stub_%s%s;' % (return_type, func_name, stub_common.ArgumentString( arg_names, arg_types ) )

print """
CR_PROC CR_APIENTRY crGetProcAddress( const char *name )
{"""

bonus_functions = [
	"crCreateContext",
	"crDestroyContext",
	"crMakeCurrent",
	"crSwapBuffers",
	"crCreateWindow",
	"crDestroyWindow",
	"crWindowSize",
	"crWindowPosition"
]

for func_name in keys:
	if stub_common.FindSpecial( "noexport", func_name ):
		continue
	if stub_common.FindSpecial( "getprocaddress", func_name ):
		print '\tif (!crStrcmp( name, "gl%s" )) return (CR_PROC) stub_%s;' % ( func_name, func_name )
		continue
	print '\tif (!crStrcmp( name, "gl%s" )) return (CR_PROC) glim.%s;' % ( func_name, func_name )

for func_name in bonus_functions:
	print '\tif (!crStrcmp( name, "%s" )) return (CR_PROC) %s;' % ( func_name, func_name )

print '\treturn NULL;'
print '}'

@@ -608,16 +608,36 @@
 error.h%22
+%0A#include %22cr_spu.h%22
 %0A%0A#inclu
@@ -854,16 +854,25 @@
 tern %25s 
+APIENTRY 
 stub_%25s%25

fix Windows build for stub_GetChromiumParametervCR()