Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for ascii2uc.bat

(view source code of ascii2uc.bat as plain text)

  1. @GOTO :Batch
  2.  
  3. a 0100
  4. MOV AH, 09
  5. MOV DX, 0000
  6. INT 21
  7. RET
  8. DB "ÿþ$"
  9.  
  10. a 102
  11. MOV DX, 108
  12.  
  13. u 0100
  14. n C:\UNIHD.COM
  15. r BX
  16. 0
  17. r CX
  18. B
  19. w
  20. q
  21.  
  22. :Batch
  23. @ECHO OFF
  24. :: Requires "CMD based" Windows version
  25. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  26. :: ASCII file must be specified and must exist
  27. IF "%~1"=="" GOTO Syntax
  28. IF NOT EXIST "%~1" GOTO Syntax
  29.  
  30. SETLOCAL
  31. SET ASCIIFile=%~1
  32. IF "%~2"=="" (SET UnicodeFile=%~n1_Unicode.%~x1) ELSE (SET UnicodeFile=%~2)
  33.  
  34. :: DEBUG won't work on 64-bit Windows
  35. IF "%ProgramFiles(x86)%"=="" (CALL :Header32) ELSE (CALL :Header64)
  36.  
  37. :: ASCII to Unicode conversion with CMD /U /C (after first
  38. :: creating a 2-byte header containing character 0xFF and
  39. :: 0xFE) as discovered by Jacques Bensimon.
  40. CMD.EXE /U /C TYPE "%ASCIIFile%" >> "%UnicodeFile%"
  41. ENDLOCAL
  42. GOTO:EOF
  43.  
  44.  
  45. :Header32
  46. :: DEBUG script code based on an article by "JustBurn":
  47. :: http://www.instructables.com/id/How-to-write-the-world-s-smallest-%22Hello-World!%22-e/
  48. :: Feel free to customize the path where UNIHD.COM will be stored (line 14: "n C:\UNIHD.COM").
  49. ::
  50. :: Use the "embedded" DEBUG script to create the 11 byte UNIHD.COM
  51. DEBUG < %~sf0 >NUL 2>&1
  52. :: Redirect UNIHD.COM's output to write the 0xFF and 0xFE
  53. :: characters to the target file
  54. C:\unihd.com > "%UnicodeFile%"
  55. GOTO:EOF
  56.  
  57.  
  58. :Header64
  59. :: Unfortunately ECHOing the header will insert an extra line break
  60. IF EXIST "%~dpn0.header" (
  61. 	COPY "%~dpn0.header" "%UnicodeFile%" >NUL 2>&1
  62. ) ELSE (
  63. 	ECHO.ÿþ> "%UnicodeFile%"
  64. )
  65. GOTO:EOF
  66.  
  67.  
  68. :Syntax
  69. ECHO.
  70. ECHO ASCII2Uc.bat,  Version 2.01 for Windows NT 4 and later
  71. ECHO Converts an ASCII text file to valid Unicode
  72. ECHO.
  73. ECHO Usage:  ASCII2UC  ascii_file  [ unicode_file ]
  74. ECHO.
  75. ECHO Where:  ascii_file    (mandatory) name of the ASCII source file
  76. ECHO         unicode_file  (optional) name of the Unicode target file (default:
  77. ECHO                       the name of the source file with "_Unicode" appended)
  78. ECHO.
  79. ECHO Notes:
  80. ECHO [1] ASCII to Unicode conversion command and header by Jacques Bensimon.
  81. ECHO [2] For 32-bit Windows versions, the Unicode file header is created by an
  82. ECHO     "embedded" DEBUG script.
  83. ECHO     In 64-bit Windows versions either an "external" header file or ECHO is used
  84. ECHO     to create the header.
  85. ECHO     Unfortunately, ECHO inserts an extra line break before the original text.
  86. ECHO [3] The path of the temporary file is hard coded in the embedded DEBUG script.
  87. ECHO [4] DEBUG script code based on an article by "JustBurn":
  88. ECHO     www.instructables.com/id/How-to-write-the-world-s-smallest-"Hello-World!"-e
  89. ECHO.
  90. ECHO Written by Rob van der Woude
  91. ECHO http://www.robvanderwoude.com
  92.  

page last modified: 2024-04-16; loaded in 0.0199 seconds