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 >
Wrap
C/C++ Source or Header
|
1993-03-10
|
2KB
|
84 lines
#include <stdio.h>
char header[]={'O','P','L','D','a','t','a','b','a','s','e','F','i','l','e',0x00, /* null terminated string containing "OPLDatabaseFile" */
0x0f, 0x10, /* File version */
0x16, 0x00, /* Offset of first record */
0x0f, 0x10 /* OPL Runtime version */ } ;
char fieldstruc[] = { 0x03, 0x20, 0x03, 0x03, 0x03 /* field structure record */} ;
/* the labels includes the header spec info, these are the type 3 TVL records */
char type3[]={ 0x27, 0x30, /* the header for this type 3 record*/
0x02, 0x10, 0x04, 0x00, /* sub type 1, TAB is 4 spaces */
0x02, 0x50, 0x05, 0x00, /* sub type 5, status win on, no wrap, template used */
0x1d, 0x40, /* sub type 4, labels */
0x09, 'P','a','r','t',' ','N','o',' ',':',
0x07, 'P','r','i','c','e',' ',0x9c,
0x0A, 'D','i','s','c',' ','C','a','t',' ',':'} ;
char terminate[] = {'\0', '\0'} ;
main()
{
char partno[50] ;
char pricelist[100] ;
char price[50] ;
char discount [10] ;
char input[1000] ;
int eof ;
eof = 1 ;
write(1, header, sizeof(header)) ;
write(1, fieldstruc, sizeof(fieldstruc)) ;
write(1, type3, sizeof(type3)) ;
while (gets(input) != NULL)
{
/* break the input line up */
sscanf(input, "%s %s %s %s", partno, pricelist, price, discount) ;
writerec(partno, price, discount) ;
}
write(1, terminate, sizeof(terminate)) ;
}
writerec(partno, price, discount)
char * partno, * price, * discount ;
{
int rechdr, length ;
int msb, lsb ;
int cptr, i ;
char recout[1000] ;
length = 1 + strlen(price) + 1 + strlen(partno) + 1 + strlen(discount) ;
rechdr = 0x1000 ;
rechdr = rechdr + length ;
msb = rechdr & 0x00FF ;
lsb = (rechdr & 0xFF00) >> 8 ;
/* store the record length data */
recout[0] = (char) msb ;
recout[1] = (char) lsb ;
cptr = 2 ;
/* add the length of the first partno to the record */
recout[cptr++] = (char) strlen(partno) ;
/* copy the part no across */
i = 0 ;
while(partno[i] != '\0')
recout[cptr++] = partno[i++] ;
/* do the same for the price */
i = 0 ;
recout[cptr++] = (char) strlen(price) ;
while(price[i] != '\0' )
recout[cptr++] = price[i++] ;
/* and the same for the discount */
i = 0 ;
recout[cptr++] = (char) strlen(discount) ;
while(discount[i] != '\0')
recout[cptr++] = discount[i++] ;
/* finaly output the string of length cptr */
write(1, recout, cptr) ;
}