Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

FORCAL

309.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

void token_error(void)
{
	char buf[10240];
	printf("TOKEN ERROR\n");
	while(fgets(buf, 1024, stdin)) {
		if (buf[0]=='\n') {
			printf("\n");
			break;
		}
	}
}

char *buf;

int main(void)
{
	int i;

	buf = malloc(1048577);
	if (!buf) {
		abort();
	}
	while(fgets(buf, 1048576, stdin)) {
		int s = strlen(buf);
		if (buf[0]=='\n') {
			printf("\n");
		}
		for(i=0; i<s; i++) {
			if (buf[i]==' ' || buf[i]=='\t' || buf[i]=='\n') {
				continue;
			}
			if (isalnum(buf[i]) || buf[i]=='_') {
				int j,k;
				char word[50];
				int all_digits;
				word[0]=buf[i];
				for(j=1; j<40; j++) {
					if (isalnum(buf[i+j]) || buf[i+j]=='_') {
						word[j]=buf[i+j];
					} else {
						break;
					}
				}
				word[j]=0;
				if (j >= 32) {
					token_error();
					goto next_while;
				}
				all_digits=1;
				for(k=0; isdigit(word[k]); k++);
				if (!word[k] && k>=8) {
					token_error();
					goto next_while;
				}
				printf("%s\n", word);
				i += j;
				i--;
				continue;
			}
			switch(buf[i]) {
				case '+':	printf("+\n");
							break;
				case '(':	printf("(\n");
							break;
				case ')':	printf(")\n");
							break;
				case ';':	printf(";\n");
							break;
				case ',':	printf(",\n");
							break;
				case '-':	if (buf[i+1]=='-') {
								goto next_while;
							} else {
								printf("-\n");
								break;
							}
				case ':':	if (buf[i+1]=='=') {
								printf(":=\n");
								i++;
								break;
							} else {
								token_error();
								goto next_while;
							}
				default:	token_error();
							goto next_while;
			}
		}
next_while:
		;
	}
	exit(0);
}