嗯,样本已更新
得到结果应该是
Global Const $ALLOC_LOG_CONF = 0x00000002
Global Const $BASIC_LOG_CONF = 0x00000000
Global Const $BOOT_LOG_CONF = 0x00000003
Global Const $CM_ADD_ID_BITS = 0x00000001
Global Const $CM_ADD_ID_COMPATIBLE = 0x00000001;以下三个作用相同,只取一个
Global Const $CM_ADD_ID_COMPATIBLE = 0x1
Global Const $CM_ADD_ID_COMPATIBLE = 1
Global Const $CM_ADD_ID_HARDWARE = 0x00000000
Global Const $CM_BIND_CLASS_BIND_DEVINST = 0x6 ;类似,只取一个
Global Const $CM_BIND_CLASS_BIND_DEVINST = 6
Global Const $CM_BIND_DEVINST_BIND_CLASS = 8
Global Const $CM_BIND_DEVINST_BIND_ID = 1
Global Const $CM_BIND_DEVINST_BIND_PHYSNAME = 2
Global Const $CM_BIND_ENUMERATOR_BIND_DEVINST = 32
Global Const $CM_BIND_PHYSNAME_BIND_DEVINST = 4
回复afan
正是此意,想通过删除重复行达到无需手工注释常量重定义目的,只是不懂正则,有个模型 ...
Qokelate 发表于 2012-7-12 14:35 http://www.autoitx.com/images/common/back.gif
这已经不是简单的重复行的问题了,简单的用正则是没法做到的……
只能用类似字典的方式来排查错误,而且只能是查,不能改,类似 Au3Check.exe 。否则可能会因为定义的常量值不同而出错。
其实你提供的范本没有错误,也无需删除重复变量。关键的对于常量的重复赋值的错误你却没有提出来,所以,本主题几乎无意义。
如果你想做到你目前的想法,比较简单的方法不妨先调用 Au3Check.exe ,从返回的信息来做替换为“If Not IsDeclared('xxx') Then Global $xxx ...”处理。那将是另外一个话题。 回复 17# afan
用5楼的代码,删除重复行的目的达成,剩下的相对就简单了,谢谢A版的耐心回复 本帖最后由 afan 于 2012-7-12 15:51 编辑
回复完才发现LZ已经改了范本,已经是常量重复定义的错误了。还有很多种情况是你没有想到的,也不会如此规则。简单的加点工就会增加不少难度。有兴趣就慢慢折腾吧,我的建议在 17 #Global Const $ALLOC_LOG_CONF = 0x00000002
Global Const $BASIC_LOG_CONF = 0x00000000
Global Const $BOOT_LOG_CONF = 0x00000003
Global Const$CM_ADD_ID_BITS = 0x00000001
Global Const $CM_ADD_ID_COMPATIBLE = 0x00000001;以下三个作用相同,只取一个
Global Const$CM_ADD_ID_COMPATIBLE = 0x1
Global Const $CM_ADD_ID_COMPATIBLE = 1
Global Const $CM_ADD_ID_HARDWARE = 0x00000000
Global Const $CM_BIND_CLASS_BIND_DEVINST = 0x6 ;类似,只取一个
Global Const $CM_BIND_PHYSNAME_BIND_DEVINST = 4, $CM_BIND_CLASS_BIND_DEVINST = 6
Global Const $CM_BIND_DEVINST_BIND_CLASS = 8
Global Const $CM_BIND_DEVINST_BIND_ID = 1
Dim Const $CM_BIND_ENUMERATOR_BIND_DEVINST = 32
Global Const $CM_BIND_DEVINST_BIND_PHYSNAME = 2
Global Const $CM_BIND_ENUMERATOR_BIND_DEVINST = 32
Func _a($x)
Global Const $CM_BIND_CLASS_BIND_DEVINST = 8
If $x Then Global Const$CM_ADD_ID_COMPATIBLE = 1
EndFunc 好玩的问题.AFAN兄17楼所说的确是个问题.
只是为了好玩,试下.
#include <Array.au3>
Local $Str = _
'Global Const $ALLOC_LOG_CONF = 0x00000002' & @CRLF & _
'Global Const $BASIC_LOG_CONF = 0x00000000' & @CRLF & _
'Global Const $BOOT_LOG_CONF = 0x00000003' & @CRLF & _
'Global Const$CM_ADD_ID_BITS = 0x00000001' & @CRLF & _
'Global Const $CM_ADD_ID_COMPATIBLE = 0x00000001;以下三个作用相同,只取一个' & @CRLF & _
'Global Const$CM_ADD_ID_COMPATIBLE = 0x1' & @CRLF & _
'Global Const $CM_ADD_ID_COMPATIBLE = 1' & @CRLF & _
'Global Const $CM_ADD_ID_HARDWARE = 0x00000000' & @CRLF & _
'Global Const $CM_BIND_CLASS_BIND_DEVINST = 0x6 ;类似,只取一个' & @CRLF & _
'Global Const $CM_BIND_PHYSNAME_BIND_DEVINST = 4, $CM_BIND_CLASS_BIND_DEVINST = 6' & @CRLF & _
'Global Const $CM_BIND_DEVINST_BIND_CLASS = 8' & @CRLF & _
'Global Const $CM_BIND_DEVINST_BIND_ID = 1' & @CRLF & _
'Dim Const $CM_BIND_ENUMERATOR_BIND_DEVINST = 32' & @CRLF & _
'Global Const $CM_BIND_DEVINST_BIND_PHYSNAME = 2' & @CRLF & _
'Global Const $CM_BIND_ENUMERATOR_BIND_DEVINST = 32' & @CRLF & _
'Func _a($x)' & @CRLF & _
' Global Const $CM_BIND_CLASS_BIND_DEVINST = 8' & @CRLF & _
' If $x Then Global Const$CM_ADD_ID_COMPATIBLE = 1' & @CRLF & _
'EndFunc'
$Str=StringRegExp($str, '(?msi)^global.*?(?=\Qfunc\E)', 3)
$Str=$Str
Local $Test = StringRegExp($str, '(?mi)^global.*?(\$[^=]+)=(.*?)(?=[\r\n;])', 3)
Local $Arr
For $i=0 To UBound($Test)-1 Step 2
$Arr[$i/2]=$Test[$i]
$Arr[$i/2]=Number(StringStripWS($Test[$i+1],3))
Next
_ArrayDisplay($Arr)
$new_arr=ArrayUnique($Arr)
_ArrayDisplay($new_arr)
Func ArrayUnique($aArray, $iBase = 0, $oBase = 0, $iCase = 0)
If Not IsArray($aArray) Then Return SetError(1, 0, 0)
If UBound($aArray, 0) > 2 Then Return SetError(2, 0, 0)
Local $oD = ObjCreate('Scripting.Dictionary')
If @error Then Return SetError(4, 0, 0)
Local $dim2 = UBound($aArray, 2)
If $dim2 Then ;2D array
Local $dim1 = UBound($aArray, 1), $aUnique[$dim1][$dim2], $j
For $i = 0 to $dim1 - 1
If Not $oD.Exists($aArray[$i]) Then
$oD.Add($aArray[$i], 0)
$aUnique[$j] = $aArray[$i]
$aUnique[$j] = $aArray[$i]
$j += 1
Else
If Not $oD.item($aArray[$i])=$aArray[$i] Then $aUnique[$j-1]=$aArray[$i]
EndIf
Next
ReDim $aUnique[$j]
Else ;1D array
For $i In $aArray
If Not $oD.Exists($i) Then $oD.Add($i, 0)
Next
Local $aUnique = $oD.Keys()
EndIf
$oD.RemoveAll
$oD = ""
Return $aUnique
EndFunc 呵呵...正则还是一头雾啊
页:
1
[2]