hStrAppend Function (ROM Call 0x45F*)

AMS 1.01 or higher alloc.h

void hStrAppend (HANDLE h, unsigned char *str);

Appends a string to a handle that contains a string.

h is the handle to string to be lengthened.
str is the string to append to the handle h.
This routine may cause heap compression, and it throws "Error: memory" if there is not enough memory to expand the handle h.

This routine provides a way to store in the clipboard something you can't paste with DIAMOND+PASTE !
But: you need to take great care when you use this routine: use it only on handles your program allocated, because writing garbage into system handles usually crashes the calculator !

hStrAppend is normally a ROM_CALL (ROM_CALL 45F) available on AMS 2.xx only, but a wrapper makes the use of this function possible on any AMS version (take great care with very old AMS 1.00 for 92+, though).

hStrAppend is implemented as follows:

void hStrAppend (HANDLE h, unsigned char *str)
{
  unsigned char* str1;
  unsigned long lstr1, lstr, lbuf;
  str1 = HeapDeref(h);
  lstr1 = strlen((char *)str1);                 /* length of string in handle */
  lstr = strlen((char *)str);                   /* length of string to append */
  lbuf = lstr1 + lstr + 1;                      /* new space requirement */
  if (!HeapRealloc(h, lbuf))                    /* try to get new space */
    ER_throw(670);
  str1 = (unsigned char *)HeapDeref(h) + lstr1; /* point to end of original string */
  memcpy(str1, str, lstr+1);                    /* append new string */
}


Uses: HeapRealloc, memcpy, strlen
Used by: SP_Define, cmd_sinreg, ROM Call 0x45B