OpenVMS Source-Code Demos

basic_calling_c_demo5_part1

1000	!=================================================================================================
	! title  : basic_calling_c_demo5_part1.bas
	! author : Neil Rieck
	! what   : passing string data from BASIC to C (and back again)
	! build  : bas  basic_calling_c_demo5_part1
	!	 : cc   basic_calling_c_demo5_part2
	!	 : link /exc=basic_calling_c_demo5.exe	-
	!		basic_calling_c_demo5_part1,	-
	!		basic_calling_c_demo5_part2
	! history:
	! ver who when   what
	! --- --- ------ ---------------------------------------------------------------------------------
	! 100 NSR 170531 original effort (one dimensional array)
	!	  170601 added support for a two dimensional array
	!	  170823 added a missing block of code (data retrieval from 2d)
	!		 added examples 53 + 54 (just hacking here)
	!	  170824 added array59
	!=================================================================================================
	option type=explicit							! no kid's stuff
	declare string constant k_program = "basic_calling_c_demo5_part1"
	!
	!	note: the second parameter will be the address of a list of string descriptors
	!
	external long function basic_calling_c_demo_example_51(	long		by ref,	&
								string dim()	by ref	)
	!
	!	note: the second parameter will be the address of a list of string descriptors
	!
	external long function basic_calling_c_demo_example_52(	long		by ref,	&
								long		by ref,	&
								string dim(,)	by ref	)
	!
	!	note: here are passing the address of an array descriptor
	!
	external long function basic_calling_c_demo_example_53(	string dim()	by desc	)
	external long function basic_calling_c_demo_example_54(	string dim(,)	by desc	)
	!
	!	global variables (BASIC only)
	!
	declare long	x_max , y_max,				&
		long	x_iter,	y_iter,				&
		long	rc,					&
		string	junk$
	!=======================================================================
	!	main
	!=======================================================================
2000	main:
	print "-i-program: "+k_program 						!
	!
	!#######################################################################
	!
3000	print "================================================="
	print "test 51 (single dimension array)"
	print "================================================="
	input "enter x (1-9, default=1)";x_max					!
	x_max = 1	if x_max = 0						!
	dim string array51(x_max)						! run-time allocation
	!
3010	print "-i-creating test data (51)"					!
	for x_iter = 0 to x_max							!
	    array51(x_iter) = "example 51 test data "+str$(x_iter)		!
	    print "-i-data stored:"; array51(x_iter)				!
	next x_iter								!
	!
3020	print "-i-calling basic_calling_c_demo_example_51"			!
	rc = basic_calling_c_demo_example_51(x_max, array51() )			!
	print "-i-back in: "+k_program						!
	print "-i-rc:";rc							!
	input "-?-hit <enter> to continue...";junk$				!
	!
3030	print "-i-Starting BASIC data retrieval (51)"				!
	for x_iter = 0 to x_max							!
	    print "-i-data read: "; array51(x_iter)				!
	next x_iter								!
	input "-?-hit <enter> to continue...";junk$				!
	!
	!#######################################################################
	!
4000	print "================================================="
	print "test 52 (two dimension array)"
	print "================================================="
	input "enter x (1-9, default=2)";x_max					!
	x_max = 2	if x_max = 0						!
	input "enter y (1-9, default=3)";y_max					!
	y_max = 3	if y_max = 0						!
	dim string array52(y_max, x_max)					! run-time allocation
	!
4010	print "-i-creating test data (52)"					!
	for y_iter = 0 to y_max							!
	    for x_iter = 0 to x_max						!
		array52(y_iter, x_iter) = "example 52 test data: "+str$(y_iter)+":"+str$(x_iter)
		print "-i-data stored:"; array52(y_iter, x_iter)		!
	    next x_iter								!
	next y_iter								!
	!
4020	print "-i-calling basic_calling_c_demo_example_51"			!
	rc = basic_calling_c_demo_example_52(y_max, x_max, array52(,))		!
	print "-i-back in: "+k_program						!
	print "-i-rc:";rc							!
	input "-?-hit <enter> to continue...";junk$				!
	!
4030	print "-i-Starting BASIC data retrieval (52)"				!
	for y_iter = 0 to y_max							!
	    for x_iter = 0 to x_max						!
		print "-i-data read: "; array52(y_iter, x_iter)			!
	    next x_iter								!
	next y_iter								!
	input "-?-hit <enter> to continue...";junk$				!
	!
	!#######################################################################
	!
	print
	print "Note: this next bit is pure hacking (see the c code)"		!
	input "-?-hit <enter> to continue...";junk$				!
	!
5000	print "-i-calling basic_calling_c_demo_example_53 (just hacking)"	!
	rc = basic_calling_c_demo_example_53( array51() )			! pass a 1d array
	print "-i-back in: "+k_program						!
	print "-i-rc:";rc							!
	input "-?-hit <enter> to continue...";junk$				!
	!
6000	print "-i-calling basic_calling_c_demo_example_54 (just hacking)"	!
	rc = basic_calling_c_demo_example_54( array52(,) )			! pass a 2d array
	print "-i-back in: "+k_program						!
	print "-i-rc:";rc							!
	input "-?-hit <enter> to continue...";junk$				!
	!
7000	print "-i-creating 2d array not based at zero"				!
	dim string array59(1 to 2, 3 to 4 )					! a 2d array not based at zero
	print "-i-calling basic_calling_c_demo_example_54 (just hacking)"	!
	rc = basic_calling_c_demo_example_54( array59(,) )			! pass a 2d array
	print "-i-back in: "+k_program						!
	print "-i-rc:";rc							!
	input "-?-hit <enter> to continue...";junk$				!
	!=======================================================================
32000	print "-i-exiting: "+k_program						!
	end program (1)								! VMS-s-

Back to OpenVMS
Back to OpenVMS Demo Index
Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.