Source Code Cross Referenced for TJCShell.java in  » Scripting » jacl » tcl » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jacl » tcl.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005 Advanced Micro Devices, Inc.
003:         *
004:         * See the file "license.amd" for information on usage and
005:         * redistribution of this file, and for a DISCLAIMER OF ALL
006:         * WARRANTIES.
007:         *
008:         * RCS: @(#) $Id: TJCShell.java,v 1.2 2006/01/24 07:55:45 mdejong Exp $
009:         *
010:         */
011:
012:        // This class implements the start up shell for the TJC compiler.
013:        package tcl.lang;
014:
015:        import java.util.*;
016:        import java.io.*;
017:
018:        public class TJCShell {
019:
020:            /*
021:             *----------------------------------------------------------------------
022:             *
023:             * main --
024:             *
025:             *	Main program for tclsh and most other Tcl-based applications.
026:             *
027:             * Results:
028:             *	None.
029:             *
030:             * Side effects:
031:             *	This procedure initializes the Tcl world and then starts
032:             *	interpreting commands; almost anything could happen, depending
033:             *	on the script being interpreted.
034:             *
035:             *----------------------------------------------------------------------
036:             */
037:
038:            public static void main(String[] args) // Array of command-line argument strings.
039:            {
040:                String fileName = "resource:/tjc/library/tjc.tcl";
041:                int startIndex = 0;
042:
043:                // Create the interpreter. This will also create the built-in
044:                // Tcl commands.
045:
046:                Interp interp = new Interp();
047:
048:                // Check for -shell or -s, this means the user wanted to start
049:                // a TJC enabled shell instead of running the tjc program.
050:
051:                if ((args.length > 0)
052:                        && (args[0].equals("-s") || args[0].equals("-shell"))) {
053:                    startIndex = 1;
054:                }
055:
056:                TclObject argv = TclList.newInstance();
057:                argv.preserve();
058:                try {
059:                    if (startIndex == 1) {
060:                        // Invoke tjc as Tcl shell with TJC commands.
061:                        interp.setVar("argv0", "tjc", TCL.GLOBAL_ONLY);
062:                        interp.setVar("tcl_interactive", "1", TCL.GLOBAL_ONLY);
063:                    } else {
064:                        // Invoke tjc as standalone executable
065:                        interp.setVar("argv0", "tjc.tcl", TCL.GLOBAL_ONLY);
066:                        interp.setVar("tcl_interactive", "0", TCL.GLOBAL_ONLY);
067:                    }
068:                    for (int i = startIndex; i < args.length; i++) {
069:                        TclList.append(interp, argv, TclString
070:                                .newInstance(args[i]));
071:                    }
072:                    interp.setVar("argv", argv, TCL.GLOBAL_ONLY);
073:                    interp.setVar("argc", TclInteger.newInstance(TclList
074:                            .getLength(interp, argv)), TCL.GLOBAL_ONLY);
075:                } catch (TclException e) {
076:                    throw new TclRuntimeError("unexpected TclException: " + e);
077:                } finally {
078:                    argv.release();
079:                }
080:
081:                // If a script file was specified then just source that file
082:                // and quit. Load the TJC runtime support package in case
083:                // the tjc.tcl to be sourced was itself compiled with TJC.
084:                // We could load via TJC::package but this works just fine.
085:
086:                if (fileName != null) {
087:                    int exitCode = 0;
088:                    try {
089:                        interp.eval("package require TJC");
090:                        interp.eval("source " + fileName);
091:                    } catch (TclException e) {
092:                        int code = e.getCompletionCode();
093:                        if (code == TCL.RETURN) {
094:                            code = interp.updateReturnInfo();
095:                            if (code != TCL.OK) {
096:                                System.err
097:                                        .println("command returned bad code: "
098:                                                + code);
099:                                exitCode = 2;
100:                            }
101:                        } else if (code == TCL.ERROR) {
102:                            System.err.println(interp.getResult().toString());
103:                            exitCode = 1;
104:                        } else {
105:                            System.err.println("command returned bad code: "
106:                                    + code);
107:                            exitCode = 2;
108:                        }
109:                    }
110:
111:                    if (startIndex == 0) {
112:                        // Note that if the above interp.evalFile() returns the main
113:                        // thread will exit.  This may bring down the VM and stop
114:                        // the execution of Tcl.
115:                        //
116:                        // If the script needs to handle events, it must call
117:                        // vwait or do something similar.
118:                        //
119:                        // Note that the script can create AWT widgets. This will
120:                        // start an AWT event handling thread and keep the VM up. However,
121:                        // the interpreter thread (the same as the main thread) would
122:                        // have exited and no Tcl scripts can be executed.
123:
124:                        interp.dispose();
125:                        System.exit(exitCode);
126:                    }
127:                }
128:
129:                if (startIndex == 1) {
130:                    // We are running in interactive mode. Start the ConsoleThread
131:                    // that loops, grabbing stdin and passing it to the interp.
132:
133:                    ConsoleThread consoleThread = new ConsoleThread(interp);
134:                    consoleThread.setDaemon(true);
135:                    consoleThread.start();
136:
137:                    // Loop forever to handle user input events in the command line.
138:
139:                    Notifier notifier = interp.getNotifier();
140:                    while (true) {
141:                        // process events until "exit" is called.
142:
143:                        notifier.doOneEvent(TCL.ALL_EVENTS);
144:                    }
145:                }
146:            }
147:        } // end class TJCShell
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.