Example 1
This program demonstrates how to receive parameters passed from a
Clipper application, from within C, using the Clipper Extend system.
/***
* Test.prg
*
* By: Scott McIntosh, Nantucket Corp.
*
* Program to test the TestC.c program.
*
* Compile: CLIPPER test /n /a /w
*
* Link: RTLINK FI test, testc LIB clipper, llibca /NOE
*/
PROCEDURE Main()
// define a set of misc. data to check the C function with.
// The array in aVar1 contains a nested array. The nested array
// can not be accessed through the extend system!
//
LOCAL aVar1 := { "Hello, world", 12, DATE(), .F., { "One", "Two" } }
LOCAL nVar1 := 1234
LOCAL cVar1 := "This string is bigger than 30 characters!"
LOCAL dVar1 := DATE()
LOCAL lVar1 := .T.
LOCAL xVar
// and create a new set of data to pass by reference
//
LOCAL aVar2 := { "First Element", "Second Element", "Third Element" }
LOCAL nVar2 := -1234
LOCAL cVar2 := "A shorter string"
LOCAL dVar2 := CTOD( "9/15/91" )
LOCAL lVar2 := .F.
CLS
ExtendTest( aVar1, nVar1, cVar1, dVar1, lVar1, xVar, ;
@aVar2, @nVar2, @cVar2, @dVar2, @lVar2, )
SETPOS( MAXROW(), 0 )
QUIT
/***
* TestC.c
*
* By: Scott McIntosh, Nantucket Corp.
*
* Demonstrates how to use the Clipper extend system to receive parameters
* from Clipper. This program simply displays the types and values of the
* parameters that are passed to it.
*
* Display is written to stdout and is DOS re-directable.
*
* Compile: cl /AL /c /FPa /Gs /Oalt /Zl testc.c
*/
#include "extend.h"
CLIPPER ExtendTest( void )
{
int parNum; // current parameter number
int arrIndex; // current array index number
// process each parameter in turn
for( parNum = 1; parNum <= PCOUNT; parNum++ )
{
// make sure the array index counter is zeroed
arrIndex = 0;
// display the current parameter number
cprintf( "\r\nParameter %2i ", parNum );
// show the type of the current parameter
ShowType( _parinfo( parNum ), parNum, arrIndex );
if( ISARRAY( parNum ) )
{
// parameter is an array - process each element in turn
for( arrIndex = 1; arrIndex <= ALENGTH( parNum ); arrIndex++ )
{
// indent and display the current array element number
cprintf( " Element %2i ", arrIndex );
// display the current array element type
ShowType( _parinfa( parNum, arrIndex ), parNum, arrIndex );
}
}
}
_ret();
}
/***
* ShowType( int parameterType, int parameterNumber, int arrayElement )
*
* Processes parameters and the individual elements of array parameters.
*
* Displays the numeric value of the data type of the parameter/element,
* a text description of the type (i.e.: "Character" ), and the value of
* the parameter/element.
*
* The text description will be preceded with a "@" to indicate a
* parameters that was passed by reference.
*
* The following substitutions are made for the actual value of the
* parameter/element:
* Arrays display "{...}"
* Logicals display 0 or 1 ( 0 = .F., 1 = .T. )
* Characters display First 30 characters of the string
* Undefines display "???"
*/
void ShowType( int type, int param, int index )
{
// show the correct text description and value for the current item
switch ( type )
{
case UNDEF:
cprintf( "Undefined Value: ???\r\n" );
break;
case CHARACTER:
cprintf( "Character Value: %.30s\r\n", _parc( param, index ) );
break;
case NUMERIC:
cprintf( "Numeric Value: %i\r\n", _parnl( param, index ) );
break;
case LOGICAL:
cprintf( "Logical Value: %i\r\n", _parl( param, index ) );
break;
case DATE:
cprintf( "Date Value: %s\r\n", _pards( param, index ) );
break;
case ARRAY:
cprintf( "Array Value: {...}\r\n" );
break;
case (MPTR + UNDEF):
cprintf( "@Undefined Value: ???\r\n" );
break;
case (MPTR + CHARACTER):
cprintf( "@Character Value: %.30s\r\n", _parc( param, index ) );
break;
case (MPTR + NUMERIC):
cprintf( "@Numeric Value: %i\r\n", _parni( param, index ) );
break;
case (MPTR + LOGICAL):
cprintf( "@Logical Value: %i\r\n", _parl( param, index ) );
break;
case (MPTR + DATE):
cprintf( "@Date Value: %s\r\n", _pards( param, index ) );
break;
case (MPTR + ARRAY):
cprintf( "@Array Value: {...}\r\n" );
break;
}
return;
}
/* EOF: Example 1 */