コード例 #1
0
/**
 * @param $filename
 * @param $array
 * @return mixed
 */
function write_txt($filename, $array)
{
    if (do_overwrite($filename, false) == !false) {
        $content = "";
        foreach ($array as $_OPTB_WOC) {
            $content .= $_OPTB_WOC['LABEL'] . "\t" . $_OPTB_WOC['OPCODE'] . "\t" . $_OPTB_WOC['OPERAND'];
            $content .= "\r\n";
        }
        file_put_contents($filename, $content);
    }
    return;
}
コード例 #2
0
function print_r_to_html($fileName, $value, $title = "")
{
    if (file_exists($fileName) == !false) {
        //unlink($fileName);	## deleter the last time running result file..
    } else {
        do_overwrite($fileName, false);
    }
    ## create error.log if not exist...
    ## Operand table(with object code) result store in html to present...
    $optb_woc_File = fopen($fileName, "w") or die("Unable to open file!");
    $log = "\r\n\t\t\t\t\t\t<html>\r\n\t\t\t\t\t\t<head>\r\n\t\t\t\t\t\t<title>" . $title . "</title>\r\n\t\t\t\t\t\t</head>\r\n\t\t\t\t\t\t<body>\r\n\t\t\t\t\t\t";
    $log .= "<pre>" . print_r($value, true) . "</pre>";
    $log .= "\r\n\t\t\t\t\t\t</body>\t\r\n\t\t\t\t\t\t</html>\r\n\t\t\t\t\t\t";
    fwrite($optb_woc_File, $log);
    fclose($optb_woc_File);
}
コード例 #3
0
ファイル: sic.php プロジェクト: BrokenPen/SIC-XE-Assembler
function show_progress()
{
    echo "------------------------------------------------------------------------\n";
    echo "Program progress : " . PHP_EOL;
    $readmeFile = dirname(__FILE__) . '/readme.txt';
    do_overwrite($readmeFile, false);
    $handle = @fopen($readmeFile, "r");
    if ($handle) {
        while (($buffer = fgets($handle, 4096)) !== false) {
            echo "  " . $buffer;
        }
        if (!feof($handle)) {
            echo "Error: unexpected fgets() fail\n";
        }
        fclose($handle);
    }
}
コード例 #4
0
 public function writeCsv($filename)
 {
     if (do_overwrite($filename, false) == !false) {
         if (max(array_column($this->OPTB_WOC, 'BLOCK')) == 0) {
             // fix bug-_-
             $column = array('LINE', 'LOC', 'LABEL', 'OPCODE', 'OPERAND', 'OBJECTCODE');
             foreach ($column as $key) {
                 if (!isset($_OPTB_WOC[$key])) {
                     $_OPTB_WOC[$key] = '';
                 }
             }
             $content = "LINE\tLOC\tLABEL\tOPCODE\tOPERAND\tOBJECTCODE";
             $content .= "\r\n";
             foreach ($this->OPTB_WOC as $_OPTB_WOC) {
                 if (empty($_OPTB_WOC['LOC'])) {
                     $_OPTB_WOC['BLOCK'] = '';
                     $_OPTB_WOC['OBJECTCODE'] = '';
                 }
                 // fix bug= =
                 $content .= $_OPTB_WOC['LINE'] . "," . $_OPTB_WOC['LOC'] . "," . $_OPTB_WOC['LABEL'] . "," . $_OPTB_WOC['OPCODE'] . "," . $_OPTB_WOC['OPERAND'] . "," . $_OPTB_WOC['OBJECTCODE'];
                 $content .= "\r\n";
             }
         } else {
             $content = "LINE\tLOC\tBLOCK\tLABEL\tOPCODE\tOPERAND\tOBJECTCODE";
             $content .= "\r\n";
             foreach ($this->OPTB_WOC as $_OPTB_WOC) {
                 if (empty($_OPTB_WOC['LOC'])) {
                     $_OPTB_WOC['BLOCK'] = '';
                     $_OPTB_WOC['OBJECTCODE'] = '';
                 }
                 // fix bug= =
                 $content .= $_OPTB_WOC['LINE'] . "," . $_OPTB_WOC['LOC'] . "," . $_OPTB_WOC['BLOCK'] . "," . $_OPTB_WOC['LABEL'] . "," . $_OPTB_WOC['OPCODE'] . "," . $_OPTB_WOC['OPERAND'] . "," . $_OPTB_WOC['OBJECTCODE'];
                 $content .= "\r\n";
             }
         }
         file_put_contents($filename, $content);
     }
 }
