1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| ' ----------------------------------------------------------
' Script de Conversion OEM -> ANSI
'
' Syntaxe:
' oem2ansi <srce> <dest>
' <srce> : fichier source (texte OEM)
' <dest> : fichier destination (texte ANSI)
'
' JC BELLAMY © 2002
' ----------------------------------------------------------
Dim oem
oem=array( _
"00","01","02","03","04","05","06","07","08","09","0A","0B","0C","0D","0E","0F", _
"10","11","12","13","14","15","16","17","18","19","1A","1B","1C","1D","1E","1F", _
"20","21","22","23","24","25","26","27","28","29","2A","2B","2C","2D","2E","2F", _
"30","31","32","33","34","35","36","37","38","39","3A","3B","3C","3D","3E","3F", _
"40","41","42","43","44","45","46","47","48","49","4A","4B","4C","4D","4E","4F", _
"50","51","52","53","54","55","56","57","58","59","5A","5B","5C","5D","5E","5F", _
"60","61","62","63","64","65","66","67","68","69","6A","6B","6C","6D","6E","6F", _
"70","71","72","73","74","75","76","77","78","79","7A","7B","7C","7D","7E","7F", _
"C7","FC","E9","E2","E4","E0","E5","E7","EA","EB","E8","EF","EE","EC","C4","C5", _
"C9","E6","C6","F4","F6","F2","FB","F9","FF","D6","DC","F8","A3","D8","D7","83", _
"E1","ED","F3","FA","F1","D1","AA","BA","BF","AE","AC","BD","BC","A1","AB","BB", _
"A6","A6","A6","A6","A6","C1","C2","C0","A9","A6","A6","2B","2B","A2","A5","2B", _
"2B","2D","2D","2B","2D","2B","E3","C3","2B","2B","2D","2D","A6","2D","2B","A4", _
"F0","D0","CA","CB","C8","69","CD","CE","CF","2B","2B","A6","5F","A6","CC","AF", _
"D3","DF","D4","D2","F5","D5","B5","FE","DE","DA","DB","D9","FD","DD","AF","B4", _
"AD","B1","3D","BE","B6","A7","F7","B8","B0","A8","B7","B9","B3","B2","A6","A0")
ForReading = 1
ForWriting = 2
Dim args, fso, fsrce, fdest
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set args = Wscript.Arguments
' Conversion OEM -> ANSI
If args.count<2 Then
strFullName =lcase(WScript.FullName)
i=InStr(1,strFullName,".exe",1)
j=InStrRev(strFullName,"\",i,1)
strCommand=Mid(strFullName,j+1,i-j-1)
if strCommand<>"cscript" then
Mess= "Conversion OEM -> ANSI" & VBCRLF
Mess=Mess & "JCB © 2002" & VBCRLF
Mess=Mess & "----------------------" & VBCRLF
Mess=Mess & "Syntaxe : " & VBCRLF
Mess=Mess & " oem2ansi <srce> <dest>" & VBCRLF
Mess=Mess & " <srce> : fichier source (texte OEM)" & VBCRLF
Mess=Mess & " <dest> : fichier destination (texte ANSI)" & VBCRLF & VBCRLF
Mess=Mess & "NB: pour utiliser les flux standards 'stdin' et 'stdout'," & VBCRLF
Mess=Mess & " le moteur de script par défaut doit être cscript.exe" & VBCRLF
Mess=Mess & " Cela s'obtient par la commande : " & VBCRLF
Mess=Mess & " cscript //H:CScript //S /Nologo" & VBCRLF & VBCRLF
Mess=Mess & "Si le script récupère en entrée la sortie d'un autre logiciel (piping)," & VBCRLF
Mess=Mess & "il faut indiquer explicitement 'cscript'" & VBCRLF
Mess=Mess & "Exemple :" & VBCRLF
Mess=Mess & "c:\>ping www.inria.fr | cscript oem2ansi.vbs > test.txt" & VBCRLF & VBCRLF
wscript.echo Mess
wscript.quit
else
Pipe=true
Set fsrce = WScript.StdIn
Set fdest = WScript.StdOut
end if
else
Pipe=false
srce=args(0)
dest=args(1)
If not fso.FileExists(srce) Then
Mess="Le fichier " & srce & " n'existe pas"
wscript.echo Mess
wscript.quit
End If
Set fsrce=fso.OpenTextFile(srce, ForReading)
Set fdest=fso.OpenTextFile(dest, ForWriting,true)
end if
While not fsrce.AtEndOfStream
oldline=fsrce.ReadLine
newline=""
For i = 1 To len(oldline)
oldc=asc(mid(oldline,i,1))
newc=oem(oldc)
newline=newline & chr(hextobyte(newc))
Next
fdest.WriteLine newline
Wend
fdest.close
fsrce.close
'If not pipe Then wscript.echo "Conversion terminée"
Wscript.quit
' Utilitaires de conversion hexadécimale
' -------------------------------------
Function hextobyte(s)
c1=Left(s,1)
c2=Right(s,1)
hextobyte=hextobin(c1)*16+hextobin(c2)
End Function
' -------------------------------------
Function hextobin(c)
Select Case c
Case "0","1","2","3","4","5","6","7","8","9"
hextobin=asc(c)-asc("0")
Case else
hextobin=asc(c)-asc("A")+10
End Select
End Function
' ------------------------------------- |
Partager