OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "bin/stdio.h" | 7 #include "bin/stdio.h" |
8 | 8 |
9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 void FUNCTION_NAME(Stdin_ReadByte)(Dart_NativeArguments args) { | 21 void FUNCTION_NAME(Stdin_ReadByte)(Dart_NativeArguments args) { |
22 ScopedBlockingCall blocker; | 22 ScopedBlockingCall blocker; |
23 int byte = -1; | 23 int byte = -1; |
24 if (Stdin::ReadByte(&byte)) { | 24 if (Stdin::ReadByte(&byte)) { |
25 Dart_SetReturnValue(args, Dart_NewInteger(byte)); | 25 Dart_SetReturnValue(args, Dart_NewInteger(byte)); |
26 } else { | 26 } else { |
27 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 27 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 | |
32 void FUNCTION_NAME(Stdin_GetEchoMode)(Dart_NativeArguments args) { | 31 void FUNCTION_NAME(Stdin_GetEchoMode)(Dart_NativeArguments args) { |
33 bool enabled = false; | 32 bool enabled = false; |
34 if (Stdin::GetEchoMode(&enabled)) { | 33 if (Stdin::GetEchoMode(&enabled)) { |
35 Dart_SetReturnValue(args, Dart_NewBoolean(enabled)); | 34 Dart_SetReturnValue(args, Dart_NewBoolean(enabled)); |
36 } else { | 35 } else { |
37 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 36 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
38 } | 37 } |
39 } | 38 } |
40 | 39 |
41 | |
42 void FUNCTION_NAME(Stdin_SetEchoMode)(Dart_NativeArguments args) { | 40 void FUNCTION_NAME(Stdin_SetEchoMode)(Dart_NativeArguments args) { |
43 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); | 41 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); |
44 if (Stdin::SetEchoMode(enabled)) { | 42 if (Stdin::SetEchoMode(enabled)) { |
45 Dart_SetReturnValue(args, Dart_True()); | 43 Dart_SetReturnValue(args, Dart_True()); |
46 } else { | 44 } else { |
47 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 45 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
48 } | 46 } |
49 } | 47 } |
50 | 48 |
51 | |
52 void FUNCTION_NAME(Stdin_GetLineMode)(Dart_NativeArguments args) { | 49 void FUNCTION_NAME(Stdin_GetLineMode)(Dart_NativeArguments args) { |
53 bool enabled = false; | 50 bool enabled = false; |
54 if (Stdin::GetLineMode(&enabled)) { | 51 if (Stdin::GetLineMode(&enabled)) { |
55 Dart_SetReturnValue(args, Dart_NewBoolean(enabled)); | 52 Dart_SetReturnValue(args, Dart_NewBoolean(enabled)); |
56 } else { | 53 } else { |
57 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 54 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
58 } | 55 } |
59 } | 56 } |
60 | 57 |
61 | |
62 void FUNCTION_NAME(Stdin_SetLineMode)(Dart_NativeArguments args) { | 58 void FUNCTION_NAME(Stdin_SetLineMode)(Dart_NativeArguments args) { |
63 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); | 59 bool enabled = DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 0)); |
64 if (Stdin::SetLineMode(enabled)) { | 60 if (Stdin::SetLineMode(enabled)) { |
65 Dart_SetReturnValue(args, Dart_True()); | 61 Dart_SetReturnValue(args, Dart_True()); |
66 } else { | 62 } else { |
67 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 63 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
68 } | 64 } |
69 } | 65 } |
70 | 66 |
71 | |
72 void FUNCTION_NAME(Stdin_AnsiSupported)(Dart_NativeArguments args) { | 67 void FUNCTION_NAME(Stdin_AnsiSupported)(Dart_NativeArguments args) { |
73 bool supported = false; | 68 bool supported = false; |
74 if (Stdin::AnsiSupported(&supported)) { | 69 if (Stdin::AnsiSupported(&supported)) { |
75 Dart_SetBooleanReturnValue(args, supported); | 70 Dart_SetBooleanReturnValue(args, supported); |
76 } else { | 71 } else { |
77 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 72 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
78 } | 73 } |
79 } | 74 } |
80 | 75 |
81 | |
82 void FUNCTION_NAME(Stdout_GetTerminalSize)(Dart_NativeArguments args) { | 76 void FUNCTION_NAME(Stdout_GetTerminalSize)(Dart_NativeArguments args) { |
83 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { | 77 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { |
84 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 78 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
85 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 79 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
86 return; | 80 return; |
87 } | 81 } |
88 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 82 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
89 if ((fd != 1) && (fd != 2)) { | 83 if ((fd != 1) && (fd != 2)) { |
90 Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2")); | 84 Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2")); |
91 return; | 85 return; |
92 } | 86 } |
93 | 87 |
94 int size[2]; | 88 int size[2]; |
95 if (Stdout::GetTerminalSize(fd, size)) { | 89 if (Stdout::GetTerminalSize(fd, size)) { |
96 Dart_Handle list = Dart_NewList(2); | 90 Dart_Handle list = Dart_NewList(2); |
97 Dart_ListSetAt(list, 0, Dart_NewInteger(size[0])); | 91 Dart_ListSetAt(list, 0, Dart_NewInteger(size[0])); |
98 Dart_ListSetAt(list, 1, Dart_NewInteger(size[1])); | 92 Dart_ListSetAt(list, 1, Dart_NewInteger(size[1])); |
99 Dart_SetReturnValue(args, list); | 93 Dart_SetReturnValue(args, list); |
100 } else { | 94 } else { |
101 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 95 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
102 } | 96 } |
103 } | 97 } |
104 | 98 |
105 | |
106 void FUNCTION_NAME(Stdout_AnsiSupported)(Dart_NativeArguments args) { | 99 void FUNCTION_NAME(Stdout_AnsiSupported)(Dart_NativeArguments args) { |
107 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { | 100 if (!Dart_IsInteger(Dart_GetNativeArgument(args, 0))) { |
108 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 101 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
109 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); | 102 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); |
110 return; | 103 return; |
111 } | 104 } |
112 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 105 intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
113 if ((fd != 1) && (fd != 2)) { | 106 if ((fd != 1) && (fd != 2)) { |
114 Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2")); | 107 Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2")); |
115 return; | 108 return; |
116 } | 109 } |
117 bool supported = false; | 110 bool supported = false; |
118 if (Stdout::AnsiSupported(fd, &supported)) { | 111 if (Stdout::AnsiSupported(fd, &supported)) { |
119 Dart_SetBooleanReturnValue(args, supported); | 112 Dart_SetBooleanReturnValue(args, supported); |
120 } else { | 113 } else { |
121 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 114 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
122 } | 115 } |
123 } | 116 } |
124 | 117 |
125 } // namespace bin | 118 } // namespace bin |
126 } // namespace dart | 119 } // namespace dart |
127 | 120 |
128 #endif // !defined(DART_IO_DISABLED) | 121 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |