wasCSharpSQLite – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * GetsCmd.java -- |
||
3 | * |
||
4 | * Copyright (c) 1997 Sun Microsystems, Inc. |
||
5 | * |
||
6 | * See the file "license.terms" for information on usage and |
||
7 | * redistribution of this file, and for a DISCLAIMER OF ALL |
||
8 | * WARRANTIES. |
||
9 | * |
||
10 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
11 | * |
||
12 | * RCS @(#) $Id: GetsCmd.java,v 1.6 2003/03/08 03:42:44 mdejong Exp $ |
||
13 | * |
||
14 | */ |
||
15 | using System.Text; |
||
16 | using System.IO; |
||
17 | namespace tcl.lang |
||
18 | { |
||
19 | |||
20 | /// <summary> This class implements the built-in "gets" command in Tcl.</summary> |
||
21 | |||
22 | class GetsCmd : Command |
||
23 | { |
||
24 | |||
25 | /// <summary> This procedure is invoked to process the "gets" Tcl command. |
||
26 | /// See the user documentation for details on what it does. |
||
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 | bool writeToVar = false; // If true write to var passes as arg |
||
38 | string varName = ""; // The variable to write value to |
||
39 | Channel chan; // The channel being operated on |
||
40 | int lineLen; |
||
41 | TclObject line; |
||
42 | |||
43 | if ( ( argv.Length < 2 ) || ( argv.Length > 3 ) ) |
||
44 | { |
||
45 | throw new TclNumArgsException( interp, 1, argv, "channelId ?varName?" ); |
||
46 | } |
||
47 | |||
48 | if ( argv.Length == 3 ) |
||
49 | { |
||
50 | writeToVar = true; |
||
51 | |||
52 | varName = argv[2].ToString(); |
||
53 | } |
||
54 | |||
55 | |||
56 | chan = TclIO.getChannel( interp, argv[1].ToString() ); |
||
57 | if ( chan == null ) |
||
58 | { |
||
59 | |||
60 | throw new TclException( interp, "can not find channel named \"" + argv[1].ToString() + "\"" ); |
||
61 | } |
||
62 | |||
63 | try |
||
64 | { |
||
65 | line = TclString.newInstance( new StringBuilder( 64 ) ); |
||
66 | lineLen = chan.read( interp, line, TclIO.READ_LINE, 0 ); |
||
67 | if ( lineLen < 0 ) |
||
68 | { |
||
69 | // FIXME: Need more specific posix error codes! |
||
70 | if ( !chan.eof() && !chan.isBlocked( interp ) ) |
||
71 | { |
||
72 | |||
73 | throw new TclPosixException( interp, TclPosixException.EIO, true, "error reading \"" + argv[1].ToString() + "\"" ); |
||
74 | } |
||
75 | lineLen = -1; |
||
76 | } |
||
77 | if ( writeToVar ) |
||
78 | { |
||
79 | interp.setVar( varName, line, 0 ); |
||
80 | interp.setResult( lineLen ); |
||
81 | } |
||
82 | else |
||
83 | { |
||
84 | interp.setResult( line ); |
||
85 | } |
||
86 | } |
||
87 | catch ( IOException e ) |
||
88 | { |
||
89 | throw new TclRuntimeError( "GetsCmd.cmdProc() Error: IOException when getting " + chan.ChanName + ": " + e.Message ); |
||
90 | } |
||
91 | return TCL.CompletionCode.RETURN; |
||
92 | } |
||
93 | } |
||
94 | } |