home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 25 / CD_ASCQ_25_1095.iso / dos / prg / bltc125 / bltxmpls / b2_lai10.c < prev    next >
Text File  |  1995-01-04  |  6KB  |  250 lines

  1.         
  2. #include <os2.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <string.h>
  7.  
  8. /* if 16-bit program, use:
  9.  *   #define __Bullet16
  10.  *   #include "bullet2.h
  11.  * otherwise (32-bit), do as below
  12.  */
  13.  
  14. #include "bullet2.h"
  15. #define BULLET BULLET32   /* if 32-bit main(), go through BULLET32 */
  16.  
  17. #pragma pack(1)
  18.             
  19. /* --test raw speed using 32-bit long integer key, unique
  20.    1) this test uses a non-standard binary field as a sort field
  21.    2) this code is for raw speed tests--it's straight inline
  22.  
  23.         OS/2 version
  24. */
  25.  
  26. struct MemoryPack MP;
  27. struct InitPack IP;
  28. struct ExitPack EP;
  29. struct FieldDescType fieldList[2];
  30. struct CreateDataPack CDP;
  31. struct CreateKeyPack CKP;
  32. struct DosFilePack DFP;
  33. struct OpenPack OP;
  34. struct AccessPack AP;
  35. struct ExitPack EP;
  36.  
  37. int    rez, level;
  38. div_t    div_rez;
  39. time_t  startTime, endTime;
  40.  
  41. char    tmpStr[129];
  42.  
  43. char    nameDat[] = ".\\BINTEST.DBB";
  44. char    nameIx1[] = ".\\BINTEST.IX1";
  45.  
  46. char    kx1[] = "CODENUMBER";
  47.  
  48. unsigned handDat, handIx1;
  49.  
  50. struct TestRecType {
  51.  char  tag;
  52.  long  codeNumber;
  53.  char  codeName[11];
  54. }; /* test program record length=16 bytes */
  55. struct TestRecType testRec;
  56.  
  57. char    keyBuffer[64]; /* MUST supply a work buffer for keys */
  58.                        /* a single one can be shared unless you */
  59.                        /* want to preserve the key buffer for each */
  60.                        /* access pack.  You read a gotten key from */
  61.                        /* here, and also specify key to find here */
  62.                        /* READ THE DOCS on exact matches, et al., */
  63.                        /* especially about "enumerator word", partial */
  64.                        /* match (follow with GetNext/Prev), and so on */
  65.  
  66. long    recs2add;
  67. long    low;
  68. long    high;
  69. long    i;
  70.  
  71. #pragma pack()
  72.  
  73. int main()
  74. {
  75.  
  76. /* implicit is the tag field at the first byte, then comes... */
  77. strcpy(fieldList[0].fieldName, "CODENUMBER");
  78. fieldList[0].fieldType = 'B';
  79. fieldList[0].fieldLen = 4;
  80. fieldList[0].fieldDC = 0;
  81. strcpy(fieldList[1].fieldName, "CODENAME\0\0");  /* must be 0-filled */
  82. fieldList[1].fieldType = 'C';
  83. fieldList[1].fieldLen = 11;   /* 10 and 1 for eos */
  84. fieldList[1].fieldDC = 0;
  85.  
  86. puts("B2_LAI10.C - LONG INT, SIGNED, UNIQUE long int, add/reindex speed test");
  87. puts("-Uses non-standard data files with binary field values, not DBF (in this test)");
  88. puts("-If TMP= defined in environment, reindex routine uses that path for temporary");
  89. puts("workspace, otherwise the current directory is used.\n");
  90.  
  91. level = 100;
  92. MP.func = MEMORYXB;
  93. rez = BULLET(&MP);   /* not really significant */
  94.  
  95. level = 110;
  96. IP.func = INITXB;
  97. IP.JFTmode = 0;
  98. rez = BULLET(&IP);
  99. if (rez != 0) goto Abend;
  100.  
  101. level = 120;
  102. EP.func = ATEXITXB;
  103. rez = BULLET(&EP);
  104. if (rez != 0) goto Abend;    /* actually, not a fatal error */
  105.  
  106. level = 130;                         /* disregard not found errors */
  107. DFP.func = DELETEFILEDOS;
  108. DFP.filenamePtr = nameDat;
  109. rez = BULLET(&DFP);
  110. DFP.filenamePtr = nameIx1;
  111. rez = BULLET(&DFP);
  112.  
  113. level = 1000;
  114. CDP.func = CREATEDXB;
  115. CDP.filenamePtr = nameDat;
  116. CDP.noFields = 2;
  117. CDP.fieldListPtr = fieldList;
  118. CDP.fileID = 255;
  119. rez = BULLET(&CDP);
  120. if (rez !=0) goto Abend;
  121.  
  122. level = 1010;
  123. OP.func = OPENDXB;
  124. OP.filenamePtr = nameDat;
  125. OP.asMode = READWRITE | DENYNONE;
  126. rez = BULLET(&OP);
  127. if (rez !=0) goto Abend;
  128. handDat = OP.handle;
  129.  
  130. level = 1100;
  131. CKP.func = CREATEKXB;
  132. CKP.filenamePtr = nameIx1;
  133. CKP.keyExpPtr = kx1;
  134. CKP.xbLink = handDat;
  135. CKP.keyFlags = cLONG | cSIGNED | cUNIQUE;
  136. CKP.codePageID = -1;
  137. CKP.countryCode = -1;
  138. CKP.collatePtr = NULL;
  139. rez = BULLET(&CKP);
  140. if (rez !=0) goto Abend;
  141.  
  142. level = 1110;
  143. OP.func = OPENKXB;
  144. OP.filenamePtr = nameIx1;
  145. OP.asMode = READWRITE | DENYNONE;
  146. OP.xbLink = handDat;
  147. rez = BULLET(&OP);
  148. if (rez !=0) goto Abend;
  149. handIx1 = OP.handle;
  150.  
  151. AP.func = ADDRECORDXB;
  152. AP.handle = handDat;
  153. AP.recPtr = &testRec;
  154. AP.keyPtr = keyBuffer;       /* set here and used throughout  */
  155. AP.nextPtr = NULL;
  156.  
  157. testRec.tag = ' ';
  158. strcpy(testRec.codeName, "xxSAME-Oxx");
  159.  
  160. printf("Recs to add/reindex: ");
  161. gets(tmpStr);
  162. recs2add = atol(tmpStr);
  163. if (recs2add == 0L) recs2add = 5L;
  164.  
  165. level = 1200;
  166. low = -3L;
  167. high = low + recs2add - 1L;
  168. printf("Adding %ld records ( keys %ld to %ld )...\n",recs2add,low,high);
  169.  
  170. time(&startTime);
  171. for (i = low; i < (recs2add+low); i++) {
  172.    testRec.codeNumber = i;
  173.    rez = BULLET(&AP);
  174.    if (rez !=0) goto Abend;
  175. }
  176. time(&endTime);
  177. printf("...took %lu secs.\n",(endTime - startTime));
  178.  
  179. level = 1210;
  180. printf("Reindexing...\n");
  181. AP.func = REINDEXXB;
  182. AP.handle = handIx1;
  183. time(&startTime);
  184. rez = BULLET(&AP);
  185. time(&endTime);
  186. if (rez != 0) {
  187.    rez = AP.stat;    /* MUST take AP.stat since a xaction routine */
  188.    goto Abend;       /* see docs and !README2.TXT for more */
  189. }
  190. printf("...took %lu secs\n\n",(endTime - startTime));
  191.  
  192. level = 1300;
  193. AP.func = GETFIRSTXB;
  194. rez = BULLET(&AP);
  195. printf("  The first 5 key/recs  (recNo --- key - data)\n");
  196. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  197. for (i=1;i < 5; i++) {
  198.    if (rez != 0) break;
  199.    AP.func = GETNEXTXB;
  200.    rez = BULLET(&AP);
  201.    printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  202. }
  203. if (rez == 202) rez = 0;
  204. if (rez != 0) goto Abend;
  205. puts(" ");
  206.  
  207. level = 1310;
  208. AP.func = GETLASTXB;
  209. rez = BULLET(&AP);
  210. printf("  The last 5 key/recs\n");
  211. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  212. for (i=1;i < 5; i++) {
  213.    if (rez != 0) break;
  214.    AP.func = GETPREVXB;
  215.    rez = BULLET(&AP);
  216.    printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  217. }
  218. if (rez == 203) rez = 0;
  219. if (rez != 0) goto Abend;
  220.  
  221. level = 1311;
  222. printf("  Finding the last gotten key, (in AP.keybuffer already)\n");
  223. AP.func = GETEQUALXB;
  224. rez = BULLET(&AP);
  225. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  226. if (rez != 0) goto Abend;
  227.  
  228. level = 1312;
  229. printf("  Finding key of 5\n");
  230. AP.func = GETEQUALXB;
  231. *((long *)keyBuffer) = 5L;
  232. rez = BULLET(&AP);
  233. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  234. if (rez != 0) goto Abend;
  235.  
  236. puts("Okay.");
  237. EP.func = EXITXB;
  238. rez = BULLET(&EP);
  239. return(0);
  240. /* program exit */
  241.  
  242.  
  243. /*----------------------------------------------*/
  244. /* that's right, we go to a termination routine */
  245.  
  246. Abend:
  247.    printf("Error: %u at level %u while performing ",rez,level);
  248.    exit(1);
  249. }
  250.