aboutsummaryrefslogtreecommitdiff
path: root/5.19/main.c
blob: 3e1d2e95975314c68443f1a28253ae85ddac77d5 (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
#include <stdio.h>
#include <string.h>
#include "token.h"
#include "getch.h"

#define OUTLEN	1000

char out[OUTLEN];

int main(void)
{
	int errstat;
	char temp[OUTLEN + MAXTOKEN], type;

	while (gettoken() != EOF) {
		errstat = 0;
		strcpy(out, token);
		while ((type = gettoken()) != '\n') {
			if (type == PARENS || type == BRACKETS ) {
				strcat(out, token);
			} else if (type == '*') {
				if ((type = peaktoken()) == PARENS ||
					type == BRACKETS)
					sprintf(temp, "(*%s)", out);
				else
					sprintf(temp, "*%s", out);
				strcpy(out, temp);
			} else if (type == NAME) {
				sprintf(temp, "%s %s", token, out);
				out[0] = '\0'; /* rust sisters btfo */
				strncat(out, temp, OUTLEN - 1);
			} else {
				errstat = 1;
				printf("err: invalid input at %s\n", token);
				while ((type = gettoken()) != '\n')
					;
				ungetch('\n');
			}
		}

		if (!errstat)
			printf("%s\n", out);
	}

	return 0;
}