コード例 #1
0
static int find_target_in_path(struct wrapper_data *data)
{
	char *token = NULL, *state;
	char str[MAXPATHLEN + 1];

	if (data->path == NULL) return 0;

	/* Make a copy since strtok_r will modify path */
	snprintf(str, MAXPATHLEN + 1, "%s", data->path);

	token = strtok_r(str, ":", &state);

	/* Find the first file with suitable name in PATH.  The idea here is
	 * that we do not want to bind ourselfs to something static like the
	 * default profile, or some odd environment variable, but want to be
	 * able to build something with a non default gcc by just tweaking
	 * the PATH ... */
	while ((token != NULL) && strlen(token)) {
		if (check_for_target(token, data))
			return 1;
		token = strtok_r(NULL, ":", &state);
	}

	return 0;
}
コード例 #2
0
ファイル: extend3.c プロジェクト: robt1019/conways-soldiers
void run (int height_coordinate, int width_coordinate){

    move *moves_array = create_move_array (MOVES_MAX);
    Node *final_board, *start;
    int move_count = 0, target_found = 0;
    int initial_board [BOARD_HEIGHT][BOARD_WIDTH];

    populate_board (initial_board);
    start = allocate_start_node (initial_board);
    target_found = check_for_target (initial_board, height_coordinate, width_coordinate);

    if (!target_found){
        final_board = find_solution (start, height_coordinate, width_coordinate);
        move_count = populate_moves_array (final_board, moves_array);
        //to copy start board into last element of moves array for printing
        copy_board ((moves_array+(move_count-1))->board, start->board);
        print_moves_SDL (moves_array, move_count);
        // print_moves (moves_array, move_count);
    }

    else {
        print_list_SDL (start);
        printf("Target already on board\n");
    }

    // print_list(start);

    free_list (start);
    free (moves_array);
}
コード例 #3
0
ファイル: extend3.c プロジェクト: robt1019/conways-soldiers
//finds route to target location and returns a pointer to the board that found it
Node* find_solution (Node *start, int height_coordinate, int width_coordinate){
    hash *hash_array = create_hash_table (HASH_TABLE_SIZE);
    set_hash_table (hash_array);
    Node *current, *previous, *parent;
    int target_found = 0;

    current = start;    
    parent = start;

    while (!target_found){
        previous = current;
        current->next = allocate_new_node (parent, previous);
        if (find_next_move (hash_array, start, current->next, parent->board, current->next->board) == 0){

            if (parent->next == NULL){
                printf("Couldn't find a solution\n");
                exit (1);
            }

            parent = parent->next;
            current->next->parent = parent;
            copy_board (current->next->board, parent->board);
    
        }
        target_found = check_for_target (current->next->board, height_coordinate, width_coordinate);
        current = current->next;
    }
    return current;
}
コード例 #4
0
/* find_target_in_envd parses /etc/env.d/05gcc, and tries to
 * extract PATH, which is set to the current profile's bin
 * directory ...
 */
static int find_target_in_envd(struct wrapper_data *data, int cross_compile)
{
	FILE *envfile = NULL;
	char *token = NULL, *state;
	char str[MAXPATHLEN + 1];
	char *strp = str;
	char envd_file[MAXPATHLEN + 1];

	if (!cross_compile) {
		snprintf(envd_file, MAXPATHLEN, "%s", ENVD_BASE);
	} else {
		char *ctarget, *end = strrchr(data->name, '-');
		if (end == NULL)
			return 0;
		ctarget = strdup(data->name);
		ctarget[end - data->name] = '\0';
		snprintf(envd_file, MAXPATHLEN, "%s-%s", ENVD_BASE, ctarget);
		free(ctarget);
	}
	envfile = fopen(envd_file, "r");
	if (envfile == NULL)
		return 0;

	while (0 != fgets(strp, MAXPATHLEN, envfile)) {
		/* Keep reading ENVD_FILE until we get a line that
		 * starts with 'PATH='
		 */
		if (((strp) && (strlen(strp) > strlen("PATH=")) &&
		    !strncmp("PATH=", strp, strlen("PATH=")))) {

			token = strtok_r(strp, "=", &state);
			if ((token != NULL) && strlen(token))
				/* The second token should be the value of PATH .. */
				token = strtok_r(NULL, "=", &state);
			else
				goto bail;

			if ((token != NULL) && strlen(token)) {
				strp = token;
				/* A bash variable may be unquoted, quoted with " or
				 * quoted with ', so extract the value without those ..
				 */
				token = strtok(strp, "\n\"\'");

				while (token != NULL) {
					if (check_for_target(token, data)) {
						fclose(envfile);
						return 1;
					}

					token = strtok(NULL, "\n\"\'");
				}
			}
		}
		strp = str;
	}

bail:
	fclose(envfile);
	return (cross_compile ? 0 : find_target_in_envd(data, 1));
}
コード例 #5
0
/* find_target_in_envd parses /etc/env.d/05gcc, and tries to
 * extract PATH, which is set to the current profile's bin
 * directory ...
 */
static int find_target_in_envd(struct wrapper_data *data, int cross_compile)
{
	FILE *envfile = NULL;
	char *token = NULL, *state;
	char str[MAXPATHLEN + 1];
	char *strp = str;
	char envd_file[MAXPATHLEN + 1];

	if (!cross_compile) {
		/* for the sake of speed, we'll keep a symlink around for
		 * the native compiler.  #190260
		 */
		snprintf(envd_file, sizeof(envd_file)-1, "/etc/env.d/gcc/.NATIVE");
	} else {
		char *ctarget, *end = strrchr(data->name, '-');
		if (end == NULL)
			return 0;
		ctarget = strdup(data->name);
		ctarget[end - data->name] = '\0';
		snprintf(envd_file, MAXPATHLEN, "%s-%s", ENVD_BASE, ctarget);
		free(ctarget);
	}

	envfile = fopen(envd_file, "r");
	if (envfile == NULL)
		return 0;

	while (fgets(strp, MAXPATHLEN, envfile) != NULL) {
		/* Keep reading ENVD_FILE until we get a line that
		 * starts with 'GCC_PATH=' ... keep 'PATH=' around
		 * for older gcc versions.
		 */
		if (strncmp(strp, "GCC_PATH=", strlen("GCC_PATH=")) &&
		    strncmp(strp, "PATH=", strlen("PATH=")))
			continue;

		token = strtok_r(strp, "=", &state);
		if ((token != NULL) && strlen(token))
			/* The second token should be the value of PATH .. */
			token = strtok_r(NULL, "=", &state);
		else
			goto bail;

		if ((token != NULL) && strlen(token)) {
			strp = token;
			/* A bash variable may be unquoted, quoted with " or
			 * quoted with ', so extract the value without those ..
			 */
			token = strtok(strp, "\n\"\'");

			while (token != NULL) {
				if (check_for_target(token, data)) {
					fclose(envfile);
					return 1;
				}

				token = strtok(NULL, "\n\"\'");
			}
		}

		strp = str;
	}

 bail:
	fclose(envfile);
	return (cross_compile ? 0 : find_target_in_envd(data, 1));
}