if (!function_exists('file_put_contents')) {
function file_put_contents($filename, $data, $respect_lock = true) {
// Open the file for writing
$fh = @fopen($filename, 'w');
if ($fh === false) {
return false;
}
// Check to see if we want to make sure the file is locked before we write to it
if ($respect_lock === true && !flock($fh, LOCK_EX)) {
fclose($fh);
return false;
}
// Convert the data to an acceptable string format
if (is_array($data)) {
$data = implode('', $data);
} else {
$data = (string) $data;
}
// Write the data to the file and close it
$bytes = fwrite($fh, $data);
// This will implicitly unlock the file if it's locked
fclose($fh);
return $bytes;
}
}
function remove_extension($strName) {
$ext = strrchr($strName, '.');
if($ext !== false) {
$strName = substr($strName, 0, -strlen($ext));
}
return $strName;
}
function enable_sources($path_to_jar,$name_jar,$file_name) {
$whoami=shell_exec("whoami");
$whoami=rtrim($whoami);
$whoami=ltrim($whoami);
$tmp_dir="/tmp/costa-".$whoami."/web";
$command="cp $path_to_jar $tmp_dir ; chmod a+rwx ".$tmp_dir."/".$name_jar."; cd $tmp_dir ; jar -xf $name_jar $file_name.class; chmod -R a+rwx $tmp_dir";
shell_exec($command);
}
function methods($file_name,$context,$edition) {
if (substr_count($file_name, 'net/datastructures/')==1) {
$netdatastruc_jar="net-datastructures-3-0.jar";
$pathnet_jar="../../../../../../costa-extra/Test_Programs/net/datastructures/".$netdatastruc_jar;
enable_sources($pathnet_jar,$netdatastruc_jar,$file_name);
}
if (substr_count($file_name, 'conditional')==1) {
$conditional_jar="conditional.jar";
$pathconditional_jar="../../../../../../costa-extra/Test_Programs/conditional/".$conditional_jar;
enable_sources($pathconditional_jar,$conditional_jar,$file_name);
}
if (substr_count($file_name, 'memory')==1) {
$memory_jar="memory.jar";
$pathmemory_jar="../../../../../../costa-extra/Test_Programs/memory/".$memory_jar;
enable_sources($pathmemory_jar,$memory_jar,$file_name);
}
if (substr_count($file_name, 'midp')==1) {
$midp_jar="midp.jar";
$pathmidp_jar="../../../../../../costa-extra/Test_Programs/midp/".$midp_jar;
enable_sources($pathmidp_jar,$midp_jar,$file_name);
}
if ($edition=='phoneME') {
$phoneme_jar="phoneme.jar";
$pathphoneme_jar="../../../../../../costa-extra/Test_Programs/phoneME/".$phoneme_jar;
enable_sources($pathphoneme_jar,$phoneme_jar,$file_name);
}
if (substr_count($file_name, 'series')==1) {
$series_jar="series.jar";
$pathseries_jar="../../../../../../costa-extra/Test_Programs/series/".$series_jar;
enable_sources($pathseries_jar,$series_jar,$file_name);
}
if
(file_exists("/tmp/costa-www-data/web/".$file_name.".class")||file_exists("../../../../../examples/".$file_name.".class"))
{
shell_exec("cd ../../../../../examples; chmod a+rx -R . ");
$execute="chmod a+rwx ./get_methods.pl; ./get_methods.pl '".$file_name."'";
$show_methods=shell_exec($execute); /////list of methods in class
if ($show_methods!="") {
$list=htmlentities($show_methods);
show_methods($list,$context,$file_name);
}
} else {
echo " WARNING: Compilation error, verify your source file
";
die("Please click 'back' on your browser.");
}
}
function show_methods($list,$context,$file_name) {
$acm=substr_count($list,'main([Ljava/lang/String;)V');
$acm_cmd=substr_count($list,'commandAction(Ljavax/microedition/lcdui/Command;Ljavax/microedition/lcdui/Displayable;)V');
if(substr_count($list,',')>0) {
$method_signature=explode(',',$list);
}else {
$method_signature=explode(" ",$list);
}
$limit=count($method_signature);
if ($limit>1) {
$limit=$limit-1;
}
if ($acm == 1 || $acm_cmd == 1) { // there is a main or cmdAction
for($i=0; $i < $limit; $i ++) { // bubble
if(substr_count($method_signature[$i],'main([Ljava/lang/String;)V')==1 || substr_count($method_signature[$i],'commandAction(Ljavax/microedition/lcdui/Command;Ljavax/microedition/lcdui/Displayable;)V')==1) {
$aux=$method_signature[0];
$method_signature[0]=$method_signature[$i];
$method_signature[$i]=$aux;
}
}
if (substr_count($file_name,'x10') != 1){
?> or Select All " ";
}
echo " ";
for($i=0; $i < $limit; $i ++) {
$method_sign=htmlentities($method_signature[$i]);
if($i==0) {
//if(substr_count($method_sign,'main([Ljava/lang/String;)V')==1 || substr_count($method_sign,'commandAction(Ljavax/microedition/lcdui/Command;Ljavax/microedition/lcdui/Displayable;)V')==1){
//echo " $method_signature[$i]"." ";
echo " $method_signature[$i]"." ";
} else {
echo " $method_signature[$i] "." ";
}
}
if($context!="") {
$size=strlen($context);
echo "
package memory.jolden.bisort;
/**
* A class that represents a value to be sorted by the <tt>BiSort</tt>
* algorithm. We represents a values as a node in a binary tree.
**/
class Value
{
private int value;
private Value left;
private Value right;
static final boolean FORWARD = false;
static final boolean BACKWARD = true;
// These are used by the Olden benchmark random no. generator
private static final int CONST_m1 = 10000;
private static final int CONST_b = 31415821;
static final int RANGE = 100;
/**
* Constructor for a node representing a value in the bitonic sort tree.
* @param v the integer value which is the sort key
**/
Value(int v)
{
value = v;
left = right = null;
}
/**
* Create a random tree of value to be sorted using the bitonic sorting algorithm.
*
* @param size the number of values to create.
* @param seed a random number generator seed value
* @return the root of the (sub) tree.
**/
static Value createTree(int size, int seed)
{
if (size > 1) {
seed = random(seed);
int next_val = seed % RANGE;
Value retval = new Value(next_val);
retval.left = createTree(size/2, seed);
retval.right = createTree(size/2, skiprand(seed, size+1));
return retval;
} else {
return null;
}
}
/**
* Perform a bitonic sort based upon the Bilardi and Nicolau algorithm.
*
* @param spr_val the "spare" value in the algorithm.
* @param direction the direction of the sort (forward or backward)
* @return the new "spare" value.
**/
int bisort(int spr_val, boolean direction)
{
if (left == null) {
if ((value > spr_val) ^ direction) {
int tmpval = spr_val;
spr_val = value;
value = tmpval;
}
} else {
int val = value;
value = left.bisort(val, direction);
boolean ndir = !direction;
spr_val = right.bisort(spr_val, ndir);
spr_val = bimerge(spr_val, direction);
}
return spr_val;
}
/**
* Perform the merge part of the bitonic sort. The merge part does
* the actualy sorting.
* @param spr_val the "spare" value in the algorithm.
* @param direction the direction of the sort (forward or backward)
* @return the new "spare" value
**/
int bimerge(int spr_val, boolean direction)
{
int rv = value;
Value pl = left;
Value pr = right;
boolean rightexchange = (rv > spr_val) ^ direction;
if (rightexchange) {
value = spr_val;
spr_val = rv;
}
while (pl != null) {
int lv = pl.value;
Value pll = pl.left;
Value plr = pl.right;
rv = pr.value;
Value prl = pr.left;
Value prr = pr.right;
boolean elementexchange = (lv > rv) ^ direction;
if (rightexchange) {
if (elementexchange) {
pl.swapValRight(pr);
pl = pll;
pr = prl;
} else {
pl = plr;
pr = prr;
}
} else {
if (elementexchange) {
pl.swapValLeft(pr);
pl = plr;
pr = prr;
} else {
pl = pll;
pr = prl;
}
}
}
if (left != null) {
value = left.bimerge(value, direction);
spr_val = right.bimerge(spr_val, direction);
}
return spr_val;
}
/**
* Swap the values and the right subtrees.
* @param n the other subtree involved in the swap.
**/
void swapValRight(Value n)
{
int tmpv = n.value;
Value tmpr = n.right;
n.value = value;
n.right = right;
value = tmpv;
right = tmpr;
}
/**
* Swap the values and the left subtrees.
* @param n the other subtree involved in the swap.
**/
void swapValLeft(Value n)
{
int tmpv = n.value;
Value tmpl = n.left;
n.value = value;
n.left = left;
value = tmpv;
left = tmpl;
}
/**
* Print out the nodes in the binary tree in infix order.
**/
void inOrder()
{
if (left != null)
left.inOrder();
System.out.println(value + " " + hashCode());
if (right != null)
right.inOrder();
}
/**
* A random generator. The original Olden benchmark uses its
* own random generator. We use the same one in the Java version.
* @return the next random number in the sequence.
**/
private static int mult(int p, int q)
{
int p1 = p/CONST_m1;
int p0 = p%CONST_m1;
int q1 = q/CONST_m1;
int q0 = q%CONST_m1;
return (((p0*q1+p1*q0) % CONST_m1) * CONST_m1+p0*q0);
}
/**
* A routine to skip the next <i>n</i> random numbers.
* @param seed the current random no. seed
* @param n the number of numbers to skip
**/
private static int skiprand(int seed, int n)
{
for (; n > 0; n--) seed = random(seed);
return seed;
}
/**
* Return a random number based upon the seed value.
* @param seed the random number seed value
* @return a random number based upon the seed value.
**/
static int random(int seed)
{
int tmp = mult(seed, CONST_b) + 1;
return tmp;
}
}