]> err.no Git - sope/blob - sope-core/NGStreams/NGTerminalSupport.m
bringing libFoundation-1.0.75 into the main branch
[sope] / sope-core / NGStreams / NGTerminalSupport.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with SOPE; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "NGTerminalSupport.h"
23 #include "NGFileStream.h"
24 #include "NGFilterStream.h"
25 #include "NGCTextStream.h"
26 #include "NGDescriptorFunctions.h"
27
28 @implementation NGStream(NGTerminalSupport)
29
30 - (BOOL)isAssociatedWithTerminalDevice {
31   return NO;
32 }
33
34 - (NSString *)nameOfAssociatedTerminalDevice {
35   return nil;
36 }
37
38 @end
39
40 @implementation NGFileStream(NGTerminalSupport)
41
42 - (BOOL)isAssociatedWithTerminalDevice {
43 #if defined(WIN32)
44   return NO;
45 #else
46   return [self isOpen] ? NGDescriptorIsAtty(self->fd) : NO;
47 #endif
48 }
49
50 - (NSString *)nameOfAssociatedTerminalDevice {
51 #if defined(WIN32)
52   return nil;
53 #else
54   return [self isOpen] ? NGDescriptorGetTtyName(self->fd) : nil;
55 #endif
56 }
57
58 @end
59
60 @implementation NGFilterStream(NGTerminalSupport)
61
62 - (BOOL)isAssociatedWithTerminalDevice {
63   id src = [self source];
64   
65   return [src respondsToSelector:_cmd]
66     ? [src isAssociatedWithTerminalDevice]
67     : NO;
68 }
69
70 - (NSString *)nameOfAssociatedTerminalDevice {
71   id src = [self source];
72   
73   return [src respondsToSelector:_cmd]
74     ? [src nameOfAssociatedTerminalDevice]
75     : NO;
76 }
77
78 @end
79
80 @implementation NGTextStream(NGTerminalSupport)
81
82 - (BOOL)isAssociatedWithTerminalDevice {
83   return NO;
84 }
85 - (NSString *)nameOfAssociatedTerminalDevice {
86   return nil;
87 }
88
89 @end
90
91 @implementation NGCTextStream(NGTerminalSupport)
92
93 - (BOOL)isAssociatedWithTerminalDevice {
94   id src = [self source];
95   
96   return [src respondsToSelector:_cmd]
97     ? [src isAssociatedWithTerminalDevice]
98     : NO;
99 }
100
101 - (NSString *)nameOfAssociatedTerminalDevice {
102   id src = [self source];
103   
104   return [src respondsToSelector:_cmd]
105     ? [src nameOfAssociatedTerminalDevice]
106     : NO;
107 }
108
109 @end
110
111 void __link_NGStreams_NGTerminalSupport(void) {
112   __link_NGStreams_NGTerminalSupport();
113 }