+static char* gradient_getToken(const char**p)
+{
+ const char*start;
+ char*result;
+ while(**p && strchr(" \t\n\r", **p)) {
+ (*p)++;
+ }
+ start = *p;
+ while(**p && !strchr(" \t\n\r", **p)) {
+ (*p)++;
+ }
+ result = malloc((*p)-start+1);
+ memcpy(result,start,(*p)-start+1);
+ result[(*p)-start] = 0;
+ return result;
+}
+
+float parsePercent(char*str);
+RGBA parseColor(char*str);
+
+GRADIENT parseGradient(const char*str)
+{
+ GRADIENT gradient;
+ const char* p = str;
+ memset(&gradient, 0, sizeof(GRADIENT));
+ while(*p) {
+ char*posstr,*colorstr;
+ float pos;
+ RGBA color;
+ posstr = gradient_getToken(&p);
+ if(!*posstr)
+ break;
+ pos = parsePercent(posstr);
+ if(!*p) syntaxerror("Error in shape data: Color expected after %s", posstr);
+ colorstr = gradient_getToken(&p);
+ color = parseColor(colorstr);
+ if(gradient.num == sizeof(gradient.ratios)/sizeof(gradient.ratios[0])) {
+ warning("gradient record too big- max size is 8, rest ignored");
+ break;
+ }
+ gradient.ratios[gradient.num] = (int)(pos*255.0);
+ gradient.rgba[gradient.num] = color;
+ gradient.num++;
+ free(posstr);
+ free(colorstr);
+ }
+ return gradient;
+}
+
+void s_gradient(char*name, const char*text, int radial)
+{
+ gradient_t* gradient;
+ gradient = malloc(sizeof(gradient_t));
+ memset(gradient, 0, sizeof(gradient_t));
+ gradient->gradient = parseGradient(text);
+ gradient->radial = radial;
+
+ if(dictionary_lookup(&gradients, name))
+ syntaxerror("gradient %s defined twice", name);
+ dictionary_put2(&gradients, name, gradient);
+}
+
+void s_action(const char*text)
+{
+ ActionTAG* a = 0;
+ a = swf_ActionCompile(text, stack[0].swf->fileVersion);
+ if(!a) {
+ syntaxerror("Couldn't compile ActionScript");
+ }
+
+ tag = swf_InsertTag(tag, ST_DOACTION);
+
+ swf_ActionSet(tag, a);
+
+ swf_ActionFree(a);
+}
+
+void s_outline(char*name, char*format, char*source)
+{
+ outline_t* outline;
+
+ drawer_t draw;
+ SHAPE* shape;
+ SHAPE2* shape2;
+ SRECT bounds;
+
+ swf_Shape11DrawerInit(&draw, 0);
+ draw_string(&draw, source);
+ draw.finish(&draw);
+ shape = swf_ShapeDrawerToShape(&draw);
+ //shape2 = swf_ShapeToShape2(shape);
+ //bounds = swf_GetShapeBoundingBox(shape2);
+ //swf_Shape2Free(shape2);
+ bounds = swf_ShapeDrawerGetBBox(&draw);
+ draw.dealloc(&draw);
+
+ outline = (outline_t*)malloc(sizeof(outline_t));
+ memset(outline, 0, sizeof(outline_t));
+ outline->shape = shape;
+ outline->bbox = bounds;
+
+ if(dictionary_lookup(&outlines, name))
+ syntaxerror("outline %s defined twice", name);
+ dictionary_put2(&outlines, name, outline);
+}
+