summaryrefslogtreecommitdiff
path: root/src/tet3/dtet2lib/addarg.c
blob: 3e6c7fd41af91f866013366828472c83fc4801d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 *      SCCS:  @(#)addarg.c	1.4 (96/11/04) 
 *
 * (C) Copyright 1994 UniSoft Ltd., London, England
 *
 * All rights reserved.  No part of this source code may be reproduced,
 * stored in a retrieval system, or transmitted, in any form or by any
 * means, electronic, mechanical, photocopying, recording or otherwise,
 * except as stated in the end-user licence agreement, without the prior
 * permission of the copyright owners.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef lint
static char sccsid[] = "@(#)addarg.c	1.4 (96/11/04) TET3 release 3.3";
#endif

/************************************************************************

SCCS:   	@(#)addarg.c	1.4 96/11/04 TETware release 3.3
NAME:		addarg.c
PRODUCT:	TETware
AUTHOR:		Andrew Dingwall, UniSoft Ltd.
DATE CREATED:	December 1993

DESCRIPTION:
	function to concatenate two argv argument lists

MODIFICATIONS:

************************************************************************/

#include <stdio.h>
#include "dtmac.h"
#include "dtetlib.h"


#ifdef NEEDsrcFile
static char srcFile[] = __FILE__;	/* file name for error reporting */
#endif


/*
**	tet_addargv() - concatenate two argv argument lists and return
**		a pointer to the results
**
**	return (char **) 0 on error
**
**	if successful, the return value points to a list containing
**	argv1[0], argv2[0] ... argv2[n], argv1[1] ... argv1[n], (char *) 0
**
**	this function is typically used to include additional option
**	arguments in an argv list before an exec
*/

char **tet_addargv(argv1, argv2)
register char **argv1, **argv2;
{
	register char **ap;
	register int newargc;
	char **newargv;
	int nalen;

	/* count the arguments in both lists + 1 for the terminating 0 */
	newargc = 1;
	if (argv1) {
		for (ap = argv1; *ap; ap++)
			;
		newargc += (ap - argv1);
	}
	if (argv2) {
		for (ap = argv2; *ap; ap++)
			;
		newargc += (ap - argv2);
	}

	/* allocate memory for the new argv array */
	newargv = (char **) 0;
	nalen = 0;
	if (BUFCHK((char **) &newargv, &nalen, (int) (newargc * sizeof *newargv)) < 0)
		return((char **) 0);

	/* copy over argv1[0] */
	ap = newargv;
	if (argv1 && *argv1)
		*ap++ = *argv1++;

	/* then copy over all of argv2 */
	if (argv2)
		while (*argv2)
			*ap++ = *argv2++;

	/* finally, copy over the rest of argv1 and terminate the array */
	if (argv1)
		while (*argv1)
			*ap++ = *argv1++;
	*ap = (char *) 0;

	return(newargv);
}