baum

diff baum.c @ 7:6a6152cf63f7

new implementation of the read input function
author meillo@marmaro.de
date Sat, 09 Feb 2008 11:57:16 +0100
parents ab87b154a96b
children 495a56e706dc
line diff
     1.1 --- a/baum.c	Fri Feb 08 21:44:07 2008 +0100
     1.2 +++ b/baum.c	Sat Feb 09 11:57:16 2008 +0100
     1.3 @@ -182,38 +182,63 @@
     1.4  
     1.5  /* read input */
     1.6  void read_input(char* filename) {
     1.7 -	FILE* fp;
     1.8 -	char c;
     1.9 -	char* line;
    1.10 -	int indent;
    1.11 -	char* name;
    1.12 +	FILE* file;
    1.13 +	int c;
    1.14 +	char* cp;
    1.15 +	int indent = 0;
    1.16 +	char name[256];
    1.17  	int value;
    1.18  
    1.19 -	fp = fopen(filename, "r");
    1.20 -	indent = 0;
    1.21 +	file = fopen(filename, "r");
    1.22  
    1.23 -	while ((c = getc(fp)) != EOF) {
    1.24 +
    1.25 +	while ((c = getc(file)) != EOF) {
    1.26 +		if (c == '#') {
    1.27 +			printf("c\n");
    1.28 +			while ((c = getc(file)) != '\n') {
    1.29 +			}
    1.30 +		}
    1.31 +
    1.32  		if (c == ' ' || c == '\t') {
    1.33  			indent++;
    1.34 -		} else if (c == '(') {
    1.35 -			fscanf(fp, "%d", &value);
    1.36 -		} else if (c == '\n') {
    1.37 +		}
    1.38  
    1.39 -			if (strcmp(name, "") != 0) {
    1.40 -				printf("\nindent: %d\nname: %s\nvalue: %d\n", indent, name, value);
    1.41 +		if (c == '\n') {
    1.42 +			if (strlen(name) > 0) {
    1.43 +				printf(" %d - %s - %d\n", indent, name, value);
    1.44 +				/*
    1.45 +				*/
    1.46 +			} else {
    1.47 +				printf("comment\n");
    1.48  			}
    1.49  			indent = 0;
    1.50  			strcpy(name, "");
    1.51  			value = 0;
    1.52 -		} else {
    1.53 -			fscanf(fp, "%[a-z]", name);
    1.54  		}
    1.55 +
    1.56 +		if (c >= 'a' && c <= 'z') {
    1.57 +			int i = 1;
    1.58 +			name[0] = (char) c;
    1.59 +			while ((c = getc(file)) != '(') {
    1.60 +				/*putc(c, stdout);*/
    1.61 +				name[i] = (char) c;
    1.62 +				i++;
    1.63 +			}
    1.64 +			name[i] = '\0';
    1.65 +		}
    1.66 +
    1.67 +		if (c == '(') {
    1.68 +			fscanf(file, "%d)", &value);
    1.69 +		}
    1.70 +
    1.71  	}
    1.72 +
    1.73 +	fclose(file);
    1.74  }
    1.75  
    1.76  /* main */
    1.77  int main(int argc, char* argv[]) {
    1.78 -	unsigned char shell_return;
    1.79 +	unsigned char shell_return = 0;
    1.80  	/*
    1.81  	init();
    1.82