Beispiel #1
0
/* Validates list of tags.  Returns zero if tags are well-formed and non-zero
 * otherwise. */
static int
validate_tags(const char tags[])
{
	return tags[0] == '\0'
	    || starts_with_lit(tags, ",") || strstr(tags, ",,") != NULL
	    || ends_with(tags, ",");
}
Beispiel #2
0
const char *
find_last_command(const char cmds[])
{
	const char *p, *q;

	p = cmds;
	q = cmds;
	while(*cmds != '\0')
	{
		if(*p == '\\')
		{
			q += (p[1] == '|') ? 1 : 2;
			p += 2;
		}
		else if(*p == '\0' || (*p == '|' &&
				line_pos(cmds, q, ' ', starts_with_lit(cmds, "fil")) == 0))
		{
			if(*p != '\0')
			{
				++p;
			}

			cmds = skip_to_cmd_name(cmds);
			if(*cmds == '!' || starts_with_lit(cmds, "com"))
			{
				break;
			}

			q = p;

			if(*q == '\0')
			{
				break;
			}

			cmds = q;
		}
		else
		{
			++q;
			++p;
		}
	}

	return cmds;
}
Beispiel #3
0
/* Applies one filename modifiers per call. */
static const char *
apply_mod(const char *path, const char *parent, const char *mod, int *mod_len,
		int for_shell)
{
	char path_buf[PATH_MAX];
	static char buf[PATH_MAX];

	snprintf(path_buf, sizeof(path_buf), "%s", path);
#ifdef _WIN32
	to_forward_slash(path_buf);
#endif

	*mod_len = 2;
	if(starts_with_lit(mod, ":p"))
		*mod_len += apply_p_mod(path_buf, parent, buf, sizeof(buf));
	else if(starts_with_lit(mod, ":~"))
		*mod_len += apply_tilde_mod(path_buf, buf, sizeof(buf));
	else if(starts_with_lit(mod, ":."))
		*mod_len += apply_dot_mod(path_buf, buf, sizeof(buf));
	else if(starts_with_lit(mod, ":h"))
		*mod_len += apply_h_mod(path_buf, buf, sizeof(buf));
#ifdef _WIN32
	else if(starts_with_lit(mod, ":u"))
		*mod_len += apply_u_mod(path_buf, buf, sizeof(buf));
#endif
	else if(starts_with_lit(mod, ":t"))
		*mod_len += apply_t_mod(path_buf, buf, sizeof(buf));
	else if(starts_with_lit(mod, ":r"))
		*mod_len += apply_r_mod(path_buf, buf, sizeof(buf));
	else if(starts_with_lit(mod, ":e"))
		*mod_len += apply_e_mod(path_buf, buf, sizeof(buf));
	else if(starts_with_lit(mod, ":s") || starts_with_lit(mod, ":gs"))
		*mod_len += apply_s_gs_mod(path_buf, mod, buf, sizeof(buf));
	else
		return NULL;

#ifdef _WIN32
	/* This is needed to run something like explorer.exe, which isn't smart enough
	 * to understand forward slashes. */
	if(for_shell && curr_stats.shell_type != ST_CMD)
	{
		if(!starts_with_lit(mod, ":s") && !starts_with_lit(mod, ":gs"))
		{
			to_back_slash(buf);
		}
	}
#endif

	return buf;
}