File: get_command_line.c

package info (click to toggle)
fis-gtm 6.3-007-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,284 kB
  • sloc: ansic: 328,861; asm: 5,182; csh: 5,102; sh: 1,918; awk: 291; makefile: 69; sed: 13
file content (90 lines) | stat: -rwxr-xr-x 2,381 bytes parent folder | download
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
/****************************************************************
 *								*
 * Copyright (c) 2001-2018 Fidelity National Information	*
 * Services, Inc. and/or its subsidiaries. All rights reserved.	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include "gtm_string.h"
#include "gtm_ctype.h"

#include "stringpool.h"
#include "get_command_line.h"
#include "restrict.h"

GBLREF spdesc		stringpool;
GBLREF int 		cmd_cnt;

#ifdef __osf__
#pragma pointer_size (save)
#pragma pointer_size (long)
#endif

GBLREF char **cmd_arg;

#ifdef __osf__
#pragma pointer_size (restore)
#endif

void get_command_line(mval *result, boolean_t zcmd_line)
{
	int		first_item, len, word_cnt;
	unsigned char	*cp;

	if (RESTRICTED(zcmdline))
	{
		result->mvtype = MV_STR;
		result->str.len = result->str.char_len = 0;
		return;
	}
	result->mvtype = 0; /* so stp_gcol, if invoked below, can free up space currently occupied by this to-be-overwritten mval */
	len = -1;							/* to compensate for no space at the end */
	if (cmd_cnt > 1)
	{
		first_item = 1;
		if (zcmd_line)
		{	/* $ZCMDLINE returns the processed command line. Remove "-direct" and/or "-run <runarg>" from cmd line */
			cp = (unsigned char *)cmd_arg[1];
			if ('-' == *cp++)
			{
				first_item++;
				if ('r' == TOLOWER(*cp))
					first_item++;
			}
		}
		for (word_cnt = first_item; word_cnt < cmd_cnt; word_cnt++)
		{
			len += STRLEN(cmd_arg[word_cnt]) + 1;		/* include space between arguments */
			assert(0 <= len);
		}
	}
	if (0 >= len)
	{
		result->str.len = 0;
		result->mvtype = MV_STR; /* initialize mvtype now that mval has been otherwise completely set up */
		return;
	}
	ENSURE_STP_FREE_SPACE(len);
	cp = stringpool.free;
	stringpool.free += len;
	result->str.addr = (char *)cp;
	result->str.len = len;
	result->mvtype = MV_STR; /* initialize mvtype now that mval has been otherwise completely set up */
	for (word_cnt = first_item; ; *cp++ = ' ')
	{
		len = STRLEN(cmd_arg[word_cnt]);
		memcpy(cp, cmd_arg[word_cnt], len);
		if (++word_cnt == cmd_cnt)
			break;
		cp += len;
	}
	assert(IS_AT_END_OF_STRINGPOOL(cp, len));
	return;
}