PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/macros/Misc/Run_Script.bsh

#
Unknown | 126 lines | 116 code | 10 blank | 0 comment | 0 complexity | f74314106197dcdeabbf76efced9c65a MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * Run_Script.bsh - a BeanShell macro script for the
  3. * jEdit text editor - Runs script using interpreter based upon
  4. * buffer's editing mode (by default, determined using file extension).
  5. *
  6. * Copyright (C) 2001 John Gellene
  7. * jgellene@nyc.rr.com
  8. * http://community.jedit.org
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or any later version.
  14. *
  15. * This program 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 the jEdit program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. *
  24. * $Id: Run_Script.bsh 3912 2001-11-24 03:56:51Z jgellene $
  25. */
  26. void execScript(interpreter, command)
  27. {
  28. params = Macros.input(view,
  29. "Specify parameters for running script under " + interpreter);
  30. if(params == null)
  31. {
  32. Macros.message(view, "Script execution was cancelled.");
  33. return;
  34. }
  35. runInSystemShell(view, command + params);
  36. }
  37. void runScript()
  38. {
  39. if(buffer.isNewFile())
  40. buffer.saveAs(view, true);
  41. else
  42. buffer.save(view, buffer.getPath());
  43. mode = buffer.getMode().getName();
  44. path = buffer.getPath() + " ";
  45. os = System.getProperty("os.name");
  46. if(os.indexOf("Windows") != -1)
  47. path = "\"" + path + "\"";
  48. if(mode.equals("beanshell")) {
  49. source(path);
  50. }
  51. else if(mode.equals("awk")) {
  52. execScript("awk", "awk -f " + path);
  53. }
  54. else if(mode.equals("batch")) {
  55. if(os.indexOf("Windows 9") == -1
  56. && os.indexOf("Windows M") == -1)
  57. {
  58. execScript("shell", "cmd /C " + path);
  59. }
  60. else execScript("shell", "command /C " + path);
  61. }
  62. else if(mode.equals("javascript")) {
  63. execScript("Windows Script Host", "wscript " + path);
  64. }
  65. else if(mode.equals("jmk")) {
  66. execScript("jmk", "java -jar jmk.jar -f" + path);
  67. }
  68. else if(mode.equals("makefile")) {
  69. if(os.indexOf("Windows") == -1) {
  70. execScript("make", "make -f " + path);
  71. }
  72. else {
  73. execScript("nmake", "nmake -f " + path);
  74. }
  75. }
  76. else if(mode.equals("netrexx")) {
  77. execScript("NetRexx", "NetRexxC -exec " + path);
  78. }
  79. else if(mode.equals("perl")) {
  80. execScript("perl", "perl " + path);
  81. }
  82. else if(mode.equals("python")) {
  83. execScript("python", "python " + path);
  84. }
  85. else if(mode.equals("ruby")) {
  86. execScript("ruby", "ruby " + path);
  87. }
  88. else if(mode.equals("scheme")) {
  89. execScript("scheme", "scheme -load " + path);
  90. }
  91. else if(mode.equals("shellscript")) {
  92. execScript("shell", "bash " + path);
  93. }
  94. else if(mode.equals("tcl")) {
  95. execScript("tcl", "tcl " + path);
  96. }
  97. else if(mode.equals("vbscript")) {
  98. execScript("Windows Script Host", "wscript " + path);
  99. }
  100. else {
  101. Macros.error(view,
  102. "The current file does not appear to be a script.");
  103. }
  104. }
  105. runScript();
  106. /*
  107. Macro index data (in DocBook format)
  108. <listitem>
  109. <para><filename>Run_Script.bsh</filename></para>
  110. <abstract><para>
  111. Runs script using interpreter based upon buffer's editing mode
  112. (by default, determined using file extension).
  113. </para></abstract>
  114. </listitem>
  115. */
  116. // end Run_Script.bsh