Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
cppsetup.c File Reference
#include "def.h"
#include "ifparser.h"

Go to the source code of this file.

Classes

struct  _parse_data

Defines

#define MAXNAMELEN   256
#define isvarfirstletter(ccc)   (isalpha(ccc) || (ccc) == '_')

Functions

static const char * my_if_errors (IfParser *ip, const char *cp, const char *expecting)
static struct symtab ** lookup_variable (IfParser *ip, const char *var, int len)
static int my_eval_defined (IfParser *ip, const char *var, int len)
static long my_eval_variable (IfParser *ip, const char *var, int len)
int cppsetup (char *filename, char *line, struct filepointer *filep, struct inclist *inc)

Class Documentation

struct _parse_data

Definition at line 126 of file cppsetup.c.

Collaboration diagram for _parse_data:
Class Members
char * filename
struct filepointer * filep
struct inclist * inc
const char * line

Define Documentation

#define isvarfirstletter (   ccc)    (isalpha(ccc) || (ccc) == '_')

Definition at line 184 of file cppsetup.c.

#define MAXNAMELEN   256

Definition at line 158 of file cppsetup.c.


Function Documentation

int cppsetup ( char *  filename,
char *  line,
struct filepointer filep,
struct inclist inc 
)

Definition at line 208 of file cppsetup.c.

{
    IfParser ip;
    struct _parse_data pd;
    long val = 0;

    pd.filep = filep;
    pd.inc = inc;
    pd.line = line;
    pd.filename = filename;
    ip.funcs.handle_error = my_if_errors;
    ip.funcs.eval_defined = my_eval_defined;
    ip.funcs.eval_variable = my_eval_variable;
    ip.data = (char *) &pd;

    (void) ParseIfExpression (&ip, line, &val);
    if (val)
       return IF;
    else
       return IFFALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct symtab** lookup_variable ( IfParser ip,
const char *  var,
int  len 
) [static, read]

Definition at line 161 of file cppsetup.c.

{
    char tmpbuf[MAXNAMELEN + 1];
    struct _parse_data *pd = (struct _parse_data *) ip->data;

    if (len > MAXNAMELEN)
       return 0;

    strncpy (tmpbuf, var, len);
    tmpbuf[len] = '\0';
    return isdefined (tmpbuf, pd->inc, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int my_eval_defined ( IfParser ip,
const char *  var,
int  len 
) [static]

Definition at line 176 of file cppsetup.c.

{
    if (lookup_variable (ip, var, len))
       return 1;
    else
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static long my_eval_variable ( IfParser ip,
const char *  var,
int  len 
) [static]

Definition at line 187 of file cppsetup.c.

{
    long val;
    struct symtab **s;

    s = lookup_variable (ip, var, len);
    if (!s)
       return 0;
    do {
       var = (*s)->s_value;
       if (!isvarfirstletter(*var) || !strcmp((*s)->s_name, var))
           break;
       s = lookup_variable (ip, var, strlen(var));
    } while (s);

    var = ParseIfExpression(ip, var, &val);
    if (var && *var) debug(4, ("extraneous: '%s'\n", var));
    return val;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const char* my_if_errors ( IfParser ip,
const char *  cp,
const char *  expecting 
) [static]

Definition at line 134 of file cppsetup.c.

{
    struct _parse_data *pd = (struct _parse_data *) ip->data;
    int lineno = pd->filep->f_line;
    char *filename = pd->filename;
    char prefix[300];
    int prefixlen;
    int i;

    sprintf (prefix, "\"%s\":%d", filename, lineno);
    prefixlen = strlen(prefix);
    fprintf (stderr, "%s:  %s", prefix, pd->line);
    i = cp - pd->line;
    if (i > 0 && pd->line[i-1] != '\n') {
       putc ('\n', stderr);
    }
    for (i += prefixlen + 3; i > 0; i--) {
       putc (' ', stderr);
    }
    fprintf (stderr, "^--- expecting %s\n", expecting);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function: