---
 software/libfpvm/Makefile |    9 ++-
 software/libfpvm/fnp.ids  |  193 +++++++++++++++++++++++++++++++++++++++++++++
 software/libfpvm/idgen    |   57 +++++++++++++
 software/libfpvm/unique.c |  152 +++++++++++++++++++++++++++++++++++
 software/libfpvm/unique.h |   18 ++++
 5 files changed, 428 insertions(+), 1 deletions(-)
 create mode 100644 software/libfpvm/fnp.ids
 create mode 100755 software/libfpvm/idgen
 create mode 100644 software/libfpvm/unique.c
 create mode 100644 software/libfpvm/unique.h

diff --git a/software/libfpvm/Makefile b/software/libfpvm/Makefile
index d2aabc1..9248c84 100644
--- a/software/libfpvm/Makefile
+++ b/software/libfpvm/Makefile
@@ -1,7 +1,8 @@
 MMDIR=../..
 include $(MMDIR)/software/include.mak
 
-OBJECTS=fpvm.o parser_helper.o scanner.o parser.o gfpus.o lnfpus.o pfpu.o
+OBJECTS=fpvm.o parser_helper.o scanner.o parser.o gfpus.o lnfpus.o pfpu.o \
+       unique.o
 
 all: libfpvm.a
 
@@ -15,6 +16,9 @@ parser.h: parser.c
 %.c: %.y
        lemon $<
 
+%.h %.inc: %.ids
+       ./idgen $<
+
 libfpvm.a: $(OBJECTS)
        $(AR) clr libfpvm.a $(OBJECTS)
        $(RANLIB) libfpvm.a
@@ -26,6 +30,7 @@ depend: parser.c scanner.c
 
 clean:
        rm -f $(OBJECTS) scanner.c parser.c parser.h parser.out libfpvm.a .*~ 
*~ Makefile.bak
+       rm -f fnp.h fnp.inc
 
 # DO NOT DELETE
 
@@ -67,3 +72,5 @@ scanner.o: ../../software/include/base/stdio.h
 scanner.o: ../../software/include/base/stdlib.h
 scanner.o: ../../software/include/base/string.h
 scanner.o: ../../software/include/base/malloc.h scanner.h parser.h
