home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / MXADSTC.C$$ / MXADSTC.bin
Encoding:
Text File  |  1990-06-24  |  2.1 KB  |  72 lines

  1. #include <string.h>
  2.  
  3. /* Function Prototypes force either correct data typing or compiler warnings.
  4.  * Note all functions exported to BASIC and all BASIC callback (extern)
  5.  * functions are declared with the far pascal calling convention.
  6.  * WARNING: This must be compiled with the Medium memory model (/AM)
  7.  */
  8.  
  9. char * pascal addstring( char far *s1, int s1len,
  10.               char far *s2, int s2len );
  11. extern void far pascal StringAssign( char far *source, int slen,
  12.                        char far *dest, int dlen );
  13.  
  14. /* Declare global char array to contain new BASIC string descriptor.
  15.  */
  16. char BASICDesc[4];
  17.  
  18. char * pascal addstring( char far *s1, int s1len,
  19.               char far *s2, int s2len )
  20. {
  21.     char TS1[50];
  22.     char TS2[50];
  23.     char TSBig[100];
  24.  
  25.     /* Use the BASIC callback StringAssign to retrieve information
  26.      * from the descriptors, s1 and s2, and place them in the temporary
  27.      * arrays TS1 and TS2.
  28.      */
  29.     StringAssign( s1, 0, TS1, 49 );    /* Get S1 as array of char */
  30.     StringAssign( s2, 0, TS2, 49 );    /* Get S2 as array of char */
  31.  
  32.     /* Copy the data from TS1 into TSBig, then append the data from
  33.      * TS2.
  34.      */
  35.     memcpy( TSBig, TS1, s1len );
  36.     memcpy( &TSBig[s1len], TS2, s2len );
  37.  
  38.     StringAssign( TSBig, s1len + s2len, BASICDesc, 0 );
  39.  
  40.     return BASICDesc;
  41. }
  42.  
  43. /*
  44.  * If, for example, we wanted to return not just one variable length string,
  45.  * but rather the variable length string and the reverse of that:
  46.  *
  47.  * call addstring( "foo ", 4, "bar", 3, a$, r$ )
  48.  *
  49.  * you get "foo bar" in a$ and "rab oof" in r$.
  50.  *
  51.  * Say you give me s1, and s2 (and their respective lengths) on input; for
  52.  * output, I want s3 and s4.
  53.  *
  54.  * Change the StringAssign for TSBig to assign to s3 instead of BASICDesc.
  55.  *
  56.  * Add the following lines of code:
  57.  *
  58.  *     TSBig[s1len + s2len] = '\0';
  59.  *     strrev( TSBig );
  60.  *     StringAssign( TSBig, s1len + s2len, s4, 0 );
  61.  *
  62.  * Delete the return statement.
  63.  *
  64.  * Change the prototype and function header to say:
  65.  *
  66.  * void far pascal addstring
  67.  *
  68.  * instead of
  69.  *
  70.  * char far * pascal addstring
  71.  */
  72.