1 |
/** |
2 |
ReadlineTranscript.m |
3 |
StepTalk simple transcript |
4 |
|
5 |
Copyright (c) 2002 Free Software Foundation |
6 |
|
7 |
Written by: Stefan Urbanek <urbanek@host.sk> |
8 |
Date: 2001 Apr 13 |
9 |
|
10 |
This file is part of the StepTalk project. |
11 |
|
12 |
This library is free software; you can redistribute it and/or |
13 |
modify it under the terms of the GNU Lesser General Public |
14 |
License as published by the Free Software Foundation; either |
15 |
version 2 of the License, or (at your option) any later version. |
16 |
|
17 |
This library is distributed in the hope that it will be useful, |
18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 |
Lesser General Public License for more details. |
21 |
|
22 |
You should have received a copy of the GNU Lesser General Public |
23 |
License along with this library; if not, write to the Free Software |
24 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
25 |
|
26 |
*/ |
27 |
|
28 |
#import "ReadlineTranscript.h" |
29 |
|
30 |
#import <Foundation/NSValue.h> |
31 |
#import <Foundation/NSString.h> |
32 |
|
33 |
#include <stdio.h> |
34 |
#include <readline/readline.h> |
35 |
|
36 |
static Class NSString_class; |
37 |
static Class NSNumber_class; |
38 |
|
39 |
static ReadlineTranscript *sharedTranscript; |
40 |
|
41 |
@implementation ReadlineTranscript:NSObject |
42 |
+ (void)initialize |
43 |
{ |
44 |
NSString_class = [NSString class]; |
45 |
NSNumber_class = [NSNumber class]; |
46 |
} |
47 |
+ sharedTranscript |
48 |
{ |
49 |
if(!sharedTranscript) |
50 |
{ |
51 |
sharedTranscript = [[ReadlineTranscript alloc] init]; |
52 |
} |
53 |
|
54 |
return sharedTranscript; |
55 |
} |
56 |
- show:(id)anObject |
57 |
{ |
58 |
NSString *string; |
59 |
|
60 |
if( [anObject isKindOfClass:NSString_class] ) |
61 |
{ |
62 |
string = anObject; |
63 |
} |
64 |
else if ( [anObject isKindOfClass:NSNumber_class] ) |
65 |
{ |
66 |
string = [anObject stringValue]; |
67 |
} |
68 |
else |
69 |
{ |
70 |
string = [anObject description]; |
71 |
} |
72 |
|
73 |
printf("%s", [string cString]); |
74 |
|
75 |
return self; |
76 |
} |
77 |
|
78 |
- showLine:(id)anObject |
79 |
{ |
80 |
[self show:anObject]; |
81 |
putchar('\n'); |
82 |
|
83 |
return self; |
84 |
} |
85 |
-(NSString*)readLine:(NSString*)prompt |
86 |
{ |
87 |
NSString *resret=nil; |
88 |
char *res; |
89 |
res = readline([prompt cString]); |
90 |
if (res) |
91 |
{ |
92 |
resret = [NSString stringWithCString: res]; |
93 |
} |
94 |
return resret; |
95 |
} |
96 |
@end |