示例#1
0
static void fail_unless_files_equal (const char *left, const char *right)
{
	pipeline *diff = pipeline_new_command_args
		("diff", "-u", left, right, NULL);
	int ret = pipeline_run (diff);
	fail_unless (ret == 0);
}
示例#2
0
文件: whatis.c 项目: Shivox/man-db
/* Do the old thing, if we cannot find the relevant database.
 * This invokes grep once per argument; we can't do much about this because
 * we need to know which arguments failed.  The only way to speed this up
 * would be to implement grep internally, but it hardly seems worth it for a
 * legacy mechanism.
 */
static void use_grep (const char * const *pages, int num_pages, char *manpath,
		      int *found)
{
	char *whatis_file = xasprintf ("%s/whatis", manpath);

	if (access (whatis_file, R_OK) == 0) {
		const char *flags;
		int i;

		if (am_apropos) {
			if (regex_opt)
				flags = get_def_user (
					"apropos_regex_grep_flags",
					APROPOS_REGEX_GREP_FLAGS);
			else
				flags = get_def_user ("apropos_grep_flags",
						      APROPOS_GREP_FLAGS);
		} else
			flags = get_def_user ("whatis_grep_flags",
					      WHATIS_GREP_FLAGS);

		for (i = 0; i < num_pages; ++i) {
			pipeline *grep_pl;
			pipecmd *grep_cmd;
			char *anchored_page;

			if (am_apropos)
				anchored_page = xstrdup (pages[i]);
			else
				anchored_page = xasprintf ("^%s", pages[i]);

			grep_cmd = pipecmd_new_argstr (get_def_user ("grep",
								     GREP));
			pipecmd_argstr (grep_cmd, flags);
			pipecmd_args (grep_cmd, anchored_page, whatis_file,
				      NULL);
			grep_pl = pipeline_new_commands (grep_cmd, NULL);

			if (pipeline_run (grep_pl) == 0)
				found[i] = 1;

			free (anchored_page);
		}
	} else
		debug ("warning: can't read the fallback whatis text database "
		       "%s/whatis\n", manpath);

	free (whatis_file);
}