+unique.o: ../../software/include/base/stdlib.h
+unique.o: ../../software/include/base/string.h unique.h fnp.inc
diff --git a/software/libfpvm/fnp.ids b/software/libfpvm/fnp.ids
new file mode 100644
index 0000000..1016fe8
--- /dev/null
+++ b/software/libfpvm/fnp.ids
@@ -0,0 +1,193 @@
+#
+# Per-Frame Variables
+#
+
+sx
+sy
+cx
+cy
+rot
+dx
+dy
+zoom
+decay
+wave_mode
+wave_scale
+wave_additive
+wave_usedots
+wave_brighten
+wave_thick
+wave_x
+wave_y
+wave_r
+wave_g
+wave_b
+wave_a
+
+ob_size
+ob_r
+ob_g
+ob_b
+ob_a
+ib_size
+ib_r
+ib_g
+ib_b
+ib_a
+
+nMotionVectorsY
+mv_dx
+mv_dy
+mv_l
+mv_r
+mv_g
+mv_b
+mv_a
+
+bTexWrap
+
+time
+bass
+mid
+treb
+bass_att
+mid_att
+treb_att
+
+warp
+fWarpAnimSpeed
+fWarpScale
+
+q1
+q2
+q3
+q4
+q5
+q6
+q7
+q8
+
+fVideoEchoAlpha
+fVideoEchoZoom
+nVideoEchoOrientation
+
+dmx1
+dmx2
+dmx3
+dmx4
+dmx5
+dmx6
+dmx7
+dmx8
+
+idmx1
+idmx2
+idmx3
+idmx4
+idmx5
+idmx6
+idmx7
+idmx8
+
+osc1
+osc2
+osc3
+osc4
+
+midi1
+midi2
+midi3
+midi4
+midi5
+midi6
+midi7
+midi8
+
+video_a
+
+image1_a
+image1_x
+image1_y
+image1_zoom
+image2_a
+image2_x
+image2_y
+image2_zoom
+
+#
+# Aliases
+#
+
+fDecay
+nWaveMode
+fWaveScale
+bAdditiveWaves
+bWaveDots
+bMaximizeWaveColor
+bWaveThick
+fWaveAlpha
+
+#
+# Per-Vertex Variables
+#
+
+# System
+
+_texsize
+_hmeshsize
+_vmeshsize
+
+# MilkDrop
+
+sx
+sy
+cx
+cy
+rot
+dx
+dy
+zoom
+
+time
+bass
+mid
+treb
+bass_att
+mid_att
+treb_att
+
+warp
+fWarpAnimSpeed
+fWarpScale
+
+q1
+q2
+q3
+q4
+q5
+q6
+q7
+q8
+
+idmx1
+idmx2
+idmx3
+idmx4
+idmx5
+idmx6
+idmx7
+idmx8
+
+osc1
+osc2
+osc3
+osc4
+
+midi1
+midi2
+midi3
+midi4
+midi5
+midi6
+midi7
+midi8
diff --git a/software/libfpvm/idgen b/software/libfpvm/idgen
new file mode 100755
index 0000000..98069cc
--- /dev/null
+++ b/software/libfpvm/idgen
@@ -0,0 +1,57 @@
+#!/bin/sh -e
+#
+# idgen - Identifier table generator
+#
+# Copyright 2011 by Werner Almesberger
+#
+# 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, version 3 of the License.
+#
+
+
+usage()
+{
+       echo "usage: $0 file" 1>&2
+       exit 1
+}
+
+
+[ "$1" ] || usage
+[ "$2" ] && usage
+[ -r "$1" ] || { echo "$1: not found" 1&2; exit 1; }
+
+trap "echo $1.h $1.inc" 0
+
+f=`basename "$1" .ids`
+
+cat <<EOF >$f.h
+/* MACHINE-GENERATED. DO NOT EDIT ! */
+
+#ifndef        IDS_H
+#define        IDS_H
+
+extern const char *well_known[];
+
+EOF
+
+cat <<EOF >$f.inc
+/* MACHINE-GENERATED. DO NOT EDIT ! */
+
+EOF
+
+sed 's/#.*//;s/ //g;/^$/d' $1 | sort | uniq | {
+       i=0
+       while read n; do
+               echo "#define ID_$n (well_known[$i])" >>$f.h
+               echo "\"$n\"," >>$f.inc
+               i=`expr $i + 1`
+       done
+}
+
+cat <<EOF >>$f.h
+
+#endif /* !IDS_H */
+EOF
+
+trap 0
diff --git a/software/libfpvm/unique.c b/software/libfpvm/unique.c
new file mode 100644
index 0000000..476118a
--- /dev/null
+++ b/software/libfpvm/unique.c
@@ -0,0 +1,152 @@
+/*
+ * unique.c - Unique string store
+ *
+ * Copyright 2011 by Werner Almesberger
+ *
+ * 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, version 3 of the License.
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "unique.h"
+
+
+#define        INITIAL_ALLOC   64
+
+
+const char *well_known[] = {
+#include "fnp.inc"
+};
+
+static const char **vars = NULL;
+static int num_vars = 0, allocated = 0;
+
+
+/* We don't have bsearch, so here's our own version. */
+
+static const char *search(const char *s)
+{
+       int low = 0;
+       int high = sizeof(well_known)/sizeof(*well_known)-1;
+       int mid, res;
+
+       while(low <= high) {
+               mid = (low+high)/2;
+               res = strcmp(s, well_known[mid]);
+               if(!res)
+                       return well_known[mid];
+               if(res < 0)
+                       high = mid-1;
+               else
+                       low = mid+1;
+       }
+       return NULL;
+}
+
+
+static const char *search_n(const char *s, int n)
+{
+       int low = 0;
+       int high = sizeof(well_known)/sizeof(*well_known)-1;
+       int mid, res;
+
+       while(low <= high) {
+               mid = (low+high)/2;
+               res = strncmp(s, well_known[mid], n+1);
+               if(!res)
+                       return well_known[mid];
+               if(res < 0)
+                       high = mid-1;
+               else
+                       low = mid+1;
+       }
+       return NULL;
+}
+
+
+/* We don't have strdup either. */
+
+static char *my_strdup(const char *s)
+{
+       size_t len;
+       char *new;
+
+       len = strlen(s)+1;
+       new = malloc(len);
+       memcpy(new, s, len);
+       return new;
+}
+
+
+static char *my_strdup_n(const char *s, int n)
+{
+       char *new;
+
+       new = malloc(n+1);
+       memcpy(new, s, n);
+       new[n] = 0;
+       return new;
+}
+
+
+static void grow_table(void)
+{
+       int allocate;
+       const char **new;
+
+       if(num_vars != allocated)
+               return;
+
+       /* There's no realloc, so we roll our own.  */
+       allocate = allocated ? allocated*2 : INITIAL_ALLOC;
+       new = malloc(allocate*sizeof(*vars));
+       memcpy(new, vars, allocated*sizeof(*vars));
+       vars = new;
+}
+
+
+const char *unique(const char *s)
+{
+       const char *res;
+       const char **walk;
+
+       res = search(s);
+       if(res)
+               return res;
+       for(walk = vars; walk != vars+num_vars; walk++)
+               if(!strcmp(*walk, s))
+                       return *walk;
+       grow_table();
+       return vars[num_vars++] = my_strdup(s);
+}
+
+
+const char *unique_n(const char *s, int n)
+{
+       const char *res;
+       const char **walk;
+
+       res = search_n(s, n);
+       if(res)
+               return res;
+       for(walk = vars; walk != vars+num_vars; walk++)
+               if(!strncmp(*walk, s, n+1))
+                       return *walk;
+       grow_table();
+       return vars[num_vars++] = my_strdup_n(s, n);
+}
+
+
+void unique_free(void)
+{
+       int i;
+
+       for(i = 0; i != num_vars; i++)
+               free((void *) vars[i]);
+       free(vars);
+       num_vars = allocated = 0;
+}
diff --git a/software/libfpvm/unique.h b/software/libfpvm/unique.h
new file mode 100644
index 0000000..ff069ac
--- /dev/null
+++ b/software/libfpvm/unique.h
@@ -0,0 +1,18 @@
+/*
+ * unique.h - Unique string store
+ *
+ * Copyright 2011 by Werner Almesberger
+ *
+ * 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, version 3 of the License.
+ */
+
+#ifndef UNIQUE_H
+#define        UNIQUE_H
+
+const char *unique(const char *s);
+const char *unique_n(const char *s, int n);
+void unique_free(void);
+
+#endif /* !UNIQUE_H */
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to