Waitrud Weber’s blog

things and reminders for memories

WindowsAPI: windows-make:

Sorry: one of gnu errors:

And no reason which stoped program.

 

 

github.com

// 20190227
// When we use tokenizer, we just call getToken.
//
//
//
char* aToken::getToken( FILE *fp, int *index, int *file_end )
{
	char *c_dummy;
	char dummy[256];
	int previous_index = 0;
	int mode_token = 0; // skip
	// 0: skip
	// 1: 
	// 2: 
	int breakable = 0;
	dummy[0] = '\0';

	printf("start of aToken::getToken\r\n");

	for ( int i=( *index ); i< (*file_end) && breakable == 0; i++ ) {
		previous_index = i;
		m_fread ( dummy, 1, fp);
		printf("i=%d mode_token=%d token=|%s|\r\n", i, mode_token );

		switch(mode_token) {
		case 0:
			switch(dummy[0]) {
			case ' ':
				break;
			default:
				if ( is_alphabet( dummy ) == 1 ) {
					mode_token = 1;
				} else {
					mode_token = 2;
				}
				token = put_token ( dummy[0] );
				// printf("token=%s dummy=%s dummy[0]=%c\r\n", token, dummy, dummy[0] );
				break;
			}
			break;
		case 1:
			//Judge if line end or not
			switch(dummy[0]) {
			case '\r':
				i++;
				m_fread ( dummy, 1, fp);
				if ( dummy[0] == '\n' ) mode_token = 0;
				else {
					printf("after \\r \r\n"); 
					exit(-1);
				}
				break;
			case '\n':
				mode_token = 0;
				break;
			default:
				token = put_token ( dummy[0] );
				break;
			}
			break;
		case 2:
			printf("case 2:token=%s dummy=%s dummy[0]=%c\r\n", token, dummy, dummy[0] );
			if ( line_or_space ( dummy ) == 1 ) {
				breakable = 1;
				*index = i;
			} else {
				token = put_token ( dummy[0] );
				printf("case 2-2:token=%s dummy=%s dummy[0]=%c\r\n", token, dummy, dummy[0] );
				// judge comment out
				if ( m_compare( token, "/*" ) == 1 ) {
					breakable = 1;
					*index = i;
				}
			}
			break;
		}

		// DEBUG
		if ( previous_index > i ) {
			printf("getToken: previous_index > i\r\n");
			printf("getToken: i=%d previous_index=%d\r\n", i, previous_index );
			exit(-1);
		}

	}

	backward( dummy );
	c_dummy = copyof( dummy );
	c_dummy = m_trim ( c_dummy );

	printf("aToken::getToken token=%s\r\n", token);
	printf("aToken::getToken c_dummy=%s\r\n", c_dummy);
	// return token;

	// DEBUG check
	if ( m_contains ( c_dummy, (char*)"\r\n" ) == 1 || m_contains ( c_dummy, (char*)"\n" ) == 1 ) {
		exit(-1);
	}

	printf("end of aToken::getToken\r\n");
	return token;
}


f:id:Waitrud_Weber:20190917230736p:plain