Subversion Repositories php-qbpwcf

Rev

Rev 226 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
226 liveuser 22
 
3 liveuser 23
*/
24
 
25
/*
26
逐一bytes比對兩個檔案有哪些bytes不同
27
*/
28
 
29
#使用命名空間qbpwcf
30
namespace qbpwcf;
31
 
32
#取得 lib path
33
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
34
 
35
#如果執行失敗
36
if($status!==0){
37
 
38
	#debug
39
	var_dump(__LINE__,$output);
40
 
41
	#結束執行,回傳shell 1.
42
	exit(1);
43
 
44
	}#if end
45
 
46
#儲存lib path
47
$folderOfUsrLib=$output[0];
48
 
49
#以該檔案的實際位置的 lib path 為 include path 首位
50
$output=array();
51
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
52
 
53
#如果執行失敗
54
if($status!==0){
55
 
56
	#debug
57
	var_dump(__LINE__,$output);
58
 
59
	#結束執行,回傳shell 1.
60
	exit(1);
61
 
62
	}#if end
63
 
226 liveuser 64
#設置 include path
3 liveuser 65
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
66
 
67
#匯入外部套件
68
include("allInOne.php");
69
 
70
#函式說明:
71
#抓取命令列的參數.
72
#回傳結果:
73
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
74
#$reuslt["error"],執行不正常結束的錯訊息陣列.
75
#$result["function"],當前執行的函式名稱.
76
#$result["argu"],使用的參數陣列.
77
#$result["content"],要回傳的參數陣列.
78
#$result["count"],參數的數量.
79
#必填參數:
80
#無
81
#可省略參數:
82
#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
83
$conf["echo"]="false";
84
$getArgu=cmd::getArgu($conf);
85
unset($conf);
86
 
87
#如果抓參數出錯
88
if($getArgu["status"]==="false")
89
{
90
	#印出內容
91
	var_dump($getArgu);
226 liveuser 92
 
3 liveuser 93
	#結束執行
94
	exit;
95
}
96
 
97
#如果參數數量不等於3
98
if($getArgu["count"]!==3)
99
{
100
	#印出內容
101
	var_dump($getArgu);
226 liveuser 102
 
3 liveuser 103
	#結束執行
104
	exit;
105
}
106
 
107
#取得檔案A名稱
108
$fileNameA=$getArgu["content"][1];
109
 
110
#取得檔案B名稱
111
$fileNameB=$getArgu["content"][2];
112
 
113
#檔案A的pointer
114
$fhA=fopen($fileNameA,"r");
115
 
116
#檔案B的pointer
117
$fhB=fopen($fileNameB,"r");
118
 
119
#位置索引
120
$addr=0;
121
 
122
#無窮迴圈
123
while(true)
124
{
125
	#位置從1開始,且每次+1.
126
	$addr++;
127
 
128
	#若檔案A尚未結束
129
	if(!feof($fhA))
130
	{
131
		#取得 1 bytes
132
		$bytesA=fread($fhA,1);
133
	}
226 liveuser 134
 
3 liveuser 135
	#若檔案B尚未結束
136
	if(!feof($fhB))
137
	{
138
		#取得 1 bytes
139
		$bytesB=fread($fhB,1);
140
	}
141
 
142
	#兩邊都有資料時
143
	if( isset($bytesA) && isset($bytesB) )
144
	{
145
		#解析A成16進位大小文數字
146
		$bytesA=strtoupper(sprintf("%02s",base_convert(ord($bytesA),10,16)));
226 liveuser 147
 
3 liveuser 148
		#解析B成16進位大小文數字
149
		$bytesB=strtoupper(sprintf("%02s",base_convert(ord($bytesB),10,16)));
226 liveuser 150
 
3 liveuser 151
		#如果有差異
152
		if($bytesA!==$bytesB)
153
		{
226 liveuser 154
 
3 liveuser 155
			echo "於第 ".$addr." 個bytes處相異,左方為:".$bytesA.";右方為:".$bytesB.PHP_EOL;
156
			unset($bytesA);
157
			unset($bytesB);
158
			continue;
159
		}
160
	}
226 liveuser 161
 
3 liveuser 162
	#單邊有資料
163
	else
164
	{
165
		if(isset($bytesA))
166
		{
167
			#解析A成16進位大小文數字
168
			$bytesA=strtoupper(sprintf("%02s",base_convert(ord($bytesA),10,16)));
226 liveuser 169
 
3 liveuser 170
			echo "於第 ".$addr." 個bytes處相異,左方為:".$bytesA.";右方不存在".PHP_EOL;
171
			unset($bytesA);
172
			continue;
173
		}
226 liveuser 174
 
3 liveuser 175
		else if(isset($bytesB))
176
		{
177
			#解析B成16進位大小文數字
178
			$bytesB=strtoupper(sprintf("%02s",base_convert(ord($bytesB),10,16)));
226 liveuser 179
 
3 liveuser 180
			echo "於第 ".$addr." 個bytes處相異,左方不存在;右方為:".$bytesB.PHP_EOL;
181
			unset($bytesB);
182
			continue;
183
		}
226 liveuser 184
 
3 liveuser 185
		else
186
		{
187
			break;
188
		}
189
	}
190
}
191
 
192
?>