wasCSharpSQLite – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* |
2 | * SeekCmd.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: SeekCmd.java,v 1.3 2003/03/08 03:42:44 mdejong Exp $ |
||
13 | * |
||
14 | */ |
||
15 | using System; |
||
16 | using System.IO; |
||
17 | namespace tcl.lang |
||
18 | { |
||
19 | |||
20 | /// <summary> This class implements the built-in "seek" command in Tcl.</summary> |
||
21 | |||
22 | class SeekCmd : Command |
||
23 | { |
||
24 | |||
25 | private static readonly string[] validOrigins = new string[] { "start", "current", "end" }; |
||
26 | |||
27 | internal const int OPT_START = 0; |
||
28 | internal const int OPT_CURRENT = 1; |
||
29 | internal const int OPT_END = 2; |
||
30 | |||
31 | /// <summary> This procedure is invoked to process the "seek" Tcl command. |
||
32 | /// See the user documentation for details on what it does. |
||
33 | /// </summary> |
||
34 | |||
35 | public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv ) |
||
36 | { |
||
37 | |||
38 | Channel chan; /* The channel being operated on this method */ |
||
39 | int mode; /* Stores the search mode, either beg, cur or end |
||
40 | * of file. See the TclIO class for more info */ |
||
41 | |||
42 | if ( argv.Length != 3 && argv.Length != 4 ) |
||
43 | { |
||
44 | throw new TclNumArgsException( interp, 1, argv, "channelId offset ?origin?" ); |
||
45 | } |
||
46 | |||
47 | // default is the beginning of the file |
||
48 | |||
49 | mode = TclIO.SEEK_SET; |
||
50 | if ( argv.Length == 4 ) |
||
51 | { |
||
52 | int index = TclIndex.get( interp, argv[3], validOrigins, "origin", 0 ); |
||
53 | |||
54 | switch ( index ) |
||
55 | { |
||
56 | |||
57 | case OPT_START: |
||
58 | { |
||
59 | mode = TclIO.SEEK_SET; |
||
60 | break; |
||
61 | } |
||
62 | |||
63 | case OPT_CURRENT: |
||
64 | { |
||
65 | mode = TclIO.SEEK_CUR; |
||
66 | break; |
||
67 | } |
||
68 | |||
69 | case OPT_END: |
||
70 | { |
||
71 | mode = TclIO.SEEK_END; |
||
72 | break; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | |||
78 | chan = TclIO.getChannel( interp, argv[1].ToString() ); |
||
79 | if ( chan == null ) |
||
80 | { |
||
81 | |||
82 | throw new TclException( interp, "can not find channel named \"" + argv[1].ToString() + "\"" ); |
||
83 | } |
||
84 | long offset = TclInteger.get( interp, argv[2] ); |
||
85 | |||
86 | try |
||
87 | { |
||
88 | chan.seek( interp, offset, mode ); |
||
89 | } |
||
90 | catch ( IOException e ) |
||
91 | { |
||
92 | // FIXME: Need to figure out Tcl specific error conditions. |
||
93 | // Should we also wrap an IOException in a ReflectException? |
||
94 | throw new TclRuntimeError( "SeekCmd.cmdProc() Error: IOException when seeking " + chan.ChanName + ":" + e.Message ); |
||
95 | } |
||
96 | return TCL.CompletionCode.RETURN; |
||
97 | } |
||
98 | } |
||
99 | } |