added (long) GPL headers.
[swftools.git] / src / swfc.c
index db12bd7..cfda5e5 100644 (file)
@@ -4,8 +4,20 @@
    Part of the swftools package.
 
    Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   This file is distributed under the GPL, see file COPYING for details */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <memory.h>
 #include <errno.h>
-#define logf logarithmf // logf is also used by ../lib/log.h
 #include <math.h>
-#undef logf
 #include "../config.h"
 #include "../lib/rfxswf.h"
 #include "../lib/log.h"
 #include "../lib/args.h"
-#include "q.h"
+#include "../lib/q.h"
 #include "parser.h"
 #include "wav.h"
 
@@ -1051,11 +1061,18 @@ int parseInt(char*str)
 }
 int parseTwip(char*str)
 {
-    char*dot = strchr(str, '.');
+    char*dot;
+    int sign=1;
+    if(str[0]=='+' || str[0]=='-') {
+       if(str[0]=='-')
+           sign = -1;
+       str++;
+    }
+    dot = strchr(str, '.');
     if(!dot) {
        int l=strlen(str);
        int t;
-       return parseInt(str)*20;
+       return sign*parseInt(str)*20;
     } else {
        int l=strlen(++dot);
        char*s;
@@ -1072,11 +1089,11 @@ int parseTwip(char*str)
            l=2;
        }
        if(l==0)
-           return atoi(str)*20;
+           return sign*atoi(str)*20;
        if(l==1)
-           return atoi(str)*20+atoi(dot)*2;
+           return sign*atoi(str)*20+atoi(dot)*2;
        if(l==2)
-           return atoi(str)*20+atoi(dot)/5;
+           return sign*atoi(str)*20+atoi(dot)/5;
     }
     return 0;
 }
@@ -1308,6 +1325,10 @@ SPOINT getPoint(SRECT r, char*name)
     l--;
     return *(SPOINT*)&mpoints.buffer[l];
 }
+static int c_gradient(map_t*args) 
+{
+    return 0;
+}
 static int c_point(map_t*args) 
 {
     char*name = lu(args, "name");
@@ -1724,6 +1745,11 @@ static struct {
  {"font", c_font, "name filename"},
  {"soundtrack", c_soundtrack, "filename"},
 
+    // generators of primitives
+
+ {"point", c_point, "name x=0 y=0"},
+ {"gradient", c_gradient, "name"},
+
     // character generators
  {"box", c_primitive, "name width height color=white line=1 @fill=none"},
  {"circle", c_primitive, "name r color=white line=1 @fill=none"},
@@ -1750,7 +1776,6 @@ static struct {
     // virtual object placement
  {"buttonput", c_buttonput, "<i> x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex=100% scaley=100% shear=0 rotate=0 above= below="},
  {"texture", c_texture, "<i> x=0 y=0 scale= scalex=100% scaley=100% shear=0 rotate=0"},
- {"point", c_point, "name x=0 y=0"},
 
     // commands which start a block
 //startclip (see above)
@@ -1844,7 +1869,7 @@ static map_t parseArguments(char*command, char*pattern)
     len = pos;
 
 /*    for(t=0;t<len;t++) {
-       printf("(%d) %s=%s %s\n", t, strndup(name[t], namelen[t]), strndup(value[t], valuelen[t]),
+       printf("(%d) %s=%s %s\n", t, strdup_n(name[t], namelen[t]), strdup_n(value[t], valuelen[t]),
                isboolean[t]?"(boolean)":"");
     }*/
 
@@ -1865,8 +1890,8 @@ static map_t parseArguments(char*command, char*pattern)
                value[pos].str = text;
                value[pos].len = strlen(text);
                /*printf("setting boolean parameter %s (to %s)\n",
-                       strndup(name[pos], namelen[pos]),
-                       strndup(value[pos], valuelen[pos]));*/
+                       strdup_n(name[pos], namelen[pos]),
+                       strdup_n(value[pos], valuelen[pos]));*/
                break;
            }
        }
@@ -1878,7 +1903,7 @@ static map_t parseArguments(char*command, char*pattern)
            if((type == ASSIGNMENT && !strncmp(name[pos].str, text, name[pos].len>textlen?name[pos].len:textlen)) ||
               (type != ASSIGNMENT && !set[pos])) {
                if(set[pos]) {
-                   syntaxerror("value %s set twice (old value:%s)", text, strndup(value[pos].str, value[pos].len));
+                   syntaxerror("value %s set twice (old value:%s)", text, strdup_n(value[pos].str, value[pos].len));
                }
                if(type == ASSIGNMENT)
                    readToken();
@@ -1887,8 +1912,8 @@ static map_t parseArguments(char*command, char*pattern)
                value[pos].len = strlen(text);
 #if 0//def DEBUG
                printf("setting parameter %s (to %s)\n",
-                       strndup(name[pos].str, name[pos].len),
-                       strndup(value[pos].str, value[pos].len));
+                       strdup_n(name[pos].str, name[pos].len),
+                       strdup_n(value[pos].str, value[pos].len));
 #endif
                break;
            }
@@ -1899,7 +1924,7 @@ static map_t parseArguments(char*command, char*pattern)
     }
 #if 0//def DEBUG
     for(t=0;t<len;t++) {
-       printf("%s=%s\n", strndup(name[t].str, name[t].len), strndup(value[t].str, value[t].len));
+       printf("%s=%s\n", strdup_n(name[t].str, name[t].len), strdup_n(value[t].str, value[t].len));
     }
 #endif
     for(t=0;t<len;t++) {
@@ -1914,7 +1939,7 @@ static map_t parseArguments(char*command, char*pattern)
        }
        if(value[t].str == 0) {
            pushBack();
-           syntaxerror("value for parameter %s missing (no default)", strndup(name[t].str, name[t].len));
+           syntaxerror("value for parameter %s missing (no default)", strdup_n(name[t].str, name[t].len));
        }
     }