C-sparse
view release on metacpan or search on metacpan
src/sparse-0.4.4/pre-process.c view on Meta::CPAN
return TOKEN_ERROR;
}
}
return TOKEN_NUMBER;
}
if (p[0] == '.' && isdigit((unsigned char)p[1]))
return TOKEN_NUMBER;
return TOKEN_SPECIAL;
}
static int merge(SCTX_ struct token *left, struct token *right)
{
static char buffer[512];
enum token_type res = combine(sctx_ left, right, buffer);
int n; struct token *tok;
struct expansion *e;
e = expansion_new(sctx_ EXPANSION_CONCAT);
e->s = dup_one(sctx_ left);
e->s->next = tok = dup_one(sctx_ right); tok->next = NULL;
e->d = left;
switch (res) {
case TOKEN_IDENT:
left->ident = built_in_ident(sctx_ buffer);
left->pos.noexpand = 0;
left->e = e;
return 1;
case TOKEN_NUMBER: {
char *number = __alloc_bytes(sctx_ strlen(buffer) + 1);
memcpy(number, buffer, strlen(buffer) + 1);
token_type(left) = TOKEN_NUMBER; /* could be . + num */
left->number = number;
left->e = e;
return 1;
}
case TOKEN_SPECIAL:
if (buffer[2] && buffer[3])
break;
for (n = SPECIAL_BASE; n < SPECIAL_ARG_SEPARATOR; n++) {
if (!memcmp(buffer, combinations[n-SPECIAL_BASE], 3)) {
left->special = n;
left->e = e;
return 1;
}
}
break;
case TOKEN_WIDE_CHAR:
case TOKEN_WIDE_STRING:
token_type(left) = res;
left->pos.noexpand = 0;
left->string = right->string;
left->e = e;
return 1;
case TOKEN_WIDE_CHAR_EMBEDDED_0 ... TOKEN_WIDE_CHAR_EMBEDDED_3:
token_type(left) = res;
left->pos.noexpand = 0;
memcpy(left->embedded, right->embedded, 4);
left->e = e;
return 1;
default:
;
}
sparse_error(sctx_ left->pos, "'##' failed: concatenation is not a valid token");
return 0;
}
static struct token *dup_token(SCTX_ struct token *token, struct position *streampos)
{
struct token *alloc = alloc_token(sctx_ streampos);
token_type(alloc) = token_type(token);
alloc->pos.newline = token->pos.newline;
alloc->pos.whitespace = token->pos.whitespace;
alloc->number = token->number;
alloc->pos.noexpand = token->pos.noexpand;
alloc->space = token->space;
return alloc;
}
static struct token **copy(SCTX_ struct token **where, struct token *body, struct token *list, int *count)
{
int need_copy = --*count; struct expansion *e;
struct token **o = where; struct cons *l;
need_copy = 1;
while (!eof_token(list)) {
struct token *token;
if (need_copy)
token = dup_token(sctx_ list, &list->pos);
else
token = list;
if (token_type(token) == TOKEN_IDENT && token->ident->tainted)
token->pos.noexpand = 1;
*where = token;
where = &token->next;
list = list->next;
}
*where = &sctxp eof_token_entry;
e = expansion_new(sctx_ EXPANSION_SUBST);
e->up = l = expansion_cons_consume(sctx_ e, body, body->next);
e->down = l = expansion_cons_produce(sctx_ e, *o, 0);
return where;
}
static int handle_kludge(SCTX_ struct token **p, struct arg *args)
{
struct token *t = (*p)->next->next;
while (1) {
struct arg *v = &args[t->argnum];
if (token_type(t->next) != TOKEN_CONCAT) {
if (v->arg) {
src/sparse-0.4.4/pre-process.c view on Meta::CPAN
sctxp includepath[0] = "";
path = sctxp includepath;
break;
default:
/* Dir of input file is first dir to search for quoted includes */
set_stream_include_path(sctx_ stream);
path = expect ? sctxp angle_includepath : sctxp quote_includepath;
break;
}
/* Check the standard include paths.. */
if (do_include_path(sctx_ path, list, token, filename, flen))
return 0;
out:
error_die(sctx_ token->pos, "unable to open '%s'", filename);
return 0;
}
static int handle_include(SCTX_ struct stream *stream, struct token **list, struct token *token)
{
return handle_include_path(sctx_ stream, list, token, 0);
}
static int handle_include_next(SCTX_ struct stream *stream, struct token **list, struct token *token)
{
return handle_include_path(sctx_ stream, list, token, 1);
}
static int handle_argv_include(SCTX_ struct stream *stream, struct token **list, struct token *token)
{
return handle_include_path(sctx_ stream, list, token, 2);
}
static int token_different(SCTX_ struct token *t1, struct token *t2)
{
int different;
if (token_type(t1) != token_type(t2))
return 1;
switch (token_type(t1)) {
case TOKEN_IDENT:
different = t1->ident != t2->ident;
break;
case TOKEN_ARG_COUNT:
case TOKEN_UNTAINT:
case TOKEN_CONCAT:
case TOKEN_GNU_KLUDGE:
different = 0;
break;
case TOKEN_NUMBER:
different = strcmp(t1->number, t2->number);
break;
case TOKEN_SPECIAL:
different = t1->special != t2->special;
break;
case TOKEN_MACRO_ARGUMENT:
case TOKEN_QUOTED_ARGUMENT:
case TOKEN_STR_ARGUMENT:
different = t1->argnum != t2->argnum;
break;
case TOKEN_CHAR_EMBEDDED_0 ... TOKEN_CHAR_EMBEDDED_3:
case TOKEN_WIDE_CHAR_EMBEDDED_0 ... TOKEN_WIDE_CHAR_EMBEDDED_3:
different = memcmp(t1->embedded, t2->embedded, 4);
break;
case TOKEN_CHAR:
case TOKEN_WIDE_CHAR:
case TOKEN_STRING:
case TOKEN_WIDE_STRING: {
struct string *s1, *s2;
s1 = t1->string;
s2 = t2->string;
different = 1;
if (s1->length != s2->length)
break;
different = memcmp(s1->data, s2->data, s1->length);
break;
}
default:
different = 1;
break;
}
return different;
}
static int token_list_different(SCTX_ struct token *list1, struct token *list2)
{
for (;;) {
if (list1 == list2)
return 0;
if (!list1 || !list2)
return 1;
if (token_different(sctx_ list1, list2))
return 1;
list1 = list1->next;
list2 = list2->next;
}
}
static inline void set_arg_count(struct token *token)
{
token_type(token) = TOKEN_ARG_COUNT;
token->count.normal = token->count.quoted =
token->count.str = token->count.vararg = 0;
}
static struct token *parse_arguments(SCTX_ struct token **arglist)
{
struct token *list = *arglist = dup_one(sctx_ *arglist);
struct token *arg = list->next = dup_one(sctx_ list->next), *next = list;
struct argcount *count = &list->count;
set_arg_count(list);
if (match_op(arg, ')')) {
next = arg->next;
list->next = &sctxp eof_token_entry;
return next;
}
while (token_type(arg) == TOKEN_IDENT) {
if (arg->ident == (struct ident *)&sctxp __VA_ARGS___ident)
( run in 0.637 second using v1.01-cache-2.11-cpan-71847e10f99 )