unix2dos.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * unix2dos.js - a simple unix2dos implementation in jscript.
  3. *
  4. * Copyright (C) 2008-2012 Alon Bar-Lev <[email protected]>
  5. *
  6. * BSD License
  7. * ============
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * o Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * o Neither the name of the Alon Bar-Lev nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  24. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. var ForReading = 1;
  34. try {
  35. var fso = new ActiveXObject("Scripting.FileSystemObject");
  36. for (var i=0;i<WScript.Arguments.length;i++) {
  37. var file = WScript.Arguments(i);
  38. var tmp = file+".tmp";
  39. var fin = fso.OpenTextFile(file, ForReading);
  40. var fout = fso.CreateTextFile(tmp);
  41. fout.Write(fin.ReadAll().replace(/\n/g, "\r\n"));
  42. fin.Close();
  43. fout.Close();
  44. fso.DeleteFile(file);
  45. fso.MoveFile(tmp, file);
  46. }
  47. WScript.Quit(0);
  48. }
  49. catch(e) {
  50. WScript.Echo("ERROR: " + e.description);
  51. WScript.Quit(1);
  52. }