home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
xxcmd.sit
/
test.c
< prev
next >
Wrap
Text File
|
1990-06-21
|
639b
|
34 lines
/* this example XXCMD returns the concatination of its parameters */
#include <Types.h>
#include <stdlib.h>
#include <string.h>
static char *result;
xxcmd_init()
{
result = NULL;
}
char *xxcmd_dispatch(argc, argv)
int argc;
char **argv;
{
int i, n;
char **p1, *p2;
/* find total length of argument strings (don't include XXCMD name) */
for (i = 1, n = 0, p1 = argv+1; i < argc; i++, n += strlen(*p1++)) ;
if (result != NULL) free(result);
result = malloc(n+1);
*result = 0;
/* concat strings together */
for (i = 1, p2 = result, p1 = argv+1; i < argc; i++, strcpy(p2, *p1), p2 += strlen(*p1++)) ;
return result;
}