Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Enumerations | Functions | Variables

extern.h File Reference

#include "type.h"
#include "parser/keywords.h"
#include <errno.h>
#include <limits.h>
Include dependency graph for extern.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define STRUCT_DEPTH   128
#define EMPTY   mm_strdup("")
#define ILLEGAL_OPTION   1
#define NO_INCLUDE_FILE   2
#define PARSE_ERROR   3
#define INDICATOR_NOT_ARRAY   4
#define OUT_OF_MEMORY   5
#define INDICATOR_NOT_STRUCT   6
#define INDICATOR_NOT_SIMPLE   7
#define INFORMIX_MODE   (compat == ECPG_COMPAT_INFORMIX || compat == ECPG_COMPAT_INFORMIX_SE)

Enumerations

enum  COMPAT_MODE {
  ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE, ECPG_COMPAT_PGSQL = 0,
  ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE
}

Functions

const char * get_dtype (enum ECPGdtype)
void lex_init (void)
void output_line_number (void)
void output_statement (char *, int, enum ECPG_statement_type)
void output_prepare_statement (char *, char *)
void output_deallocate_prepare_statement (char *)
void output_simple_statement (char *)
char * hashline_number (void)
int base_yyparse (void)
int base_yylex (void)
void base_yyerror (const char *)
void * mm_alloc (size_t)
void ** mm_realloc (void *, size_t)
char * mm_strdup (const char *)
void mmerror (int, enum errortype, const char *,...) __attribute__((format(PG_PRINTF_ATTRIBUTE
void void output_get_descr_header (char *)
void output_get_descr (char *, char *)
void output_set_descr_header (char *)
void output_set_descr (char *, char *)
void push_assignment (char *, enum ECPGdtype)
struct variablefind_variable (char *)
void whenever_action (int)
void add_descriptor (char *, char *)
void drop_descriptor (char *, char *)
struct descriptorlookup_descriptor (char *, char *)
struct variabledescriptor_variable (const char *name, int input)
struct variablesqlda_variable (const char *name)
void add_variable_to_head (struct arguments **, struct variable *, struct variable *)
void add_variable_to_tail (struct arguments **, struct variable *, struct variable *)
void remove_variable_from_list (struct arguments **list, struct variable *var)
void dump_variables (struct arguments *, int)
struct typedefsget_typedef (char *)
void adjust_array (enum ECPGttype, char **, char **, char *, char *, int, bool)
void reset_variables (void)
void check_indicator (struct ECPGtype *)
void remove_typedefs (int)
void remove_variables (int)
struct variablenew_variable (const char *, struct ECPGtype *, int)
const ScanKeywordScanCKeywordLookup (const char *)
const ScanKeywordScanECPGKeywordLookup (const char *text)
void scanner_init (const char *)
void parser_init (void)
void scanner_finish (void)
int filtered_base_yylex (void)

Variables

bool autocommit
bool auto_create_c
bool system_includes
bool force_indicator
bool questionmarks
bool regression_mode
bool auto_prepare
int braces_open
int ret_value
int struct_level
int ecpg_internal_var
char * current_function
char * descriptor_index
char * descriptor_name
char * connection
char * input_filename
char * yytext
char * token_start
int yylineno
FILE * yyin
FILE * yyout
char * output_filename
struct _include_pathinclude_paths
struct cursorcur
struct typedefstypes
struct _definesdefines
struct ECPGtype ecpg_no_indicator
struct variable no_indicator
struct argumentsargsinsert
struct argumentsargsresult
struct when when_error when_nf when_warn
struct ECPGstruct_memberstruct_member_list [STRUCT_DEPTH]
enum COMPAT_MODE compat

Define Documentation

#define EMPTY   mm_strdup("")

Definition at line 17 of file extern.h.

#define ILLEGAL_OPTION   1

Definition at line 112 of file extern.h.

Referenced by main().

#define INDICATOR_NOT_ARRAY   4

Definition at line 115 of file extern.h.

Referenced by ECPGdump_a_type().

#define INDICATOR_NOT_SIMPLE   7

Definition at line 118 of file extern.h.

Referenced by ECPGdump_a_type().

#define INDICATOR_NOT_STRUCT   6

Definition at line 117 of file extern.h.

Referenced by ECPGdump_a_type().

#define INFORMIX_MODE   (compat == ECPG_COMPAT_INFORMIX || compat == ECPG_COMPAT_INFORMIX_SE)

Definition at line 126 of file extern.h.

#define NO_INCLUDE_FILE   2

Definition at line 113 of file extern.h.

#define OUT_OF_MEMORY   5

Definition at line 116 of file extern.h.

Referenced by mm_alloc(), and mm_strdup().

#define PARSE_ERROR   3
#define STRUCT_DEPTH   128

Definition at line 16 of file extern.h.


Enumeration Type Documentation

Enumerator:
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 

Definition at line 120 of file extern.h.

{
    ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE
};


Function Documentation

void add_descriptor ( char *  ,
char *   
)

Definition at line 76 of file descriptor.c.

References mm_alloc(), and descriptor::name.

{
    struct descriptor *new;

    if (name[0] != '"')
        return;

    new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));

    new->next = descriptors;
    new->name = mm_alloc(strlen(name) + 1);
    strcpy(new->name, name);
    if (connection)
    {
        new->connection = mm_alloc(strlen(connection) + 1);
        strcpy(new->connection, connection);
    }
    else
        new->connection = connection;
    descriptors = new;
}

void add_variable_to_head ( struct arguments **  ,
struct variable ,
struct variable  
)

Definition at line 379 of file variable.c.

References arguments::indicator, mm_alloc(), arguments::next, and arguments::variable.

{
    struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));

    p->variable = var;
    p->indicator = ind;
    p->next = *list;
    *list = p;
}

