Question: How this C code is translated into PB?

Just starting out? Need help? Post your questions and find answers here.
Aming
New User
New User
Posts: 3
Joined: Fri Nov 02, 2012 10:02 am

Question: How this C code is translated into PB?

Post by Aming »

Please help to translation the c code into pb.
I don't know the Structure of '_FoxTable','FoxInfo' how to translated into PB?
Thank you.

//+--------------------------------------------------------------------------
//
// File: pro_ext.h
//
//---------------------------------------------------------------------------

#ifndef PRO_EXT_INCLUDED
#define PRO_EXT_INCLUDED

#if defined(_MSC_VER)
#pragma pack(push, 1) // Assume byte structure packing
#endif

#ifdef __cplusplus
extern "C" { // Assume C declarations for C++
#endif


// Fastcall calling convention
#define FASTCALL _fastcall

// FPFI is a 32 bit pointer to a function returning an int
typedef long (*FPFI)();

// The FoxInfo structure contains the descriptions of the functions
// contained in the library.
typedef struct {
char * funcName; /* Function name (all caps) */
FPFI function; /* Actual function address */
short parmCount; /* # parameters specified or a flag value */
char * parmTypes; /* Parameter list description */
} FoxInfo;

typedef struct _FoxTable {
struct _FoxTable *nextLibrary; /* Linked list of libraries */
short infoCount; /* # of functions in this library */
FoxInfo *infoPtr; /* Function list */
} FoxTable;

// An expression's value
typedef struct {
char ev_type;
char ev_padding;
short ev_width;
unsigned ev_length;
long ev_long;
double ev_real;
long ev_currency;
long ev_currency2;
unsigned ev_handle;
unsigned long ev_object;
} Value;

// A reference to a database or memory variable
typedef struct {
char l_type;
short l_where, /* Database number or -1 for memory */
l_NTI, /* Variable name table offset */
l_offset, /* Index into database */
l_subs, /* # subscripts specified 0 <= x <= 2 */
l_sub1, l_sub2; /* subscript integral values */
} Locator;

typedef union {
Value val;
Locator loc; /* An 'R' in l_type means the Locator */
/* part of this union is in use. */
} FoxParameter;

// A paramter list to a library function.
typedef struct {
short pCount; /* Number of Parameters PASSED. */
FoxParameter p[1]; /* pCount Parameters. */
} ParamBlk;

int FASTCALL _Execute(char *stmt);
int FASTCALL _Evaluate(Value *val, char *expr);
void FASTCALL _Error(int code);
void FASTCALL _RetVal(Value *val);
void FASTCALL _RetLogical(int flag);
int FASTCALL _Store(Locator *loc, Value *val);
int FASTCALL _Load(Locator *loc, Value *val);
int FASTCALL _FindVar(int nti, int where, Locator *loc);
int FASTCALL _NameTableIndex(char *name);


#ifdef __cplusplus
} // End of extern "C" {
#endif

#if defined(_MSC_VER)
#pragma pack(pop) // Restore structure packing
#endif

#endif // PRO_EXT_INCLUDED


void ADD(ParamBlk *parm)
{
int retval;
retval=parm->p[0].val.ev_long+parm->p[1].val.ev_long;
_RetInt(retval,10);
}

FoxInfo xFoxInfo[]={
{"ADD",(FPFI)ADD,2,"I,I"},
};

FoxTable _FoxTable={
(FoxTable *)0,sizeof(xFoxInfo)/sizeof(FoxInfo),xFoxInfo
};
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Question: How this C code is translated into PB?

Post by idle »

not sure if you could use that in PB, it looks like it's requiring fastcall
and it's not supported by PB on x86
Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply