Beispiel #1
0
static int _mapMaker(struct tree_node_t *node, void *cargo)
{
	uidToTitleMap_t *uidToTitleMapPtr = (uidToTitleMap_t *)cargo;
	struct guide_nodedata_t *data = 
		(struct guide_nodedata_t *)tree_get_data(node);

	uint32 existingUID = 0;
	if (uidToTitleMapPtr->Lookup(data->title, existingUID) == FALSE)
		uidToTitleMapPtr->SetAt(data->title, data->uid);

	return 0;
}
int
check_directory_for_color_scheme(int left, const char dir[])
{
	char *p;
	char t;
	int altered;

	union
	{
		char *name;
		tree_val_t buf;
	}
	u;

	if(dirs == NULL_TREE)
	{
		return 0;
	}

	curr_stats.cs = left ? &lwin.cs : &rwin.cs;
	assign_color_scheme(curr_stats.cs, &cfg.cs);

	/* TODO: maybe use split_and_get() here as in io/iop:iop_mkdir(). */
	p = (char *)dir;
	altered = 0;
	do
	{
		t = *p;
		*p = '\0';

		if(tree_get_data(dirs, dir, &u.buf) == 0 && color_scheme_exists(u.name))
		{
			(void)source_cs(u.name);
			altered = 1;
		}

		*p = t;
		p = until_first(p + 1, '/');
	}
	while(t != '\0');

	curr_stats.cs = &cfg.cs;

	if(!altered)
	{
		return 0;
	}

	check_color_scheme(curr_stats.cs);
	load_color_pairs(curr_stats.cs);

	return 1;
}
Beispiel #3
0
/* The return value is the color scheme base number for the colorpairs.
 *
 * The color scheme with the longest matching directory path is the one that
 * should be returned.
 */
int
check_directory_for_color_scheme(int left, const char *dir)
{
	char *p;
	char t;

	union
	{
		char *name;
		tree_val_t buf;
	}u;

	if(dirs == NULL_TREE)
	{
		return DCOLOR_BASE;
	}

	curr_stats.cs_base = left ? LCOLOR_BASE : RCOLOR_BASE;
	curr_stats.cs = left ? &lwin.cs : &rwin.cs;
	*curr_stats.cs = cfg.cs;

	p = (char *)dir;
	do
	{
		char full[PATH_MAX];
		t = *p;
		*p = '\0';

		if(tree_get_data(dirs, dir, &u.buf) != 0 || !color_scheme_exists(u.name))
		{
			*p = t;
			if((p = strchr(p + 1, '/')) == NULL)
				p = (char *)dir + strlen(dir);
			continue;
		}

		snprintf(full, sizeof(full), "%s/colors/%s", cfg.config_dir, u.name);
		(void)source_file(full);

		*p = t;
		if((p = strchr(p + 1, '/')) == NULL)
			p = (char *)dir + strlen(dir);
	}
	while(t != '\0');

	check_color_scheme(curr_stats.cs);
	load_color_pairs(curr_stats.cs_base, curr_stats.cs);
	curr_stats.cs_base = DCOLOR_BASE;
	curr_stats.cs = &cfg.cs;

	return left ? LCOLOR_BASE : RCOLOR_BASE;
}
Beispiel #4
0
static int _linkFixer(struct tree_node_t *node, void *cargo)
{
	uidToTitleMap_t *uidToTitleMapPtr = (uidToTitleMap_t *)cargo;

	struct guide_nodedata_t *data = 
		(struct guide_nodedata_t *)tree_get_data(node);

	CStringA rtf = data->text;
	if (fixLinks(rtf, uidToTitleMapPtr))
		guide_nodedata_set_text(data, rtf);

	return 0;
}
Beispiel #5
0
int RTFConcatenator::CollectCallback(HTREEITEM item, 
	struct tree_node_t *node, void *cargo)
{
	RTFConcatenator *that = (RTFConcatenator *)cargo;
	struct guide_nodedata_t *data = 
		(struct guide_nodedata_t *)tree_get_data(node);
	ASSERT(node);
	ASSERT(cargo);
	ASSERT(item);

	// position cursor at end and clear selection
	HWND hWnd = that->m_hWnd;
	::SendMessage(hWnd, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);

	// get heading level
	int level = 0; // 0 => no other top nodes
	struct tree_node_t *node2 = node;
	while (tree_get_parent(node2) != that->m_pTopNode)
	{
		level++;
		node2 = tree_get_parent(node2);
	}

	// append heading rtf text
	CStringA heading = 
		that->m_TemplateHelper.GetHeading(
			that->m_HeadingCounter.GetHeadingNumber(node),
			level,
			data->title,
			that->m_bLastTextEmpty,
			data->color, data->bgcolor);
	SETTEXTEX tex;
	tex.codepage = CP_ACP; // ???
	tex.flags = ST_SELECTION;
	LRESULT lr = ::SendMessage(hWnd, EM_SETTEXTEX, (WPARAM)&tex, (LPARAM)(const char *)heading);
	ASSERT(lr > 0);

	// check the number of characters in the text
	SetRTF(that->m_hZeroCheckWnd, data->text, false);
	LRESULT nChars = ::SendMessage(that->m_hZeroCheckWnd, WM_GETTEXTLENGTH, 0, 0);
	if (nChars > 0)
	{
		// append rtf text (only if some text is really present)
		if (data->text[0] != 0 && strcmp(theEmptyRTFText, data->text) != 0) //theEmptyRTFText != data->text)
			::SendMessage(hWnd, EM_SETTEXTEX, (WPARAM)&tex, (LPARAM)data->text);
	}
	that->m_bLastTextEmpty = (nChars == 0);

	// continue
	return 0;
}
Beispiel #6
0
void
redraw_file_info_dialog(void)
{
	const dir_entry_t *entry;
	char perm_buf[26];
	char size_buf[56];
	char buf[256];
#ifndef _WIN32
	char id_buf[26];
#endif
	int curr_y;
	uint64_t size;
	int size_not_precise;

	assert(view != NULL);

	if(resize_for_menu_like() != 0)
	{
		return;
	}

	werase(menu_win);

	entry = &view->dir_entry[view->list_pos];

	size = 0;
	if(entry->type == FT_DIR)
	{
		char full_path[PATH_MAX];
		get_current_full_path(view, sizeof(full_path), full_path);
		tree_get_data(curr_stats.dirsize_cache, full_path, &size);
	}

	if(size == 0)
	{
		size = entry->size;
	}

	size_not_precise = friendly_size_notation(size, sizeof(size_buf), size_buf);

	curr_y = 2;

	curr_y += print_item("Path: ", entry->origin, curr_y);
	curr_y += print_item("Name: ", entry->name, curr_y);

	mvwaddstr(menu_win, curr_y, 2, "Size: ");
	mvwaddstr(menu_win, curr_y, 8, size_buf);
	if(size_not_precise)
	{
		snprintf(size_buf, sizeof(size_buf), " (%" PRId64 " bytes)", size);
		waddstr(menu_win, size_buf);
	}
	curr_y += 2;

	curr_y += show_file_type(view, curr_y);
	curr_y += show_mime_type(view, curr_y);

#ifndef _WIN32
	get_perm_string(perm_buf, sizeof(perm_buf), entry->mode);
	curr_y += print_item("Permissions: ", perm_buf, curr_y);
#else
	copy_str(perm_buf, sizeof(perm_buf), attr_str_long(entry->attrs));
	curr_y += print_item("Attributes: ", perm_buf, curr_y);
#endif

	format_time(entry->mtime, buf, sizeof(buf));
	curr_y += print_item("Modified: ", buf, curr_y);

	format_time(entry->atime, buf, sizeof(buf));
	curr_y += print_item("Accessed: ", buf, curr_y);

	format_time(entry->ctime, buf, sizeof(buf));
#ifndef _WIN32
	curr_y += print_item("Changed: ", buf, curr_y);
#else
	curr_y += print_item("Created: ", buf, curr_y);
#endif

#ifndef _WIN32
	get_uid_string(entry, 0, sizeof(id_buf), id_buf);
	curr_y += print_item("Owner: ", id_buf, curr_y);

	get_gid_string(entry, 0, sizeof(id_buf), id_buf);
	curr_y += print_item("Group: ", id_buf, curr_y);
#endif

	/* Fake use after last assignment. */
	(void)curr_y;

	box(menu_win, 0, 0);
	checked_wmove(menu_win, 0, 3);
	wprint(menu_win, " File Information ");
	wrefresh(menu_win);

	was_redraw = 1;
}
Beispiel #7
0
void
redraw_file_info_dialog(void)
{
	char name_buf[NAME_MAX];
	char perm_buf[26];
	char size_buf[56];
	char buf[256];
#ifndef _WIN32
	char uid_buf[26];
	struct passwd *pwd_buf;
	struct group *grp_buf;
#endif
	struct tm *tm_ptr;
	int curr_y;
	uint64_t size;
	int size_not_precise;

	assert(view != NULL);

	resize_for_menu_like();

	werase(menu_win);

	snprintf(name_buf, sizeof(name_buf), "%s",
			view->dir_entry[view->list_pos].name);

	size = 0;
	if(view->dir_entry[view->list_pos].type == DIRECTORY)
		tree_get_data(curr_stats.dirsize_cache,
				view->dir_entry[view->list_pos].name, &size);

	if(size == 0)
		size = view->dir_entry[view->list_pos].size;

	size_not_precise = friendly_size_notation(size, sizeof(size_buf), size_buf);

#ifndef _WIN32
	if((pwd_buf = getpwuid(view->dir_entry[view->list_pos].uid)) == NULL)
	{
		snprintf(uid_buf, sizeof(uid_buf), "%d",
				(int) view->dir_entry[view->list_pos].uid);
	}
	else
	{
		snprintf(uid_buf, sizeof(uid_buf), "%s", pwd_buf->pw_name);
	}
	get_perm_string(perm_buf, sizeof(perm_buf),
			view->dir_entry[view->list_pos].mode);
#else
	snprintf(perm_buf, sizeof(perm_buf), "%s",
			attr_str_long(view->dir_entry[view->list_pos].attrs));
#endif

	curr_y = 2;
	mvwaddstr(menu_win, curr_y, 2, "File: ");
	name_buf[getmaxx(menu_win) - 8] = '\0';
	checked_wmove(menu_win, curr_y, 8);
	wprint(menu_win, name_buf);
	curr_y += 2;
	mvwaddstr(menu_win, curr_y, 2, "Size: ");
	mvwaddstr(menu_win, curr_y, 8, size_buf);
	if(size_not_precise)
	{
		snprintf(size_buf, sizeof(size_buf), " (%" PRId64 " bytes)", size);
		waddstr(menu_win, size_buf);
	}
	curr_y += 2;

	curr_y += show_file_type(view, curr_y);
	curr_y += show_mime_type(view, curr_y);

#ifndef _WIN32
	mvwaddstr(menu_win, curr_y, 2, "Permissions: ");
#else
	mvwaddstr(menu_win, curr_y, 2, "Attributes: ");
#endif
	mvwaddstr(menu_win, curr_y, 15, perm_buf);
	curr_y += 2;

	mvwaddstr(menu_win, curr_y, 2, "Modified: ");
	tm_ptr = localtime(&view->dir_entry[view->list_pos].mtime);
	strftime(buf, sizeof (buf), "%a %b %d %Y %I:%M %p", tm_ptr);
	checked_wmove(menu_win, curr_y, 13);
	wprint(menu_win, buf);
	curr_y += 2;

	mvwaddstr(menu_win, curr_y, 2, "Accessed: ");
	tm_ptr = localtime(&view->dir_entry[view->list_pos].atime);
	strftime(buf, sizeof (buf), "%a %b %d %Y %I:%M %p", tm_ptr);
	checked_wmove(menu_win, curr_y, 13);
	wprint(menu_win, buf);
	curr_y += 2;

#ifndef _WIN32
	mvwaddstr(menu_win, curr_y, 2, "Changed: ");
#else
	mvwaddstr(menu_win, curr_y, 2, "Created: ");
#endif
	tm_ptr = localtime(&view->dir_entry[view->list_pos].ctime);
	strftime(buf, sizeof (buf), "%a %b %d %Y %I:%M %p", tm_ptr);
	checked_wmove(menu_win, curr_y, 13);
	wprint(menu_win, buf);
	curr_y += 2;

#ifndef _WIN32
	mvwaddstr(menu_win, curr_y, 2, "Owner: ");
	mvwaddstr(menu_win, curr_y, 10, uid_buf);
	curr_y += 2;

	mvwaddstr(menu_win, curr_y, 2, "Group: ");
	if((grp_buf = getgrgid(view->dir_entry[view->list_pos].gid)) != NULL)
		mvwaddstr(menu_win, curr_y, 10, grp_buf->gr_name);
#endif

	box(menu_win, 0, 0);
	checked_wmove(menu_win, 0, 3);
	wprint(menu_win, " File Information ");
	wrefresh(menu_win);

	was_redraw = 1;
}
Beispiel #8
0
Datei: sort.c Projekt: lyuts/vifm
static int
sort_dir_list(const void *one, const void *two)
{
	int retval;
	char *pfirst, *psecond;
	dir_entry_t *const first = (dir_entry_t *)one;
	dir_entry_t *const second = (dir_entry_t *)two;
	int first_is_dir;
	int second_is_dir;
	int dirs;

	if(is_parent_dir(first->name))
	{
		return -1;
	}
	else if(is_parent_dir(second->name))
	{
		return 1;
	}

	first_is_dir = is_directory_entry(first);
	second_is_dir = is_directory_entry(second);

	dirs = first_is_dir || second_is_dir;

	retval = 0;
	switch(sort_type)
	{
		case SORT_BY_NAME:
		case SORT_BY_INAME:
			if(first->name[0] == '.' && second->name[0] != '.')
				retval = -1;
			else if(first->name[0] != '.' && second->name[0] == '.')
				retval = 1;
			else
				retval = compare_file_names(dirs, first->name, second->name,
						sort_type == SORT_BY_INAME);
			break;

		case SORT_BY_TYPE:
			if(first_is_dir != second_is_dir)
			{
				retval = first_is_dir ? -1 : 1;
			}
			break;

		case SORT_BY_EXTENSION:
			pfirst  = strrchr(first->name,  '.');
			psecond = strrchr(second->name, '.');

			if(pfirst && psecond)
				retval = compare_file_names(dirs, ++pfirst, ++psecond, 0);
			else if(pfirst || psecond)
				retval = pfirst ? -1 : 1;
			else
				retval = compare_file_names(dirs, first->name, second->name, 0);
			break;

		case SORT_BY_SIZE:
			{
				if(first_is_dir)
					tree_get_data(curr_stats.dirsize_cache, first->name, &first->size);

				if(second_is_dir)
					tree_get_data(curr_stats.dirsize_cache, second->name, &second->size);

				retval = (first->size < second->size) ?
						-1 : (first->size > second->size);
			}
			break;

		case SORT_BY_TIME_MODIFIED:
			retval = first->mtime - second->mtime;
			break;

		case SORT_BY_TIME_ACCESSED:
			retval = first->atime - second->atime;
			break;

		case SORT_BY_TIME_CHANGED:
			retval = first->ctime - second->ctime;
			break;
#ifndef _WIN32
		case SORT_BY_MODE:
			retval = first->mode - second->mode;
			break;

		case SORT_BY_OWNER_NAME: /* FIXME */
		case SORT_BY_OWNER_ID:
			retval = first->uid - second->uid;
			break;

		case SORT_BY_GROUP_NAME: /* FIXME */
		case SORT_BY_GROUP_ID:
			retval = first->gid - second->gid;
			break;

		case SORT_BY_PERMISSIONS:
			{
				char first_perm[11], second_perm[11];
				get_perm_string(first_perm, sizeof(first_perm), first->mode);
				get_perm_string(second_perm, sizeof(second_perm), second->mode);
				retval = strcmp(first_perm, second_perm);
			}
			break;
#endif

		default:
			assert(0 && "All possible sort options should be handled");
			break;
	}

	if(retval == 0)
	{
		retval = first->list_num - second->list_num;
	}
	else if(sort_descending)
	{
		retval = -retval;
	}

	return retval;
}
Beispiel #9
0
Datei: sort.c Projekt: sklnd/vifm
static int
sort_dir_list(const void *one, const void *two)
{
	int retval;
	char *pfirst, *psecond;
	dir_entry_t *first = (dir_entry_t *) one;
	dir_entry_t *second = (dir_entry_t *) two;
	int first_is_dir = 0;
	int second_is_dir = 0;

	if(first->type == DIRECTORY)
		first_is_dir = 1;
	else if(first->type == LINK)
		first_is_dir = (first->name[strlen(first->name) - 1] == '/');

	if(second->type == DIRECTORY)
		second_is_dir = 1;
	else if(second->type == LINK)
		second_is_dir = (second->name[strlen(second->name) - 1] == '/');

	if(first_is_dir != second_is_dir)
		return first_is_dir ? -1 : 1;

	if(pathcmp(first->name, "../") == 0)
		return -1;
	else if(pathcmp(second->name, "../") == 0)
		return 1;

	retval = 0;
	switch(sort_type)
	{
		case SORT_BY_NAME:
		case SORT_BY_INAME:
			if(first->name[0] == '.' && second->name[0] != '.')
				retval = -1;
			else if(first->name[0] != '.' && second->name[0] == '.')
				retval = 1;
			else
				retval = compare_file_names(first->name, second->name,
						sort_type == SORT_BY_INAME);
			break;

		case SORT_BY_EXTENSION:
			pfirst  = strrchr(first->name,  '.');
			psecond = strrchr(second->name, '.');

			if(pfirst && psecond)
				retval = compare_file_names(++pfirst, ++psecond, 0);
			else if(pfirst || psecond)
				retval = pfirst ? -1 : 1;
			else
				retval = compare_file_names(first->name, second->name, 0);
			break;

		case SORT_BY_SIZE:
			{
				if(first_is_dir)
					tree_get_data(curr_stats.dirsize_cache, first->name, &first->size);

				if(second_is_dir)
					tree_get_data(curr_stats.dirsize_cache, second->name, &second->size);

				retval = (first->size < second->size) ?
						-1 : (first->size > second->size);
			}
			break;

		case SORT_BY_TIME_MODIFIED:
			retval = first->mtime - second->mtime;
			break;

		case SORT_BY_TIME_ACCESSED:
			retval = first->atime - second->atime;
			break;

		case SORT_BY_TIME_CHANGED:
			retval = first->ctime - second->ctime;
			break;
#ifndef _WIN32

		case SORT_BY_MODE:
			retval = first->mode - second->mode;
			break;

		case SORT_BY_OWNER_NAME: /* FIXME */
		case SORT_BY_OWNER_ID:
			retval = first->uid - second->uid;
			break;

		case SORT_BY_GROUP_NAME: /* FIXME */
		case SORT_BY_GROUP_ID:
			retval = first->gid - second->gid;
			break;
#endif
	}

	if(retval == 0)
		retval = first->list_num - second->list_num;
	else if(sort_descending)
		retval = -retval;

	return retval;
}
Beispiel #10
0
static int
sort_dir_list(const void *one, const void *two)
{
	int retval;
	char *pfirst, *psecond;
	dir_entry_t *const first = (dir_entry_t *)one;
	dir_entry_t *const second = (dir_entry_t *)two;
	int first_is_dir;
	int second_is_dir;

	if(is_parent_dir(first->name))
	{
		return -1;
	}
	else if(is_parent_dir(second->name))
	{
		return 1;
	}

	first_is_dir = is_directory_entry(first);
	second_is_dir = is_directory_entry(second);

	retval = 0;
	switch(sort_type)
	{
		case SK_BY_NAME:
		case SK_BY_INAME:
			if(custom_view)
			{
				retval = compare_entry_names(first, second, sort_type == SK_BY_INAME);
			}
			else
			{
				retval = compare_full_file_names(first->name, second->name,
						sort_type == SK_BY_INAME);
			}
			break;

		case SK_BY_DIR:
			if(first_is_dir != second_is_dir)
			{
				retval = first_is_dir ? -1 : 1;
			}
			break;

		case SK_BY_TYPE:
			retval = strcmp(get_type_str(first->type), get_type_str(second->type));
			break;

		case SK_BY_FILEEXT:
		case SK_BY_EXTENSION:
			pfirst = strrchr(first->name,  '.');
			psecond = strrchr(second->name, '.');

			if(first_is_dir && second_is_dir && sort_type == SK_BY_FILEEXT)
			{
				retval = compare_file_names(first->name, second->name, 0);
			}
			else if(first_is_dir != second_is_dir && sort_type == SK_BY_FILEEXT)
			{
				retval = first_is_dir ? -1 : 1;
			}
			else if(pfirst && psecond)
			{
				if(pfirst == first->name && psecond != second->name)
				{
					retval = -1;
				}
				else if(pfirst != first->name && psecond == second->name)
				{
					retval = 1;
				}
				else
				{
					retval = compare_file_names(++pfirst, ++psecond, 0);
				}
			}
			else if(pfirst || psecond)
				retval = pfirst ? -1 : 1;
			else
				retval = compare_file_names(first->name, second->name, 0);
			break;

		case SK_BY_SIZE:
			{
				if(first_is_dir)
				{
					char full_path[PATH_MAX];
					get_full_path_of(first, sizeof(full_path), full_path);
					tree_get_data(curr_stats.dirsize_cache, full_path, &first->size);
				}

				if(second_is_dir)
				{
					char full_path[PATH_MAX];
					get_full_path_of(second, sizeof(full_path), full_path);
					tree_get_data(curr_stats.dirsize_cache, full_path, &second->size);
				}

				retval = (first->size < second->size)
				       ? -1
				       : (first->size > second->size);
			}
			break;

		case SK_BY_TIME_MODIFIED:
			retval = first->mtime - second->mtime;
			break;

		case SK_BY_TIME_ACCESSED:
			retval = first->atime - second->atime;
			break;

		case SK_BY_TIME_CHANGED:
			retval = first->ctime - second->ctime;
			break;
#ifndef _WIN32
		case SK_BY_MODE:
			retval = first->mode - second->mode;
			break;

		case SK_BY_OWNER_NAME: /* FIXME */
		case SK_BY_OWNER_ID:
			retval = first->uid - second->uid;
			break;

		case SK_BY_GROUP_NAME: /* FIXME */
		case SK_BY_GROUP_ID:
			retval = first->gid - second->gid;
			break;

		case SK_BY_PERMISSIONS:
			{
				char first_perm[11], second_perm[11];
				get_perm_string(first_perm, sizeof(first_perm), first->mode);
				get_perm_string(second_perm, sizeof(second_perm), second->mode);
				retval = strcmp(first_perm, second_perm);
			}
			break;
#endif
	}

	if(retval == 0)
	{
		retval = first->list_num - second->list_num;
	}
	else if(sort_descending)
	{
		retval = -retval;
	}

	return retval;
}