コード例 #5
0
ファイル: config.php プロジェクト: BrokenPen/SIC-XE-Assembler
## require some class
//require_once("./load_class.php"); // error - -
require_once CLASS_PATH . "ReadFile.php";
## read operand table , txt or csv
## Deloveping now...
require_once CLASS_PATH . "GenerateObjectCode.php";
require_once CLASS_PATH . "GenerateObjectProgram.php";
## downloaded class..
require_once CLASS_PATH . "class.Diff.php";
## template for output log
define("OUTPUT_LOG_PREFIX", date("Y-m-d-His") . "_");
echo "Now : " . OUTPUT_LOG_PREFIX . "\n";
//echo "Now : ". OUTPUT_LOG_PREFIX ."\n";
define("EORROR_LOG_FILE", dirname(__FILE__) . "/error.log");
if (file_exists(EORROR_LOG_FILE) == false) {
    do_overwrite(EORROR_LOG_FILE);
}
## create error.log if not exist...
## make sure error.lg are empty
$logFile = fopen(EORROR_LOG_FILE, "w") or die("Unable to open file!");
$log = "Error " . OUTPUT_LOG_PREFIX . " : ";
fwrite($logFile, $log);
fclose($logFile);
ini_set("log_errors", 1);
ini_set("error_log", "error.log");
# generate the sic symbol table[array] from a symtb.csv
# global $SYMTB use in class...
/****************************************************************
 *	Note : I also add WD TD in the optab csv... too				*
 ***************************************************************/
/****************************************************************
コード例 #6
0
function create_file($filename, $content, $overwrite = false)
{
    if (do_overwrite($filename, $overwrite) == !false) {
        file_put_contents($filename, $content);
    }
}
コード例 #7
0
function json_to_csv($json_filename, $csv_filename, $csv_delimiter = ",", $overwrite = false)
{
    //echo "Hi I'm json_to_csv function\n";
    if (($array = json_decode(file_get_contents($json_filename), false)) == !false) {
        //print_r($array);
        //print_r_to_html("../test/test_json_array.html",$array);
        if (do_overwrite($csv_filename, $overwrite) == false) {
            //echo "Hi I in do_overwrite == false\n";
            return false;
        }
        //echo "Hi f****r, bye f****r\n";
        if (($fp = fopen($csv_filename, 'w')) == !false) {
            //echo "Hi I in fopen == !false\n";
            $line_index = 0;
            $line_length = count($array);
            ## count how  many line...
            $content = "";
            var_dump($line_length);
            //echo "Last key : ". $last_key ."\n";
            foreach ($array as $line) {
                end($line);
                ## move the internal pointer to the end of the array
                $last_key = key($line);
                ## this code fail, <int>1 <---
                //$key_length = count($line);	## count how  many element ...
                //var_dump($key_length); ## <int>1
                ++$line_index;
                ## add line number..
                $key_index = 0;
                foreach ($line as $key => $value) {
                    echo $key;
                    //break;
                    if ($line_index === 1) {
                        ++$key_index;
                        $content .= $key;
                        if ($key !== $last_key) {
                            $content .= $csv_delimiter;
                        } else {
                            if ($key == $last_key) {
                                echo "new line\n";
                                $content .= "\n";
                            }
                        }
                    } else {
                        ++$key_index;
                        $content .= $value;
                        //if($key_index !== $key_length)
                        if ($key !== $last_key) {
                            $content .= $csv_delimiter;
                        } else {
                            if ($key == $last_key) {
                                $content .= "\n";
                            }
                        }
                    }
                }
                ## end foreach in a line
                //fwrite($csv_filename, $content);
            }
            ## end foreach line
            fwrite($fp, $content);
            fclose($fp);
            return true;
            ## json_to_csv success
        } else {
            return false;
        }
    } else {
        return false;
    }
}