aboutsummaryrefslogblamecommitdiff
path: root/5.19/main.c
blob: 3e1d2e95975314c68443f1a28253ae85ddac77d5 (plain) (tree)













































                                                                            
#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;
}