Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: runtime/bin/stdio_linux.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/stdio_fuchsia.cc ('k') | runtime/bin/stdio_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(HOST_OS_LINUX) 8 #if defined(HOST_OS_LINUX)
9 9
10 #include "bin/stdio.h" 10 #include "bin/stdio.h"
(...skipping 10 matching lines...) Expand all
21 21
22 bool Stdin::ReadByte(int* byte) { 22 bool Stdin::ReadByte(int* byte) {
23 int c = NO_RETRY_EXPECTED(getchar()); 23 int c = NO_RETRY_EXPECTED(getchar());
24 if ((c == EOF) && (errno != 0)) { 24 if ((c == EOF) && (errno != 0)) {
25 return false; 25 return false;
26 } 26 }
27 *byte = (c == EOF) ? -1 : c; 27 *byte = (c == EOF) ? -1 : c;
28 return true; 28 return true;
29 } 29 }
30 30
31
32 bool Stdin::GetEchoMode(bool* enabled) { 31 bool Stdin::GetEchoMode(bool* enabled) {
33 struct termios term; 32 struct termios term;
34 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term)); 33 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
35 if (status != 0) { 34 if (status != 0) {
36 return false; 35 return false;
37 } 36 }
38 *enabled = ((term.c_lflag & ECHO) != 0); 37 *enabled = ((term.c_lflag & ECHO) != 0);
39 return true; 38 return true;
40 } 39 }
41 40
42
43 bool Stdin::SetEchoMode(bool enabled) { 41 bool Stdin::SetEchoMode(bool enabled) {
44 struct termios term; 42 struct termios term;
45 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term)); 43 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
46 if (status != 0) { 44 if (status != 0) {
47 return false; 45 return false;
48 } 46 }
49 if (enabled) { 47 if (enabled) {
50 term.c_lflag |= (ECHO | ECHONL); 48 term.c_lflag |= (ECHO | ECHONL);
51 } else { 49 } else {
52 term.c_lflag &= ~(ECHO | ECHONL); 50 term.c_lflag &= ~(ECHO | ECHONL);
53 } 51 }
54 status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term)); 52 status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term));
55 return (status == 0); 53 return (status == 0);
56 } 54 }
57 55
58
59 bool Stdin::GetLineMode(bool* enabled) { 56 bool Stdin::GetLineMode(bool* enabled) {
60 struct termios term; 57 struct termios term;
61 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term)); 58 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
62 if (status != 0) { 59 if (status != 0) {
63 return false; 60 return false;
64 } 61 }
65 *enabled = ((term.c_lflag & ICANON) != 0); 62 *enabled = ((term.c_lflag & ICANON) != 0);
66 return true; 63 return true;
67 } 64 }
68 65
69
70 bool Stdin::SetLineMode(bool enabled) { 66 bool Stdin::SetLineMode(bool enabled) {
71 struct termios term; 67 struct termios term;
72 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term)); 68 int status = NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
73 if (status != 0) { 69 if (status != 0) {
74 return false; 70 return false;
75 } 71 }
76 if (enabled) { 72 if (enabled) {
77 term.c_lflag |= ICANON; 73 term.c_lflag |= ICANON;
78 } else { 74 } else {
79 term.c_lflag &= ~(ICANON); 75 term.c_lflag &= ~(ICANON);
80 } 76 }
81 status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term)); 77 status = NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term));
82 return (status == 0); 78 return (status == 0);
83 } 79 }
84 80
85
86 static bool TermHasXTerm() { 81 static bool TermHasXTerm() {
87 const char* term = getenv("TERM"); 82 const char* term = getenv("TERM");
88 if (term == NULL) { 83 if (term == NULL) {
89 return false; 84 return false;
90 } 85 }
91 return strstr(term, "xterm") != NULL; 86 return strstr(term, "xterm") != NULL;
92 } 87 }
93 88
94
95 bool Stdin::AnsiSupported(bool* supported) { 89 bool Stdin::AnsiSupported(bool* supported) {
96 *supported = isatty(STDIN_FILENO) && TermHasXTerm(); 90 *supported = isatty(STDIN_FILENO) && TermHasXTerm();
97 return true; 91 return true;
98 } 92 }
99 93
100
101 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { 94 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
102 struct winsize w; 95 struct winsize w;
103 int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w)); 96 int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w));
104 if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) { 97 if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) {
105 size[0] = w.ws_col; 98 size[0] = w.ws_col;
106 size[1] = w.ws_row; 99 size[1] = w.ws_row;
107 return true; 100 return true;
108 } 101 }
109 return false; 102 return false;
110 } 103 }
111 104
112
113 bool Stdout::AnsiSupported(intptr_t fd, bool* supported) { 105 bool Stdout::AnsiSupported(intptr_t fd, bool* supported) {
114 *supported = isatty(fd) && TermHasXTerm(); 106 *supported = isatty(fd) && TermHasXTerm();
115 return true; 107 return true;
116 } 108 }
117 109
118 } // namespace bin 110 } // namespace bin
119 } // namespace dart 111 } // namespace dart
120 112
121 #endif // defined(HOST_OS_LINUX) 113 #endif // defined(HOST_OS_LINUX)
122 114
123 #endif // !defined(DART_IO_DISABLED) 115 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/stdio_fuchsia.cc ('k') | runtime/bin/stdio_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698