Skip to content

Commit

Permalink
Initial commit, ported from subversion repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shevek committed Jul 15, 2011
0 parents commit 33f7176
Show file tree
Hide file tree
Showing 95 changed files with 18,729 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
docs/*.png
9 changes: 9 additions & 0 deletions README
@@ -0,0 +1,9 @@
There is no version of LZO in pure Java. The obvious solution is to
take the C source code, and feed it to the Java compiler, modifying
the Java compiler as necessary to make it compile.

This package is an implementation of that obvious solution, for which
I can only apologise to the world.

Shevek

178 changes: 178 additions & 0 deletions build.xml
@@ -0,0 +1,178 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="lzo" default="default" basedir=".">
<description>Builds, tests, and runs the project lzo.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="lzo-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->

<target name="jcpp">
<property name="build.dir" value="build" />
<property name="build.generated.sources.dir" value="build/generated-sources" />

<path id="antcontrib-classpath">
<fileset dir="lib/ant">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef
resource="net/sf/antcontrib/antlib.xml"
classpathref="antcontrib-classpath"
loaderref="ant" />

<mkdir dir="${build.dir}/timestamps" />
<mkdir dir="${build.generated.sources.dir}/jcpp" />

<outofdate>
<sourcefiles>
<fileset dir="jcpp">
<include name="**/*.jcpp" />
</fileset>
</sourcefiles>
<targetfiles path="${build.dir}/timestamps/timestamp.jcpp"/>
<sequential>
<path id="jcpp-classpath">
<fileset dir="lib/jcpp">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef
name="cpp"
classname="org.anarres.cpp.CppTask"
classpathref="jcpp-classpath"
loaderref="jcpp"
/>
<cpp todir="${build.generated.sources.dir}/jcpp">
<fileset dir="jcpp" includes="**/*.jcpp" />
<globmapper from="*.jcpp" to="*.java"/>
<systemincludepath>
</systemincludepath>
<localincludepath>
<pathelement path="jcpp/src" />
<pathelement path="jcpp/include" />
</localincludepath>
</cpp>
<!-- touch file="${build.dir}/timestamps/timestamp.jcpp" / -->
</sequential>
</outofdate>

<pathconvert property="rmwhite.files" pathsep=" ">
<path>
<fileset dir="${build.generated.sources.dir}/jcpp">
<include name="**/*.java" />
</fileset>
</path>
</pathconvert>
<exec executable="perl" osfamily="unix">
<arg value="-n" />
<arg value="-i" />
<arg value="-e" />
<arg value="/^\s+$/ or print;" />
<arg line="${rmwhite.files}" />
</exec>
</target>

<target name="jalopy" depends="init">
<path id="jalopy-classpath">
<fileset dir="lib/jalopy">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef
name="jalopy"
classpathref="jalopy-classpath"
classname="de.hunsicker.jalopy.plugin.ant.AntPlugin" />
<path id="jalopy-format-classpath" path="${javac.classpath}" />
<jalopy fileformat="unix"
loglevel="info"
classpathref="jalopy-format-classpath">
<fileset dir="${build.generated.sources.dir}/jcpp">
<include name="**/*.java" />
</fileset>
</jalopy>
</target>

<target name="jalopy-preferences">
<path id="jalopy-classpath">
<fileset dir="lib/jalopy">
<include name="**/*.jar" />
</fileset>
</path>
<java
classpathref="jalopy-classpath"
classname="de.hunsicker.jalopy.swing.SettingsDialog"
fork="true"
spawn="true"
/>
</target>

<target name="-pre-compile" depends="jcpp">
</target>

</project>
17 changes: 17 additions & 0 deletions docs/Makefile
@@ -0,0 +1,17 @@
TARGETS=

all : ${TARGETS}

.PRECIOUS : %.png

%.png : %.dot
dot -Tpng -o $*.png $*.dot

%.map : %.dot
dot -Tcmapx -o $*.map $*.dot

%.eog : %.png
eog $*.png

