Announcement

Collapse
No announcement yet.

Make PowerBasic do what C program is doing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Make PowerBasic do what C program is doing

    Hi
    I have this old C code and is wondering if Powerbasic can do what this code is doing. The C code reads/writes from/to the DOS version of Navision accounting system.


    /*******************************************************************************
    * Database C-Library Test application. *
    * *
    * (c) 1996 Navision Software a/s. *
    *******************************************************************************/
    #ifdef __TURBOC__
    extern int _stklen = 0x4000;
    #endif

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <dbl.h>
    #define RECORDCOUNT 500

    typedef struct {
    DBL_U8 FieldNo;
    DBL_S16 FieldType;
    DBL_S16 FieldSize;
    char *FieldName;
    } FieldDefinitionType;

    FieldDefinitionType fieldsstruct[] = {
    {1, DBL_Type_S16 , 2, "Counter"},
    {2, DBL_Type_STR , 31, "Text"},
    {3, DBL_Type_BYTE , 1, "SelectionField"}
    };


    void verifyTables(void)
    {
    DBL_S16 TableNo;
    DBL_HTABLE hTable;

    for (TableNo = 0 ; 0 != (TableNo = DBL_NextTable(TableNo))
    {
    DBL_Allow(DBL_Err_TableNotFound);
    if (!DBL_OpenTable(&hTable, TableNo))
    {
    printf("Table No %d Not Found Error !\n",TableNo);
    return;
    }

    if (TableNo != DBL_TableNo(DBL_TableName(hTable)))
    {
    printf("Table No %d Name Error !\n",TableNo);
    return;
    }

    DBL_BWT();
    DBL_LockTable(hTable,DBL_LockNoWait);
    DBL_AWT();
    DBL_CloseTable(hTable);
    }
    printf("OK\n");
    }


    int verifyTableSetup(DBL_HTABLE hTable)
    {
    DBL_U8 FieldNo;
    DBL_U8 DBL_FAR *Keys;
    DBL_U8 DBL_FAR *ByteSet;
    DBL_S16 i;

    printf("Verifying the table layout ..");

    if (DBL_FieldCount(hTable) != sizeof(fieldsstruct)/sizeof(FieldDefinitionType))
    {
    printf("Field count\nError !");
    return(-1);
    }

    for (FieldNo = 0,i = 0; 0 != (FieldNo = DBL_NextField(hTable,FieldNo)); i++)
    {
    if (FieldNo != fieldsstruct[i].FieldNo)
    {
    printf("Unknown fieldNo %d in table\nError !",FieldNo);
    return(-1);
    }

    if (DBL_FieldClass(hTable, FieldNo) == DBL_Class_Calculated)
    {
    printf("FieldNo %d was a calculated field\nError !",FieldNo);
    return(-1);
    }

    if (DBL_FieldClass(hTable, FieldNo) != DBL_Class_Ordinary)
    {
    printf("FieldNo %d was not a normal field\nError !",FieldNo);
    return(-1);
    }

    if (DBL_FieldType(hTable,FieldNo) != fieldsstruct[i].FieldType)
    {
    printf("FieldType error FieldNo %d was %d, expected %d\nError !",FieldNo,DBL_FieldType(hTable,FieldNo),fieldsstruct[i].FieldType);
    return(-1);
    }

    if (DBL_FieldSize(hTable,FieldNo) != fieldsstruct[i].FieldSize)
    {
    printf("FieldSize error FieldNo %d was %d, expected %d\nError !",FieldNo,DBL_FieldSize(hTable, FieldNo),fieldsstruct[i].FieldSize);
    return(-1);
    }

    if (strcmp((char*)DBL_FieldName(hTable,FieldNo),fieldsstruct[i].FieldName))
    {
    printf("Fieldname error FieldNo %d was %s, expected %s\nError !", FieldNo,DBL_FieldName(hTable,FieldNo),fieldsstruct[i].FieldName);
    return(-1);
    }

    if ((ByteSet = DBL_FieldOptionStr(hTable,FieldNo)) != NULL)
    if (strcmp((char*)ByteSet,"Selection 1, Selection 2, Selection 3") != 0)
    {
    printf("ByteSet error was %s,expected %s\nError !",ByteSet,"Selection 1, Selection 2, Selection 3");
    return(-1);
    }
    }

    if (DBL_KeyCount(hTable) != 1)
    {
    printf("Key count\nError !");
    return(-1);
    }

    Keys = DBL_NextKey(hTable,NULL);
    if ((*Keys != 1) && (strlen((char*)Keys) != 1))
    {
    printf("Key field\nError !");
    return(-1);
    }
    printf("OK\n");
    return(0);
    }


    void deleteAllRecords(DBL_HTABLE hTable)
    {
    void DBL_FAR *Rec;

    printf("Deleting all records ..");

    DBL_AllocRec(hTable,&Rec);
    DBL_BWT();
    DBL_Allow(DBL_Err_RecordNotFound);
    while (DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"-"))
    {
    DBL_DeleteRec(hTable,Rec);
    DBL_Allow(DBL_Err_RecordNotFound);
    }
    DBL_EWT();
    DBL_FreeRec(Rec);
    printf("OK\n");
    }


    void DBL_FAR * RecFieldAddr(DBL_HTABLE hTable,
    void DBL_FAR *Rec,
    DBL_U8 FieldNo)
    {
    return(((DBL_U8 DBL_FAR *)Rec) + DBL_FieldOffset(hTable,FieldNo));
    }


    void AssignRecField(DBL_HTABLE hTable,
    void DBL_FAR *Rec,
    DBL_U8 FieldNo,
    void *Val)

    {
    memcpy(RecFieldAddr(hTable,Rec,FieldNo),Val,DBL_FieldSize(hTable,FieldNo));
    }


    int createTestData(DBL_HTABLE hTable)
    {
    DBL_S16 i;
    void DBL_FAR *Rec;
    char s[100];

    printf("Creating test data ..");

    DBL_AllocRec(hTable,&Rec);
    DBL_BWT();
    for (i = 0 ; i < RECORDCOUNT ; i++ )
    {
    DBL_InitRec(hTable,Rec);
    sprintf(s,"This is record number %d",i);
    AssignRecField(hTable,Rec,1,&i);
    AssignRecField(hTable,Rec,2,s);

    DBL_Allow(DBL_Err_RecordExists);
    if (!DBL_InsertRec(hTable,Rec))
    {
    printf("Record %d was allready present in database\nError !!\n",i);
    DBL_AWT();
    DBL_FreeRec(Rec);
    return(-1);
    }
    }
    DBL_EWT();
    DBL_FreeRec(Rec);
    printf("OK\n");
    return(0);
    }


    int verifyTestData(DBL_HTABLE hTable)
    {
    DBL_S16 i;
    char s[100];
    void DBL_FAR *Rec;

    printf("Verifying test data ..");

    DBL_AllocRec(hTable,&Rec);

    for (i = 0 ; i < RECORDCOUNT ; i++ )
    {
    DBL_InitRec(hTable,Rec);
    AssignRecField(hTable,Rec,1,&i);

    DBL_Allow(DBL_Err_RecordNotFound);
    if (!DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"="))
    {
    printf("Record %d not found\nError !!\n",i);
    DBL_FreeRec(Rec);
    return(-1);
    }

    if (memcmp(RecFieldAddr(hTable,Rec,1),&i,sizeof(i)))
    {
    printf("Counter field differs %d\nError !!\n",i);
    DBL_FreeRec(Rec);
    return(-1);
    }

    sprintf(s,"This is record number %d",i);
    if (memcmp(RecFieldAddr(hTable,Rec,2),s,strlen(s)+1))
    {
    printf("Tekst field differs %s\nError !!\n",s);
    DBL_FreeRec(Rec);
    return(-1);
    }
    }

    DBL_FreeRec(Rec);
    printf("OK\n");
    return(0);
    }


    int verifyModifiedTestData(DBL_HTABLE hTable)
    {
    DBL_S16 i;
    void DBL_FAR *Rec;
    char s[100];

    printf("Verifying modified test data ..");

    DBL_AllocRec(hTable,&Rec);

    if (DBL_FieldNo(hTable,DBL_FieldName(hTable,1)) != 1)
    {
    printf("%s FieldName is not field no 1\n",DBL_FieldName(hTable,1));
    DBL_FreeRec(Rec);
    return(-1);
    }

    DBL_BWT();
    DBL_InitRec(hTable,Rec);
    i = 256;

    sprintf(s,"%d modified",i);
    AssignRecField(hTable,Rec,1,&i);
    AssignRecField(hTable,Rec,2,s);

    DBL_Allow(DBL_Err_RecordNotFound);
    if (!DBL_ModifyRec(hTable,Rec))
    {
    printf("Record %d not found\nError !!\n",i);
    DBL_AWT();
    DBL_FreeRec(Rec);
    return(-1);
    }
    DBL_EWT();

    DBL_Allow(DBL_Err_RecordNotFound);
    if (!DBL_FindRec(hTable,Rec,(DBL_U8 DBL_FAR*)"="))
    {
    printf("Record %d not found\nError !!\n",i);
    DBL_FreeRec(Rec);
    return(-1);
    }

    if (memcmp(RecFieldAddr(hTable,Rec,1),&i,sizeof(i)))
    {
    printf("Counter field differs %d\nError !!\n",i);
    DBL_FreeRec(Rec);
    return(-1);
    }

    if (memcmp(RecFieldAddr(hTable,Rec,2),s,strlen(s)+1))
    {
    printf("Tekst field differs %s\nError !!\n",s);
    DBL_FreeRec(Rec);
    return(-1);
    }

    DBL_FreeRec(Rec);
    printf("OK\n");
    return(0);
    }


    int verifySetFilter(DBL_HTABLE hTable)
    {
    char s[80];
    DBL_U16 MinValue;
    DBL_U16 MaxValue;

    printf("Testing filter functions ..");

    DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)">100&<200","",NULL);

    if (DBL_RecCount(hTable) != 99)
    {
    printf("Error\n");
    DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
    return(-1);
    }

    DBL_GetFilter(hTable,1,(DBL_U8 DBL_FAR*)s,sizeof(s)-1);
    if (strcmp(s,">100&<200") != 0)
    {
    printf("Error\n");
    DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
    return(-1);
    }

    MinValue = 100;
    MaxValue = 200;
    DBL_SetRange(hTable,1,&MinValue,&MaxValue);
    MinValue = 0;
    MaxValue = 0;
    DBL_GetRange(hTable, 1,&MinValue, &MaxValue);

    if ((MinValue != 100) || (MaxValue != 200))
    {
    printf("Error\n");
    DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
    return(-1);
    }

    DBL_SetFilter(hTable,1,(DBL_U8 DBL_FAR*)"",NULL);
    printf("OK\n");
    return(0);
    }


    int verifyKeyFunctions(DBL_HTABLE hTable)
    {
    DBL_U8 DBL_FAR *Key;
    DBL_U8 DBL_FAR *SumFields;

    printf("Testing key functions ..");

    Key = DBL_NextKey(hTable,NULL);

    if (Key == NULL)
    {
    printf("Error\n");
    return(-1);
    }

    if (*Key != 1)
    {
    printf("Error\n");
    return(-1);
    }

    DBL_Allow(DBL_Err_KeyNotFound);
    if (!DBL_SetCurrentKey(hTable,Key))
    {
    printf("Error\n");
    return(-1);
    }

    Key = DBL_GetCurrentKey(hTable);

    if (Key == NULL)
    {
    printf("Error\n");
    return(-1);
    }

    if (*Key != 1)
    {
    printf("Error\n");
    return(-1);
    }

    SumFields = DBL_KeySumFields(hTable,Key);
    if (SumFields == NULL)
    {
    printf("Error\n");
    return(-1);
    }

    if (*SumFields != 0)
    {
    printf("Error\n");
    return(-1);
    }

    printf("OK\n");
    return(0);
    }


    void verifySumFunctions(DBL_HTABLE hTable)
    {
    DBL_U8 DBL_FAR *Key;
    DBL_U8 DBL_FAR *SumFields;
    void DBL_FAR *Rec;

    printf("Testing sum functions ..");

    DBL_AllocRec(hTable,&Rec);
    Key = DBL_NextKey(hTable,NULL);
    SumFields = DBL_KeySumFields(hTable,Key);
    DBL_CalcSums(hTable,Rec,SumFields);
    DBL_FreeRec(Rec);
    printf("OK\n");
    }


    void DBL_PASCAL DBL_FAR DBL_LOADDS My_ExceptionHandler(DBL_U8 DBL_FAR * DBL_FAR *texts)
    {
    while (*texts)
    {
    printf("%s\n",*texts);
    texts++;
    }
    fflush(stdout);
    }


    void main(int argc, DBL_U8 *argv[], DBL_U8 *envp[])
    {
    DBL_S16 ServerNo = 0;
    DBL_U8 *NetType = (DBL_U8*)"tcpi";
    DBL_U8 *DatabaseName = (DBL_U8*)"CTOOLKIT";
    DBL_S16 ExceptionHandlerTest = 0;
    DBL_HTABLE hMainTable;
    DBL_U8 DBL_FAR *CompanyNamePtr;

    if (DBL_Init(argc, argv, envp) != 0)
    {
    printf("DBL_Init failed\n");
    return;
    }

    for (argc--,argv++;argc;argc--,argv++)
    {
    if (argv[0][0] == '-')
    switch (argv[0][1])
    {
    case 'd': DatabaseName = argv[0] + 2; continue;
    case 's': ServerNo = atoi((char*)(argv[0] + 2)); continue;
    case 'n': NetType = argv[0] + 2; continue;
    case 't': ExceptionHandlerTest = 1; continue;
    }
    printf("Invalid Command line option\n\r [-d[DATABASENAME], [-s[SERVERNUMBER], -n[NETTYPE], -t (Exception Handler test)]\n\r");
    return;
    }

    if (ServerNo)
    DBL_ConnectServer(ServerNo,NetType);
    else
    #ifdef DOS
    DBL_OpenDatabase(DatabaseName,20, 0);
    #else
    DBL_OpenDatabase(DatabaseName,1000, 100);
    #endif

    for (CompanyNamePtr = NULL ; 0 != (CompanyNamePtr = DBL_NextCompany(CompanyNamePtr)); )
    printf("Company present %s\n",CompanyNamePtr);

    DBL_OpenCompany((DBL_U8 DBL_FAR*)"C-TOOLKIT");

    printf("Testing some table functions ..");
    verifyTables();

    DBL_OpenTable(&hMainTable,1000);

    if (strcmp("C-TOOLKIT",(char*)DBL_TableName(hMainTable)) != 0)
    {
    printf("C-TOOLKIT account not found\n");
    goto Error;
    }

    if (verifyTableSetup(hMainTable) != 0) goto Error;
    deleteAllRecords(hMainTable);
    if (createTestData(hMainTable) != 0) goto Error;
    if (verifyTestData(hMainTable) != 0) goto Error;
    if (verifyModifiedTestData(hMainTable) != 0) goto Error;
    if (verifySetFilter(hMainTable) != 0) goto Error;
    if (verifyKeyFunctions(hMainTable) != 0) goto Error;
    verifySumFunctions(hMainTable);

    if (ExceptionHandlerTest)
    {
    printf("Exception Handler test\n");
    DBL_SetExceptionHandler(My_ExceptionHandler);
    DBL_OpenTable(&hMainTable,2000);
    printf("Exception Handler test failed\n");
    }

    Error:

    DBL_CloseCompany();

    if (ServerNo)
    DBL_DisconnectServer();
    else
    DBL_CloseDatabase();

    DBL_Exit();
    printf("Database test ended\n");
    }
    Magnus Soffaniasson
    http://vdsl.is

  • #2
    I dont see why not. It would require the conversion but the displayed code doesnt seem to have anything extraordinarily hard to convert, I dont know the dbl.h contents, depending on it, the conversion should be very straightforward.

    www.pluribasic.com

    Comment


    • #3
      dbl.h is this:
      /*******************************************************************************
      * Database C-Library Version 2.01 Release 1 *
      * *
      * (c) 1996 Navision Software a/s. *
      *******************************************************************************/
      #define DBL_MaxRecSize 1000
      #define DBL_MaxCompanyNameLen 15
      #define DBL_MaxTableNameLen 30
      #define DBL_MaxFieldNameLen 20
      #define DBL_MaxUserIDLen 10
      #define DBL_MaxNoOfKeys 20
      #define DBL_MaxFieldsPerKey 10
      #define DBL_MaxSumFieldsPerKey 10
      #define DBL_MaxPassWordLen 10

      #define DBL_Err_TableNotFound -1001
      #define DBL_Err_RecordNotFound -1008
      #define DBL_Err_RecordExists -1009
      #define DBL_Err_KeyNotFound -1007


      typedef unsigned char DBL_U8;
      typedef unsigned short int DBL_U16;
      typedef signed short int DBL_S16;

      #ifdef OSF1
      typedef unsigned int DBL_U32;
      typedef signed int DBL_S32;
      #else
      typedef unsigned long int DBL_U32;
      typedef signed long int DBL_S32;
      #endif

      typedef DBL_S16 DBL_BOOL;
      typedef DBL_U16 DBL_DATE;
      typedef DBL_U32 DBL_TIME;

      typedef struct { DBL_U8 Exp; DBL_U8 Mant[9]; } DBL_BCD;

      #ifdef OS2
      #define DBL_CDECL cdecl
      #define DBL_PASCAL pascal
      #define DBL_FAR far
      #define DBL_EXPORT(_type) _type
      #else
      #ifdef DOS
      #define DBL_CDECL cdecl
      #define DBL_PASCAL pascal
      #define DBL_FAR far
      #define DBL_EXPORT(_type) _type
      #else
      #ifdef WIN32
      #define DBL_CDECL _cdecl
      #define DBL_PASCAL __stdcall
      #define DBL_FAR
      #define DBL_EXPORT(_type) _type
      #else
      #ifdef UNIX
      #define DBL_CDECL
      #define DBL_PASCAL
      #define DBL_FAR
      #define DBL_EXPORT(_type) _type
      #else
      One of the symbols DOS, OS2 or UNIX must be defined.

      Fx:
      #define OS2
      #include <dbl.h>

      #endif
      #endif
      #endif
      #endif

      typedef DBL_S32 DBL_FAR* DBL_HTABLE;

      #define DBL_Class_Ordinary 0
      #define DBL_Class_Calculated 1
      #define DBL_Class_CalcFilter 2


      #define DBL_VERSION 5

      #define DBL_LockWait 0 /* DBL_LockTable() Option */
      #define DBL_LockNoWait 1 /* DBL_LockTable() Option */


      #ifdef OS2
      #define DBL_LOADDS _loadds
      #else
      #ifdef DOS
      #define DBL_LOADDS _loadds
      #else
      #define DBL_LOADDS
      #endif
      #endif
      /*******************************************************************************
      * FIELD TYPES AND FUNCTIONS *
      * *
      *******************************************************************************/

      #define DBL_Type_BYTE 0 /* 1 byte 0.. */
      #define DBL_Type_SBOOL 2 /* 1 byte 0 or 1 */
      #define DBL_Type_S16 3 /* 2 bytes */
      #define DBL_Type_BCD 5 /* 10 bytes */
      #define DBL_Type_STR 6 /* Max Field Len + 1 byte C-string */
      #define DBL_Type_DATE 7 /* 2 bytes */
      #define DBL_Type_TIME 8 /* 4 bytes */
      #define DBL_Type_ALPHA 10 /* Max Field Len + 2 bytes */
      #define DBL_Type_S32 11 /* 4 bytes */
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_Allow)(DBL_S16 ErrorCode);
      extern tDBL_Allow DBL_Allow ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_ConnectServer)(DBL_S16 ServerNo, DBL_U8 DBL_FAR * NetType);
      extern tDBL_ConnectServer DBL_ConnectServer ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_DisconnectServer)(void);
      extern tDBL_DisconnectServer DBL_DisconnectServer ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_OpenDatabase)(DBL_U8 DBL_FAR * DatabaseName, DBL_S16 CacheSize, DBL_S16 LazyCache);
      extern tDBL_OpenDatabase DBL_OpenDatabase ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_CloseDatabase)(void);
      extern tDBL_CloseDatabase DBL_CloseDatabase ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR *) (DBL_FAR DBL_PASCAL *tDBL_NextCompany)(DBL_U8 DBL_FAR * CompanyName);
      extern tDBL_NextCompany DBL_NextCompany ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_OpenCompany)(DBL_U8 DBL_FAR * CompanyName);
      extern tDBL_OpenCompany DBL_OpenCompany ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_CloseCompany)(void);
      extern tDBL_CloseCompany DBL_CloseCompany ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_TableNo)(DBL_U8 DBL_FAR *TableName);
      extern tDBL_TableNo DBL_TableNo ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_NextTable)(DBL_S16 TableNo);
      extern tDBL_NextTable DBL_NextTable ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_OpenTable)(DBL_HTABLE DBL_FAR * hTablePtr, DBL_S16 TableNo);
      extern tDBL_OpenTable DBL_OpenTable ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR *) (DBL_FAR DBL_PASCAL *tDBL_TableName)(DBL_HTABLE hTable);
      extern tDBL_TableName DBL_TableName ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_CloseTable)(DBL_HTABLE hTable);
      extern tDBL_CloseTable DBL_CloseTable ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_LockTable)(DBL_HTABLE hTable, DBL_U16 Mode);
      extern tDBL_LockTable DBL_LockTable ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_AllocRec)(DBL_HTABLE hTable, void DBL_FAR * DBL_FAR * Rec);
      extern tDBL_AllocRec DBL_AllocRec ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_FreeRec)(void DBL_FAR * Rec);
      extern tDBL_FreeRec DBL_FreeRec ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_RecSize)(DBL_HTABLE hTable);
      extern tDBL_RecSize DBL_RecSize ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_FindRec)(DBL_HTABLE hTable, void DBL_FAR * Rec, DBL_U8 DBL_FAR * SearchMethod);
      extern tDBL_FindRec DBL_FindRec ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_NextRec)(DBL_HTABLE hTable, void DBL_FAR * Rec, DBL_S16 Step);
      extern tDBL_NextRec DBL_NextRec ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_InsertRec)(DBL_HTABLE hTable, void DBL_FAR * Rec);
      extern tDBL_InsertRec DBL_InsertRec ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_DeleteRec)(DBL_HTABLE hTable, void DBL_FAR * Rec);
      extern tDBL_DeleteRec DBL_DeleteRec ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_ModifyRec)(DBL_HTABLE hTable, void DBL_FAR * Rec);
      extern tDBL_ModifyRec DBL_ModifyRec ;
      typedef DBL_EXPORT(DBL_S32) (DBL_FAR DBL_PASCAL *tDBL_RecCount)(DBL_HTABLE hTable);
      extern tDBL_RecCount DBL_RecCount ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_InitRec)(DBL_HTABLE hTable, void DBL_FAR * Rec);
      extern tDBL_InitRec DBL_InitRec ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_CalcFields)(DBL_HTABLE hTable, void DBL_FAR * Rec, DBL_U8 DBL_FAR * FieldList);
      extern tDBL_CalcFields DBL_CalcFields ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_CalcSums)(DBL_HTABLE hTable, void DBL_FAR * Rec, DBL_U8 DBL_FAR * FieldList);
      extern tDBL_CalcSums DBL_CalcSums ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_KeyCount)(DBL_HTABLE hTable);
      extern tDBL_KeyCount DBL_KeyCount ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR*) (DBL_FAR DBL_PASCAL *tDBL_NextKey)(DBL_HTABLE hTable, DBL_U8 DBL_FAR * Key);
      extern tDBL_NextKey DBL_NextKey ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR*) (DBL_FAR DBL_PASCAL *tDBL_KeySumFields)(DBL_HTABLE hTable, DBL_U8 DBL_FAR * Key);
      extern tDBL_KeySumFields DBL_KeySumFields ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_SetCurrentKey)(DBL_HTABLE hTable, DBL_U8 DBL_FAR * Key);
      extern tDBL_SetCurrentKey DBL_SetCurrentKey ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR *) (DBL_FAR DBL_PASCAL *tDBL_GetCurrentKey)(DBL_HTABLE hTable);
      extern tDBL_GetCurrentKey DBL_GetCurrentKey ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_CDECL *tDBL_SetFilter)(DBL_HTABLE hTable, DBL_U8 FieldNo, DBL_U8 DBL_FAR * FilterStr, void DBL_FAR * ValuePtr1, ...);
      extern tDBL_SetFilter DBL_SetFilter ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_GetFilter)(DBL_HTABLE hTable, DBL_U8 FieldNo, DBL_U8 DBL_FAR * FilterStr, DBL_S16 FilterStrSize);
      extern tDBL_GetFilter DBL_GetFilter ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_SetRange)(DBL_HTABLE hTable, DBL_U8 FieldNo, void DBL_FAR * MinValue,
      void DBL_FAR * MaxValue);
      extern tDBL_SetRange DBL_SetRange ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_GetRange)(DBL_HTABLE hTable, DBL_U8 FieldNo, void DBL_FAR * MinValue,
      void DBL_FAR * MaxValue);
      extern tDBL_GetRange DBL_GetRange ;
      typedef DBL_EXPORT(DBL_U8) (DBL_FAR DBL_PASCAL *tDBL_FieldNo)(DBL_HTABLE hTable, DBL_U8 DBL_FAR *FieldName);
      extern tDBL_FieldNo DBL_FieldNo ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_FieldCount)(DBL_HTABLE hTable);
      extern tDBL_FieldCount DBL_FieldCount ;
      typedef DBL_EXPORT(DBL_U8) (DBL_FAR DBL_PASCAL *tDBL_NextField)(DBL_HTABLE hTable, DBL_U8 FieldNo);
      extern tDBL_NextField DBL_NextField ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_FieldType)(DBL_HTABLE hTable, DBL_U8 FieldNo);
      extern tDBL_FieldType DBL_FieldType ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_FieldSize)(DBL_HTABLE hTable, DBL_U8 FieldNo);
      extern tDBL_FieldSize DBL_FieldSize ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_FieldOffset)(DBL_HTABLE hTable, DBL_U8 FieldNo);
      extern tDBL_FieldOffset DBL_FieldOffset ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR *) (DBL_FAR DBL_PASCAL *tDBL_FieldName)(DBL_HTABLE hTable, DBL_U8 FieldNo);
      extern tDBL_FieldName DBL_FieldName ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR *) (DBL_FAR DBL_PASCAL *tDBL_FieldOptionStr)(DBL_HTABLE hTable, DBL_U8 FieldNo);
      extern tDBL_FieldOptionStr DBL_FieldOptionStr ;
      typedef DBL_EXPORT(DBL_S16) (DBL_FAR DBL_PASCAL *tDBL_FieldClass)(DBL_HTABLE hTable, DBL_U8 FieldNo);
      extern tDBL_FieldClass DBL_FieldClass ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_SelectLatestVersion)(void);
      extern tDBL_SelectLatestVersion DBL_SelectLatestVersion ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_BWT)(void);
      extern tDBL_BWT DBL_BWT ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_EWT)(void);
      extern tDBL_EWT DBL_EWT ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_AWT)(void);
      extern tDBL_AWT DBL_AWT ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR *) (DBL_FAR DBL_PASCAL *tDBL_UserID)(void);
      extern tDBL_UserID DBL_UserID ;
      typedef DBL_EXPORT(DBL_U8 DBL_FAR *) (DBL_FAR DBL_PASCAL *tDBL_CompanyName)(void);
      extern tDBL_CompanyName DBL_CompanyName ;
      typedef DBL_EXPORT(DBL_S32) (DBL_FAR DBL_PASCAL *tDBL_UserCount)(void);
      extern tDBL_UserCount DBL_UserCount ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_Login)(DBL_U8 DBL_FAR *UserID, DBL_U8 DBL_FAR * PassWord);
      extern tDBL_Login DBL_Login ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_Field_2_Str)(DBL_U8 DBL_FAR * Str, DBL_S16 StrSize, DBL_HTABLE hTable, void DBL_FAR * Rec, DBL_U8 FieldNo);
      extern tDBL_Field_2_Str DBL_Field_2_Str ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_BCD_2_Str)(DBL_U8 DBL_FAR * Str, DBL_S16 StrSize, DBL_BCD DBL_FAR * Bcd);
      extern tDBL_BCD_2_Str DBL_BCD_2_Str ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_Str_2_BCD)(DBL_BCD DBL_FAR * Bcd, DBL_U8 DBL_FAR * Str);
      extern tDBL_Str_2_BCD DBL_Str_2_BCD ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_YMD_2_Date)(DBL_DATE DBL_FAR * Date, DBL_U16 y, DBL_U16 m, DBL_U16 d, DBL_BOOL Closing);
      extern tDBL_YMD_2_Date DBL_YMD_2_Date ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_Date_2_YMD)(DBL_U16 DBL_FAR * y, DBL_U16 DBL_FAR * m, DBL_U16 DBL_FAR * d, DBL_BOOL DBL_FAR * Closing, DBL_DATE Date);
      extern tDBL_Date_2_YMD DBL_Date_2_YMD ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_HMST_2_Time)(DBL_TIME DBL_FAR * Time, DBL_U16 h, DBL_U16 m, DBL_U16 s, DBL_U16 t);
      extern tDBL_HMST_2_Time DBL_HMST_2_Time ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_Time_2_HMST)(DBL_U16 DBL_FAR * h, DBL_U16 DBL_FAR * m, DBL_U16 DBL_FAR * s, DBL_U16 DBL_FAR * t, DBL_TIME Time);
      extern tDBL_Time_2_HMST DBL_Time_2_HMST ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_Alpha_2_Str)(DBL_U8 DBL_FAR * Str, DBL_S16 StrSize, DBL_U8 DBL_FAR * Alpha);
      extern tDBL_Alpha_2_Str DBL_Alpha_2_Str ;
      typedef DBL_EXPORT(void) (DBL_FAR DBL_PASCAL *tDBL_Str_2_Alpha)(DBL_U8 DBL_FAR * Alpha, DBL_S16 AlphaSize, DBL_U8 DBL_FAR * Str);
      extern tDBL_Str_2_Alpha DBL_Str_2_Alpha ;
      typedef void (DBL_FAR DBL_PASCAL DBL_LOADDS *DBL_ExceptionHandlerType)(DBL_U8 DBL_FAR * DBL_FAR *);

      typedef DBL_EXPORT(DBL_ExceptionHandlerType) (DBL_FAR DBL_PASCAL *tDBL_SetExceptionHandler)(DBL_ExceptionHandlerType ExceptionHandler);
      extern tDBL_SetExceptionHandler DBL_SetExceptionHandler ;
      typedef DBL_EXPORT(DBL_BOOL) (DBL_FAR DBL_PASCAL *tDBL_GetDatabaseName)(DBL_U8 DBL_FAR *DatabaseName);
      extern tDBL_GetDatabaseName DBL_GetDatabaseName ;
      DBL_S16 DBL_FAR DBL_PASCAL DBL_Init(DBL_S16 ArgC, DBL_U8 DBL_FAR * DBL_FAR *ArgV, DBL_U8 DBL_FAR * DBL_FAR *EnvP);
      void DBL_PASCAL DBL_FAR DBL_Exit(void);
      
      Magnus Soffaniasson
      http://vdsl.is

      Comment


      • #4
        Just for the record, one can better see the source code when it is posted between [CODE] tags. That way the source code is not converted to emoticons and preserves the indentation.
        www.pluribasic.com

        Comment


        • #5
          >I have this old C code and is wondering if Powerbasic can do what this code is doing.

          The PowerBasic compilers support their own intrinsic statements as well as any call to a procedure in a standard Windows' DLL.

          I don't see anything in your 'c' code requiring any more than that.

          It's not so much "Can PowerBASIC do something?" as it is "Can the PowerBASIC programmer do it?"



          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            I have this old C code and is wondering if Powerbasic can do what this code is doing
            Yes, it can.
            The C code reads/writes from/to the DOS version of...
            Does the solution require 16-bit code? If so, you might look at the PBDOS compiler or possibly and earlier Console Compiler, I don't know when 32 bit executables became the norm.

            Having chosen your target compiler, it's just a matter of converting each statement/group of statements, suggest you make a start and ask for specifics if you get stuck.

            Comment


            • #7
              >I don't know when 32 bit executables became the norm.

              PB/DLL 5.0+ (Later renamed PB/Windows) created 32-bit executables. Only PB/DLL 1.0 and PB/DLL 2.0 created 16-bit EXEs and DLLs.
              PB/CC 1.0+. CC always created 32-bit executable files.

              The compilers themselves became 32 bit apps partway thru a "major" release; that is, PB/Windows 8.0.something greater than one and PB/CC 4.0.same something greater than one. (I am pretty sure it was Win8 and CC4, anyway).

              re your comment Chris: That 'c' code calls externals, so if those ARE 16- bit externals then yes he will require a 16-bit caller and no it can't be PB/DOS unless the externals are in an OBJ file which can be $LINKed to PB/DOS executables.

              But in that case might be easier to start asking, "what is the brand name of the DBMS, and does it offer either an OLE or ODBC interface?" because those are both pretty straightforward to handle in the world of 32-bit; that is, instead of trying to work with a 16-bit interface to "something,", just start over.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                did you notice the reference to win32 in dbl.h?

                #ifdef OS2
                #define DBL_CDECL cdecl
                #define DBL_PASCAL pascal
                #define DBL_FAR far
                #define DBL_EXPORT(_type) _type
                #else
                #ifdef DOS
                #define DBL_CDECL cdecl
                #define DBL_PASCAL pascal
                #define DBL_FAR far
                #define DBL_EXPORT(_type) _type
                #else
                #ifdef WIN32
                #define DBL_CDECL _cdecl
                #define DBL_PASCAL __stdcall
                #define DBL_FAR
                #define DBL_EXPORT(_type) _type
                #else
                #ifdef UNIX
                #define DBL_CDECL
                #define DBL_PASCAL
                #define DBL_FAR
                #define DBL_EXPORT(_type) _type
                #else
                One of the symbols DOS, OS2 or UNIX must be defined. ** win32 not here nut listed above.

                Comment

                Working...
                X