1 package org.sentrysoftware.jawk; 2 3 /*- 4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 5 * Jawk 6 * ჻჻჻჻჻჻ 7 * Copyright (C) 2006 - 2023 Sentry Software 8 * ჻჻჻჻჻჻ 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation, either version 3 of the 12 * License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Lesser Public License for more details. 18 * 19 * You should have received a copy of the GNU General Lesser Public 20 * License along with this program. If not, see 21 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 23 */ 24 25 import java.io.InputStream; 26 import java.io.PrintStream; 27 28 import org.sentrysoftware.jawk.util.AwkParameters; 29 import org.sentrysoftware.jawk.util.AwkSettings; 30 31 /** 32 * Entry point into the parsing, analysis, and execution/compilation 33 * of a Jawk script. 34 * This entry point is used when Jawk is executed as a stand-alone application. 35 * If you want to use Jawk as a library, please use {@see Awk}. 36 * 37 * @author Danny Daglas 38 */ 39 public class Main { 40 41 /** 42 * Prohibit the instantiation of this class, other than the 43 * way required by JSR 223. 44 */ 45 @SuppressWarnings("unused") 46 private Main() {} 47 48 /** 49 * Class constructor to support the JSR 223 scripting interface 50 * already provided by Java SE 6. 51 * 52 * @param args String arguments from the command-line. 53 * @param is The input stream to use as stdin. 54 * @param os The output stream to use as stdout. 55 * @param es The output stream to use as stderr. 56 * @throws java.lang.Exception enables exceptions to propagate to the callee. 57 */ 58 public Main(String[] args, InputStream is, PrintStream os, PrintStream es) 59 throws Exception 60 { 61 System.setIn(is); 62 System.setOut(os); 63 System.setErr(es); 64 65 AwkSettings settings = AwkParameters.parseCommandLineArguments(args); 66 Awk awk = new Awk(); 67 awk.invoke(settings); 68 } 69 70 /** 71 * The entry point to Jawk for the VM. 72 * <p> 73 * The main method is a simple call to the invoke method. 74 * The current implementation is basically as follows: 75 * <blockquote> 76 * <pre> 77 * System.exit(invoke(args)); 78 * </pre> 79 * </blockquote> 80 * 81 * @param args Command line arguments to the VM. 82 */ 83 public static void main(String[] args) { 84 85 try { 86 AwkSettings settings = AwkParameters.parseCommandLineArguments(args); 87 Awk awk = new Awk(); 88 awk.invoke(settings); 89 } catch (ExitException e) { 90 System.exit(e.getCode()); 91 } catch (Exception e) { 92 System.err.printf("%s: %s\n", e.getClass().getSimpleName(), e.getMessage()); 93 System.exit(1); 94 } 95 96 } 97 98 99 }