clean:
rm -f ${TARGETS}
55 changes: 55 additions & 0 deletions docs/state-machine.dot
@@ -0,0 +1,55 @@
digraph G {
node [shape=box];
init -> a_literal_run [label="0-15"];
init -> match [label="16,17"];
init -> match_next [label="18,19,20"];
init -> init_copy [label="21-255"];

init_copy [label="Initial copy\n*ip - 17 bytes follow"];
init_copy -> first_literal_run;

a_literal_run [label="A literal run\nlength=3 + RLE(15)"];

a_literal_run -> first_literal_run;

first_literal_run -> match [label="16-255"];

first_literal_run -> first_literal_run_do [label="0-15 (4 bits)"];

first_literal_run_do [label="First literal run\n0000ppxx qqqqqqqq\nop - M2_MAX_OFFSET - 1 - qqqqqqqqpp\n3 bytes\n"];

first_literal_run_do -> match_done;

match -> match_m2 [label=">= 64 / x1......"];
match -> match_m3 [label=">= 32 / 001....."];
match -> match_m4 [label=">= 16 / 0001...."];
match -> match_m1 [label="0000...."];

match_m2 [label="M2 match\nlllpppxx qqqqqqqq\nm_pos = op - 1 - qqqqqqqqppp\nt(len) = lll - 1"];
match_m2 -> copy_match;

match_m3 [label="M3 match\n001lllll RLE(32) ppppppxx qqqqqqqq\nm_pos = op - 1 - qqqqqqqqpppppp\nt(len) = RLE(32)"];
match_m3 -> pre_copy_match;

match_m4 [label="M4 match\n0001plll RLE(7) qqqqqqxx rrrrrrrr\nm_pos = op - prrrrrrrrqqqqqq\nt(len) = RLE(7)"];
match_m4 -> pre_copy_match;

match_m1 [label="M1 match\n0000ppxx qqqqqqqq\nm_pos = op - 1 - qqqqqqqqpp\nt(len) = 2"];
match_m1 -> match_done;

pre_copy_match -> copy_match;

copy_match [label="\N\ncopy t + 2 bytes from m_pos"];
copy_match -> match_done;

match_done [label="\N\nt(len) = ip[-2] & 3"];
match_done -> eof;
match_done -> match_next;
match_done -> init [label="xx = 0",constraint=false];

match_next [label="\N\nt = ______xx @ ip[-2]\ncopy xx from ip"];
match_next -> match [constraint=false];

eof;

}
8 changes: 8 additions & 0 deletions jcpp/include/lzo/lzo1x.h
@@ -0,0 +1,8 @@
/* Memory required for the wrkmem parameter.
* When the required size is 0, you can also pass a NULL pointer.
*/

#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
#define LZO1X_MEM_DECOMPRESS (0)
#define LZO1X_MEM_OPTIMIZE (0)

8 changes: 8 additions & 0 deletions jcpp/include/lzo/lzoconf.h
@@ -0,0 +1,8 @@
#ifndef __LZOCONF_H_INCLUDED
#define __LZOCONF_H_INCLUDED 1

#define LZO_VERSION 0x2050
#define LZO_VERSION_STRING "2.05-Java"
#define LZO_VERSION_DATE "Jul 8 2011"

#endif
41 changes: 41 additions & 0 deletions jcpp/include/lzojava.h
@@ -0,0 +1,41 @@
#define LZO_CFG_FREESTANDING 1
#define LZO_PUBLIC(x) public static x
#define LZO_UNUSED(x)
#define LZO_DEFINE_UNINITIALIZED_VAR(t,n,v) t n = v

#define const
#define register
#define unsigned
#define char byte
#define lzo_bytep byte[]
#define lzo_uint int
#define lzo_uint32 long
#define lzo_xint long // ?
#define lzo_voidp Object

#define GOTO_INIT() int state = init; // Java-goto
#define GOTO_BEGIN(label) label: for (;;) { switch (state) { case init: // Java-goto
#define GOTO_END() break; default: throw new IllegalStateException("Illegal state " + state); } break; }
#define GOTO_END_UNREACHABLE() default: throw new IllegalStateException("Illegal state " + state); } }

#define __lzo_unlikely(x) (x)

#define LZO_CPP_STRINGIZE(x) #x
#define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x)
#define LZO_CPP_CONCAT2(a,b) a ## b
#define LZO_CPP_CONCAT3(a,b,c) a ## b ## c
#define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d
#define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e
#define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b)
#define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c)
#define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d)
#define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e)

#define PTR(x) (x)
#define PTR_LT(a,b) (PTR(a) < PTR(b))
#define PTR_GE(a,b) (PTR(a) >= PTR(b))
#define PTR_DIFF(a, b) (PTR(a) - PTR(b))

#define U(x) ((x) & 0xff)
#define PRINT(x) // System.out.println(x)

55 changes: 55 additions & 0 deletions jcpp/org/anarres/lzo/LzoCompressor1x.jcpp
@@ -0,0 +1,55 @@
package org.anarres.lzo;

import java.util.Arrays;

public class LzoCompressor1x implements LzoConstants {

private static final int init = 0;
private static final int next = 1;
private static final int try_match = 2;
private static final int literal = 3;
private static final int m_len_done = 4;

#include "lzojava.h"

#if 1 //Java && defined(UA_GET32)
#undef LZO_DICT_USE_PTR
#define LZO_DICT_USE_PTR 0
#endif

#define pd(a,b) PTR_DIFF(a,b)

#define LZO_NEED_DICT_H 1
#ifndef D_BITS
#define D_BITS 14
#endif
#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
#if 1
#define DINDEX(dv,p) DM(((DMUL(0x1824429d,dv)) >> (32-D_BITS)))
#else
#define DINDEX(dv,p) DM((dv) + ((dv) >> (32-D_BITS)))
#endif
#include "config1x.h"
#define LZO_DETERMINISTIC (1)

#undef lzo_dict_t
#define lzo_dict_t int
#undef lzo_dict_p
#define lzo_dict_p int[]

#ifndef DO_COMPRESS
#define DO_COMPRESS lzo1x_1_compress
#endif

#define UA_INT(b) ((b) & 0xff)

public static int UA_GET32(byte[] in, int in_ptr) {
return (UA_INT(in[in_ptr]) << 24) | (UA_INT(in[in_ptr + 1]) << 16) | (UA_INT(in[in_ptr + 2]) << 8) | UA_INT(in[in_ptr + 3]);
}

#define lzo_uintptr_t int

#include "lzo1x_c.ch"

}

0 comments on commit 33f7176

Please sign in to comment.