ih_sub_t *
ih_sub_new (MateVFSURI *uri, MateVFSMonitorType mon_type)
{
	ih_sub_t *sub = NULL;

	sub = g_new0 (ih_sub_t, 1);
	sub->type = mon_type;
	sub->uri = uri;
	mate_vfs_uri_ref (uri);
	sub->pathname = mate_vfs_unescape_string (mate_vfs_uri_get_path (uri), "/");
	/* mate_vfs_unescape_string returns NULL when
	 * the uri path passed to it is invalid.
	 */
	if (!sub->pathname)
	{
		IS_W("new subscription for %s failed because of invalid characters.\n", mate_vfs_uri_get_path (uri));
		g_free (sub);
		mate_vfs_uri_unref (uri);
		return NULL;
	}
/* TODO: WAITING for flag to be implemented
	if (mon_type & MATE_VFS_DONT_FOLLOW_SYMLINK)
	{
		sub->extra_flags |= IN_DONT_FOLLOW;
	}
*/

	IS_W("new subscription for %s being setup\n", sub->pathname);

	ih_sub_setup (sub);
	return sub;
}
Ejemplo n.º 2
0
/*
 * XXX: Currently we just follow the gnome vfs monitor type flags when
 * deciding how to treat the path. In the future we could try
 * and determine whether the path points to a directory or a file but
 * that is racey.
 */
static void
ih_sub_setup (ih_sub_t *sub)
{
	if (sub->is_dir)
	{
		sub->dirname = g_strdup (sub->pathname);
		sub->filename = NULL;
	} else {
		sub->dirname = ih_sub_get_dirname (sub->pathname);
		sub->filename = ih_sub_get_filename (sub->pathname);
	}

	ih_sub_fix_dirname (sub);

	IS_W("sub->dirname = %s\n", sub->dirname);
	if (sub->filename)
	{
		IS_W("sub->filename = %s\n", sub->filename);
	}
}
/*
 * XXX: Currently we just follow the mate vfs monitor type flags when
 * deciding how to treat the path. In the future we could try
 * and determine whether the path points to a directory or a file but
 * that is racey.
 */
static void
ih_sub_setup (ih_sub_t *sub)
{
	if (sub->type & MATE_VFS_MONITOR_DIRECTORY)
	{
		sub->dirname = g_strdup (sub->pathname);
		sub->filename = NULL;
	} else {
		sub->dirname = ih_sub_get_uri_dirname (sub->uri);
		sub->filename = ih_sub_get_uri_filename (sub->uri);
	}

	ih_sub_fix_dirname (sub);

	IS_W("sub->dirname = %s\n", sub->dirname);
	if (sub->filename)
	{
		IS_W("sub->filename = %s\n", sub->filename);
	}
}
Ejemplo n.º 4
0
ih_sub_t *
ih_sub_new (const char *pathname, gboolean is_dir, guint32 flags, void *userdata)
{
	ih_sub_t *sub = NULL;

	sub = g_new0 (ih_sub_t, 1);
	sub->usersubdata = userdata;
	sub->is_dir = is_dir;
	sub->extra_flags = flags;
	sub->pathname = g_strdup (pathname);

	IS_W("new subscription for %s being setup\n", sub->pathname);

	ih_sub_setup (sub);
	return sub;
}
/**
 * Returns C tokens one at a time, only supports a subset of C.
 * 
 * Implemented (hopefully mostly correctly) as specified in
 * http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
 */
