home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / x_psion / psion.progs / support / pspriceconv.c < prev    next >
C/C++ Source or Header  |  1993-03-10  |  2KB  |  84 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[] = { 0x03, 0x20, 0x03, 0x03, 0x03 /* field structure record */} ;
  8. /* the labels includes the header spec info, these are the type 3 TVL records */
  9. char type3[]={ 0x27, 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.         0x1d, 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. char terminate[] = {'\0', '\0'} ;
  17. main()
  18. {
  19.     char partno[50] ;
  20.     char pricelist[100] ;
  21.     char price[50] ;
  22.     char discount [10] ;
  23.     char input[1000] ;
  24.     int eof ;
  25.  
  26.     eof = 1 ;
  27.     write(1, header, sizeof(header)) ;
  28.     write(1, fieldstruc, sizeof(fieldstruc)) ;
  29.     write(1, type3, sizeof(type3)) ;
  30.  
  31.     while (gets(input) != NULL)
  32.     {
  33.         /* break the input line up */
  34.         sscanf(input, "%s %s %s %s", partno, pricelist, price, discount) ;
  35.         writerec(partno, price, discount) ;
  36.     }
  37.     write(1, terminate, sizeof(terminate)) ;
  38. }
  39.  
  40. writerec(partno, price, discount)
  41. char * partno, * price, * discount ;
  42. {
  43.     int rechdr, length ;
  44.     int msb, lsb ;
  45.     int cptr, i ;
  46.     char recout[1000] ;
  47.  
  48.     length = 1 + strlen(price) + 1 + strlen(partno) + 1 + strlen(discount) ;
  49.  
  50.     rechdr = 0x1000 ;
  51.  
  52.     rechdr = rechdr + length ;
  53.  
  54.     msb = rechdr & 0x00FF ;
  55.     lsb = (rechdr & 0xFF00) >> 8 ;
  56.  
  57.     /* store the record length data */
  58.     recout[0] = (char) msb ;
  59.     recout[1] = (char) lsb ;
  60.  
  61.     cptr = 2 ;
  62.  
  63.     /* add the length of the first partno to the record */
  64.     recout[cptr++] = (char) strlen(partno) ;
  65.     /* copy the part no across */
  66.     i = 0 ;
  67.     while(partno[i] != '\0')
  68.         recout[cptr++] = partno[i++] ;
  69.     /* do the same for the price */
  70.     i = 0 ;
  71.     recout[cptr++] = (char) strlen(price) ;
  72.     while(price[i] != '\0' )
  73.         recout[cptr++] = price[i++] ;
  74.     
  75.     /* and the same for the discount */
  76.     i = 0 ;
  77.     recout[cptr++] = (char) strlen(discount) ;
  78.     while(discount[i] != '\0')
  79.         recout[cptr++] = discount[i++] ;
  80.  
  81.     /* finaly output the string of length cptr */
  82.     write(1, recout, cptr) ;
  83. }
  84.