aboutsummaryrefslogtreecommitdiff
path: root/5.20/dcl.c
blob: 085c4240ee4dfbeaece5409c5da69de6911a3120 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <string.h>
#include "token.h"
#include "err.h"
#include "dcl.h"

char out[OUTLEN];
char name[MAXTOKEN];

void dcl(void)
{
	int ns;

	for (ns = 0; gettoken() == '*';)
		ns++;
	dirdcl();
	while (ns-- > 0)
		strncat(out, " pointer to", OUTLEN - 1);
}

void dirdcl(void)
{
	int type;

	if (tokentype == '(') {
		dcl();
		if (tokentype != ')')
			warn("missing )");
	} else if (tokentype == ')') {
		prevtoken = YES;
	} else if (tokentype == NAME) {
		if (!strlen(name))
			strcpy(name, token);
	} else {
		printf("%c - %d : ", tokentype, tokentype);
		warn("expected () or name or (dcl)");
	}

	while ((type = gettoken()) == PARENS || type == BRACKETS ||
		type == '(') {
		if (type == PARENS) {
			strncat(out, " function returning", OUTLEN - 1);
		} else if (type == '(') {
			strncat(out, "function expecting", OUTLEN - 1);
			parmdcl();
			strncat(out, " and returning", OUTLEN - 1);
		} else {
			strncat(out, " array", OUTLEN - 1);
			strncat(out, token, OUTLEN - 1);
			strncat(out, " of", OUTLEN - 1);
		}
	}
}

void parmdcl(void)
{
	char parmdt[MAXTOKEN];

	do {
		strncpy(parmdt, (tokentype == ',') ? "," : "", MAXTOKEN - 1);
		while (gettoken() == NAME && isdtspec()) {
			strncat(parmdt, " ", MAXTOKEN - 1);
			strncat(parmdt, token, MAXTOKEN - 1);
		}

		prevtoken = YES;
		dcl();
		strncat(out, parmdt, OUTLEN - 1);
	} while (tokentype == ',');
}