Token *Token_nextToken(SrcFile *f, int return_whitespace)
{
	char c;
	CDECL_CHAR_BUF(buf, CHAR_BUF_INITIAL_SIZE);
	
	find_token:
	/* Eat all whitespace */
	if( ! return_whitespace) {
		/* TODO: Is it ok to eat \0 ? */
		while((c = SrcFile_getc(f)) != EOF && IS_W(c)) {
			SrcFile_count(f, c);
		}
	} else if((c = SrcFile_getc(f)) != EOF && IS_W(c)) {
		SrcFile_count(f, c);
		BUF_PUT(buf, c);
		
		while((c = SrcFile_getc(f)) != EOF && IS_W(c)) {
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		SrcFile_ungetc(f, c);
		BUF_PUT(buf, '\0');
		
		return Token_Whitespace(buf);
	}
	
	if(c == EOF){
		free(buf);
		
		return Token_fromType(T_EOF);
	}
	
	/* Comment: "/ *" */
	if(c == '/' && SrcFile_testc(f, '*'))
	{
		SrcFile_count(f, c);
		SrcFile_count(f, '*');
		char c1;
		
		eat_comment:
		while((c = SrcFile_getc(f)) != EOF && c != '*') {
			SrcFile_count(f, c);
		}
		
		SrcFile_count(f, c);
		
		if((c1 = SrcFile_getc(f)) != EOF && c1 != '/') {
			SrcFile_ungetc(f, c1);
			goto eat_comment;
		}
		
		SrcFile_count(f, c1);
		
		/* Skip comments */
		goto find_token;
	}
	
	/* TODO: Parse some macros? */
	if(c == '#')
	{
		char c1;
		SrcFile_count(f, c);
		BUF_PUT(buf, c);
		
		eat_macro:
		while((c = SrcFile_getc(f)) != EOF && c != '\n' && c != '\\') {
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		if(c == '\\') {
			if((c1 = SrcFile_getc(f)) != EOF && c1 == '\n') {
				SrcFile_count(f, c);
				SrcFile_count(f, c1);
				BUF_PUT(buf, c1);
				goto eat_macro;
			} else {
				SrcFile_ungetc(f, c1);
			}
		}
		
		SrcFile_ungetc(f, c);
		BUF_PUT(buf, '\0');
		
		return Token_Macro(buf);
	}
	
	/* Identifier: {L}({L}|{D})* */
	if(IS_L(c))
	{
		SrcFile_count(f, c);
		BUF_PUT(buf, c);
		
		while((c = SrcFile_getc(f)) != EOF && (IS_L(c) || IS_D(c)))
		{
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		SrcFile_ungetc(f, c);
		BUF_PUT(buf, '\0');
		
		return Token_Identifier(buf);
	}
	
	/* TODO: Fix {IS} support? */
	/* Ignoring {IS} on lines below */
	/* Constant Hexadecimal: 0[Xx]{H}+{IS} */
	if(c == '0' && (SrcFile_testc(f, 'x') || SrcFile_testc(f, 'X')))
	{
		SrcFile_count(f, c);
		SrcFile_count(f, 'x');
		
		c = SrcFile_getc(f);
		
		if( ! IS_H(c)) {
			SrcFile_error(f, "Hexadecimal number expected after \"0x\"");
			
			free(buf);
			return NULL;
		}
		
		SrcFile_count(f, c);
		BUF_PUT(buf, c);
		
		while((c = SrcFile_getc(f)) != EOF && IS_H(c))
		{
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		SrcFile_ungetc(f, c);
		BUF_PUT(buf, '\0');
		
		return Token_HexNum(buf);
	}

	/* Octal number  0{D}+ */
	if(c == '0')
	{
		SrcFile_count(f, c);
		c = SrcFile_getc(f);
		
		if( ! IS_D(c)) {
			/* Just a plain zero */
			BUF_PUT(buf, '0');
			BUF_PUT(buf, '\0');
			SrcFile_ungetc(f, c);
			
			return Token_DecNum(buf);
		}
		
		SrcFile_count(f, c);
		BUF_PUT(buf, c);
		
		while((c = SrcFile_getc(f)) != EOF && IS_D(c))
		{
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		SrcFile_ungetc(f, c);
		BUF_PUT(buf, '\0');
		
		return Token_OctNum(buf);
	}
	
	/* Decimal number {D}+ */
	if(IS_D(c))
	{
		SrcFile_count(f, c);
		BUF_PUT(buf, c);
		
		while((c = SrcFile_getc(f)) != EOF && IS_D(c))
		{
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		SrcFile_ungetc(f, c);
		BUF_PUT(buf, '\0');
		
		return Token_DecNum(buf);
	}
	
	/* Char constant L?'(\\.|[^\\'])+' DOES NOT SUPPORT THE L? PART */
	if(c == '\'')
	{
		SrcFile_count(f, c);
		if((c = SrcFile_getc(f)) == '\\') {
			char c1;
			SrcFile_count(f, c);
			if((c1 = SrcFile_getc(f)) == EOF) {
				goto error_constchr_eof;
			}
			BUF_PUT(buf, c);
			SrcFile_count(f, c1);
			BUF_PUT(buf, c1);
		} else {
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		if((c = SrcFile_getc(f)) != '\'') {
			goto error_constchr_expectend;
		}
		
		BUF_PUT(buf, '\0');
		
		return Token_ConstChr(buf);
	}
	
	/* TODO: Fix the comment below? */
	/* Ignoring the
	   {D}+{E}{FS}?
	   {D}*"."{D}+({E})?{FS}?
	   {D}+"."{D}*({E})?{FS}?
	   T_CONSTANT rules for now */
	
	/* Constant String "(\.|[^\"])*" */
	if(c == '"')
	{
		SrcFile_count(f, c);
		parse_conststr:
		/* \. */
		if((c = SrcFile_getc(f)) == '\\') {
			char c1;
			
			SrcFile_count(f, c);
			if((c1 = SrcFile_getc(f)) == EOF) {
				goto error_conststr_eof;
			}
			
			BUF_PUT(buf, c);
			SrcFile_count(f, c1);
			BUF_PUT(buf, c1);
			
			goto parse_conststr;
		}
		
		if(c == EOF) {
			goto error_conststr_eof;
		}
		
		if(c != '"')
		{
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
			
			goto parse_conststr;
		}
		else
		{
			/* c == '"' */
			BUF_PUT(buf, '\0');
			return Token_ConstStr(buf);
		}
	}
	
	LITERAL2('.', "..", T_ELLIPSIS);
	LITERAL2('>', ">=", T_RIGHT_ASSIGN);
	LITERAL2('<', "<=", T_LEFT_ASSIGN);
	LITERAL2('+', "=",  T_ADD_ASSIGN);
	LITERAL2('-', "=",  T_SUB_ASSIGN);
	LITERAL2('*', "=",  T_MUL_ASSIGN);
	LITERAL2('/', "=",  T_DIV_ASSIGN);
	LITERAL2('%', "=",  T_MOD_ASSIGN);
	LITERAL2('&', "=",  T_AND_ASSIGN);
	LITERAL2('^', "=",  T_XOR_ASSIGN);
	LITERAL2('|', "=",  T_OR_ASSIGN);
	LITERAL2('>', ">",  T_RIGHT_OP);
	LITERAL2('<', "<",  T_LEFT_OP);
	LITERAL2('+', "+",  T_INC_OP);
	LITERAL2('-', "-",  T_DEC_OP);
	LITERAL2('-', ">",  T_PTR_OP);
	LITERAL2('&', "&",  T_AND_OP);
	LITERAL2('|', "|",  T_OR_OP);
	LITERAL2('<', "=",  T_LE_OP);
	LITERAL2('>', "=",  T_GE_OP);
	LITERAL2('=', "=",  T_EQ_OP);
	LITERAL2('!', "=",  T_NE_OP);
	LITERAL1(';',       T_SEMICOLON);
	LITERAL1('{', T_BLOCKSTART);
	LITERAL1('}', T_BLOCKEND);
	LITERAL1(',', T_COMMA);
	LITERAL1(':', T_COLON);
	LITERAL1('=', T_EQUALS);
	LITERAL1('(', T_LPAREN);
	LITERAL1(')', T_RPAREN);
	LITERAL1('[', T_LBRACKET);
	LITERAL1(']', T_RBRACKET);
	LITERAL1('.', T_DOT);
	LITERAL1('&', T_BW_AND);
	LITERAL1('!', T_NOT);
	LITERAL1('~', T_BW_NOT);
	LITERAL1('-', T_MINUS);
	LITERAL1('+', T_PLUS);
	LITERAL1('*', T_MUL);
	LITERAL1('/', T_DIV);
	LITERAL1('%', T_PERCENT);
	LITERAL1('<', T_LT);
	LITERAL1('>', T_GT);
	LITERAL1('^', T_BW_XOR);
	LITERAL1('|', T_BW_OR);
	LITERAL1('?', T_TERNARY);
	
	if(c == '$') {
		SrcFile_count(f, c);
		
		while((c = SrcFile_getc(f)) != EOF && (IS_L(c) || IS_D(c)))
		{
			SrcFile_count(f, c);
			BUF_PUT(buf, c);
		}
		
		SrcFile_ungetc(f, c);
		BUF_PUT(buf, '\0');
		
		return Token_Placeholder(buf);
	}
	
	SrcFile_error(f, "Undefined token \"%c\"(%d)", c, (int) c);
	
	free(buf);
	
	return NULL;
	
	error_constchr_expectend:
		SrcFile_error(f, "Expecting ' in constant char");
		
		free(buf);
		return NULL;
	
	error_constchr_eof:
		SrcFile_error(f, "Unexpected EOF in constant char");
		
		free(buf);
		return NULL;
	
	error_conststr_eof:
		SrcFile_error(f, "Unexpected EOF in constant string");
		
		free(buf);
		return NULL;
}