# 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 "chromium.h"
#include "api_templates.h"
#include "cr_string.h"
#include "cr_error.h"
#include "cr_spu.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 APIENTRY 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",
	"crWindowCreate",
	"crWindowDestroy",
	"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 '}'

# 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 "chromium.h"
#include "api_templates.h"
#include "cr_string.h"
#include "cr_error.h"
#include "cr_spu.h"
#include "stub.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 APIENTRY stub_%s%s;' % (return_type, func_name, stub_common.ArgumentString( arg_names, arg_types ) )

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

bonus_functions = [
	"crCreateContext",
	"crDestroyContext",
	"crMakeCurrent",
	"crSwapBuffers",
	"crWindowCreate",
	"crWindowDestroy",
	"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 '}'

call StubInit() to start Chromium if application calls GetProcAddress first.