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 "