From 85fa8ae39ab226ea6319a583b7bb2189beddc8b6 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 16 Sep 2017 16:51:55 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D0=B6?= =?utf8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2?= =?utf8?q?=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- rtl/Oberon.obn | 1 - rtl/java/Launcher.java | 87 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 10 deletions(-) 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); + } } } -- 2.29.2