To shorten the porting time and avoid problems which are difficult to isolate, we use the C program in Listing One , which tests each of the system-specific dependencies found in c-tree Plus. By compiling and executing this module (which does not require any of the c-tree API) you can determine, among many other things, if your definition of COUNT really results in 2-byte integers, or whether the memcmp
function performs signed or unsigned byte-wise comparisons. When we port to a new environment, executing this test program is one of the first steps we take.
Listing One
/* Copyright (c) 1984 - 1994 FairCom Corporation. ALL RIGHTS RESERVED * FairCom Corporation, 4006 West Broadway, Columbia, MO 65203. * 314-445-6833 */ #include "ctstdr.h" #include "ctoptn.h" #define CTF " 1 3 " #define S377 "'\\377'" typedef struct { TEXT mb1; } MB; TEXT getbuf[128]; TEXT *align[5] = { "strange: call FairCom (314) 445-6833", "byte", "word (2 bytes)", "strange: call FairCom (314) 445-6833", "double word (4 bytes)" }; #ifdef PROTOTYPE main () #else main () #endif { TEXT buffer[8]; TEXT t255,*tp; COUNT i,done,d[4],afactor; UCOUNT tu; TEXT *th,*tl; MB mb[2]; struct { ctRECPT pa1; TEXT pa2; ctRECPT pp; ctRECPT pa3; ctRECPT pa4; } p; struct { ctRECPT ca1; TEXT ca2; COUNT cc; } c; struct { ctRECPT aa1; TEXT aa2; TEXT aa[3]; } a; struct { ctRECPT ta1; TEXT ta2; TEXT tt; } t; if (SIZEOF(COUNT) != 2 || SIZEOF(UCOUNT) != 2 || SIZEOF(LONG) !=4 || SIZEOF(VRLEN) != 4) { printf( "\n\nBefore continuing with CTTEST be sure that the following types are"); printf( "\ncorrectly sized. Make the necessary changes in CTPORT.H.\n\n"); printf(" COUNT UCOUNT LONG VRLEN\n"); printf(" ------- ------- ------- -------\n"); printf(" Should be: 2 bytes 2 bytes 4 bytes 4 bytes\n"); printf("Actual size: %d %d %d %d\n\n", SIZEOF(COUNT),SIZEOF(UCOUNT),SIZEOF(LONG),SIZEOF(VRLEN)); exit(0); } else { printf("\n\nCOUNT, UCOUNT, LONG & VRLEN are properly sized."); tu = 40000; if (!(tu > 0)) { printf( "\n\nBefore continuing with CTTEST, be sure that UCOUNT is an"); printf("\nunsigned short integer. See CTPORT.H\n\n"); exit(0); } } t255 = '\377'; printf("\n\nC255 Test for CTCMPL.H:"); printf("\n\tUse the following setup in CTCMPL.H - \t#define C255\t"); if (t255 == -1) printf("%d",t255); else printf(S377); printf("\n\t\t\t Current setting - \t#define C255\t"); if (C255 == 0x00ff) printf(S377); if (C255 == -1) printf("%d",C255); i = 0x0201; tp = (TEXT *) &i; printf("\n\nLOW HIGH Test for CTOPTN.H:"); printf("\n\tUse the following setup in CTOPTN.H - \t#define "); if ((*tp & 0x00ff) > (*(tp + 1) & 0x00ff)) printf("HIGH_LOW"); else printf("LOW_HIGH"); printf("\n\t\t\t Current setting - \t#define "); #ifdef LOW_HIGH printf("LOW_HIGH"); #endif #ifdef HIGH_LOW printf("HIGH_LOW"); #endif /* NULL size test */ printf("\nNULL Size Test: "); if (SIZEOF(NULL) == SIZEOF(tp)) printf("ok (%d bytes)",SIZEOF(NULL)); else printf("inconsistent (NULL is %d bytes & ptr's are %d bytes)", SIZEOF(NULL),SIZEOF(tp)); /* test of compar function for byte-wise comparisons */ for (i = 0; i < 4; i++) { buffer[i] = 'A'; buffer[i+4] = '\377'; } tp = buffer; #ifndef FASTCOMP #ifdef ctDS done = ((COUNT) *tp & 0x00ff) - ((COUNT) *(tp + 4) & 0x00ff); #else done = (*tp & 0x00ff) - (*(tp + 4) & 0x00ff); #endif if (done >= 0) { printf( "\n\n\nBefore continuing with CTTEST, call FairCom (314) 445-6833 concerning"); printf( "\nthe critical compar function in CTCOMP.C. Please report the following"); printf( "\nthree numbers to FairCom: %d %d %d\n",(*tp & 0x00ff),(*(tp + 4) & 0x00ff), done); exit(0); } else #endif /* ~FASTCOMP */ printf("\n\ncompar function (CTCOMP.C) test is successful."); #ifndef ctNOMEMCMP done = ctrt_memcmp(tp,tp + 4,1); if (done >= 0) { printf( "\n\n\nBefore continuing with CTTEST, add '#define ctNOMEMCMP' to ctcmpl.h."); printf( "\nThis indicates that your memcmp function cannot be used in our high speed"); printf( "\nkey loading routine since its treats bytes as signed quantities.\n"); exit(0); } #endif /* PAUSE IN OUTPUT */ printf("\n\nHit RETURN (or ENTER) to continue..."); gets(getbuf); printf("\n\nAlignment test for help in computing key segment offsets."); th = (TEXT *) &p.pa4; tl = (TEXT *) &p.pa3; i = th - tl; if (i == 1) { printf( "\n\n*** This machine addresses 32 bit words (not bytes). Call ***"); printf( "\n*** FairCom at (314) 445-6833. STATUS & HDRSIZ must be changed. ***"); afactor = 4; } else if (i == 2) { printf( "\n\n*** This machine addresses words (not bytes). Add 2 to STATUS in ***"); printf( "\n*** CTOPTN.H and add 4 to HDRSIZ in CTOPTN.H. Also each member ***"); printf( "\n*** of a structure will be at least word aligned. In particular,"); afactor = 2; } else afactor = 1; printf(" Members of\nstructures will be aligned as follows:\n\n"); printf("\tMember Type Alignment\n"); printf("\t----------- -----------------\n"); th = (TEXT *) &p.pp; tl = &p.pa2; i = (th - tl) * afactor; if (i > 4) i = 0; printf("\t4 byte int %s\n",align[i]); th = (TEXT *) &c.cc; tl = &c.ca2; i = (th - tl) * afactor; if (i > 4) i = 0; printf("\t2 byte int %s\n",align[i]); if (i > 2) printf( "\nCall FairCom (314) 445-6833 concerning 2 byte integer alignment.\n"); th = (TEXT *) a.aa; tl = &a.aa2; i = (th - tl) * afactor; if (i > 4) i = 0; printf("\tchar array %s\n",align[i]); th = &t.tt; tl = &t.ta2; i = (th - tl) * afactor; if (i > 4) i = 0; printf("\tchar %s\n",align[i]); printf("\n\nStructure 'SIZEOF' Test: "); i = SIZEOF(MB); th = &mb[1].mb1; tl = &mb[0].mb1; if (i == (th - tl)) printf(" OK"); else printf( "\nCall FairCom at (314) 445-6833 to report these two numbers: %d %d\n", i, (th - tl)); printf("\n\nShort Integer Input Test for CTOPTN.H:"); done = NO; d[1] = d[3] = 5; if (sscanf(CTF,"%h %h",d,d+2) == 2 && d[0] == 1 && d[2] == 3 && d[1] == 5 && d[3] == 5) { printf( "\n\tUse the PERC_H option in CTOPTN.H.\n"); done = YES; } if (!done) { d[1] = d[3] = 5; if (sscanf(CTF,"%d %d",d,d+2) == 2 && d[0] == 1 && d[2] == 3 && d[1] == 5 && d[3] == 5) { printf( "\n\tUse the PERC_D option in CTOPTN.H.\n"); done = YES; } } if (!done) { d[1] = d[3] = 5; if (sscanf(CTF,"%hd %hd",d,d+2) == 2 && d[0] == 1 && d[2] == 3 && d[1] == 5 && d[3] == 5) { printf( "\n\tUse the PERC_HD option in CTOPTN.H.\n"); done = YES; } } if (!done) printf( "\n\n*** COMPILER DOES NOT CONFORM TO KNOWN CONVENTIONS ***\n"); printf("\tCurrent setting - "); #ifdef PERC_H printf("PERC_H"); #endif #ifdef PERC_D printf("PERC_D"); #endif #ifdef PERC_HD printf("PERC_HD"); #endif /* PAUSE IN OUTPUT */ printf("\n\nHit RETURN (or ENTER) to continue..."); gets(getbuf); printf("\n\nCTOPTN.H SUMMARY -\n"); #ifdef FPUTFGET printf("\nFPUTFGET:\tnon-server, multi-user application"); #endif #ifdef NOTFORCE printf("\nNOTFORCE:\tsingle-user or server based application"); #endif #ifdef RESOURCE printf("\nRESOURCE:\tresources are supported"); #else printf("\nNO_RESOURCE:\tresources are NOT supported"); #endif #ifdef CTBATCH printf("\nCTBATCH:\tbatch retrieval is supported"); #else printf("\nNO_BATCH:\tbatch retrieval is NOT supported"); #endif #ifdef CTSUPER printf("\nCTSUPER:\tsuperfiles are supported"); #else printf("\nNO_SUPER:\tsuperfiles are NOT supported"); #endif #ifdef LOW_HIGH printf("\nLOW_HIGH:\tLSB to MSB ordering (ala Intel 8086 family)"); #endif #ifdef HIGH_LOW printf("\nHIGH_LOW:\tMSB to LSB ordering (ala Motorola 68000 family)"); #endif #ifdef VARLDATA printf("\nVARLDATA:\tvariable length data records are supported"); #else printf("\nNO_VARLD:\tvariable length data records are NOT supported"); #endif #ifdef PERC_H printf("\nPERC_H:\t\t%%h"); #endif #ifdef PERC_D printf("\nPERC_D:\t\t%%d"); #endif #ifdef PERC_HD printf("\nPERC_HD:\t%%hd"); #endif printf(" short integer format specification"); #ifdef VARLKEYS printf("\nVARLKEYS:\tkey compression supported"); #else printf("\nNO_VARLK:\tkey compression is NOT supported"); #endif #ifdef PARMFILE printf("\nPARMFILE:\tISAM parameter files are supported"); #else printf("\nNO_PARMF:\tISAM parameter files are NOT supported"); #endif #ifdef RTREE printf("\nRTREE:\t\tr-tree supported"); #else printf("\nNO_RTREE:\tr-tree is NOT supported"); #endif #ifdef CTS_ISAM printf("\nCTS_ISAM:\tISAM functionality supported"); #else printf("\nNO_ISAM:\tISAM functionality is NOT supported"); #endif #ifdef CTBOUND printf("\nCTBOUND:\tnon-server mode of operation"); #else printf("\nNO_BOUND:\tserver mode of operation"); #endif #ifdef PROTOTYPE printf("\nPROTOTYPE:\tfunction prototypes are supported"); #else printf("\nNO_PROTOTYPE:\tfunction prototypes are NOT supported"); #endif printf("\n\nEnd Of CTTEST\n"); exit(0); }
C lends itself to run-time library support. Many developers turn to third-party libraries to assist with database I/O, report generation, and other application necessities. When examining a third-party library, it is important to investigate its portability. If the library is developed and used properly, it can be a tremendous timesaver to the development and port of the application. Of course, if the library is not portable or available on different platforms, it may prove detrimental.