void add_variable_to_tail ( struct arguments **  ,
struct variable ,
struct variable  
)

Definition at line 391 of file variable.c.

References mm_alloc(), variable::next, and arguments::next.

{
    struct arguments *p,
               *new = (struct arguments *) mm_alloc(sizeof(struct arguments));

    for (p = *list; p && p->next; p = p->next);

    new->variable = var;
    new->indicator = ind;
    new->next = NULL;

    if (p)
        p->next = new;
    else
        *list = new;
}

void adjust_array ( enum  ECPGttype,
char **  ,
char **  ,
char *  ,
char *  ,
int  ,
bool   
)

Definition at line 506 of file variable.c.

References ECPGt_char, ECPGt_string, ECPGt_struct, ECPGt_union, ECPGt_unsigned_char, ECPGt_varchar, ET_FATAL, mm_strdup(), mmerror(), ngettext, and PARSE_ERROR.

{
    if (atoi(type_index) >= 0)
    {
        if (atoi(*length) >= 0)
            mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");

        *length = type_index;
    }

    if (atoi(type_dimension) >= 0)
    {
        if (atoi(*dimension) >= 0 && atoi(*length) >= 0)
            mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");

        if (atoi(*dimension) >= 0)
            *length = *dimension;

        *dimension = type_dimension;
    }

    if (pointer_len > 2)
        mmerror(PARSE_ERROR, ET_FATAL, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level",
                                                "multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len),
                pointer_len);

    if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char && type_enum != ECPGt_string)
        mmerror(PARSE_ERROR, ET_FATAL, "pointer to pointer is not supported for this data type");

    if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0))
        mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");

    if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len)
        mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays are not supported");

    switch (type_enum)
    {
        case ECPGt_struct:
        case ECPGt_union:
            /* pointer has to get dimension 0 */
            if (pointer_len)
            {
                *length = *dimension;
                *dimension = mm_strdup("0");
            }

            if (atoi(*length) >= 0)
                mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays for structures are not supported");

            break;
        case ECPGt_varchar:
            /* pointer has to get dimension 0 */
            if (pointer_len)
                *dimension = mm_strdup("0");

            /* one index is the string length */
            if (atoi(*length) < 0)
            {
                *length = *dimension;
                *dimension = mm_strdup("-1");
            }

            break;
        case ECPGt_char:
        case ECPGt_unsigned_char:
        case ECPGt_string:
            /* char ** */
            if (pointer_len == 2)
            {
                *length = *dimension = mm_strdup("0");
                break;
            }

            /* pointer has to get length 0 */
            if (pointer_len == 1)
                *length = mm_strdup("0");

            /* one index is the string length */
            if (atoi(*length) < 0)
            {
                /*
                 * make sure we return length = -1 for arrays without given
                 * bounds
                 */
                if (atoi(*dimension) < 0 && !type_definition)

                    /*
                     * do not change this for typedefs since it will be
                     * changed later on when the variable is defined
                     */
                    *length = mm_strdup("1");
                else if (strcmp(*dimension, "0") == 0)
                    *length = mm_strdup("-1");
                else
                    *length = *dimension;

                *dimension = mm_strdup("-1");
            }
            break;
        default:
            /* a pointer has dimension = 0 */
            if (pointer_len)
            {
                *length = *dimension;
                *dimension = mm_strdup("0");
            }

            if (atoi(*length) >= 0)
                mmerror(PARSE_ERROR, ET_FATAL, "multidimensional arrays for simple data types are not supported");

            break;
    }
}

void base_yyerror ( const char *   ) 

Referenced by ECPGdump_a_type(), and ECPGfree_type().

int base_yylex ( void   ) 
int base_yyparse ( void   ) 
void check_indicator ( struct ECPGtype  ) 

Definition at line 461 of file variable.c.

References check_indicator(), ECPGt_array, ECPGt_int, ECPGt_long, ECPGt_long_long, ECPGt_short, ECPGt_struct, ECPGt_union, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGtype::element, ET_ERROR, ECPGtype::members, mmerror(), ECPGstruct_member::next, PARSE_ERROR, ECPGstruct_member::type, ECPGtype::type, and ECPGtype::u.

Referenced by check_indicator().

{
    /* make sure this is a valid indicator variable */
    switch (var->type)
    {
            struct ECPGstruct_member *p;

        case ECPGt_short:
        case ECPGt_int:
        case ECPGt_long:
        case ECPGt_long_long:
        case ECPGt_unsigned_short:
        case ECPGt_unsigned_int:
        case ECPGt_unsigned_long:
        case ECPGt_unsigned_long_long:
            break;

        case ECPGt_struct:
        case ECPGt_union:
            for (p = var->u.members; p; p = p->next)
                check_indicator(p->type);
            break;

        case ECPGt_array:
            check_indicator(var->u.element);
            break;
        default:
            mmerror(PARSE_ERROR, ET_ERROR, "indicator variable must have an integer type");
            break;
    }
}

struct variable* descriptor_variable ( const char *  name,
int  input 
) [read]

Definition at line 317 of file descriptor.c.

References NULL, and strlcpy().

{
    static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
    static struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL, NULL, NULL, {NULL}, 0};
    static struct variable varspace[2] = {
        {descriptor_names[0], &descriptor_type, 0, NULL},
        {descriptor_names[1], &descriptor_type, 0, NULL}
    };

    strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
    return &varspace[input];
}

void drop_descriptor ( char *  ,
char *   
)

Definition at line 99 of file descriptor.c.

References descriptor::connection, ET_WARNING, free, i, mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

{
    struct descriptor *i;
    struct descriptor **lastptr = &descriptors;

    if (name[0] != '"')
        return;

    for (i = descriptors; i; lastptr = &i->next, i = i->next)
    {
        if (strcmp(name, i->name) == 0)
        {
            if ((!connection && !i->connection)
                || (connection && i->connection
                    && strcmp(connection, i->connection) == 0))
            {
                *lastptr = i->next;
                if (i->connection)
                    free(i->connection);
                free(i->name);
                free(i);
                return;
            }
        }
    }
    mmerror(PARSE_ERROR, ET_WARNING, "descriptor \"%s\" does not exist", name);
}

void dump_variables ( struct arguments ,
int   
)

Definition at line 438 of file variable.c.

References variable::brace_level, dump_variables(), ECPGdump_a_type(), free, arguments::indicator, mm_strdup(), variable::name, arguments::next, NULL, variable::type, arguments::variable, and yyout.

Referenced by dump_variables(), and output_statement().

{
    if (list == NULL)
        return;

    /*
     * The list is build up from the beginning so lets first dump the end of
     * the list:
     */

    dump_variables(list->next, mode);

    /* Then the current element and its indicator */
    ECPGdump_a_type(yyout, list->variable->name, list->variable->type, list->variable->brace_level,
                    list->indicator->name, list->indicator->type, list->indicator->brace_level,
                    NULL, NULL, mm_strdup("0"), NULL, NULL);

    /* Then release the list element. */
    if (mode != 0)
        free(list);
}

int filtered_base_yylex ( void   ) 

Definition at line 48 of file parser.c.

References base_yylex(), have_lookahead, lookahead_token, lookahead_yylloc, lookahead_yylval, and YYLTYPE.

{
    int         cur_token;
    int         next_token;
    YYSTYPE     cur_yylval;
    YYLTYPE     cur_yylloc;

    /* Get next token --- we might already have it */
    if (have_lookahead)
    {
        cur_token = lookahead_token;
        base_yylval = lookahead_yylval;
        base_yylloc = lookahead_yylloc;
        have_lookahead = false;
    }
    else
        cur_token = base_yylex();

    /* Do we need to look ahead for a possible multiword token? */
    switch (cur_token)
    {
        case NULLS_P:

            /*
             * NULLS FIRST and NULLS LAST must be reduced to one token
             */
            cur_yylval = base_yylval;
            cur_yylloc = base_yylloc;
            next_token = base_yylex();
            switch (next_token)
            {
                case FIRST_P:
                    cur_token = NULLS_FIRST;
                    break;
                case LAST_P:
                    cur_token = NULLS_LAST;
                    break;
                default:
                    /* save the lookahead token for next time */
                    lookahead_token = next_token;
                    lookahead_yylval = base_yylval;
                    lookahead_yylloc = base_yylloc;
                    have_lookahead = true;
                    /* and back up the output info to cur_token */
                    base_yylval = cur_yylval;
                    base_yylloc = cur_yylloc;
                    break;
            }
            break;

        case WITH:

            /*
             * WITH TIME must be reduced to one token
             */
            cur_yylval = base_yylval;
            cur_yylloc = base_yylloc;
            next_token = base_yylex();
            switch (next_token)
            {
                case TIME:
                    cur_token = WITH_TIME;
                    break;
                default:
                    /* save the lookahead token for next time */
                    lookahead_token = next_token;
                    lookahead_yylval = base_yylval;
                    lookahead_yylloc = base_yylloc;
                    have_lookahead = true;
                    /* and back up the output info to cur_token */
                    base_yylval = cur_yylval;
                    base_yylloc = cur_yylloc;
                    break;
            }
            break;

        default:
            break;
    }

    return cur_token;
}

struct variable* find_variable ( char *   )  [read]

Definition at line 194 of file variable.c.

References variable::brace_level, ECPGmake_array_type(), ECPGmake_simple_type(), ECPGmake_struct_type(), ECPGt_array, ECPGt_struct, ECPGt_union, ET_FATAL, find_simple(), find_struct(), mmerror(), new_variable(), variable::next, NULL, PARSE_ERROR, and variable::type.

Referenced by ECPGdump_a_type(), ECPGnumeric_lvalue(), find_struct(), output_get_descr(), and output_set_descr().

{
    char       *next,
               *end;
    struct variable *p;
    int         count;

    next = strpbrk(name, ".[-");
    if (next)
    {
        if (*next == '[')
        {
            /*
             * We don't care about what's inside the array braces so just eat
             * up the characters
             */
            for (count = 1, end = next + 1; count; end++)
            {
                switch (*end)
                {
                    case '[':
                        count++;
                        break;
                    case ']':
                        count--;
                        break;
                    default:
                        break;
                }
            }
            if (*end == '.')
                p = find_struct(name, next, end);
            else
            {
                char        c = *next;

                *next = '\0';
                p = find_simple(name);
                if (p == NULL)
                    mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not declared", name);

                *next = c;
                switch (p->type->u.element->type)
                {
                    case ECPGt_array:
                        return (new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(p->type->u.element->u.element->type, p->type->u.element->u.element->size, p->type->u.element->u.element->counter), p->type->u.element->size), p->brace_level));
                    case ECPGt_struct:
                    case ECPGt_union:
                        return (new_variable(name, ECPGmake_struct_type(p->type->u.element->u.members, p->type->u.element->type, p->type->u.element->type_name, p->type->u.element->struct_sizeof), p->brace_level));
                    default:
                        return (new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size, p->type->u.element->counter), p->brace_level));
                }
            }
        }
        else
            p = find_struct(name, next, next);
    }
    else
        p = find_simple(name);

    if (p == NULL)
        mmerror(PARSE_ERROR, ET_FATAL, "variable \"%s\" is not declared", name);

    return (p);
}

const char* get_dtype ( enum  ECPGdtype  ) 

Definition at line 601 of file type.c.

References ECPGd_cardinality, ECPGd_count, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ET_ERROR, mmerror(), and PARSE_ERROR.

Referenced by output_get_descr(), and output_set_descr().

{
    switch (type)
    {
        case ECPGd_count:
            return ("ECPGd_countr");
            break;
        case ECPGd_data:
            return ("ECPGd_data");
            break;
        case ECPGd_di_code:
            return ("ECPGd_di_code");
            break;
        case ECPGd_di_precision:
            return ("ECPGd_di_precision");
            break;
        case ECPGd_indicator:
            return ("ECPGd_indicator");
            break;
        case ECPGd_key_member:
            return ("ECPGd_key_member");
            break;
        case ECPGd_length:
            return ("ECPGd_length");
            break;
        case ECPGd_name:
            return ("ECPGd_name");
            break;
        case ECPGd_nullable:
            return ("ECPGd_nullable");
            break;
        case ECPGd_octet:
            return ("ECPGd_octet");
            break;
        case ECPGd_precision:
            return ("ECPGd_precision");
            break;
        case ECPGd_ret_length:
            return ("ECPGd_ret_length");
        case ECPGd_ret_octet:
            return ("ECPGd_ret_octet");
            break;
        case ECPGd_scale:
            return ("ECPGd_scale");
            break;
        case ECPGd_type:
            return ("ECPGd_type");
            break;
        case ECPGd_cardinality:
            return ("ECPGd_cardinality");
        default:
            mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
    }

    return NULL;
}

struct typedefs* get_typedef ( char *   )  [read]

Definition at line 494 of file variable.c.

References ET_FATAL, mmerror(), typedefs::next, PARSE_ERROR, and types.

{
    struct typedefs *this;

    for (this = types; this && strcmp(this->name, name) != 0; this = this->next);
    if (!this)
        mmerror(PARSE_ERROR, ET_FATAL, "unrecognized data type name \"%s\"", name);

    return (this);
}

char* hashline_number ( void   ) 

Definition at line 89 of file output.c.

References input_filename, mm_alloc(), and yylineno.

Referenced by output_line_number().

{
    /* do not print line numbers if we are in debug mode */
    if (input_filename
#ifdef YYDEBUG
        && !yydebug
#endif
        )
    {
        char       *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename));

        sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);

        return line;
    }

    return EMPTY;
}

void lex_init ( void   ) 

Referenced by main().

struct descriptor* lookup_descriptor ( char *  ,
char *   
) [read]

Definition at line 129 of file descriptor.c.

References descriptor::connection, ET_WARNING, i, mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

{
    struct descriptor *i;

    if (name[0] != '"')
        return NULL;

    for (i = descriptors; i; i = i->next)
    {
        if (strcmp(name, i->name) == 0)
        {
            if ((!connection && !i->connection)
                || (connection && i->connection
                    && strcmp(connection, i->connection) == 0))
                return i;
        }
    }
    mmerror(PARSE_ERROR, ET_WARNING, "descriptor \"%s\" does not exist", name);
    return NULL;
}

void* mm_alloc ( size_t   ) 
void* * mm_realloc ( void *  ,
size_t   
)
char* mm_strdup ( const char *   ) 

Definition at line 25 of file type.c.

References ET_FATAL, mmerror(), NULL, and OUT_OF_MEMORY.

Referenced by add_preprocessor_define(), adjust_array(), dump_variables(), ECPGdump_a_type(), ECPGmake_struct_member(), ECPGmake_struct_type(), new_variable(), output_get_descr(), output_set_descr(), and sqlda_variable().

{
    char       *new = strdup(string);

    if (new == NULL)
        mmerror(OUT_OF_MEMORY, ET_FATAL, "out of memory");

    return new;
}

void mmerror ( int  ,
enum  errortype,
const char *  ,
  ... 
)
struct variable* new_variable ( const char *  ,
struct ECPGtype ,
int   
) [read]

Definition at line 10 of file variable.c.

References variable::brace_level, mm_alloc(), mm_strdup(), variable::name, variable::next, and variable::type.

Referenced by find_struct_member(), and find_variable().

{
    struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));

    p->name = mm_strdup(name);
    p->type = type;
    p->brace_level = brace_level;

    p->next = allvariables;
    allvariables = p;

    return (p);
}

void output_deallocate_prepare_statement ( char *   ) 

Definition at line 162 of file output.c.

References compat, free, NULL, output_escaped_str(), whenever_action(), and yyout.

{
    const char *con = connection ? connection : "NULL";

    if (strcmp(name, "all") != 0)
    {
        fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con);
        output_escaped_str(name, true);
        fputs(");", yyout);
    }
    else
        fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);

    whenever_action(2);
    free(name);
    if (connection != NULL)
        free(connection);
}

void output_get_descr ( char *  ,
char *   
)

Definition at line 170 of file descriptor.c.

References variable::brace_level, drop_assignments(), ECPGd_key_member, ECPGd_nullable, ECPGdump_a_type(), ET_WARNING, find_variable(), get_dtype(), mm_strdup(), mmerror(), variable::name, assignment::next, NULL, PARSE_ERROR, variable::type, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGget_desc(__LINE__, %s, %s,", desc_name, index);
    for (results = assignments; results != NULL; results = results->next)
    {
        const struct variable *v = find_variable(results->variable);

        switch (results->value)
        {
            case ECPGd_nullable:
                mmerror(PARSE_ERROR, ET_WARNING, "nullable is always 1");
                break;
            case ECPGd_key_member:
                mmerror(PARSE_ERROR, ET_WARNING, "key_member is always 0");
                break;
            default:
                break;
        }
        fprintf(yyout, "%s,", get_dtype(results->value));
        ECPGdump_a_type(yyout, v->name, v->type, v->brace_level, NULL, NULL, -1, NULL, NULL, mm_strdup("0"), NULL, NULL);
    }
    drop_assignments();
    fputs("ECPGd_EODT);\n", yyout);

    whenever_action(2 | 1);
}

void void output_get_descr_header ( char *   ) 

Definition at line 151 of file descriptor.c.

References drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGget_desc_header(__LINE__, %s, &(", desc_name);
    for (results = assignments; results != NULL; results = results->next)
    {
        if (results->value == ECPGd_count)
            ECPGnumeric_lvalue(results->variable);
        else
            mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
    }

    drop_assignments();
    fprintf(yyout, "));\n");
    whenever_action(3);
}

void output_line_number ( void   ) 

Definition at line 10 of file output.c.

References free, hashline_number(), and yyout.

Referenced by main(), output_simple_statement(), and whenever_action().

{
    char       *line = hashline_number();

    fprintf(yyout, "%s", line);
    free(line);
}

void output_prepare_statement ( char *  ,
char *   
)

Definition at line 148 of file output.c.

References free, NULL, output_escaped_str(), questionmarks, whenever_action(), and yyout.

{
    fprintf(yyout, "{ ECPGprepare(__LINE__, %s, %d, ", connection ? connection : "NULL", questionmarks);
    output_escaped_str(name, true);
    fputs(", ", yyout);
    output_escaped_str(stmt, true);
    fputs(");", yyout);
    whenever_action(2);
    free(name);
    if (connection != NULL)
        free(connection);
}

void output_set_descr ( char *  ,
char *   
)

Definition at line 261 of file descriptor.c.

References variable::brace_level, descriptor_item_name(), drop_assignments(), ECPGd_cardinality, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGdump_a_type(), ET_FATAL, find_variable(), get_dtype(), mm_strdup(), mmerror(), variable::name, assignment::next, NULL, PARSE_ERROR, variable::type, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGset_desc(__LINE__, %s, %s,", desc_name, index);
    for (results = assignments; results != NULL; results = results->next)
    {
        const struct variable *v = find_variable(results->variable);

        switch (results->value)
        {
            case ECPGd_cardinality:
            case ECPGd_di_code:
            case ECPGd_di_precision:
            case ECPGd_precision:
            case ECPGd_scale:
                mmerror(PARSE_ERROR, ET_FATAL, "descriptor item \"%s\" is not implemented",
                        descriptor_item_name(results->value));
                break;

            case ECPGd_key_member:
            case ECPGd_name:
            case ECPGd_nullable:
            case ECPGd_octet:
            case ECPGd_ret_length:
            case ECPGd_ret_octet:
                mmerror(PARSE_ERROR, ET_FATAL, "descriptor item \"%s\" cannot be set",
                        descriptor_item_name(results->value));
                break;

            case ECPGd_data:
            case ECPGd_indicator:
            case ECPGd_length:
            case ECPGd_type:
                fprintf(yyout, "%s,", get_dtype(results->value));
                ECPGdump_a_type(yyout, v->name, v->type, v->brace_level, NULL, NULL, -1, NULL, NULL, mm_strdup("0"), NULL, NULL);
                break;

            default:
                ;
        }
    }
    drop_assignments();
    fputs("ECPGd_EODT);\n", yyout);

    whenever_action(2 | 1);
}

void output_set_descr_header ( char *   ) 

Definition at line 200 of file descriptor.c.

References drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGset_desc_header(__LINE__, %s, (int)(", desc_name);
    for (results = assignments; results != NULL; results = results->next)
    {
        if (results->value == ECPGd_count)
            ECPGnumeric_lvalue(results->variable);
        else
            mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
    }

    drop_assignments();
    fprintf(yyout, "));\n");
    whenever_action(3);
}

void output_simple_statement ( char *   ) 

Definition at line 19 of file output.c.

References free, output_escaped_str(), and output_line_number().

{
    output_escaped_str(stmt, false);
    output_line_number();
    free(stmt);
}

void output_statement ( char *  ,
int  ,
enum  ECPG_statement_type 
)

Definition at line 116 of file output.c.

References argsinsert, argsresult, auto_prepare, compat, dump_variables(), ecpg_statement_type_name, ECPGst_exec_immediate, ECPGst_execute, ECPGst_prepnormal, force_indicator, free, NULL, output_escaped_str(), questionmarks, reset_variables(), whenever_action(), and yyout.

{
    fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
    if (st == ECPGst_execute || st == ECPGst_exec_immediate)
    {
        fprintf(yyout, "%s, %s, ", ecpg_statement_type_name[st], stmt);
    }
    else
    {
        if (st == ECPGst_prepnormal && auto_prepare)
            fputs("ECPGst_prepnormal, \"", yyout);
        else
            fputs("ECPGst_normal, \"", yyout);

        output_escaped_str(stmt, false);
        fputs("\", ", yyout);
    }

    /* dump variables to C file */
    dump_variables(argsinsert, 1);
    fputs("ECPGt_EOIT, ", yyout);
    dump_variables(argsresult, 1);
    fputs("ECPGt_EORT);", yyout);
    reset_variables();

    whenever_action(whenever_mode | 2);
    free(stmt);
    if (connection != NULL)
        free(connection);
}

void parser_init ( void   ) 
void push_assignment ( char *  ,
enum  ECPGdtype 
)

Definition at line 21 of file descriptor.c.

References mm_alloc(), and assignment::variable.

{
    struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));

    new->next = assignments;
    new->variable = mm_alloc(strlen(var) + 1);
    strcpy(new->variable, var);
    new->value = value;
    assignments = new;
}

