wasCSharpSQLite – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * PutsCmd.java |
||
3 | * |
||
4 | * Copyright (c) 1997 Cornell University. |
||
5 | * Copyright (c) 1997 Sun Microsystems, Inc. |
||
6 | * |
||
7 | * See the file "license.terms" for information on usage and |
||
8 | * redistribution of this file, and for a DISCLAIMER OF ALL |
||
9 | * WARRANTIES. |
||
10 | * |
||
11 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
12 | * |
||
13 | * RCS @(#) $Id: PutsCmd.java,v 1.6 2002/01/21 06:34:26 mdejong Exp $ |
||
14 | * |
||
15 | */ |
||
16 | using System; |
||
17 | using System.IO; |
||
18 | namespace tcl.lang |
||
19 | { |
||
20 | |||
21 | /// <summary> This class implements the built-in "puts" command in Tcl.</summary> |
||
22 | |||
23 | class PutsCmd : Command |
||
24 | { |
||
25 | /// <summary> Prints the given string to a channel. See Tcl user |
||
26 | /// documentation for details. |
||
27 | /// |
||
28 | /// </summary> |
||
29 | /// <param name="interp">the current interpreter. |
||
30 | /// </param> |
||
31 | /// <param name="argv">command arguments. |
||
32 | /// </param> |
||
33 | |||
34 | public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv ) |
||
35 | { |
||
36 | |||
37 | Channel chan; // The channel being operated on this method |
||
38 | string channelId; // String containing the key to chanTable |
||
39 | string arg; // Argv[i] converted to a string |
||
40 | int i = 1; // Index to the next arg in argv |
||
41 | bool newline = true; |
||
42 | // Indicates to print a newline in result |
||
43 | |||
44 | |||
45 | if ( ( argv.Length >= 2 ) && ( argv[1].ToString().Equals( "-nonewline" ) ) ) |
||
46 | { |
||
47 | newline = false; |
||
48 | i++; |
||
49 | } |
||
50 | if ( ( i < argv.Length - 3 ) || ( i >= argv.Length ) ) |
||
51 | { |
||
52 | throw new TclNumArgsException( interp, 1, argv, "?-nonewline? ?channelId? string" ); |
||
53 | } |
||
54 | |||
55 | // The code below provides backwards compatibility with an old |
||
56 | // form of the command that is no longer recommended or documented. |
||
57 | |||
58 | if ( i == ( argv.Length - 3 ) ) |
||
59 | { |
||
60 | |||
61 | arg = argv[i + 2].ToString(); |
||
62 | if ( !arg.Equals( "nonewline" ) ) |
||
63 | { |
||
64 | throw new TclException( interp, "bad argument \"" + arg + "\": should be \"nonewline\"" ); |
||
65 | } |
||
66 | newline = false; |
||
67 | } |
||
68 | |||
69 | if ( i == ( argv.Length - 1 ) ) |
||
70 | { |
||
71 | channelId = "stdout"; |
||
72 | } |
||
73 | else |
||
74 | { |
||
75 | |||
76 | channelId = argv[i].ToString(); |
||
77 | i++; |
||
78 | } |
||
79 | |||
80 | if ( i != ( argv.Length - 1 ) ) |
||
81 | { |
||
82 | throw new TclNumArgsException( interp, 1, argv, "?-nonewline? ?channelId? string" ); |
||
83 | } |
||
84 | |||
85 | chan = TclIO.getChannel( interp, channelId ); |
||
86 | if ( chan == null ) |
||
87 | { |
||
88 | throw new TclException( interp, "can not find channel named \"" + channelId + "\"" ); |
||
89 | } |
||
90 | |||
91 | try |
||
92 | { |
||
93 | if ( newline ) |
||
94 | { |
||
95 | chan.write( interp, argv[i] ); |
||
96 | chan.write( interp, "\n" ); |
||
97 | } |
||
98 | else |
||
99 | { |
||
100 | chan.write( interp, argv[i] ); |
||
101 | } |
||
102 | } |
||
103 | catch ( IOException e ) |
||
104 | { |
||
105 | throw new TclRuntimeError( "PutsCmd.cmdProc() Error: IOException when putting " + chan.ChanName ); |
||
106 | } |
||
107 | return TCL.CompletionCode.RETURN; |
||
108 | } |
||
109 | } |
||
110 | } |