From: DeaDDooMER Date: Sat, 16 Sep 2017 13:51:55 +0000 (+0300) Subject: Добавлена возможножность вызова команд X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=85fa8ae39ab226ea6319a583b7bb2189beddc8b6;p=dsw-obn.git Добавлена возможножность вызова команд --- diff --git a/rtl/Oberon.obn b/rtl/Oberon.obn index 3316b85..37067d7 100644 --- a/rtl/Oberon.obn +++ b/rtl/Oberon.obn @@ -29,7 +29,6 @@ BEGIN i := 1; WHILE i < Args.count DO Args.GetArg(i, str); Texts.WriteString(W, str); Texts.Write(W, " "); - Out.String("Param "); Out.Int(i, 0); Out.Char(" "); Out.String(str); Out.Ln; INC(i) END; Texts.Append(Par.text, W.buf); diff --git a/rtl/java/Launcher.java b/rtl/java/Launcher.java index a49e328..3135732 100644 --- a/rtl/java/Launcher.java +++ b/rtl/java/Launcher.java @@ -3,16 +3,85 @@ import java.lang.reflect.*; class Launcher { public static void main(String[] args) - throws - ClassNotFoundException, - InstantiationException, - IllegalAccessException, - NoSuchMethodException, - InvocationTargetException { + /* Этап 1: Сохраняем список параметров */ Args.args = args; - Class module = Class.forName(args[0]); - Method begin = module.getMethod("BEGIN"); - begin.invoke(null); + + /* Этап 2: Получаем имена связки Модуль.Команда */ + if(args == null || args.length < 1) + { + System.err.println("uses: Launcher Module[.Command] {Argumets}"); + System.exit(1); + } + + String moduleName = args[0]; + String commandName = ""; + int i = args[0].indexOf('.'); + if(i >= 0) + { + moduleName = args[0].substring(0, i); + commandName = args[0].substring(i + 1); + if(commandName == "BEGIN") + { + commandName = ""; + } + } + + /* Этап 3: Выполнение тела модуля и команды */ + Class module = null; + Method begin = null; + Method command = null; + + try { + module = Class.forName(moduleName); + } catch(ClassNotFoundException e) { + System.err.println("Module " + moduleName + " not found"); + System.exit(1); + } + + try { + begin = module.getMethod("BEGIN"); + } catch(Exception e) { + System.err.println("Invalid module " + moduleName); + System.exit(1); + } + + try { + begin.invoke(null); + } catch(IllegalAccessException e) { + System.err.println("Invalid module " + moduleName); + System.exit(1); + } catch(IllegalArgumentException e) { + System.err.println("Invalid module " + moduleName); + System.exit(1); + } catch(InvocationTargetException e) { + System.err.println("Invalid module " + moduleName); + System.exit(1); + } + + if(commandName == "") + { + return; + } + + try { + command = module.getMethod(commandName); + } catch(Exception e) { + System.err.println("Invalid command " + moduleName + "." + commandName); + System.exit(1); + } + + try { + command.invoke(null); + } catch(IllegalAccessException e) { + System.err.println("Invalid command " + moduleName + "." + commandName); + System.exit(1); + } catch(IllegalArgumentException e) { + System.err.println("Invalid command " + moduleName + "." + commandName); + System.exit(1); + } catch(InvocationTargetException e) { + System.err.println("Invalid command " + moduleName + "." + commandName); + System.exit(1); + } } }