wm: 5552

ref: 1aae10955bf95d49872cfcedd935a064908c232e
dir: /5551a.c/

View raw version
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>

enum
{
	NOT = 1,
	AND,
	XOR,
	ADD,
	RST, /* reset the machine state */
	CPY, /* copy stuff from a reg or addr to another */
	SET, /* sets mode to bool and int */
	OUT
};

void main(int argc, char* argv[])
{
	unsigned int a, b;
	char string[16], *op;
	FILE *fd = open("5551.out", O_WRONLY);
	if(fd < 0)
	{
		fprintf(stderr, "unable to open file\n");
		return;
	}
	while(scanf("%s %[^\n]", op, string) > 0) /* %s removes spaces, what did i expected? */
	{
		sscanf(string, "%u %u", &a, &b);
		if(!strcmp(op, "NOT"))
			printf("%u %u\n", NOT, a);
		if(!strcmp(op, "AND"))
			printf("%u %u %u\n", AND, a, b);
		if(!strcmp(op, "XOR"))
			printf("%u %u %u\n", XOR, a, b);
//		if(!strcmp(op, "RST"))
			// reset():
		if(!strcmp(op, "CPY"))
			printf("%u %u %u\n", CPY, a, b);
		if(!strcmp(op, "SET"))
			printf("%u %u\n", SET, a);
		if(!strcmp(op, "OUT"))
			printf("%u %u\n", OUT, a);
		if(!strcmp(op, "DIE"))
			return;
	}
	return;
}