Damn, this list is active.  *shudder*  Seems to really calm down on the 
weekends, though.  You've probably already got working code, but here's my 
way of looking at it.

Anyway... when I need to do things like this (and you know the length of the 
string, that's kinda why the nulls are there btw) I use pointers.  Lots of 
them.  (Also, I typed up about four different ways of copying strings and 
adding terminating NULLS, from streight copying, to using MemPtrResize, and 
how to do it with a buffer.  If you want any of those methods posted, just 
ask.  They were a bit long in total, so I removed them from this post.)

{Removed Lots-O-Code}

There are a bunch of ways to do this.  In your case, I'd use a running 
pointer.  Also, calling system functions really increases the size of your 
code, as well as slows things down.  I've tested previousally, and my own 
StrCopy routine was quite a bit faster.  The following code should work for 
an unlimited number of string fields: (from the look of your code, each field 
-is- null terminated)

        Char *p, *q;
        Char *packed;
        Char *field[NUM_FIELDS];        // NUM_FIELDS is a define somewhere...
        UInt32 packed_size = 0;
        UInt16 i;                       // current field (had to be short)

        // First pass, used to allocate the packed string.      
        for ( i = 0, i < NUM_FIELDS; i++ )
          packed_size += StrLen(field[i]) + 1;

        // Allocate the packed string... check for error?
        packed = (Char *)MemPtrNew(sizeof(Char) * packed_size);
        p = packed;                     // packed running pointer

        for ( i = 0, i < NUM_FIELDS; i++ ) {
          q = field[i];                 // field running pointer
          while ( &q != 0 ) {
            &p++ = &q++;                // copy the string
          } &p++ = 0;                   // add the NULL
        }

At the end of the above, 'packed' should contain the packed string, including 
final terminating null.  Am I making any glaring mistakes in the above?  If 
so, tell me.  I might want to use the above in any database code I make in 
the future. (Currently, my databases are limited to structured numbers, so I 
can't really pack anything.  I really dislike the way databases are handled 
in PalmOS...)

My few dollars,
        Matthew Bevan
        
-- 
Matthew (Darkstorm) Bevan       [EMAIL PROTECTED]
Margin Software, NECTI.         http://www.marginsoftware.com
        Re-inventing the wheel, every time.

 - This life is a test.  It is only a test.  Had this been an actual life,
you would have received further instructions as to what to do and where
to go.


--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to