home *** CD-ROM | disk | FTP | other *** search
- /*Copyright (c) 1991 Xerox Corporation. All Rights Reserved.
-
- Permission to use, copy, modify and distribute without
- charge this software, documentation, images, etc. is grant-
- ed, provided that this copyright and the author's name is
- retained.
-
- A fee may be charged for this program ONLY to recover costs
- for distribution (i.e. media costs). No profit can be made
- on this program.
-
- The author assumes no responsibility for disasters (natural
- or otherwise) as a consequence of use of this software.
-
- Adam Stein (stein.wbst129@xerox.com)
- */
-
- #include <stdio.h>
-
- extern char *program;
-
- /*This function will combine multiple argv[] strings into a single string.
-
- Inputs: argc - number of arguments
- argv - list of arguments
- Outputs: pointer - pointer to single string of arguments
- Locals: loop - loop through arguments
- numbytes - number of bytes needed for single argument string
- pointer - pointer to single string of arguments
- Globals: NULL - 0
- */
- char *combine(argc,argv)
- register int argc;
- register char *argv[];
- {
- register int numbytes,loop;
- register char *pointer;
- char *malloc(),*strdup();
-
- /*If argc equals 1, then all the arguments are already in a single
- string and there's no reason to do anything else but copy it*/
- if(argc != 1) {
- /*Set numbytes initially to count the spaces between arguments
- and the NULL (number of arguments - 1 + 1)*/
- numbytes = argc;
-
- /*Count bytes in each argument*/
- for(loop = 0;loop < argc;++loop)
- numbytes += strlen(argv[loop]);
-
- if((pointer = malloc(numbytes)) == NULL) {
- perror(program);
- exit(1);
- }
-
- strcpy(pointer,argv[0]);
-
- for(loop = 1;loop < argc;++loop) {
- strcat(pointer," ");
- strcat(pointer,argv[loop]);
- }
- } else if((pointer = strdup(argv[0])) == NULL) {
- perror(program);
- exit(1);
- }
-
- return(pointer);
- }
-
-