Waitrud Weber’s blog

things and reminders for memories

WindowsAPI: windows-make: Analyzer: function step: 002: extract blocks of fucction we found:

We don't think about the below:

// prototype:
//
//
//
//
//
int aToken::block_to_function_end( int *index , int file_end, FILE *fp) {
	char dummy[256];
	char* a_token = nullptr;

	// function start which is '{'.
	// function end which is '}'.

	a_token = m_concat( a_token, &dummy[0] );
	this->block = a_token; // the answer of token.

	return 1;
}


//
//
//
//
//
int Analyzer::parse ( char* filename ) {
	FILE *fp;
	aToken *iToken = nullptr;
	char *parse_token;
	int previous_index = 0;
	char dummy[256];
	char* a_token;

	int mode_token = 0;
	iToken = new aToken();
	fp = fopen ( filename, "rb" );
	int file_end = filesize ( fp );

	int anz_count = 0;
	int inc_count = 0;

	Sleep(1000);

	level_error_msg = 2;
	set_level_error_msg = 3;
	// printf ("Analyzer::parse: starts.\r\n");
	err_msg_006 ("Analyzer::parse: starts.\r\n");

	for( int i=0; igetToken( fp, &i, &file_end );
		err_msg_006 ("Analyzer::getToken ends.\r\n");

		if ( m_compare( (char*) "#define", parse_token ) == 1 ) {
			iToken->block_to( (char*)"\n", &i, file_end, fp);
			a_token = iToken->block;
			err_msg_006( "#define a_token: |%s|\r\n", a_token );
			// 20190923 printed and qualified.
			// dummy[0] = iToken->getChar( fp, &i, &file_end);
			// dummy[1] = '\0';
			// printf("#define next: i:%d  dummy: |%s|\r\n", i, dummy );
			// exit(-1);
			// end of m_fread: 1
			// #define next: i:1903  dummy: |#|
			anz_count++;
		} else if ( m_compare( (char*) "#include", parse_token ) == 1 ) {
			iToken->block_to( (char*)"\n", &i, file_end, fp);
			a_token = iToken->block;
			err_msg_006( "#include a_token: |%s|\r\n", a_token );
			inc_count++;
		}  else if ( is_function_start( parse_token ) == 1 ) {
			
			err_msg_006( "is_function_start: parse_token: |%s| a_token: |%s|\r\n", parse_token, a_token );
			err_msg_006("Exit(-1): Analyzer::parse: %s\r\n", filename);
			exit(-1);

			iToken->block_to_function_end( &i, file_end, fp );
			a_token = iToken->block; // the ansewer of function codes

		}  else {
			err_msg_006( "else: parse_token: |%s| a_token: |%s|\r\n", parse_token, a_token );
			err_msg_006("Exit(-1): Analyzer::parse: %s i: %d / %d \r\n", filename, i, PARSE_NUM);
			exit(-1);
		}

		iToken->free_main_token ();

		if ( inc_count == 6 ) break;
		// if ( anz_count == 3 ) break;

		switch( mode_token ) {
		case 0:
			break;
		case 1:
			break;
		}
	}

	fclose(fp);

	err_msg_006("Analyzer::parse: ends.\r\n");

	return 1;

}