home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / x_psion / psion.progs / support / ps.c next >
C/C++ Source or Header  |  1993-03-10  |  3KB  |  92 lines

  1. #include <stdio.h>
  2.  
  3. char header[]={'O','P','L','D','a','t','a','b','a','s','e','F','i','l','e',0x00,        /* null terminated string containing "OPLDatabaseFile" */
  4.         0x0f, 0x10, /* File version */
  5.         0x16, 0x00, /* Offset of first record */
  6.         0x0f, 0x10 /* OPL Runtime version */ } ;
  7. char fieldstruc[] = { 0x04, 0x20, 0x03, 0x03, 0x03, 0x03 /* field structure record */} ;
  8. /* the labels includes the header spec info, these are the type 3 TVL records */
  9. char type3[]={ 0x2D, 0x30, /* the header for this type 3 record*/
  10.         0x02, 0x10, 0x04, 0x00, /* sub type 1, TAB is 4 spaces */
  11.         0x02, 0x50, 0x05, 0x00, /* sub type 5, status win on, no wrap, template used */
  12.         0x22, 0x40, /* sub type 4, labels */
  13.         0x09, 'P','a','r','t',' ','N','o',' ',':',
  14.         0x07, 'P','r','i','c','e',' ',0x9c,
  15.         0x0A, 'D','i','s','c',' ','C','a','t',' ',':',
  16.         0x05, 'L','i','s','t',':'} ;
  17.  
  18. char terminate[] = {'\0', '\0'} ;
  19. main()
  20. {
  21.     char partno[50] ;
  22.     char pricelist[100] ;
  23.     char price[50] ;
  24.     char discount [10] ;
  25.     char input[1000] ;
  26.     int eof ;
  27.  
  28.     eof = 1 ;
  29.     write(1, header, sizeof(header)) ;
  30.     write(1, fieldstruc, sizeof(fieldstruc)) ;
  31.     write(1, type3, sizeof(type3)) ;
  32.  
  33.     while (gets(input) != NULL)
  34.     {
  35.         /* break the input line up */
  36.         sscanf(input, "%s %s %s %s", partno, pricelist, price, discount) ;
  37.         writerec(partno, price, discount) ;
  38.     }
  39.     write(1, terminate, sizeof(terminate)) ;
  40. }
  41.  
  42. writerec(partno, price, discount, pricelist)
  43. char * partno, * price, * discount, *pricelist ;
  44. {
  45.     int rechdr, length ;
  46.     int msb, lsb ;
  47.     int cptr, i ;
  48.     char recout[1000] ;
  49.  
  50.     length = 1 + strlen(price) + 1 + strlen(partno) + 1 + strlen(discount) + 1 + strlen(pricelist) ;
  51.  
  52.     rechdr = 0x1000 ;
  53.  
  54.     rechdr = rechdr + length ;
  55.  
  56.     msb = rechdr & 0x00FF ;
  57.     lsb = (rechdr & 0xFF00) >> 8 ;
  58.  
  59.     /* store the record length data */
  60.     recout[0] = (char) msb ;
  61.     recout[1] = (char) lsb ;
  62.  
  63.     cptr = 2 ;
  64.  
  65.     /* add the length of the first partno to the record */
  66.     recout[cptr++] = (char) strlen(partno) ;
  67.     /* copy the part no across */
  68.     i = 0 ;
  69.     while(partno[i] != '\0')
  70.         recout[cptr++] = partno[i++] ;
  71.     /* do the same for the price */
  72.     i = 0 ;
  73.     recout[cptr++] = (char) strlen(price) ;
  74.     while(price[i] != '\0' )
  75.         recout[cptr++] = price[i++] ;
  76.     
  77.     /* and the same for the discount */
  78.     i = 0 ;
  79.     recout[cptr++] = (char) strlen(discount) ;
  80.     while(discount[i] != '\0')
  81.         recout[cptr++] = discount[i++] ;
  82.  
  83.     /* and the same for the pricelist */
  84.     i = 0 ;
  85.     recout[cptr++] = (char) strlen(pricelist) ;
  86.     while(pricelist[i] != '\0')
  87.         recout[cptr++] = pricelist[i++] ;
  88.  
  89.     /* finaly output the string of length cptr */
  90.     write(1, recout, cptr) ;
  91. }
  92.