File: m_recall.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (133 lines) | stat: -rw-r--r-- 3,612 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/****************************************************************
 *								*
 *	Copyright 2001 Sanchez Computer Associates, Inc.	*
 *								*
 *	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 <descrip.h>
#include <iodef.h>
#include <ssdef.h>
#include <efndef.h>

#include "comline.h"
#include "gtm_caseconv.h"
#include "m_recall.h"

#define DEF_BUF_SZ		1024	/* from IOTT_OPEN.C */
#define	CCPROMPT 		0x00010000
#define ERR_RECBADNUM		"Recall error: bad numeric argument format"
#define ERR_RECNOTFND		"Recall error: command not found"
#define ERR_RECOUTOFRANGE	"Recall error: numeric argument out of range"

GBLREF mstr		*comline_base;
GBLREF int		comline_index;

int m_recall (short len, char *addr, int4 *index, short tt_channel)
{
	unsigned char	*cp, *cp_top;
	unsigned char	recbuf[8];
	unsigned char	faobuf[DEF_BUF_SZ];
	unsigned short	reclen, arglen, iosb[4];
	unsigned short	faolen;
 	unsigned int	n, cl;
	$DESCRIPTOR	(faodsc, faobuf);
	static readonly $DESCRIPTOR	(ctrstr, "!2SL !AD");

	cp = addr; cp_top = cp + len;
	while (cp < cp_top && *cp != SP && *cp != '\t')
		cp++;
	reclen = (char *) cp - addr;
	if (reclen != 3 && reclen != 6)
		return FALSE;

	lower_to_upper (recbuf, addr, reclen);
	if (memcmp (recbuf, "RECALL", reclen))
		return FALSE;

	while (cp < cp_top && (*cp == SP || *cp == '\t'))
		cp++;
	if (cp == cp_top)
	{
		flush_pio ();
		cl = comline_index;
		n = 1;
		do
		{
			cl = clmod (cl - 1);
			if (!comline_base[cl].len)
				break;
			sys$fao(&ctrstr, &faolen, &faodsc, n++, comline_base[cl].len, comline_base[cl].addr);

			/* don't do status on terminal qiow'w in this module,
			as errors should be unlikely and would cause messy exit from dm_read
			if you don't like it revise the interface between the routines */

 			sys$qiow(EFN$C_ENF, tt_channel, IO$_WRITEVBLK, &iosb, 0, 0, faobuf, faolen, 0, CCPROMPT, 0, 0);
		} while (cl != comline_index);
		assert (!comline_base[cl].len || (n == MAX_RECALL + 1 && cl == comline_index));
		*index = 0;
		return TRUE;
	}
	/* cp now points to beginning of arg */

	/* throw away trailing whitespace */
	while (*--cp_top == SP || *cp_top == '\t')
		assert(cp < cp_top);
	cp_top++;
	arglen = cp_top - cp;

	if ('0' <= *cp && *cp <= '9')	/* numeric argument */
	{
		n = 0;
		while (cp < cp_top && *cp != SP && *cp != '\t')
		{
			n *= 10;
			if ('0' <= *cp && *cp <= '9')
				n += (*cp++ - '0');
			else
			{
				sys$qiow(EFN$C_ENF, tt_channel, IO$_WRITEVBLK, &iosb, 0, 0,
					ERR_RECBADNUM, sizeof ERR_RECBADNUM - 1, 0, CCPROMPT, 0, 0);
				*index = -1;
				return TRUE;
			}
		}
		if (n <= 0 || n > MAX_RECALL)
		{
			sys$qiow(EFN$C_ENF, tt_channel, IO$_WRITEVBLK, &iosb, 0, 0,
				ERR_RECOUTOFRANGE, sizeof ERR_RECOUTOFRANGE - 1, 0, CCPROMPT, 0, 0);
			*index = -1;
			return TRUE;
		}
		assert (arglen == 1 || arglen == 2);
	}
	else				/* string argument */
	{
		cl = comline_index;
		n = 1;
		do
		{
			cl = clmod (cl - 1);
			if (!comline_base[cl].len) break;
			if (!memcmp (comline_base[cl].addr, cp, arglen))
				break;
			n++;
		} while (cl != comline_index);
		if (!comline_base[cl].len || cl == comline_index)
		{
			sys$qiow(EFN$C_ENF, tt_channel, IO$_WRITEVBLK, &iosb, 0, 0,
				ERR_RECNOTFND, sizeof ERR_RECNOTFND - 1, 0, CCPROMPT, 0, 0);
			*index = -1;
			return TRUE;
		}
	}
	assert (0 < n && n <= MAX_RECALL);
	*index = n;
	return TRUE;
}