void remove_typedefs ( int   ) 

Definition at line 261 of file variable.c.

References typedefs::brace_level, ECPGt_struct, ECPGt_union, free, typedefs::name, typedefs::next, typedefs::struct_member_list, typedefs::type, this_type::type_enum, and types.

{
    struct typedefs *p,
               *prev;

    for (p = prev = types; p;)
    {
        if (p->brace_level >= brace_level)
        {
            /* remove it */
            if (p == types)
                prev = types = p->next;
            else
                prev->next = p->next;

            if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union)
                free(p->struct_member_list);
            free(p->type);
            free(p->name);
            free(p);
            if (prev == types)
                p = types;
            else
                p = prev ? prev->next : NULL;
        }
        else
        {
            prev = p;
            p = prev->next;
        }
    }
}

void remove_variable_from_list ( struct arguments **  list,
struct variable var 
)

Definition at line 409 of file variable.c.

References arguments::next, and arguments::variable.

{
    struct arguments *p,
               *prev = NULL;
    bool        found = false;

    for (p = *list; p; p = p->next)
    {
        if (p->variable == var)
        {
            found = true;
            break;
        }
        prev = p;
    }
    if (found)
    {
        if (prev)
            prev->next = p->next;
        else
            *list = p->next;
    }
}

void remove_variables ( int   ) 

Definition at line 295 of file variable.c.

References cursor::argsinsert, cursor::argsresult, variable::brace_level, cur, ECPGfree_type(), free, variable::name, variable::next, arguments::next, cursor::next, NULL, variable::type, and arguments::variable.

{
    struct variable *p,
               *prev;

    for (p = prev = allvariables; p;)
    {
        if (p->brace_level >= brace_level)
        {
            /* is it still referenced by a cursor? */
            struct cursor *ptr;

            for (ptr = cur; ptr != NULL; ptr = ptr->next)
            {
                struct arguments *varptr,
                           *prevvar;

                for (varptr = prevvar = ptr->argsinsert; varptr != NULL; varptr = varptr->next)
                {
                    if (p == varptr->variable)
                    {
                        /* remove from list */
                        if (varptr == ptr->argsinsert)
                            ptr->argsinsert = varptr->next;
                        else
                            prevvar->next = varptr->next;
                    }
                }
                for (varptr = prevvar = ptr->argsresult; varptr != NULL; varptr = varptr->next)
                {
                    if (p == varptr->variable)
                    {
                        /* remove from list */
                        if (varptr == ptr->argsresult)
                            ptr->argsresult = varptr->next;
                        else
                            prevvar->next = varptr->next;
                    }
                }
            }

            /* remove it */
            if (p == allvariables)
                prev = allvariables = p->next;
            else
                prev->next = p->next;

            ECPGfree_type(p->type);
            free(p->name);
            free(p);
            if (prev == allvariables)
                p = allvariables;
            else
                p = prev ? prev->next : NULL;
        }
        else
        {
            prev = p;
            p = prev->next;
        }
    }
}

void reset_variables ( void   ) 

Definition at line 369 of file variable.c.

Referenced by output_statement().

{
    argsinsert = NULL;
    argsresult = NULL;
}

const ScanKeyword* ScanCKeywordLookup ( const char *   ) 

