I'll Email this so you can be the judge of whether this is worth while or
not. I use a standard format to structure transactions when I'm developing
applications that are transaction-oriented. A typical transaction might
look something like this: FMOVE|W0123|LA|D03/11/06/09:45:07|E555|. This
transaction reflects that employee 555 moved work order 0123 to location A
at the time indicated. The vertical bar separates the fields and the first
letter of every field is a prefix code which makes the data
position-independent in the transaction. You can see that F is the prefix
for the transaction code, W is the work order, L the new location, D the
date, and E the employee number. It's easy to put it together but picking
it apart is a little more challanging.
This code returns the number of fields you have (call it with the
transaction buffer and the delimiter character):
unsigned CountDelimiters(char txt[], char delim){
unsigned ic;
unsigned id = 0;
for(ic = 0, id = 0; ic < StrLen(txt); ic++){
if (txt[ic] == delim) id++;
}
return(id);
}
This code picks off a field at a time and puts it in a global variable
called thisfield
unsigned NextField(char txt[], char delim, unsigned pos){
unsigned cp = 0, fp = 0, ml, cpos = 1;
thisfield[0] = '\0';
ml = StrLen(txt);
do{
if (cpos < pos) {
do{
cp++;
} while ((cp < ml) && (txt[cp] != delim));
}
if (cp == ml) return(0);
if (cpos == pos) {
if (pos > 1) cp++;
do{
if (txt[cp] != delim) thisfield[fp++] = txt[cp++];
} while ((cp < ml) && (txt[cp] != delim));
thisfield[fp] = '\0';
return(fp);
}
cpos++;
} while (1);
}
This code parses a transaction and puts the results in global variables:
void ParseTransaction(void){
UInt nodel = 0, thisdel, i;
char prefix;
function[0] = '\0';
workorder[0] = '\0';
newlocation[0] = '\0';
trandate[0] = '\0';
employee[0] = '\0';
nodel = CountDelimiters(tranbuf, '|') + 1;
for (thisdel = 1; thisdel <= nodel; thisdel++){
NextField(tranbuf, '|', thisdel);
prefix = thisfield[0];
switch (prefix){
case 'F':
for (i=0; i < (StrLen(thisfield) - 1); i++) function
[i] = thisfield[i +
1];
function [i] = '\0';
break;
case 'W':
for (i=0; i < (StrLen(thisfield) - 1); i++) workorder
[i] = thisfield[i
+ 1];
workorder [i] = '\0';
break;
case 'L':
for (i=0; i < (StrLen(thisfield) - 1); i++)
newlocation [i] =
thisfield[i + 1];
newlocation [i] = '\0';
break;
case 'D':
for (i=0; i < (StrLen(thisfield) - 1); i++) trandate
[i] = thisfield[i +
1];
trandate [i] = '\0';
break;
case 'E':
for (i=0; i < (StrLen(thisfield) - 1); i++) employee
[i] = thisfield[i +
1];
employee [i] = '\0';
break;
}
}
}
This technique has been around for decades and I didn't invent it. I've
used it to develop dozens of systems and the only problem I've run into is
I've run short of printable characters and had to use noseeums from the
upper ascii 128.
regards,
Dave Mottorn
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Jason
Oakley
Sent: Wednesday, November 05, 2003 10:37 PM
To: Palm Developer Forum
Subject: Do you have any handy functions/libraries you would like to
donate?
I'm collecting a bunch of functions to archive on my website so programmers
(new and old) have a central location to look for handy code.
Does anyone have any functions they would like to donate (or libraries?).
You can either email me or add it to my forum below.
Cheers,
Jason.
----
http://zigzag.bangrocks.com/ - PalmOS Software
Also "Palm Game Programmers" forum
Discuss and post your handy functions!
-- For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/