/* * $Id$ */ /* * GT CLIPPER STANDARD HEADER * * File......: charmix.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 * User Name.: Andy Leighton * Date......: 24/05/93 * Revision..: 1.00 * * This is an original work by Andy Leighton and is placed in the * public domain. */ /* * $DOC$ * $FUNCNAME$ * GT_CHARMIX() * $CATEGORY$ * String * $ONELINER$ * Amalgamate two strings to form the return value * $SYNTAX$ * GT_CharMix(, ) --> cRet * $ARGUMENTS$ * - A character string to mix * - A character string to mix with * $RETURNS$ * cRet - A string consisting of all the characters in * mixed with all the characters in * $DESCRIPTION$ * Return a string consisting of all the characters in * mixed with the characters from . * * NOTE: * invalid parameters will return "" * $EXAMPLES$ * * ? gt_CharMix("abc", "123") // prints "a1b2c3" * ? gt_CharMix("abcde", "123") // prints "a1b2c3de" * ? gt_CharMix("abc", "12345") // prints "a1b2c345" * * $END$ */ #include "extend.h" HARBOUR HB_GT_CHARMIX( void ) { char *s1, *s2, *s3; int l1, l2, i, pos3; if (ISCHAR(1) && ISCHAR(2)) { s1 = hb_parc(1); s2 = hb_parc(2); l1 = hb_parclen(1); l2 = hb_parclen(2); pos3 = 0; s3 = (char*)hb_xgrab(l1 + l2 + 1); /* grab us some mem to work with */ for (i = 0; i < l1; i++) { s3[pos3++] = s1[i]; if (i < l2) s3[pos3++] = s2[i]; } if (l2 > l1) for (; i < l2; i++) s3[pos3++] = s2[i]; s3[pos3] = '\0'; hb_retclen(s3, l1 + l2); hb_xfree(s3); /* free alloc'ed mem */ } else { hb_retc((char *) NULL); /* parameter mismatch - error NullStr */ } }