home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / byteunix.lzh / byte.1 / buildbms.c < prev    next >
C/C++ Source or Header  |  1990-05-11  |  4KB  |  172 lines

  1.  
  2. /*******************************************************************************
  3.  *  The BYTE UNIX Benchmarks - Release 2
  4.  *          Module: buildbms.c   SID: 2.4 4/17/90 16:45:38
  5.  *          
  6.  *******************************************************************************
  7.  * Bug reports, patches, comments, suggestions should be sent to:
  8.  *
  9.  *    Ben Smith or Rick Grehan at BYTE Magazine
  10.  *    bensmith@bixpb.UUCP    rick_g@bixpb.UUCP
  11.  *
  12.  *******************************************************************************
  13.  *  Modification Log:
  14.  *
  15.  ******************************************************************************/
  16. /*
  17.  * Multi-user DBMS simulation.
  18.  * Initialization
  19.  * Database has the form:
  20.  * IIIINNNNNNNNNNNNNNNNNNNNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPPPPPPPPPP
  21.  * Where IIII is the 4-digit id number (0-padded)
  22.  *       NN... is the 20-character name
  23.  *       AA... is the 40-character address
  24.  *       PP... is the 10-character phone number
  25.  * Records are accessed by ID number (1 is the 0th record, 2 is 1st..etc.)
  26.  *
  27.  * Execute this program with:
  28.  *    buildbms <filename> <n>
  29.  *      where <filename> is the name of the database file and
  30.  *            <n> is the number of records to create in the database.
  31.  */
  32. char id[] = "@(#) @(#)buildbms.c:2.4 -- 4/17/90 16:45:38";
  33.  
  34. #include <stdio.h>
  35.  
  36. #define ERROR (-1)
  37.  
  38. /*
  39. ** Record definitions.
  40. */
  41.  
  42. #define IDLEN 4
  43. #define NAMELEN 20
  44. #define ADDRLEN 40
  45. #define PHONLEN 10
  46. #define RECLEN  74    /* Sum of the above. */
  47.  
  48. /*
  49. ** Structures.
  50. */
  51.  
  52. struct dbrec {            /* Database record */
  53.     char id[IDLEN];
  54.     char name[NAMELEN];
  55.     char address[ADDRLEN];
  56.     char phone[PHONLEN];
  57.     };
  58.  
  59. /*
  60. ** Structure instances.
  61. */
  62. struct dbrec myrec;
  63.  
  64. FILE *dbfp;            /* Pointer for database file */
  65.  
  66. main(argc,argv)
  67. int argc;
  68. char *argv[];
  69.  
  70. {
  71.  
  72.     int i,j;        /* Loop variables */
  73.  
  74.     /*
  75.     ** Make sure we have the proper data.
  76.     */
  77.     if(argc!=3)
  78.     {
  79.         fprintf(stderr,"usage: %s <filename> <n>\n",argv[0]);
  80.         exit(1);
  81.     }
  82.     /*
  83.     ** Create the file. 
  84.     ** Also notice that we are using binary mode.
  85.     */
  86.     if((dbfp=fopen(argv[1],"a+"))==NULL)
  87.     {
  88.         fprintf(stderr,"**Open error on: %s\n",argv[1]);
  89.         exit(1);
  90.     }
  91.  
  92.     j=atoi(argv[2]);
  93.     for(i=0;i<j;i++)
  94.     {
  95.         sprintf(myrec.id,"%#04d",i+1);
  96.         loadrec(i%10);
  97.         fwrite((char *)&myrec,RECLEN,1,dbfp);
  98.     }
  99.  
  100.     fclose(dbfp);
  101.     exit(0);
  102. }
  103.  
  104. /*
  105. ** Load the record up with random data.
  106. */
  107. loadrec(sel)
  108. int sel;        /* Select which fake record */
  109.  
  110. {
  111.  
  112.     char *nname;
  113.     char *naddr;
  114.     char *nphon;
  115.  
  116.     switch(sel)
  117.     {
  118.     case 0:    nname="Tom Thompson        ";
  119.         naddr="9401 Billy Willy Road                   ";
  120.         nphon="3334442222";
  121.         break;
  122.     case 1: nname="Steve Apiki         ";
  123.         naddr="50 Hawaii Way c/o Jack Lord             ";
  124.         nphon="1234443333";
  125.         break;
  126.     case 2: nname="Stan Diehl          ";
  127.         naddr="27 Hoptoad Hollow Way                   ";
  128.         nphon="3332221111";
  129.         break;
  130.     case 3: nname="Judy Grehan         ";
  131.         naddr="Suite 3, WallState Building             ";
  132.         nphon="9995556666";
  133.         break;
  134.     case 4: nname="Aaron Richards      ";
  135.         naddr="Highway 40 OverPass, Second Pylon       ";
  136.         nphon="8883339999";
  137.         break;
  138.     case 5: nname="Benjamin Davidson   ";
  139.         naddr="Under The Bridge, HeavyWater City       ";
  140.         nphon="7773229988";
  141.         break;
  142.     case 6: nname="Dayle Woolston      ";
  143.         naddr="4040 Pleasant Way, WICAT Central        ";
  144.         nphon="2228332299";
  145.         break;
  146.     case 7: nname="Jim Carls           ";
  147.         naddr="Big Oak Tree Behind Barsodie's          ";
  148.         nphon="32244566657";
  149.         break;
  150.     case 8: nname="Steve Smith         ";
  151.         naddr="7000 Aloth Cove                         ";
  152.         nphon="2118332929";
  153.         break;
  154.     case 9: 
  155.     default: nname="Blind Willy Chitlins";
  156.         naddr="Unavailable Until Further Notice        ";
  157.         nphon="3456789012";
  158.         break;
  159.     }
  160.  
  161.     /*
  162.     ** Fill the structure with fake data.
  163.     */
  164.     strncpy(myrec.name,nname,NAMELEN);
  165.     strncpy(myrec.address,naddr,ADDRLEN);
  166.     strncpy(myrec.phone,nphon,PHONLEN);
  167.  
  168.     return;
  169. }
  170.  
  171.  
  172.