PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/macros/Misc/Run_Script.bsh

#
Unknown | 126 lines | 116 code | 10 blank | 0 comment | 0 complexity | f74314106197dcdeabbf76efced9c65a MD5 | raw file
  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
 27
 28void execScript(interpreter, command)
 29{
 30	params = Macros.input(view,
 31		"Specify parameters for running script under " + interpreter);
 32	if(params == null)
 33	{
 34		Macros.message(view, "Script execution was cancelled.");
 35		return;
 36	}
 37	runInSystemShell(view, command + params);
 38}
 39
 40void runScript()
 41{
 42	if(buffer.isNewFile())
 43		buffer.saveAs(view, true);
 44	else
 45		buffer.save(view, buffer.getPath());
 46	mode = buffer.getMode().getName();
 47	path = buffer.getPath() + " ";
 48	os = System.getProperty("os.name");
 49	if(os.indexOf("Windows") != -1)
 50		path = "\"" + path + "\"";
 51	if(mode.equals("beanshell")) {
 52		source(path);
 53	}
 54	else if(mode.equals("awk")) {
 55		execScript("awk", "awk -f " + path);
 56	}
 57	else if(mode.equals("batch")) {
 58		if(os.indexOf("Windows 9") == -1
 59			&& os.indexOf("Windows M") == -1)
 60		{
 61			execScript("shell", "cmd /C " + path);
 62		}
 63		else execScript("shell", "command /C " + path);
 64	}
 65	else if(mode.equals("javascript")) {
 66		execScript("Windows Script Host", "wscript " + path);
 67	}
 68	else if(mode.equals("jmk")) {
 69		execScript("jmk", "java -jar jmk.jar -f" + path);
 70	}
 71	else if(mode.equals("makefile")) {
 72		if(os.indexOf("Windows") == -1) {
 73			execScript("make", "make -f " + path);
 74		}
 75		else {
 76			execScript("nmake", "nmake -f " + path);
 77		}
 78	}
 79	else if(mode.equals("netrexx"))  {
 80		execScript("NetRexx", "NetRexxC -exec " + path);
 81	}
 82	else if(mode.equals("perl"))	{
 83		execScript("perl", "perl " + path);
 84	}
 85	else if(mode.equals("python")) {
 86		execScript("python", "python " + path);
 87	}
 88	else if(mode.equals("ruby")) {
 89		execScript("ruby", "ruby " + path);
 90	}
 91	else if(mode.equals("scheme")) {
 92		execScript("scheme", "scheme -load " + path);
 93	}
 94	else if(mode.equals("shellscript"))  {
 95		execScript("shell", "bash " + path);
 96	}
 97	else if(mode.equals("tcl")) {
 98		execScript("tcl", "tcl " + path);
 99	}
100	else if(mode.equals("vbscript"))  {
101		execScript("Windows Script Host", "wscript " + path);
102	}
103	else {
104		Macros.error(view,
105			"The current file does not appear to be a script.");
106	}
107}
108
109runScript();
110
111
112/*
113
114Macro index data (in DocBook format)
115
116  <listitem>
117    <para><filename>Run_Script.bsh</filename></para>
118    <abstract><para>
119      Runs script using interpreter based upon buffer's editing mode
120	  (by default, determined using file extension).
121    </para></abstract>
122  </listitem>
123
124*/
125
126// end Run_Script.bsh