Example #1
0
static void
ExecTable(char *param)
{
    char *t;

    VERBOSE(1, ("ExecTable(%s)\n", param));
    if (FltOptions('c')) {
	t = skip_ident(param);
	if (*skip_blanks(t) == '\0') {
	    int save = *t;

	    *t = 0;
	    if (*param) {
		flt_make_symtab(param);
		flt_read_keywords(MY_NAME);
	    } else {
		set_symbol_table(default_table);
	    }
	    *t = (char) save;
	}
    }

    t = skip_ident(param);
    flt_puts(param, (int) (t - param), Literal_attr);
    if (*skip_blanks(t) == '\0') {
	flt_puts(t, (int) strlen(t), "");
    } else {
	flt_error("unexpected tokens");
	flt_puts(t, (int) strlen(t), Error_attr);
    }
}
Example #2
0
static void
parse_nondirective(char *s)
{
    char *base = s;
    char *t;
    const char *attr0 = Ident_attr;
    const char *attr1 = Ident2_attr;
    char *attr2 = Literal_attr;

    if (FltOptions('c')) {
	t = skip_ident(s = base);
	if (t != s) {
	    int save = *t;

	    /* this parses one of
	     * "name"
	     * "name:class"
	     * "name:color"
	     */
	    parse_keyword(s, 0);

	    *t = 0;
	    attr0 = actual_color(s, abbr_len(s), 0);
	    *t = (char) save;
	}
	if (skip_eqls_ch(&t)) {
	    s = skip_ident(t);
	    if (s != t) {
		attr1 = actual_color(t, (int) (s - t), 1);
	    }
	}
    }

    t = skip_ident(s = base);
    flt_puts(s, (int) (t - s), attr0);
    if (parse_eqls_ch(&t)) {
	s = skip_ident(t);
	if (s != t) {
	    int save = *s;
	    *s = 0;
	    if (!FltOptions('c')) {
		if (*(attr1 = color_of(t, 0)) == '\0')
		    attr1 = Action_attr;
	    }
	    flt_puts(t, (int) strlen(t), attr1);
	    *s = (char) save;
	}
	if (parse_eqls_ch(&s)) {
	    flt_puts(s, (int) strlen(s), attr2);
	} else if (*s) {
	    flt_puts(s, (int) strlen(s), Error_attr);
	}
    } else if (*t) {
	flt_puts(t, (int) strlen(t), Error_attr);
    }
}
Example #3
0
static void
parse_indexdef(IndexDef *stmt, Oid index, Oid table)
{
    char *sql = pg_get_indexdef_string(index);
    const char *idxname = get_quoted_relname(index);
    const char *tblname = get_relation_name(table);

    /* CREATE [UNIQUE] INDEX */
    stmt->create = sql;
    sql = skip_const(index, sql, "CREATE INDEX", "CREATE UNIQUE INDEX");
    /* index */
    stmt->index = sql;
    sql = skip_const(index, sql, idxname, NULL);
    /* ON */
    sql = skip_const(index, sql, "ON", NULL);
    /* table */
    stmt->table = sql;
    sql = skip_const(index, sql, tblname, NULL);
    /* USING */
    sql = skip_const(index, sql, "USING", NULL);
    /* type */
    stmt->type = sql;
    sql = skip_ident(index, sql);
    /* (columns) */
    if ((sql = strchr(sql, '(')) == NULL)
        parse_error(index);
    sql++;
    stmt->columns = sql;
    if ((sql = skip_until(index, sql, ')')) == NULL)
        parse_error(index);
    /* options */
    stmt->options = sql;
}
Example #4
0
File: lbind.c Project: ifzz/nui
static int parse_mask(lbind_Enum *et, const char *s, int *penum, lua_State *L) {
  *penum = 0;
  while (*s != '\0') {
    const char *e;
    int inversion = 0;
    lbind_EnumItem *item;
    s = skip_white(s);
    if (*s == '~') {
      inversion = 1;
      s = skip_white(s+1);
    }
    if (*s == '\0') break;
    e = skip_ident(s);
    if (e == s || (item = lbind_findenum(et, s, e-s)) == NULL) {
      if (L == NULL) return 0;
      if (e == s)
        return luaL_error(L, "unexpected token '%c' in %s", *s, et->name);
      else {
        lua_pushlstring(L, s, e-s);
        return luaL_error(L, "unexpected mask '%s' in %s", lua_tostring(L, -1), et->name);
      }
    }
    s = e;
    if (inversion)
      *penum &= ~item->value;
    else
      *penum |= item->value;
  }
  return 1;
}
Example #5
0
static void
ExecDefault(const char *param)
{
    char *temp = strmalloc(param);
    char *s = skip_ident(temp);
    int save = *s;
    int isClass;

    *s = 0;
    if (!*temp) {
	free(temp);
	temp = strmalloc(NAME_KEYWORD);
	isClass = (is_class(temp) != 0);
    } else {
	isClass = (is_class(temp) != 0);
	*s = (char) save;
    }

    if (isClass) {
	flt_init_attr(temp);
	VERBOSE(1, ("set default_attr '%s' %p", default_attr, default_attr));
    } else {
	VERBOSE(1, ("not a class:%s", temp));
    }

    free(temp);
}
Example #6
0
static void
ExecClass(char *param)
{
    char *t = strmalloc(param);
    char *s;
    const char *attr = "";

    parse_keyword(t, 1);
    free(t);
    t = flt_put_blanks(param);
    s = skip_ident(t);
    if (FltOptions('c')) {
	attr = actual_color(param, (int) (s - param), 1);
    } else {
	attr = Ident2_attr;
    }
    flt_puts(param, (int) (s - param), attr);
    if (parse_eqls_ch(&s)) {
	t = s;
	s = skip_ident(t);
	if (FltOptions('c')) {
	    attr = actual_color(t, (int) (s - t), 1);
	} else {
	    if (*(attr = color_of(t, 0)) == '\0')
		attr = Action_attr;
	}
	flt_puts(t, (int) (s - t), attr);
	if (parse_eqls_ch(&s)) {
	    flt_puts(s, (int) strlen(s), Literal_attr);
	} else if (*s) {
	    flt_puts(s, (int) strlen(s), Error_attr);
	}
    } else if (*s) {
	flt_puts(s, (int) strlen(s), Error_attr);
    }
}
Example #7
0
static const char *
color_of(char *s, int arg)
{
    const char *result = "";
    char *t;
    int quoted = 0;
    int save;

    s = skip_blanks(s);
    t = skip_ident(s);
    if ((save = *t) != 0)
	*t = 0;

    if (is_class(s)) {
	if (FltOptions('c')) {
	    result = keyword_attr(s);
	    if (result == 0)
		result = class_attr(s);
	    if (result == 0)
		result = Ident2_attr;
	} else {
	    result = Ident2_attr;
	}
    } else if (arg && (*s != 0)) {
	char *base = s;

	if (!FltOptions('c'))
	    result = Action_attr;
	while (*s != 0) {
	    if (quoted) {
		if (*s == QUOTE)
		    quoted = 0;
	    } else if (*s == QUOTE) {
		quoted = 1;
		result = Literal_attr;
	    } else if ((s == base) && color_code(s, &result)) {
		break;
	    }
	    s++;
	}
    }
    if (save)
	*t = (char) save;
    return result;
}
Example #8
0
static int
parse_directive(char *line)
{
    /* *INDENT-OFF* */
    static struct {
	const char *name;
	void (*func) (char *);
    } table[] = {
	{ "abbrev",  ExecAbbrev   },
	{ "brief",   ExecBrief    },
	{ "class",   ExecClass    },
	{ "default", ExecDefault  },
	{ "equals",  ExecEquals   },
	{ "include", ExecInclude  },
	{ "merge",   ExecSource   },
	{ "meta",    ExecMeta     },
	{ "source",  ExecSource   },
	{ "table",   ExecTable    },
    };
    /* *INDENT-ON* */

    unsigned n, len;
    char *s;

    VERBOSE(1, ("parse_directive(%s)\n", line));
    if (*(s = skip_blanks(line)) == meta_ch) {
	s = skip_blanks(s + 1);
	if ((len = (unsigned) (skip_ident(s) - s)) != 0) {
	    for (n = 0; n < sizeof(table) / sizeof(table[0]); n++) {
		if (!strncmp(s, table[n].name, len)) {
		    flt_puts(line, (int) (s + len - line), Ident_attr);
		    s = flt_put_blanks(s + len);
		    (*table[n].func) (s);
		    return 1;
		}
	    }
	}
	flt_error("unknown directive");
	flt_puts(line, (int) strlen(line), Error_attr);
    }
    return 0;
}
Example #9
0
static void
ExecDefault(char *param)
{
    char *s = skip_ident(param);
    const char *t = param;
    const char *attr = Literal_attr;
    int save = *s;

    VERBOSE(1, ("ExecDefault(%s)\n", param));
    *s = 0;
    if (!*t)
	t = NAME_KEYWORD;
    if (is_class(t)) {
	free(default_attr);
	default_attr = strmalloc(t);
    }
    if (FltOptions('c')) {
	attr = actual_color(t, -1, 1);
	VERBOSE(2, ("actual_color(%s) = %s\n", t, attr));
    }
    *s = (char) save;
    flt_puts(param, (int) strlen(param), attr);
}
Example #10
0
static int
ParseDirective(char *line)
{
    static struct {
	const char *name;
	void (*func) (const char *param);
    } table[] = {
	/* *INDENT-OFF* */
	{ "abbrev",  ExecAbbrev   },
	{ "brief",   ExecBrief    },
	{ "class",   ExecClass    },
	{ "default", ExecDefault  },
	{ "equals",  ExecEquals   },
	{ "include", flt_read_keywords },
	{ "merge",   ExecMerge    },
	{ "meta",    ExecMeta     },
	{ "source",  ExecSource   },
	{ "table",   ExecTable    },
	/* *INDENT-ON* */

    };
    size_t n, len;

    if (*(line = skip_blanks(line)) == meta_ch) {
	line = skip_blanks(line + 1);
	if ((len = (size_t) (skip_ident(line) - line)) != 0) {
	    for (n = 0; n < sizeof(table) / sizeof(table[0]); n++) {
		if (!strncmp(line, table[n].name, len)) {
		    (*table[n].func) (skip_blanks(line + len));
		    break;
		}
	    }
	}
	return 1;
    }
    return 0;
}
Example #11
0
static void
parse_indexdef(IndexDef *stmt, Oid index, Oid table)
{
	char *sql = pg_get_indexdef_string(index);
	const char *idxname = get_quoted_relname(index);
	const char *tblname = get_relation_name(table);
	const char *limit = strchr(sql, '\0');

	/* CREATE [UNIQUE] INDEX */
	stmt->create = sql;
	sql = skip_const(index, sql, "CREATE INDEX", "CREATE UNIQUE INDEX");
	/* index */
	stmt->index = sql;
	sql = skip_const(index, sql, idxname, NULL);
	/* ON */
	sql = skip_const(index, sql, "ON", NULL);
	/* table */
	stmt->table = sql;
	sql = skip_const(index, sql, tblname, NULL);
	/* USING */
	sql = skip_const(index, sql, "USING", NULL);
	/* type */
	stmt->type = sql;
	sql = skip_ident(index, sql);
	/* (columns) */
	if ((sql = strchr(sql, '(')) == NULL)
		parse_error(index);
	sql++;
	stmt->columns = sql;
	if ((sql = skip_until(index, sql, ')')) == NULL)
		parse_error(index);

	/* options */
	stmt->options = sql;
	stmt->tablespace = NULL;
	stmt->where = NULL;

	/* Is there a tablespace? Note that apparently there is never, but
	 * if there was one it would appear here. */
	if (sql < limit && strstr(sql, "TABLESPACE"))
	{
		sql = skip_until_const(index, sql, "TABLESPACE");
		stmt->tablespace = sql;
		sql = skip_ident(index, sql);
	}

	/* Note: assuming WHERE is the only clause allowed after TABLESPACE */
	if (sql < limit && strstr(sql, "WHERE"))
	{
		sql = skip_until_const(index, sql, "WHERE");
		stmt->where = sql;
	}

	elog(DEBUG2, "indexdef.create  = %s", stmt->create);
	elog(DEBUG2, "indexdef.index   = %s", stmt->index);
	elog(DEBUG2, "indexdef.table   = %s", stmt->table);
	elog(DEBUG2, "indexdef.type    = %s", stmt->type);
	elog(DEBUG2, "indexdef.columns = %s", stmt->columns);
	elog(DEBUG2, "indexdef.options = %s", stmt->options);
	elog(DEBUG2, "indexdef.tspace  = %s", stmt->tablespace);
	elog(DEBUG2, "indexdef.where   = %s", stmt->where);
}