<?xml version="1.0"?>
<parser ns="#GRACE_NS_URI">
    <!-- Preamble -->
    <preamble><![CDATA[
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "defines.h"
#include "files.h"
#include "utils.h"
#include "dicts.h"
#include "core_utils.h"
#include "protos.h"

#include "xstrings.h"

typedef struct {
    RunTime *rt;
    int nrow;
} ParserData;

typedef struct _Page {
    int width;
    int height;
    int bgfill;
    int bgcolor;
} Page;

Page *page_new(void)
{
    Page *retval;
    
    retval = xmalloc(sizeof(Page));
    if (retval) {
        memset(retval, 0, sizeof(Page));
        retval->bgfill = TRUE;
    }
    
    return retval;
}

Colordef *colordef_new(void)
{
    Colordef *retval;
    retval = xmalloc(sizeof(Colordef));
    retval->id = -1;
    retval->cname = NULL;
    return retval;
}

void colordef_free(Colordef *cd)
{
    if (cd) {
        xfree(cd->cname);
        xfree(cd);
    }
}

Fontdef *fontdef_new()
{
    Fontdef *retval;
    retval = xmalloc(sizeof(Fontdef));
    retval->id = -1;
    retval->fontname = NULL;
    retval->fallback = NULL;
    return retval;
}

void fontdef_free(Fontdef *fd)
{
    if (fd) {
        xfree(fd->fontname);
        xfree(fd->fallback);
        xfree(fd);
    }
}

typedef struct {
    int font;
    int color;
    double size;
} FaceSpec;

FaceSpec *facespec_new()
{
    FaceSpec *fs;
    fs = xmalloc(sizeof(FaceSpec));
    if (fs) {
        memset(fs, 0, sizeof(FaceSpec));
    }
    return fs;
}

void facespec_free(FaceSpec *fs)
{
    if (fs) {
        xfree(fs);
    }
}

typedef struct {
    GraphType type;
    int stacked;
    double bargap;
} PresentationSpec;


PresentationSpec *presentationspec_new()
{
    PresentationSpec *ps;
    ps = xmalloc(sizeof(PresentationSpec));
    if (ps) {
        memset(ps, 0, sizeof(PresentationSpec));
    }
    return ps;
}

void presentationspec_free(PresentationSpec *ps)
{
    if (ps) {
        xfree(ps);
    }
}

view *view_new()
{
    view *v;
    v = xmalloc(sizeof(view));
    if (v) {
        memset(v, 0, sizeof(view));
    }
    return v;
}

typedef struct {
    int type;
    double min;
    double max;
    int invert;
} Scale;

Scale *scale_new()
{
    Scale *s;
    s = xmalloc(sizeof(Scale));
    if (s) {
        memset(s, 0, sizeof(Scale));
    }
    return s;
}

typedef struct {
    int type;
    APoint ap;
} Location;

Location *location_new()
{
    Location *retval;
    retval = xmalloc(sizeof(Location));
    if (retval) {
        memset(retval, 0, sizeof(Location));
    }
    return retval;
}

typedef struct {
    FPoint anchor;
    int just;
    VPoint offset;
    Line line;
    Pen fillpen;
} Legframe;

legend *legend_new()
{
    legend *l;
    l = xmalloc(sizeof(legend));
    if (l) {
        memset(l, 0, sizeof(legend));
    }
    return l;
}

Legframe *legframe_new()
{
    Legframe *lf;
    lf = xmalloc(sizeof(Legframe));
    if (lf) {
        memset(lf, 0, sizeof(Legframe));
    }
    return lf;
}

typedef struct {
    int active;
    double x;
    double y;
} Fixedpoint;

Fixedpoint *fixedpoint_new()
{
    Fixedpoint *fp;
    fp = xmalloc(sizeof(Fixedpoint));
    if (fp) {
        memset(fp, 0, sizeof(Fixedpoint));
    }
    return fp;
}

GLocator *glocator_new()
{
    GLocator *retval;
    retval = xmalloc(sizeof(GLocator));
    if (retval) {
        memset(retval, 0, sizeof(GLocator));
    }
    return retval;
}

typedef struct {
    int type;
    int prec;
} Format;

Format *format_new()
{
    Format *retval;
    retval = xmalloc(sizeof(Format));
    if (retval) {
        memset(retval, 0, sizeof(Format));
    }
    return retval;
}

typedef struct {
    int zero;
    VPoint offset;
} APlacement;

APlacement *axisplacement_new()
{
    APlacement *retval;
    retval = xmalloc(sizeof(APlacement));
    if (retval) {
        memset(retval, 0, sizeof(APlacement));
    }
    return retval;
}

typedef struct {
    int active;
    Line line;
} ABar;

ABar *axisbar_new()
{
    ABar *retval;
    retval = xmalloc(sizeof(ABar));
    if (retval) {
        memset(retval, 0, sizeof(ABar));
    }
    return retval;
}

typedef struct {
    char *s;
    
    TextProps tprops;
    
    int layout;
    int sideplacement;
    int autoplace;
    VPoint offset;
} ALabel;

ALabel *axislabel_new()
{
    ALabel *retval;
    retval = xmalloc(sizeof(ALabel));
    if (retval) {
        memset(retval, 0, sizeof(ALabel));
    }
    return retval;
}

typedef struct {
    int active;
    int sideplacement;
    tickprops props;
    tickprops mprops;
} TMarks;

TMarks *tmarks_new()
{
    TMarks *retval;
    retval = xmalloc(sizeof(TMarks));
    if (retval) {
        memset(retval, 0, sizeof(TMarks));
    }
    return retval;
}

typedef struct {
    int active;
    int sideplacement;
    char *transform;
    char *prepend;
    char *append;
    int autoplace;
    VPoint offset;
    
    TextProps tprops;
    
    int skip;
    int stagger;
    int autostart;
    double start;
    int autostop;
    double stop;
    Format format;
} TLabels;

TLabels *tlabels_new()
{
    TLabels *retval;
    retval = xmalloc(sizeof(TLabels));
    if (retval) {
        memset(retval, 0, sizeof(TLabels));
    }
    return retval;
}

typedef struct {
    int type;                   /* type of user ticks */
    int nticks;                 /* total number of ticks */
    tickloc tloc[MAX_TICKS];    /* locations of ticks */
} UTicks;

UTicks *uticks_new()
{
    UTicks *retval;
    retval = xmalloc(sizeof(UTicks));
    if (retval) {
        memset(retval, 0, sizeof(UTicks));
    }
    return retval;
}

tickloc *tick_new()
{
    tickloc *retval;
    retval = xmalloc(sizeof(tickloc));
    if (retval) {
        memset(retval, 0, sizeof(tickloc));
    }
    return retval;
}

int utick_add(UTicks *uticks, tickloc *tick)
{
    if (uticks && uticks->nticks < MAX_TICKS) {
        uticks->tloc[uticks->nticks++] = *tick;
        return RETURN_SUCCESS;
    } else {
        return RETURN_FAILURE;
    }
}


typedef struct {
    double major;
    int nminor;
    int autonum;
    int round;
    UTicks uticks;
    TMarks tmarks;
    TLabels tlabels;
} Ticks;

Ticks *ticks_new()
{
    Ticks *retval;
    retval = xmalloc(sizeof(Ticks));
    if (retval) {
        memset(retval, 0, sizeof(Ticks));
    }
    return retval;
}

tickprops *tickprops_new()
{
    tickprops *retval;
    retval = xmalloc(sizeof(tickprops));
    if (retval) {
        memset(retval, 0, sizeof(tickprops));
    }
    return retval;
}

typedef struct {
    int autov;
    double value;
} Autoval;

Arrow *arrow_new(void)
{
    Arrow *retval;
    retval = xmalloc(sizeof(Arrow));
    if (retval) {
        memset(retval, 0, sizeof(Arrow));
    }
    return retval;
}

typedef struct {
    int decor;
    double offset;
    Line line;
    Pen fillpen;
} TextFrame;

TextFrame *textframe_new(void)
{
    TextFrame *retval;
    retval = xmalloc(sizeof(TextFrame));
    if (retval) {
        memset(retval, 0, sizeof(TextFrame));
    }
    return retval;
}

typedef struct {
    int active;
    Arrow arrow;
} TextPointer;

TextPointer *textpointer_new(void)
{
    TextPointer *retval;
    retval = xmalloc(sizeof(TextPointer));
    if (retval) {
        memset(retval, 0, sizeof(TextPointer));
    }
    return retval;
}

AValue *avalue_new(void)
{
    AValue *retval;
    retval = xmalloc(sizeof(AValue));
    if (retval) {
        memset(retval, 0, sizeof(AValue));
    }
    return retval;
}

void avalue_free(AValue *av)
{
    if (av) {
        xfree(av->prestr);
        xfree(av->appstr);
        xfree(av);
    }
}

char *utf2iso(const char *s)
{
    char *retval;
    char *p1, *p2;
    
    if (!s) {
        return NULL;
    }
    
    retval = xmalloc(strlen(s) + 1);
    if (!retval) {
        return NULL;
    }
    
    p1 = (char *) s;
    p2 = retval;
    
    while (*p1) {
        if (*p1 & 0x80) {
            /* last 2 bits */
            *p2 = (*p1 & 0x03) << 6; p1++;
            /* last 6 bits of the next byte */
            *p2 += *p1 & 0x3F;
        } else {
            *p2 = *p1;
        }
        p1++; p2++;
    }
    
    *(p2) = '\0';
    
    return retval;
}

    ]]></preamble>

    <!-- Attribute types -->
    <attribute-type name="ival" ctype="int"><![CDATA[
        $$ = atoi($?);
    ]]></attribute-type>
    <attribute-type name="dval" ctype="double"><![CDATA[
        $$ = atof($?);
    ]]></attribute-type>
    <attribute-type name="sval" ctype="char *"><![CDATA[
        $$ = utf2iso($?);
    ]]></attribute-type>
    <attribute-type name="bval" ctype="int"><![CDATA[
        $$ = compare_strings($?, "yes");
    ]]></attribute-type>
    <attribute-type name="rgb" ctype="RGB *"><![CDATA[
        unsigned int r, g, b;
        $$ = xmalloc(sizeof(RGB));
        sscanf($?, "#%02x%02x%02x", &r, &g, &b);
        $$->red = r; $$->green = g; $$->blue = b;
    ]]></attribute-type>
    <attribute-type name="ftype" ctype="int"><![CDATA[
        $$ = get_format_type_by_name($?);
    ]]></attribute-type>
    <attribute-type name="fontid" ctype="int"><![CDATA[
        $$ = atoi($?);
    ]]></attribute-type>
    <attribute-type name="offset" ctype="VPoint *"><![CDATA[
        if (!strcmp($?, VStrAuto)) {
            $$ = NULL;
        } else {
            $$ = xmalloc(sizeof(VPoint));
            sscanf($?, "(%lg, %lg)", &($$->x), &($$->y));
        }
    ]]></attribute-type>
    <attribute-type name="fpoint" ctype="FPoint *"><![CDATA[
        $$ = xmalloc(sizeof(FPoint));
        sscanf($?, "(%lg, %lg)", &($$->x), &($$->y));
    ]]></attribute-type>
    <attribute-type name="axislayout" ctype="int"><![CDATA[
        if (!strcmp($?, VStrParallel)) {
            $$ = LAYOUT_PARALLEL;
        } else {
            $$ = LAYOUT_PERPENDICULAR;
        }
    ]]></attribute-type>
    <attribute-type name="sideplacement" ctype="int"><![CDATA[
        if (!strcmp($?, VStrNormal)) {
            $$ = PLACEMENT_NORMAL;
        } else
        if (!strcmp($?, VStrOpposite)) {
            $$ = PLACEMENT_OPPOSITE;
        } else
        if (!strcmp($?, VStrBoth)) {
            $$ = PLACEMENT_BOTH;
        } else {
            $$ = PLACEMENT_NORMAL;
            errmsg("Wrong sideplacement");
        }
    ]]></attribute-type>
    <attribute-type name="inoutplacement" ctype="int"><![CDATA[
        if (!strcmp($?, VStrIn)) {
            $$ = TICKS_IN;
        } else
        if (!strcmp($?, VStrOut)) {
            $$ = TICKS_OUT;
        } else
        if (!strcmp($?, VStrBoth)) {
            $$ = TICKS_BOTH;
        } else {
            $$ = TICKS_IN;
            errmsg("Wrong inoutplacement");
        }
    ]]></attribute-type>
    <attribute-type name="uticktype" ctype="int"><![CDATA[
        if (!strcmp($?, VStrNone)) {
            $$ = TICKS_SPEC_NONE;
        } else
        if (!strcmp($?, VStrTicks)) {
            $$ = TICKS_SPEC_MARKS;
        } else
        if (!strcmp($?, VStrBoth)) {
            $$ = TICKS_SPEC_BOTH;
        } else {
            $$ = TICKS_SPEC_BOTH;
            errmsg("Wrong uticktype");
        }
    ]]></attribute-type>
    <attribute-type name="ticktype" ctype="int"><![CDATA[
        if (!strcmp($?, VStrMajor)) {
            $$ = TICK_TYPE_MAJOR;
        } else
        if (!strcmp($?, VStrMinor)) {
            $$ = TICK_TYPE_MINOR;
        } else {
            $$ = TICK_TYPE_MINOR;
            errmsg("Wrong ticktype");
        }
    ]]></attribute-type>
    <attribute-type name="autoval" ctype="Autoval *"><![CDATA[
        $$ = xmalloc(sizeof(Autoval));
        if (!strcmp($?, VStrAuto)) {
            $$->autov = TRUE;
            $$->value = 0.0;
        } else {
            $$->autov = FALSE;
            $$->value = atof($?);
        }
    ]]></attribute-type>
    <attribute-type name="loctype" ctype="int"><![CDATA[
        if (!strcmp($?, VStrWorld)) {
            $$ = COORD_WORLD;
        } else {
            $$ = COORD_VIEW;
        }
    ]]></attribute-type>
    <attribute-type name="settype" ctype="SetType"><![CDATA[
        RunTime *rt = ((ParserData *)$U)->rt;
        $$ = get_settype_by_name(rt, $?);
    ]]></attribute-type>
    <attribute-type name="fillrule" ctype="int"><![CDATA[
        if (!strcmp($?, VStrWinding)) {
            $$ = FILLRULE_WINDING;
        } else {
            $$ = FILLRULE_EVENODD;
        }
    ]]></attribute-type>
    <attribute-type name="regiontype" ctype="int"><![CDATA[
        RunTime *rt = ((ParserData *)$U)->rt;
        $$ = get_regiontype_by_name(rt, $?);
    ]]></attribute-type>
    <attribute-type name="dateordval" ctype="double"><![CDATA[
        if (parse_date_or_number($0, $?, FALSE, &$$) != RETURN_SUCCESS) {
                $$ = 0.0;
        }
    ]]></attribute-type>
    <attribute-type name="autodateordval" ctype="Autoval *"><![CDATA[
        $$ = xmalloc(sizeof(Autoval));
        if (!strcmp($?, VStrAuto)) {
            $$->autov = TRUE;
            $$->value = 0.0;
        } else {
            $$->autov = FALSE;
            if (parse_date_or_number($0, $?, FALSE, &$$->value) != RETURN_SUCCESS) {
                    $$->value = 0.0;
            }
        }
    ]]></attribute-type>
    
    <!-- Element types -->
    <element-type name="project" ctype="Quark *"><![CDATA[
        $$ = project_new(((ParserData *) $U)->rt->qfactory);
    ]]></element-type>
    <element-type name="page" ctype="Page *"><![CDATA[
        $$ = page_new();
    ]]></element-type>
    <element-type name="string" ctype="XCCString *"><![CDATA[
        $$ = xcc_string_new();
    ]]></element-type>
    <element-type name="pen" ctype="Pen *"><![CDATA[
        $$ = xmalloc(sizeof(Pen));
        $$->color = $$->pattern = 1;
    ]]></element-type>
    <element-type name="line" ctype="Line *"><![CDATA[
        $$ = xmalloc(sizeof(Line));
        $$->pen.color = $$->pen.pattern = 1;
        $$->width = 1.0;
        $$->style = 1;
    ]]></element-type>
    <element-type name="dummy" ctype="void *"><![CDATA[
        $$ = NULL;
    ]]></element-type>
    <element-type name="colordef" ctype="Colordef *"><![CDATA[
        $$ = colordef_new();
    ]]></element-type>
    <element-type name="fontdef" ctype="Fontdef *"><![CDATA[
        $$ = fontdef_new();
    ]]></element-type>
    <element-type name="facespec" ctype="FaceSpec *"><![CDATA[
        $$ = facespec_new();
    ]]></element-type>
    <element-type name="graph" ctype="Quark *"><![CDATA[
        $$ = graph_new((Quark *)$P);
    ]]></element-type>
    <element-type name="presentationspec" ctype="PresentationSpec *"><![CDATA[
        $$ = presentationspec_new();
    ]]></element-type>
    <element-type name="view" ctype="view *"><![CDATA[
        $$ = view_new();
    ]]></element-type>
    <element-type name="scale" ctype="Scale *"><![CDATA[
        $$ = scale_new();
    ]]></element-type>
    <element-type name="dptr" ctype="double *"><![CDATA[
        $$ = xcalloc(1, SIZEOF_DOUBLE);
    ]]></element-type>
    <element-type name="legend" ctype="legend *"><![CDATA[
        $$ = legend_new();
    ]]></element-type>
    <element-type name="legframe" ctype="Legframe *"><![CDATA[
        $$ = legframe_new();
    ]]></element-type>
    <element-type name="glocator" ctype="GLocator *"><![CDATA[
        $$ = glocator_new();
    ]]></element-type>
    <element-type name="fixedpoint" ctype="Fixedpoint *"><![CDATA[
        $$ = fixedpoint_new();
    ]]></element-type>
    <element-type name="format" ctype="Format *"><![CDATA[
        $$ = format_new();
    ]]></element-type>
    <element-type name="frame" ctype="Quark *"><![CDATA[
        $$ = frame_new((Quark *)$P);
    ]]></element-type>
    <element-type name="textprops" ctype="TextProps *"><![CDATA[
        $$ = textprops_new();
    ]]></element-type>
    <element-type name="axis" ctype="Quark *"><![CDATA[
        $$ = axis_new((Quark *)$P);
    ]]></element-type>
    <element-type name="axisplacement" ctype="APlacement *"><![CDATA[
        $$ = axisplacement_new();
    ]]></element-type>
    <element-type name="axisbar" ctype="ABar *"><![CDATA[
        $$ = axisbar_new();
    ]]></element-type>
    <element-type name="axislabel" ctype="ALabel *"><![CDATA[
        $$ = axislabel_new();
    ]]></element-type>
    <element-type name="ticks" ctype="Ticks *"><![CDATA[
        $$ = ticks_new();
    ]]></element-type>
    <element-type name="tmarks" ctype="TMarks *"><![CDATA[
        $$ = tmarks_new();
    ]]></element-type>
    <element-type name="tickprops" ctype="tickprops *"><![CDATA[
        $$ = tickprops_new();
    ]]></element-type>
    <element-type name="tlabels" ctype="TLabels *"><![CDATA[
        $$ = tlabels_new();
    ]]></element-type>
    <element-type name="uticks" ctype="UTicks *"><![CDATA[
        $$ = uticks_new();
    ]]></element-type>
    <element-type name="tick" ctype="tickloc *"><![CDATA[
        $$ = tick_new();
    ]]></element-type>
    <element-type name="object" ctype="Quark *"><![CDATA[
        $$ = object_new((Quark *)$P);
    ]]></element-type>
    <element-type name="atext" ctype="Quark *"><![CDATA[
        $$ = atext_new((Quark *)$P);
    ]]></element-type>
    <element-type name="location" ctype="Location *"><![CDATA[
        $$ = location_new();
    ]]></element-type>
    <element-type name="do_line_data" ctype="DOLineData *"><![CDATA[
        $$ = object_odata_new(DO_LINE);
    ]]></element-type>
    <element-type name="do_box_data" ctype="DOBoxData *"><![CDATA[
        $$ = object_odata_new(DO_BOX);
    ]]></element-type>
    <element-type name="do_arc_data" ctype="DOArcData *"><![CDATA[
        $$ = object_odata_new(DO_ARC);
    ]]></element-type>
    <element-type name="textframe" ctype="TextFrame *"><![CDATA[
        $$ = textframe_new();
    ]]></element-type>
    <element-type name="textpointer" ctype="TextPointer *"><![CDATA[
        $$ = textpointer_new();
    ]]></element-type>
    <element-type name="arrow" ctype="Arrow *"><![CDATA[
        $$ = arrow_new();
    ]]></element-type>
    <element-type name="set" ctype="Quark *"><![CDATA[
        $$ = grace_set_new((Quark *)$P);
    ]]></element-type>
    <element-type name="symbol" ctype="Symbol *"><![CDATA[
        $$ = symbol_new();
    ]]></element-type>
    <element-type name="setline" ctype="SetLine *"><![CDATA[
        $$ = setline_new();
    ]]></element-type>
    <element-type name="annotation" ctype="AValue *"><![CDATA[
        $$ = avalue_new();
    ]]></element-type>
    <element-type name="errorbar" ctype="Errbar *"><![CDATA[
        $$ = xmalloc(sizeof(Errbar));
        memset($$, 0, sizeof(Errbar));
    ]]></element-type>
    <element-type name="barline" ctype="BarLine *"><![CDATA[
        $$ = barline_new();
    ]]></element-type>
    <element-type name="riserline" ctype="RiserLine *"><![CDATA[
        $$ = riserline_new();
    ]]></element-type>
    <element-type name="dataset" ctype="Dataset *"><![CDATA[
        $$ = dataset_new();
        ((ParserData *) $U)->nrow = 0;
    ]]></element-type>
    <element-type name="datapoint" ctype="Datapoint *"><![CDATA[
        $$ = datapoint_new();
    ]]></element-type>
    <element-type name="region" ctype="Quark *"><![CDATA[
        $$ = region_new((Quark *)$P);
    ]]></element-type>


    <!-- Now describe the document structure -->
    <element name="#EStrGrace" type="project">
        <!-- Attributes -->
        <attribute name="#AStrVersion" type="ival">
            project_set_version_id($$, $?);
        </attribute>

        <!-- Child elements -->
        <child name="#EStrDescription">
            project_set_description($$, $?->s);
            xcc_string_free($?);
        </child>
        <child name="#EStrDefinitions">
        </child>
        <child name="#EStrPage">
            Project *pr  = project_get_data($$);
            pr->page_wpp = $?->width;
            pr->page_hpp = $?->height,
            pr->bgfill   = $?->bgfill;
            pr->bgcolor  = $?->bgcolor;
            xfree($?);
        </child>
        <child name="#EStrDataFormats">
        </child>
        <child name="#EStrFrame">
        </child>
        <child name="#EStrObject">
        </child>
        <child name="#EStrAText">
        </child>
    </element>
    <element name="#EStrDefinitions" type="dummy">
        <!-- Child elements -->
        <child name="#EStrColormap">
        </child>
        <child name="#EStrFontmap">
        </child>
        <child name="#EStrScales">
        </child>
    </element>
    <element name="#EStrColormap" type="dummy">
        <!-- Child elements -->
        <child name="#EStrColorDef"><![CDATA[
            project_add_color($0, $?);
            colordef_free($?);
        ]]></child>
    </element>
    <element name="#EStrFontmap" type="dummy">
        <!-- Child elements -->
        <child name="#EStrFontDef"><![CDATA[
	    project_add_font($0, $?);
            fontdef_free($?);
        ]]></child>
    </element>
    <element name="#EStrScales" type="dummy">
        <!-- Attributes -->
        <attribute name="#AStrFontSize" type="dval">
	    project_set_fontsize_scale($0, $?);
        </attribute>
        <attribute name="#AStrLineWidth" type="dval">
	    project_set_linewidth_scale($0, $?);
        </attribute>
    </element>
    <element name="#EStrColorDef" type="colordef">
        <!-- Attributes -->
        <attribute name="#AStrId" type="ival">
            $$->id = $?;
        </attribute>
        <attribute name="#AStrRgb" type="rgb">
            $$->rgb = *($?);
            xfree($?);
        </attribute>
        <attribute name="#AStrName" type="sval">
            $$->cname = $?;
        </attribute>
    </element>
    <element name="#EStrFontDef" type="fontdef">
        <!-- Attributes -->
        <attribute name="#AStrId" type="ival">
            $$->id = $?;
        </attribute>
        <attribute name="#AStrName" type="sval">
            $$->fontname = $?;
        </attribute>
        <attribute name="#AStrFallback" type="sval">
            $$->fallback = $?;
        </attribute>
    </element>
    <element name="#EStrPage" type="page">
        <!-- Attributes -->
        <attribute name="#AStrWidth" type="ival">
            $$->width = $?;
        </attribute>
        <attribute name="#AStrHeight" type="ival">
            $$->height = $?;
        </attribute>
        <attribute name="#AStrColorId" type="ival">
            $$->bgcolor = $?;
        </attribute>
        <attribute name="#AStrFill" type="bval">
            $$->bgfill = $?;
        </attribute>
    </element>
    <element name="#EStrDescription" type="string">
        <!-- Child elements -->
        <child name="#EStrText">
            xcc_string_set($$, $?->s);
            xcc_string_free($?);
        </child>
    </element>
    <element name="#EStrDataFormats" type="dummy">
        <!-- Child elements -->
        <child name="#EStrDates">
        </child>
        <child name="#EStrWorld">
        </child>
    </element>
    <element name="#EStrFaceSpec" type="facespec">
        <!-- Attributes -->
        <attribute name="#AStrFontId" type="fontid">
            $$->font = $?;
        </attribute>
        <attribute name="#AStrColorId" type="ival">
            $$->color = $?;
        </attribute>
        <attribute name="#AStrCharSize" type="dval">
            $$->size = $?;
        </attribute>
    </element>
    <element name="#EStrDates" type="dummy">
        <!-- Attributes -->
        <attribute name="#AStrReference" type="ival">
            project_set_ref_date($0, $?);
        </attribute>
        <attribute name="#AStrWrap" type="bval">
            project_allow_two_digits_years($0, $?);
        </attribute>
        <attribute name="#AStrWrapYear" type="ival">
            project_set_wrap_year($0, $?);
        </attribute>
    </element>
    <element name="#EStrWorld" type="dummy">
        <!-- Attributes -->
        <attribute name="#AStrFormat" type="sval">
            project_set_sformat($0, $?);
            xfree($?);
        </attribute>
    </element>
    <element name="#EStrText" type="string">
        <!-- Character data -->
        <data>
            char *s;
            s = utf2iso($?);
            xcc_string_set($$, s);
            xfree(s);
        </data>
    </element>
    <element name="#EStrFillSpec" type="pen">
        <!-- Attributes -->
        <attribute name="#AStrColorId" type="ival">
            $$->color = $?;
        </attribute>
        <attribute name="#AStrPatternId" type="ival">
            $$->pattern = $?;
        </attribute>
    </element>
    <element name="#EStrFrame" type="frame">
        <!-- Attributes -->
        <attribute name="#AStrId" type="sval">
            quark_idstr_set($$, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrActive" type="bval">
            quark_set_active($$, $?);
        </attribute>
        <attribute name="#AStrType" type="ival">
            frame_set_type($$, $?);
        </attribute>
        <!-- Child elements -->
        <child name="#EStrViewport">
            frame_set_view($$, $?);
            xfree($?);
        </child>
        <child name="#EStrLegend">
            frame_set_legend($$, $?);
            xfree($?);
        </child>
        <child name="#EStrLineSpec">
            frame_set_outline($$, $?);
            xfree($?);
        </child>
        <child name="#EStrFillSpec">
            frame_set_fillpen($$, $?);
            xfree($?);
        </child>
        <child name="#EStrGraph">
        </child>
        <child name="#EStrObject">
        </child>
        <child name="#EStrAText">
        </child>
    </element>
    <element name="#EStrGraph" type="graph">
        <!-- Attributes -->
        <attribute name="#AStrId" type="sval">
            quark_idstr_set($$, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrActive" type="bval">
            quark_set_active($$, $?);
        </attribute>

        <!-- Child elements -->
        <child name="#EStrPresentationSpec">
            graph_set_type($$, $?->type);
            graph_set_bargap($$, $?->bargap);
            graph_set_stacked($$, $?->stacked);
            presentationspec_free($?);
        </child>
        <child name="#EStrXscale"><![CDATA[
            world w;
            graph_get_world($$, &w);
            w.xg1 = $?->min;
            w.xg2 = $?->max;
            graph_set_world($$, &w);
            graph_set_xscale($$, $?->type);
            graph_set_xinvert($$, $?->invert);
            xfree($?);
        ]]></child>
        <child name="#EStrYscale"><![CDATA[
            world w;
            graph_get_world($$, &w);
            w.yg1 = $?->min;
            w.yg2 = $?->max;
            graph_set_world($$, &w);
            graph_set_yscale($$, $?->type);
            graph_set_yinvert($$, $?->invert);
            xfree($?);
        ]]></child>
        <child name="#EStrZscale">
            graph_set_znorm($$, *($?));
            xfree($?);
        </child>
        <child name="#EStrLocator">
            graph_set_locator($$, $?);
            xfree($?);
        </child>
        <child name="#EStrAxis">
        </child>
        <child name="#EStrSet">
        </child>
        <child name="#EStrObject">
        </child>
        <child name="#EStrAText">
        </child>
        <child name="#EStrRegion">
        </child>
    </element>
    <element name="#EStrPresentationSpec" type="presentationspec">
        <!-- Attributes -->
        <attribute name="#AStrType" type="sval">
            RunTime *rt = ((ParserData *)$U)->rt;
            $$->type = graph_get_type_by_name(rt, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrStacked" type="bval">
            $$->stacked = $?;
        </attribute>
        <attribute name="#AStrBargap" type="dval">
            $$->bargap = $?;
        </attribute>
    </element>
    <element name="#EStrViewport" type="view">
        <!-- Attributes -->
        <attribute name="#AStrXmin" type="dval">
            $$->xv1 = $?;
        </attribute>
        <attribute name="#AStrYmin" type="dval">
            $$->yv1 = $?;
        </attribute>
        <attribute name="#AStrXmax" type="dval">
            $$->xv2 = $?;
        </attribute>
        <attribute name="#AStrYmax" type="dval">
            $$->yv2 = $?;
        </attribute>
    </element>
    <element name="#EStrXscale" type="scale">
        <!-- Attributes -->
        <attribute name="#AStrMin" type="dateordval">
            $$->min = $?;
        </attribute>
        <attribute name="#AStrMax" type="dateordval">
            $$->max = $?;
        </attribute>
        <attribute name="#AStrType" type="sval">
            $$->type = get_scale_type_by_name($?);
            xfree($?);
        </attribute>
        <attribute name="#AStrInvert" type="bval">
            $$->invert = $?;
        </attribute>
    </element>
    <element name="#EStrYscale" type="scale">
        <!-- Attributes -->
        <attribute name="#AStrMin" type="dateordval">
            $$->min = $?;
        </attribute>
        <attribute name="#AStrMax" type="dateordval">
            $$->max = $?;
        </attribute>
        <attribute name="#AStrType" type="sval">
            $$->type = get_scale_type_by_name($?);
            xfree($?);
        </attribute>
        <attribute name="#AStrInvert" type="bval">
            $$->invert = $?;
        </attribute>
    </element>
    <element name="#EStrZscale" type="dptr">
        <!-- Attributes -->
        <attribute name="#AStrNorm" type="dval">
            *($$) = $?;
        </attribute>
    </element>
    <element name="#EStrLegend" type="legend">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>
        <attribute name="#AStrLength" type="dval">
            $$->len = $?;
        </attribute>
        <attribute name="#AStrVgap" type="dval">
            $$->vgap = $?;
        </attribute>
        <attribute name="#AStrHgap" type="dval">
            $$->hgap = $?;
        </attribute>
        <attribute name="#AStrInvert" type="bval">
            $$->invert = $?;
        </attribute>
        <attribute name="#AStrSingleSymbol" type="bval">
            $$->singlesym = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrFaceSpec">
            $$->font     = $?->font;
            $$->color    = $?->color;
            $$->charsize = $?->size;
            facespec_free($?);
        </child>
        <child name="#EStrLegframe">
            $$->boxfillpen = $?->fillpen;
            $$->boxline    = $?->line;
            $$->anchor     = $?->anchor;
            $$->just       = $?->just;
            $$->offset     = $?->offset;
            xfree($?);
        </child>
    </element>
    <element name="#EStrLegframe" type="legframe">
        <attribute name="#AStrAnchor" type="fpoint">
            $$->anchor = *($?);
            xfree($?);
        </attribute>
        <attribute name="#AStrJustification" type="ival">
            $$->just = $?;
        </attribute>
        <attribute name="#AStrOffset" type="offset">
            $$->offset = *($?);
            xfree($?);
        </attribute>
        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->line = *($?);
            xfree($?);
        </child>
        <child name="#EStrFillSpec">
            $$->fillpen = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrLineSpec" type="line">
        <!-- Attributes -->
        <attribute name="#AStrColorId" type="ival">
            $$->pen.color = $?;
        </attribute>
        <attribute name="#AStrPatternId" type="ival">
            $$->pen.pattern = $?;
        </attribute>
        <attribute name="#AStrStyleId" type="ival">
            $$->style = $?;
        </attribute>
        <attribute name="#AStrWidth" type="dval">
            $$->width = $?;
        </attribute>
    </element>
    <element name="#EStrLocator" type="glocator">
        <!-- Attributes -->
        <attribute name="#AStrType" type="ival">
            $$->type = $?;
        </attribute>
        <!-- Child elements -->
        <child name="#EStrFixedpoint">
            $$->pointset = $?->active;
            $$->origin.x = $?->x;
            $$->origin.y = $?->y;
            xfree($?);
        </child>
        <child name="#EStrXformat">
            $$->fx = $?->type;
            $$->px = $?->prec;
            xfree($?);
        </child>
        <child name="#EStrYformat">
            $$->fy = $?->type;
            $$->py = $?->prec;
            xfree($?);
        </child>
    </element>
    <element name="#EStrFixedpoint" type="fixedpoint">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>
        <attribute name="#AStrX" type="dval">
            $$->x = $?;
        </attribute>
        <attribute name="#AStrY" type="dval">
            $$->y = $?;
        </attribute>
    </element>
    <element name="#EStrXformat" type="format">
        <!-- Attributes -->
        <attribute name="#AStrFormat" type="ftype">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrPrec" type="ival">
            $$->prec = $?;
        </attribute>
    </element>
    <element name="#EStrYformat" type="format">
        <!-- Attributes -->
        <attribute name="#AStrFormat" type="ftype">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrPrec" type="ival">
            $$->prec = $?;
        </attribute>
    </element>
    <element name="#EStrAxis" type="axis">
        <!-- Attributes -->
        <attribute name="#AStrId" type="sval">
            quark_idstr_set($$, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrType" type="sval">
            int axis_type;
            if (!strcmp($?, "x")) {
                axis_type = AXIS_TYPE_X;
            } else {
                axis_type = AXIS_TYPE_Y;
            }
            axis_set_type($$, axis_type);
            xfree($?);
        </attribute>
        <attribute name="#AStrActive" type="bval">
            quark_set_active($$, $?);
        </attribute>
        <!-- Child elements -->
        <child name="#EStrPlacement">
            tickmarks *t = axis_get_data($$);
            if (t) {
                t->zero   = $?->zero;
                t->offsx  = $?->offset.x;
                t->offsy  = $?->offset.y;
            }
            xfree($?);
        </child>
        <child name="#EStrAxisbar">
            tickmarks *t = axis_get_data($$);
            if (t) {
                t->t_drawbar      = $?->active;
                t->t_drawbarcolor = $?->line.pen.color;
                t->t_drawbarlines = $?->line.style;
                t->t_drawbarlinew = $?->line.width;
            }
            xfree($?);
        </child>
        <child name="#EStrAxislabel">
            tickmarks *t = axis_get_data($$);
            if (t) {
                t->label        = $?->s;
                t->label_tprops = $?->tprops;
            
                t->label_layout = $?->layout;
                t->label_place  = $?->autoplace ? TYPE_AUTO:TYPE_SPEC;
                t->label_offset = $?->offset;
                t->label_op     = $?->sideplacement;
            }
            xfree($?);
        </child>
        <child name="#EStrTicks"><![CDATA[
            tickmarks *t = axis_get_data($$);
            if (t) {
                t->tmajor    = $?->major;
                t->nminor    = $?->nminor;
                t->t_autonum = $?->autonum;
                t->t_round   = $?->round;

                t->t_flag    = $?->tmarks.active;
                t->t_op      = $?->tmarks.sideplacement;
                t->props     = $?->tmarks.props;
                t->mprops    = $?->tmarks.mprops;

                t->t_spec    = $?->uticks.type;
                if (t->t_spec != TICKS_SPEC_NONE) {
                    int i;
                    t->nticks = $?->uticks.nticks;
                    for (i = 0; i < t->nticks; i++) {
                        t->tloc[i] = $?->uticks.tloc[i];
                    }
                }

                t->tl_flag      = $?->tlabels.active;

                t->tl_op        = $?->tlabels.sideplacement;
                t->tl_formula   = $?->tlabels.transform;
                t->tl_tprops    = $?->tlabels.tprops;
                t->tl_skip      = $?->tlabels.skip;
                t->tl_staggered = $?->tlabels.stagger;
                t->tl_format    = $?->tlabels.format.type;
                t->tl_prec      = $?->tlabels.format.prec;
                t->tl_gaptype   = $?->tlabels.autoplace ? TYPE_AUTO:TYPE_SPEC;
                t->tl_gap.x     = $?->tlabels.offset.x;
                t->tl_gap.y     = $?->tlabels.offset.y;
                t->tl_starttype = $?->tlabels.autostart ? TYPE_AUTO:TYPE_SPEC;
                t->tl_start     = $?->tlabels.start;
                t->tl_stoptype  = $?->tlabels.autostop ? TYPE_AUTO:TYPE_SPEC;
                t->tl_stop      = $?->tlabels.stop;
                t->tl_prestr    = copy_string(NULL, $?->tlabels.prepend);
                t->tl_appstr    = copy_string(NULL, $?->tlabels.append);
            }
            xfree($?->tlabels.prepend);
            xfree($?->tlabels.append);
            xfree($?);
        ]]></child>
    </element>
    <element name="#EStrPlacement" type="axisplacement">
        <!-- Attributes -->
        <attribute name="#AStrZero" type="bval">
            $$->zero = $?;
        </attribute>
        <attribute name="#AStrOffset" type="offset">
            if ($?) {
                $$->offset.x = $?->x;
                $$->offset.y = $?->y;
                xfree($?);
            }
        </attribute>
    </element>
    <element name="#EStrAxisbar" type="axisbar">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>
        <child name="#EStrLineSpec">
            $$->line = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrAxislabel" type="axislabel">
        <!-- Attributes -->
        <attribute name="#AStrLayout" type="axislayout">
            $$->layout = $?;
        </attribute>
        <attribute name="#AStrOffset" type="offset">
            if ($?) {
                $$->autoplace = FALSE;
                $$->offset.x  = $?->x;
                $$->offset.y  = $?->y;
                xfree($?);
            } else {
                $$->autoplace = TRUE;
            }
        </attribute>
        <attribute name="#AStrSidePlacement" type="sideplacement">
            $$->sideplacement = $?;
        </attribute>
        <!-- Child elements -->
        <child name="#EStrTextProperties">
            $$->tprops = *$?;
            xfree($?);
        </child>
        <child name="#EStrText">
            $$->s = copy_string(NULL, $?->s);
            xcc_string_free($?);
        </child>
    </element>
    <element name="#EStrTicks" type="ticks">
        <!-- Attributes -->
        <attribute name="#AStrMajorStep" type="dval">
            $$->major = $?;
        </attribute>
        <attribute name="#AStrMinorDivisions" type="ival">
            $$->nminor = $?;
        </attribute>
        <attribute name="#AStrAutoTicking" type="ival">
            $$->autonum = $?;
        </attribute>
        <attribute name="#AStrRoundedPosition" type="bval">
            $$->round = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrUserticks">
            $$->uticks = *($?);
            xfree($?);
        </child>
        <child name="#EStrTickmarks">
            $$->tmarks = *($?);
            xfree($?);
        </child>
        <child name="#EStrTicklabels">
            $$->tlabels = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrUserticks" type="uticks">
        <!-- Attributes -->
        <attribute name="#AStrType" type="uticktype">
            $$->type = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrTick">
            utick_add($$, $?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrTickmarks" type="tmarks">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>
        <attribute name="#AStrSidePlacement" type="sideplacement">
            $$->sideplacement = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrMajor">
            $$->props = *($?);
            xfree($?);
        </child>
        <child name="#EStrMinor">
            $$->mprops = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrMajor" type="tickprops">
        <!-- Attributes -->
        <attribute name="#AStrInoutPlacement" type="inoutplacement">
            $$->inout = $?;
        </attribute>
        <attribute name="#AStrSize" type="dval">
            $$->size = $?;
        </attribute>
        <attribute name="#AStrGridLines" type="bval">
            $$->gridflag = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->color = $?->pen.color;
            $$->linew = $?->width;
            $$->lines = $?->style;
            xfree($?);
        </child>
    </element>
    <element name="#EStrMinor" type="tickprops">
        <!-- Attributes -->
        <attribute name="#AStrInoutPlacement" type="inoutplacement">
            $$->inout = $?;
        </attribute>
        <attribute name="#AStrSize" type="dval">
            $$->size = $?;
        </attribute>
        <attribute name="#AStrGridLines" type="bval">
            $$->gridflag = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->color = $?->pen.color;
            $$->linew = $?->width;
            $$->lines = $?->style;
            xfree($?);
        </child>
    </element>
    <element name="#EStrTicklabels" type="tlabels">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>
        <attribute name="#AStrSidePlacement" type="sideplacement">
            $$->sideplacement = $?;
        </attribute>
        <attribute name="#AStrTransform" type="sval">
            $$->transform = $?;
        </attribute>
        <attribute name="#AStrPrepend" type="sval">
            $$->prepend = $?;
        </attribute>
        <attribute name="#AStrAppend" type="sval">
            $$->append = $?;
        </attribute>
        <attribute name="#AStrOffset" type="offset">
            if ($?) {
                $$->autoplace = FALSE;
                $$->offset.x  = $?->x;
                $$->offset.y  = $?->y;
                xfree($?);
            } else {
                $$->autoplace = TRUE;
            }
        </attribute>
        <attribute name="#AStrSkip" type="ival">
            $$->skip = $?;
        </attribute>
        <attribute name="#AStrStagger" type="ival">
            $$->stagger = $?;
        </attribute>
        <attribute name="#AStrStart" type="autodateordval">
            $$->autostart = $?->autov;
            $$->start     = $?->value;
            xfree($?);
        </attribute>
        <attribute name="#AStrStop" type="autodateordval">
            $$->autostop = $?->autov;
            $$->stop     = $?->value;
            xfree($?);
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrTextProperties">
            $$->tprops = *($?);
            xfree($?);
        </child>
        <child name="#EStrFormat">
            $$->format = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrTick" type="tick">
        <!-- Attributes -->
        <attribute name="#AStrType" type="ticktype">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrPosition" type="dateordval">
            $$->wtpos = $?;
        </attribute>
        <attribute name="#AStrLabel" type="sval">
            $$->label = $?;
        </attribute>
    </element>
    <element name="#EStrFormat" type="format">
        <!-- Attributes -->
        <attribute name="#AStrFormat" type="ftype">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrPrec" type="ival">
            $$->prec = $?;
        </attribute>
    </element>
    <element name="#EStrObject" type="object">
        <!-- Attributes -->
        <attribute name="#AStrId" type="sval">
            quark_idstr_set($$, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrActive" type="bval">
            quark_set_active($$, $?);
        </attribute>
        <attribute name="#AStrAngle" type="dval">
            object_set_angle($$, $?);
        </attribute>
        <attribute name="#AStrOffset" type="offset">
            object_set_offset($$, $?);
            xfree($?);
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrLineSpec">
            object_set_line($$, $?);
            xfree($?);
        </child>
        <child name="#EStrLocation"><![CDATA[
            object_set_location($$, &($?->ap));
            xfree($?);
        ]]></child>
        <child name="#EStrFillSpec">
            object_set_fillpen($$, $?);
            xfree($?);
        </child>
        <child name="#EStrLineData">
            DObject *o = object_get_data($$);
            if (o) {
                o->odata = $?;
                o->type  = DO_LINE;
            }
        </child>
        <child name="#EStrBoxData">
            DObject *o = object_get_data($$);
            if (o) {
                o->odata = $?;
                o->type  = DO_BOX;
            }
        </child>
        <child name="#EStrArcData">
            DObject *o = object_get_data($$);
            if (o) {
                o->odata = $?;
                o->type  = DO_ARC;
            }
        </child>
    </element>
    <element name="#EStrLocation" type="location">
        <!-- Attributes -->
        <attribute name="#AStrX" type="dateordval">
            $$->ap.x = $?;
        </attribute>
        <attribute name="#AStrY" type="dateordval">
            $$->ap.y = $?;
        </attribute>
    </element>
    <element name="#EStrBoxData" type="do_box_data">
        <!-- Attributes -->
        <attribute name="#AStrWidth" type="dval">
            $$->width = $?;
        </attribute>
        <attribute name="#AStrHeight" type="dval">
            $$->height = $?;
        </attribute>
    </element>
    <element name="#EStrArcData" type="do_arc_data">
        <!-- Attributes -->
        <attribute name="#AStrWidth" type="dval">
            $$->width = $?;
        </attribute>
        <attribute name="#AStrHeight" type="dval">
            $$->height = $?;
        </attribute>
        <attribute name="#AStrStartAngle" type="dval">
            $$->angle1 = $?;
        </attribute>
        <attribute name="#AStrExtentAngle" type="dval">
            $$->angle2 = $?;
        </attribute>
        <attribute name="#AStrFillMode" type="ival">
            $$->fillmode = $?;
        </attribute>
    </element>
    <element name="#EStrLineData" type="do_line_data">
        <!-- Attributes -->
        <attribute name="#AStrX" type="dval">
            $$->vector.x = $?;
        </attribute>
        <attribute name="#AStrY" type="dval">
            $$->vector.y = $?;
        </attribute>
        <attribute name="#AStrArrowsAt" type="ival">
            $$->arrow_end = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrArrow">
            $$->arrow = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrAText" type="atext">
        <!-- Attributes -->
        <attribute name="#AStrId" type="sval">
            quark_idstr_set($$, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrActive" type="bval">
            quark_set_active($$, $?);
        </attribute>
        <attribute name="#AStrOffset" type="offset">
            atext_set_offset($$, $?);
            xfree($?);
        </attribute>
    
        <!-- Child elements -->
        <child name="#EStrLocation"><![CDATA[
            atext_set_ap($$, &($?->ap));
            xfree($?);
        ]]></child>
        <child name="#EStrText">
            atext_set_string($$, $?->s);
            xcc_string_free($?);
        </child>
        <child name="#EStrTextProperties">
            atext_set_tprops($$, $?);
            xfree($?);
        </child>
        <child name="#EStrTextFrame"><![CDATA[
            AText *at = atext_get_data($$);
            if (at) {
                at->frame_decor  = $?->decor;
                at->frame_offset = $?->offset;
                at->line         = $?->line;
                at->fillpen      = $?->fillpen;
            }
            xfree($?);
        ]]></child>
        <child name="#EStrPointer"><![CDATA[
            AText *at = atext_get_data($$);
            if (at) {
                at->arrow_flag = $?->active;
                at->arrow      = $?->arrow;
            }
            xfree($?);
        ]]></child>
    </element>
    <element name="#EStrTextFrame" type="textframe">
        <!-- Attributes -->
        <attribute name="#AStrType" type="ival">
            $$->decor = $?;
        </attribute>
        <attribute name="#AStrOffset" type="dval">
            $$->offset = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->line = *($?);
            xfree($?);
        </child>
        <child name="#EStrFillSpec">
            $$->fillpen = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrPointer" type="textpointer">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrArrow">
            $$->arrow = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrArrow" type="arrow">
        <!-- Attributes -->
        <attribute name="#AStrType" type="ival">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrLength" type="dval">
            $$->length = $?;
        </attribute>
        <attribute name="#AStrDlFf" type="dval">
            $$->dL_ff = $?;
        </attribute>
        <attribute name="#AStrLlFf" type="dval">
            $$->lL_ff = $?;
        </attribute>
    </element>
    <element name="#EStrSet" type="set">
        <!-- Attributes -->
        <attribute name="#AStrId" type="sval">
            quark_idstr_set($$, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrActive" type="bval">
            quark_set_active($$, $?);
        </attribute>
        <attribute name="#AStrType" type="settype">
            set_set_type($$, $?);
        </attribute>
        <attribute name="#AStrSkip" type="ival">
            set_set_symskip($$, $?);
        </attribute>
        <attribute name="#AStrSkipMinDist" type="dval">
            set_set_symskipmindist($$, $?);
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrSymbol">
            set_set_symbol($$, $?);
            xfree($?);
        </child>
        <child name="#EStrLine">
            set_set_line($$, $?);
            xfree($?);
        </child>
        <child name="#EStrAnnotation">
            set_set_avalue($$, $?);
            avalue_free($?);
        </child>
        <child name="#EStrErrorbar">
            set_set_errbar($$, $?);
            xfree($?);
        </child>
        <child name="#EStrLegendEntry">
            set_set_legstr($$, $?->s);
            xcc_string_free($?);
        </child>
        <child name="#EStrDataset">
            set_set_dataset($$, $?);
        </child>
    </element>
    <element name="#EStrSymbol" type="symbol">
        <!-- Attributes -->
        <attribute name="#AStrType" type="ival">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrSize" type="dval">
            $$->size = $?;
        </attribute>
        <attribute name="#AStrChar" type="ival">
            $$->symchar = $?;
        </attribute>
        <attribute name="#AStrFontId" type="fontid">
            $$->charfont = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->line = *($?);
            xfree($?);
        </child>
        <child name="#EStrFillSpec">
            $$->fillpen = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrLine" type="setline">
        <!-- Attributes -->
        <attribute name="#AStrType" type="ival">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrFillType" type="ival">
            $$->filltype = $?;
        </attribute>
        <attribute name="#AStrFillRule" type="fillrule">
            $$->fillrule = $?;
        </attribute>
        <attribute name="#AStrBaselineType" type="ival">
            $$->baseline_type = $?;
        </attribute>
        <attribute name="#AStrDrawBaseline" type="bval">
            $$->baseline = $?;
        </attribute>
        <attribute name="#AStrDrawDroplines" type="bval">
            $$->droplines = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->line = *($?);
            xfree($?);
        </child>
        <child name="#EStrFillSpec">
            $$->fillpen = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrAnnotation" type="annotation">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>
        <attribute name="#AStrType" type="ival">
            $$->type = $?;
        </attribute>
        <attribute name="#AStrOffset" type="offset">
            if ($?) {
                $$->offset = *($?);
                xfree($?);
            }
        </attribute>
        <attribute name="#AStrPrepend" type="sval">
            $$->prestr = $?;
        </attribute>
        <attribute name="#AStrAppend" type="sval">
            $$->appstr = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrTextProperties">
            $$->tprops = *$?;
            xfree($?);
        </child>
        <child name="#EStrFormat">
            $$->format = $?->type;
            $$->prec   = $?->prec;
            xfree($?);
        </child>
    </element>
    <element name="#EStrTextProperties" type="textprops">
        <!-- Attributes -->
        <attribute name="#AStrAngle" type="dval">
            $$->angle = $?;
        </attribute>
        <attribute name="#AStrJustification" type="ival">
            $$->just = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrFaceSpec">
            $$->charsize  = $?->size;
            $$->font      = $?->font;
            $$->color     = $?->color;
            xfree($?);
        </child>
    </element>
    <element name="#EStrErrorbar" type="errorbar">
        <!-- Attributes -->
        <attribute name="#AStrActive" type="bval">
            $$->active = $?;
        </attribute>
        <attribute name="#AStrSidePlacement" type="sideplacement">
            $$->ptype = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrBarline">
            $$->barsize = $?->size;
            $$->pen     = $?->line.pen;
            $$->linew   = $?->line.width;
            $$->lines   = $?->line.style;
            xfree($?);
        </child>
        <!-- Child elements -->
        <child name="#EStrRiserline">
            $$->arrow_clip  = $?->arrow_clip;
            $$->cliplen     = $?->clip_length;
            $$->riser_linew = $?->line.width;
            $$->riser_lines = $?->line.style;
            xfree($?);
        </child>
    </element>
    <element name="#EStrBarline" type="barline">
        <!-- Attributes -->
        <attribute name="#AStrSize" type="dval">
            $$->size = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->line = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrRiserline" type="riserline">
        <!-- Attributes -->
        <attribute name="#AStrArrowClip" type="bval">
            $$->arrow_clip = $?;
        </attribute>
        <attribute name="#AStrClipLength" type="dval">
            $$->clip_length = $?;
        </attribute>

        <!-- Child elements -->
        <child name="#EStrLineSpec">
            $$->line = *($?);
            xfree($?);
        </child>
    </element>
    <element name="#EStrLegendEntry" type="string">
        <!-- Child elements -->
        <child name="#EStrText">
            xcc_string_set($$, $?->s);
            xcc_string_free($?);
        </child>
    </element>
    <element name="#EStrDataset" type="dataset">
        <!-- Attributes -->
        <attribute name="#AStrCols" type="ival">
            dataset_set_ncols($$, $?);
        </attribute>
        <attribute name="#AStrRows" type="ival">
            dataset_set_nrows($$, $?);
        </attribute>
        <attribute name="#AStrComment" type="sval">
            $$->comment = $?;
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrRow">
            dataset_set_datapoint($$, $?, ((ParserData *) $U)->nrow);
            datapoint_free($?);
            ((ParserData *) $U)->nrow++;
        </child>
    </element>
    <element name="#EStrRow" type="datapoint">
        <!-- Attributes -->
        <attribute name="X" type="dateordval">
            $$->ex[DATA_X] = $?;
        </attribute>
        <attribute name="Y" type="dateordval">
            $$->ex[DATA_Y] = $?;
        </attribute>
        <attribute name="Y1" type="dateordval">
            $$->ex[DATA_Y1] = $?;
        </attribute>
        <attribute name="Y2" type="dateordval">
            $$->ex[DATA_Y2] = $?;
        </attribute>
        <attribute name="Y3" type="dateordval">
            $$->ex[DATA_Y3] = $?;
        </attribute>
        <attribute name="Y4" type="dateordval">
            $$->ex[DATA_Y4] = $?;
        </attribute>
        <attribute name="s" type="sval">
            $$->s = $?;
        </attribute>
    </element>
    <element name="#EStrRegion" type="region">
        <!-- Attributes -->
        <attribute name="#AStrId" type="sval">
            quark_idstr_set($$, $?);
            xfree($?);
        </attribute>
        <attribute name="#AStrActive" type="bval">
            quark_set_active($$, $?);
        </attribute>
        <attribute name="#AStrType" type="regiontype">
            region_set_type($$, $?);
        </attribute>
        <attribute name="#AStrColorId" type="ival">
            region_set_color($$, $?);
        </attribute>
        
        <!-- Child elements -->
        <child name="#EStrRow"><![CDATA[
            WPoint wp;
            wp.x = $?->ex[DATA_X];
            wp.y = $?->ex[DATA_Y];
            region_add_point($$, &wp);
            datapoint_free($?);
        ]]></child>
    </element>

    <!-- Postamble -->
    <postamble><![CDATA[
int load_xgr_project(Grace *grace, char *fn)
{
    ParserData udata;
    void *p;
    Quark *project;
    FILE *fp;
    int ret;

    fp = grace_openr(grace, fn, SOURCE_DISK);
    if (fp == NULL) {
	return RETURN_FAILURE;
    }

    udata.rt = grace->rt;
    udata.nrow = -1;
    
    ret = xcc_parse(fp, &udata, &p, xcc_start_handler, xcc_end_handler);
    project = p;

    grace_close(fp);
    
    if (ret == XCC_RETURN_SUCCESS) {
        return grace_set_project(grace, project);
    } else {
        quark_free(project);
        
        return RETURN_FAILURE;
    }
}
    ]]></postamble>
</parser>