Definition at line 64 of file c_keywords.c.

References lengthof, and ScanKeyword::name.

{
    const ScanKeyword *low = &ScanCKeywords[0];
    const ScanKeyword *high = &ScanCKeywords[lengthof(ScanCKeywords) - 1];

    while (low <= high)
    {
        const ScanKeyword *middle;
        int         difference;

        middle = low + (high - low) / 2;
        difference = strcmp(middle->name, text);
        if (difference == 0)
            return middle;
        else if (difference < 0)
            low = middle + 1;
        else
            high = middle - 1;
    }

    return NULL;
}

const ScanKeyword* ScanECPGKeywordLookup ( const char *  text  ) 

Definition at line 89 of file ecpg_keywords.c.

References lengthof, NumSQLScanKeywords, and ScanKeywordLookup().

{
    const ScanKeyword *res;

    /* First check SQL symbols defined by the backend. */
    res = ScanKeywordLookup(text, SQLScanKeywords, NumSQLScanKeywords);
    if (res)
        return res;

    /* Try ECPG-specific keywords. */
    res = ScanKeywordLookup(text, ECPGScanKeywords, lengthof(ECPGScanKeywords));
    if (res)
        return res;

    return NULL;
}

void scanner_finish ( void   ) 
void scanner_init ( const char *   ) 
struct variable* sqlda_variable ( const char *  name  )  [read]

Definition at line 331 of file descriptor.c.

References variable::brace_level, mm_alloc(), mm_strdup(), variable::name, variable::next, and variable::type.

{
    struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));

    p->name = mm_strdup(name);
    p->type = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
    p->type->type = ECPGt_sqlda;
    p->type->size = NULL;
    p->type->struct_sizeof = NULL;
    p->type->u.element = NULL;
    p->type->counter = 0;
    p->brace_level = 0;
    p->next = NULL;

    return p;
}

void whenever_action ( int   ) 

Definition at line 61 of file output.c.

References when::code, output_line_number(), print_action(), W_NOTHING, when_warn, and yyout.

Referenced by output_deallocate_prepare_statement(), output_get_descr(), output_get_descr_header(), output_prepare_statement(), output_set_descr(), output_set_descr_header(), and output_statement().

{
    if ((mode & 1) == 1 && when_nf.code != W_NOTHING)
    {
        output_line_number();
        fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
        print_action(&when_nf);
    }
    if (when_warn.code != W_NOTHING)
    {
        output_line_number();
        fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
        print_action(&when_warn);
    }
    if (when_error.code != W_NOTHING)
    {
        output_line_number();
        fprintf(yyout, "\nif (sqlca.sqlcode < 0) ");
        print_action(&when_error);
    }

    if ((mode & 2) == 2)
        fputc('}', yyout);

    output_line_number();
}


Variable Documentation

Definition at line 365 of file variable.c.

Referenced by output_statement().

Definition at line 366 of file variable.c.

Referenced by output_statement().

Definition at line 16 of file ecpg.c.

Referenced by main().

Definition at line 21 of file ecpg.c.

Referenced by main(), and output_statement().

Definition at line 15 of file ecpg.c.

Referenced by main().

Definition at line 25 of file ecpg.c.

Referenced by ECPGconnect(), main(), output_deallocate_prepare_statement(), and output_statement().

char* connection
struct cursor* cur
struct _defines* defines

Definition at line 30 of file ecpg.c.

Referenced by main().

Referenced by ECPGdump_a_struct().

Definition at line 18 of file ecpg.c.

Referenced by main(), and output_statement().

Definition at line 27 of file ecpg.c.

Referenced by hashline_number(), and main().

Definition at line 23 of file ecpg.c.

Referenced by main().

Definition at line 19 of file ecpg.c.

Referenced by main(), output_prepare_statement(), and output_statement().

Definition at line 20 of file ecpg.c.

Referenced by main().

int ret_value

Definition at line 14 of file ecpg.c.

Referenced by main(), and pltcl_trigger_handler().

struct ECPGstruct_member* struct_member_list[STRUCT_DEPTH]

Definition at line 17 of file ecpg.c.

Referenced by main().

char * token_start
struct typedefs* types

Definition at line 29 of file ecpg.c.

Referenced by get_typedef(), PLy_procedure_create(), remove_typedefs(), and writezone().

struct when when_error when_nf when_warn

Definition at line 30 of file output.c.

Referenced by main(), and whenever_action().

FILE* yyin

Referenced by main().

int yylineno

Referenced by hashline_number().

FILE * yyout
char* yytext

Referenced by __attribute__(), and internal_yylex().