예제 #1
0
파일: json-list.c 프로젝트: irods/baton
int do_list_paths(FILE *input, print_flags pflags) {
    int path_count = 0;
    int error_count = 0;

    rodsEnv env;
    rcComm_t *conn = rods_login(&env);
    if (!conn) goto error;

    size_t jflags = JSON_DISABLE_EOF_CHECK | JSON_REJECT_DUPLICATES;

    while (!feof(input)) {
        json_error_t load_error;
        json_t *target = json_loadf(input, jflags, &load_error);
        if (!target) {
            if (!feof(input)) {
                log(ERROR, "JSON error at line %d, column %d: %s",
                    load_error.line, load_error.column, load_error.text);
            }

            continue;
        }

        baton_error_t path_error;
        char *path = json_to_path(target, &path_error);
        path_count++;

        if (path_error.code != 0) {
            error_count++;
            add_error_value(target, &path_error);
            print_json(target);
        }
        else {
            rodsPath_t rods_path;
            int status = resolve_rods_path(conn, &env, &rods_path, path);
            if (status < 0) {
                error_count++;
                set_baton_error(&path_error, status,
                                "Failed to resolve path '%s'", path);
                add_error_value(target, &path_error);
                print_json(target);
            }
            else {
                baton_error_t error;
                json_t *results = list_path(conn, &rods_path, pflags, &error);

                if (error.code != 0) {
                    error_count++;
                    add_error_value(target, &error);
                    print_json(target);
                }
                else {
                    print_json(results);
                    json_decref(results);
                }
            }

            if (rods_path.rodsObjStat) free(rods_path.rodsObjStat);
        }

        if (unbuffered_flag) fflush(stdout);

        json_decref(target);
        free(path);
    } // while

    rcDisconnect(conn);

    log(DEBUG, "Processed %d paths with %d errors", path_count, error_count);

    return error_count;

error:
    if (conn) rcDisconnect(conn);

    log(ERROR, "Processed %d paths with %d errors", path_count, error_count);

    return 1;
}
예제 #2
0
int browser_list(list_t *list, int buttons)
{

	char *temp;

	static short history[50];

	static int filled = 0;
	static int index = 0;

	settings_t settings = settings_get();

	if(buttons & PAD_DOWN)
	{
		list->selection++;

		if (!(list->selection < list->num))
		{
			list->selection = 0;
		}

	}

	if(buttons & PAD_UP)
	{
		list->selection--;

		if (list->selection < 0)
		{
			list->selection = list->num - 1;
		}
	}

	if(buttons & settings.input.confirm)
	{

		printf("entry = %s\n", list->entries[list->selection]);
		printf("path = %s\n", path);

		// Going backwards
		if (!strcmp(list->entries[list->selection],".."))
		{

			// Reset current history index
			history[index] = 0;
			index--;

			// Shouldn't happen, but just in case
			if (index <= 0)
			{
				index = 0;
			}

			if (index == 1)
			{
				// Fix the path based on mounted device
				if (!strncmp(path,"mc",2))
				{
					strcpy(path,"mc");
				}
				if (!strncmp(path,"mass",4))
				{
					strcpy(path,"mass");
				}
				if (!strncmp(path,"cdfs",4))
				{
					strcpy(path,"cdfs");
				}
				if (!strncmp(path,"pfs1",4))
				{
					unmount_partition(1);
					strcpy(path,"hdd");
				}
				if (!strncmp(path,"pfs0",4))
				{
					strcpy(path,"hdd");
				}
			}

			if (index > 1)
			{

				// Not sure why my dirname implementation isn't working...
				// Goes along with the strcat() bug
				temp = path + strlen(path);
				temp--;
				temp--;

				while (*temp != '/') temp--;
				temp++;

				*temp = 0;

			}

			filled = 0;

		}
		// Going forwards
		else
		{

			if (index == 0)
			{
				// index == 0 is device mounts list
				strcpy(path,list->entries[list->selection]);
				history[index] = 0;
			}

			if (index == 1)
			{
				// index == 1 is for mounting devices or any additional handling to get a root directory
				if (!strcmp(path,"hdd"))
				{
					mount_partition(path,list->entries[list->selection],1);
				}
				else
				{
					strcpy(path,list->entries[list->selection]);
				}
				history[index] = 0;
			}

			if (index > 1)
			{
				// If the selection is not a directory
				if (!strchr(list->entries[list->selection],'/'))
				{
					strkat(path,list->entries[list->selection]);
					filled = 0;
					history[index] = list->selection;
					return 1;
				}
				else
				{
					// If not then add entry to the path
					printf("selection = %s\n",list->entries[list->selection]);
					strkat(path,list->entries[list->selection]);
					history[index] = list->selection;
				}
			}

			// Reset selection to 0
			list->selection = 0;
			filled = 0;
			index++;

		}
	}

	if (!filled)
	{

		// List the directory, clearing only entries previously used
		list_clear(list,list->num);

		// List root if index is at start
		// else list directory
		if (index == 0)
		{
			list_device_types(list);
			list_sort(list,list->num,LIST_NORMAL);
		}
		else if (index == 1)
		{
			list_mountable_devices(path,list);
			list_sort(list,list->num-1,LIST_NORMAL);
		}
		else
		{

			list_path(path,list);
			printf("num = %d\n", list->num);

			list_sort(list,list->num-1,LIST_NORMAL);

		}

		list->selection = history[index];

		// List has been filled
		filled = 1;

	}

	return 0;

}