main.c
/*
 * Reads initial configuration
 * and feels a MinerConfig structure.
 */
Reads initial configuration
and feels a MinerConfig structure.
Reads initial configuration and feels a MinerConfig structure .
gboolean read_miner_conifg(MinerConfig *config)
{
	FILE *fd_config;
	gchar current_line[LINE_SIZE];
	gchar current_token[TOKEN_SIZE];
	gchar current_token_value[TOKEN_SIZE];
	gint line_pos = 0;
	gint pos = 0;
	gint i = 0;
	double double_val;;
	init_miner_config(config);
	fd_config = fopen(".miner", "r");
	if (fd_config == NULL)
		return FALSE;
	while (!feof(fd_config)) {
		fgets(current_line, LINE_SIZE, fd_config);
		line_pos = 0;
		pos = 0;
		while (current_line[line_pos] == 0x20 && line_pos < LINE_SIZE)
			line_pos++;
		while (current_line[line_pos] != 0x20
		        && line_pos < LINE_SIZE
		        && pos < TOKEN_SIZE
		        && current_line[line_pos]
		        && current_line[line_pos] != '\n') {
			current_token[pos] = current_line[line_pos];
			pos++;
			line_pos++;
		}
		current_token[pos] = '\0';
		while (current_line[line_pos] == 0x20 && line_pos < LINE_SIZE)
			line_pos++;
		pos = 0;
		while (current_line[line_pos] != 0x20
		        && line_pos < LINE_SIZE
		        && pos < TOKEN_SIZE
		        && current_line[line_pos]
		        && current_line[line_pos] != '\n') {
			current_token_value[pos] = current_line[line_pos];
			line_pos++;
			pos++;
		}
		current_token_value[pos] = '\0';
		for (i = 0; i < TOKEN_NUMBER; i++)
			if (!g_ascii_strcasecmp(token[i], current_token)) {
				switch (i) {
				case TOKEN_BOMBS:
					config->bombs = atoi(current_token_value);
					break;
				case TOKEN_HEIGHT:
					config->height = atoi(current_token_value);
					break;
				case TOKEN_WIDTH:
					config->width = atoi(current_token_value);
					break;
				case TOKEN_SMALL_TIME:
					double_val = strtod(current_token_value, NULL);
					double_to_tv(&config->small_time, double_val);
					break;
				case TOKEN_MEDIUM_TIME:
					double_val = strtod(current_token_value, NULL);
					double_to_tv(&config->medium_time, double_val);
					break;
				case TOKEN_LARGE_TIME:
					double_val = strtod(current_token_value, NULL);
					double_to_tv(&config->large_time, double_val);
					break;
				}
			}
	}
	fclose(fd_config);
	return TRUE;
}
gboolean read_miner_conifg ( MinerConfig * config ) { FILE * fd_config ; gchar current_line [ LINE_SIZE ] ; gchar current_token [ TOKEN_SIZE ] ; gchar current_token_value [ TOKEN_SIZE ] ; gint line_pos = 0 ; gint pos = 0 ; gint i = 0 ; double double_val ; ; init_miner_config ( config ) ; fd_config = fopen ( " " , " " ) ; if ( fd_config == NULL ) return FALSE ; while ( ! feof ( fd_config ) ) { fgets ( current_line , LINE_SIZE , fd_config ) ; line_pos = 0 ; pos = 0 ; while ( current_line [ line_pos ] == 0x20 && line_pos < LINE_SIZE ) line_pos ++ ; while ( current_line [ line_pos ] != 0x20 && line_pos < LINE_SIZE && pos < TOKEN_SIZE && current_line [ line_pos ] && current_line [ line_pos ] != ' \n ' ) { current_token [ pos ] = current_line [ line_pos ] ; pos ++ ; line_pos ++ ; } current_token [ pos ] = ' \0 ' ; while ( current_line [ line_pos ] == 0x20 && line_pos < LINE_SIZE ) line_pos ++ ; pos = 0 ; while ( current_line [ line_pos ] != 0x20 && line_pos < LINE_SIZE && pos < TOKEN_SIZE && current_line [ line_pos ] && current_line [ line_pos ] != ' \n ' ) { current_token_value [ pos ] = current_line [ line_pos ] ; line_pos ++ ; pos ++ ; } current_token_value [ pos ] = ' \0 ' ; for ( i = 0 ; i < TOKEN_NUMBER ; i ++ ) if ( ! g_ascii_strcasecmp ( token [ i ] , current_token ) ) { switch ( i ) { case TOKEN_BOMBS : config -> bombs = atoi ( current_token_value ) ; break ; case TOKEN_HEIGHT : config -> height = atoi ( current_token_value ) ; break ; case TOKEN_WIDTH : config -> width = atoi ( current_token_value ) ; break ; case TOKEN_SMALL_TIME : double_val = strtod ( current_token_value , NULL ) ; double_to_tv ( & config -> small_time , double_val ) ; break ; case TOKEN_MEDIUM_TIME : double_val = strtod ( current_token_value , NULL ) ; double_to_tv ( & config -> medium_time , double_val ) ; break ; case TOKEN_LARGE_TIME : double_val = strtod ( current_token_value , NULL ) ; double_to_tv ( & config -> large_time , double_val ) ; break ; } } } fclose ( fd_config ) ; return TRUE ; }
Reads initial configuration
 and feels a MinerConfig structure.
Reads initial configuration and feels a MinerConfig structure .
/* At first set miner config to default values if
	 * somthing well goes wrong with config file */ /* remove spaces before */