aboutsummaryrefslogtreecommitdiff
path: root/pkg/system/help/lroff/nextcmd.x
blob: d4b09f44551cad0757c97efd89795114401c5f35 (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<ctype.h>
include	"lroff.h"

.help nextcmd
.nf ________________________________________________________________________
NEXTCMD -- Examine the input line; if it is an Lroff directive, return
the integer code of the directive, otherwise NULL.  Leave IP pointing
to the argument field if a command, otherwise leave it pointing at the
first char of the text line.  Note that the "directives" string must
match the opcode definitions given in lroff.h
.endhelp ___________________________________________________________________

define	SZ_OPCODE	2

int procedure nextcmd (linebuf, ip)

char	linebuf[ARB]
int	ip, op
char	opcode[SZ_OPCODE]
int	command, kwp, strmatch(), strncmp()
string	directives "finfjunjrjshihnhbrcespinlslebptpkskehrhn"

begin
	if (linebuf[1] != '.')			# not a command line?
	    return (NULL)
	if (strmatch (linebuf, "^.endhelp") > 0)
	    return (ENDHELP)
	ip = 2					# skip the '.'

	# Directives may be either upper or lower case.
	for (op=1;  op <= SZ_OPCODE;  op=op+1) {
	    opcode[op] = linebuf[ip]
	    if (IS_UPPER (opcode[op]))
		opcode[op] = TO_LOWER (opcode[op])
	    ip = ip + 1
	}

	# Just in case a directive happens to be longer than 2 chars, make
	# sure IP points past the directive name.
	while (IS_ALPHA (linebuf[ip]))
	    ip = ip + 1

	# Lookup directive, return opcode number if found.
	command = NULL
	for (kwp=1;  directives[kwp] != EOS;  kwp=kwp+SZ_OPCODE)
	    if (strncmp (opcode, directives[kwp], SZ_OPCODE) == 0) {
		command = (kwp+1) / SZ_OPCODE
		break
	    }

	if (command == NULL)			# unrecognized directive
	    ip = 1		
	return (command)
end