Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 621 | Rev 906 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
464 liveuser 5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
621 liveuser 6
    Copyright (C) 2015~2024 Min-Jhin,Chen
464 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/>.
22
 
23
*/
24
 
25
/*
1 liveuser 26
逐一bytes比對兩個檔案有哪些bytes不同
27
*/
28
 
29
#使用命名空間qbpwcf
30
namespace qbpwcf;
31
 
466 liveuser 32
#以該檔案的實際位置的 lib path 為 include path 首位
33
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../;pwd;",$output,$status);
34
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
35
 
1 liveuser 36
#匯入外部套件
466 liveuser 37
include("allInOne.php");
1 liveuser 38
 
39
#函式說明:
40
#抓取命令列的參數.
41
#回傳結果:
42
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
43
#$reuslt["error"],執行不正常結束的錯訊息陣列.
44
#$result["function"],當前執行的函式名稱.
45
#$result["argu"],使用的參數陣列.
46
#$result["content"],要回傳的參數陣列.
47
#$result["count"],參數的數量.
48
#必填參數:
49
#無
50
#可省略參數:
51
#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
52
$conf["echo"]="false";
53
$getArgu=cmd::getArgu($conf);
54
unset($conf);
55
 
56
#如果抓參數出錯
57
if($getArgu["status"]==="false")
58
{
59
	#印出內容
60
	var_dump($getArgu);
61
 
62
	#結束執行
63
	exit;
64
}
65
 
66
#如果參數數量不等於3
67
if($getArgu["count"]!==3)
68
{
69
	#印出內容
70
	var_dump($getArgu);
71
 
72
	#結束執行
73
	exit;
74
}
75
 
76
#取得檔案A名稱
77
$fileNameA=$getArgu["content"][1];
78
 
79
#取得檔案B名稱
80
$fileNameB=$getArgu["content"][2];
81
 
82
#檔案A的pointer
83
$fhA=fopen($fileNameA,"r");
84
 
85
#檔案B的pointer
86
$fhB=fopen($fileNameB,"r");
87
 
88
#位置索引
89
$addr=0;
90
 
91
#無窮迴圈
92
while(true)
93
{
94
	#位置從1開始,且每次+1.
95
	$addr++;
96
 
97
	#若檔案A尚未結束
98
	if(!feof($fhA))
99
	{
100
		#取得 1 bytes
101
		$bytesA=fread($fhA,1);
102
	}
103
 
104
	#若檔案B尚未結束
105
	if(!feof($fhB))
106
	{
107
		#取得 1 bytes
108
		$bytesB=fread($fhB,1);
109
	}
110
 
111
	#兩邊都有資料時
112
	if( isset($bytesA) && isset($bytesB) )
113
	{
114
		#解析A成16進位大小文數字
115
		$bytesA=strtoupper(sprintf("%02s",base_convert(ord($bytesA),10,16)));
116
 
117
		#解析B成16進位大小文數字
118
		$bytesB=strtoupper(sprintf("%02s",base_convert(ord($bytesB),10,16)));
119
 
120
		#如果有差異
121
		if($bytesA!==$bytesB)
122
		{
123
 
124
			echo "於第 ".$addr." 個bytes處相異,左方為:".$bytesA.";右方為:".$bytesB.PHP_EOL;
125
			unset($bytesA);
126
			unset($bytesB);
127
			continue;
128
		}
129
	}
130
 
131
	#單邊有資料
132
	else
133
	{
134
		if(isset($bytesA))
135
		{
136
			#解析A成16進位大小文數字
137
			$bytesA=strtoupper(sprintf("%02s",base_convert(ord($bytesA),10,16)));
138
 
139
			echo "於第 ".$addr." 個bytes處相異,左方為:".$bytesA.";右方不存在".PHP_EOL;
140
			unset($bytesA);
141
			continue;
142
		}
143
 
144
		else if(isset($bytesB))
145
		{
146
			#解析B成16進位大小文數字
147
			$bytesB=strtoupper(sprintf("%02s",base_convert(ord($bytesB),10,16)));
148
 
149
			echo "於第 ".$addr." 個bytes處相異,左方不存在;右方為:".$bytesB.PHP_EOL;
150
			unset($bytesB);
151
			continue;
152
		}
153
 
154
		else
155
		{
156
			break;
157
		}
158
	}
159
}
160
 
161
?>