]> err.no Git - sope/blob - sope-core/NGStreams/NGTerminalSupport.m
Drop apache 1 build-dependency
[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) : (NSString *)nil;
55 #endif
56 }
57
58 @end /* NGFileStream(NGTerminalSupport) */
59
60
61 @implementation NGFilterStream(NGTerminalSupport)
62
63 - (BOOL)isAssociatedWithTerminalDevice {
64   id src = [self source];
65   
66   return [src respondsToSelector:_cmd]
67     ? [src isAssociatedWithTerminalDevice]
68     : NO;
69 }
70
71 - (NSString *)nameOfAssociatedTerminalDevice {
72   id src = [self source];
73   
74   return [src respondsToSelector:_cmd]
75     ? [src nameOfAssociatedTerminalDevice]
76     : NO;
77 }
78
79 @end /* NGFilterStream(NGTerminalSupport) */
80
81
82 @implementation NGTextStream(NGTerminalSupport)
83
84 - (BOOL)isAssociatedWithTerminalDevice {
85   return NO;
86 }
87 - (NSString *)nameOfAssociatedTerminalDevice {
88   return nil;
89 }
90
91 @end /* NGTextStream(NGTerminalSupport) */
92
93
94 @implementation NGCTextStream(NGTerminalSupport)
95
96 - (BOOL)isAssociatedWithTerminalDevice {
97   id src = [self source];
98   
99   return [src respondsToSelector:_cmd]
100     ? [src isAssociatedWithTerminalDevice]
101     : NO;
102 }
103
104 - (NSString *)nameOfAssociatedTerminalDevice {
105   id src = [self source];
106   
107   return [src respondsToSelector:_cmd]
108     ? [src nameOfAssociatedTerminalDevice]
109     : NO;
110 }
111
112 @end /* NGCTextStream(NGTerminalSupport) */
113
114 void __link_NGStreams_NGTerminalSupport(void) {
115   __link_NGStreams_NGTerminalSupport();
116 }