mirror of
https://github.com/gnustep/libs-steptalk.git
synced 2025-02-19 09:50:43 +00:00
Added missing files
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@18064 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
615c291ede
commit
5ce611c23e
4 changed files with 407 additions and 0 deletions
52
Frameworks/StepTalk/STConversation.h
Normal file
52
Frameworks/StepTalk/STConversation.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
STConversation
|
||||||
|
|
||||||
|
Copyright (c) 2002 Free Software Foundation
|
||||||
|
|
||||||
|
Written by: Stefan Urbanek <urbanek@host.sk>
|
||||||
|
Date: 2003 Sep 21
|
||||||
|
|
||||||
|
This file is part of the StepTalk project.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <Foundation/NSObject.h>
|
||||||
|
|
||||||
|
@class STLanguage;
|
||||||
|
@class STEngine;
|
||||||
|
@class STEnvironment;
|
||||||
|
|
||||||
|
@interface STConversation:NSObject
|
||||||
|
{
|
||||||
|
STLanguage *lanuage;
|
||||||
|
STEngine *engine;
|
||||||
|
NSString *languageName;
|
||||||
|
STEnvironment *environment;
|
||||||
|
}
|
||||||
|
+ conversationInEnvironment:(STEnvironment *)env
|
||||||
|
language:(NSString *)langName;
|
||||||
|
|
||||||
|
- initWithEnvironment:(STEnvironment *)env
|
||||||
|
language:(NSString *)aString;
|
||||||
|
|
||||||
|
- (void)setLanguage:(NSString *)newLanguage;
|
||||||
|
- (NSString *)language;
|
||||||
|
|
||||||
|
- (STEnvironment *)environment;
|
||||||
|
|
||||||
|
- (id)runScriptFromString:(NSString *)aString;
|
||||||
|
@end
|
119
Frameworks/StepTalk/STConversation.m
Normal file
119
Frameworks/StepTalk/STConversation.m
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
/**
|
||||||
|
STConversation
|
||||||
|
|
||||||
|
Copyright (c) 2002 Free Software Foundation
|
||||||
|
|
||||||
|
Written by: Stefan Urbanek <urbanek@host.sk>
|
||||||
|
Date: 2003 Sep 21
|
||||||
|
|
||||||
|
This file is part of the StepTalk project.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "STConversation.h"
|
||||||
|
|
||||||
|
#import <Foundation/NSException.h>
|
||||||
|
|
||||||
|
#import "STEngine.h"
|
||||||
|
#import "STEnvironment.h"
|
||||||
|
#import "STLanguage.h"
|
||||||
|
|
||||||
|
@implementation STConversation
|
||||||
|
/** Creates a new conversation with environment created using default
|
||||||
|
description and default language. */
|
||||||
|
+ conversation
|
||||||
|
{
|
||||||
|
STEnvironment *env = [STEnvironment environmentWithDefaultDescription];
|
||||||
|
|
||||||
|
return AUTORELEASE([[self alloc] initWithEnvironment:env language:nil]);
|
||||||
|
}
|
||||||
|
/** Creates a new conversation with environment created using default
|
||||||
|
description and language with name <var>langName</var>. */
|
||||||
|
+ conversationInEnvironment:(STEnvironment *)env
|
||||||
|
language:(NSString *)langName
|
||||||
|
{
|
||||||
|
STConversation *c;
|
||||||
|
c = [[self alloc] initWithEnvironment:env language:langName];
|
||||||
|
return AUTORELEASE(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
- initWithEnvironment:(STEnvironment *)env
|
||||||
|
language:(NSString *)langName
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
if(!env)
|
||||||
|
{
|
||||||
|
[NSException raise:@"STConversationException"
|
||||||
|
format:@"Unspecified environment for a conversation"];
|
||||||
|
[self dealloc];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!langName || [langName isEqual:@""])
|
||||||
|
{
|
||||||
|
languageName = RETAIN([STLanguage defaultLanguageName]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
languageName = RETAIN(langName);
|
||||||
|
}
|
||||||
|
|
||||||
|
environment = RETAIN(env);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
RELEASE(languageName);
|
||||||
|
RELEASE(environment);
|
||||||
|
RELEASE(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)_createEngine
|
||||||
|
{
|
||||||
|
ASSIGN(engine,[STEngine engineForLanguageWithName:languageName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setLanguage:(NSString *)newLanguage
|
||||||
|
{
|
||||||
|
if(![newLanguage isEqual:languageName])
|
||||||
|
{
|
||||||
|
RELEASE(engine);
|
||||||
|
engine = nil;
|
||||||
|
ASSIGN(languageName, newLanguage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return name of the language used in the receiver conversation */
|
||||||
|
- (NSString *)language
|
||||||
|
{
|
||||||
|
return languageName;
|
||||||
|
}
|
||||||
|
- (STEnvironment *)environment
|
||||||
|
{
|
||||||
|
return environment;
|
||||||
|
}
|
||||||
|
- (id)runScriptFromString:(NSString *)aString
|
||||||
|
{
|
||||||
|
if(!engine)
|
||||||
|
{
|
||||||
|
[self _createEngine];
|
||||||
|
}
|
||||||
|
return [engine executeCode: aString inEnvironment:environment];
|
||||||
|
}
|
||||||
|
@end
|
44
Frameworks/StepTalk/STFileScript.h
Normal file
44
Frameworks/StepTalk/STFileScript.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
STScript
|
||||||
|
|
||||||
|
Copyright (c) 2002 Stefan Urbanek
|
||||||
|
|
||||||
|
Written by: Stefan Urbanek <stefanurbanek@yahoo.fr>
|
||||||
|
Date: 2002 Mar 10
|
||||||
|
|
||||||
|
This file is part of the StepTalk project.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <StepTalk/STScript.h>
|
||||||
|
|
||||||
|
@interface STFileScript:STScript
|
||||||
|
{
|
||||||
|
NSString *fileName;
|
||||||
|
NSString *localizedName;
|
||||||
|
NSString *menuKey;
|
||||||
|
NSString *description;
|
||||||
|
}
|
||||||
|
+ scriptWithFile:(NSString *)file;
|
||||||
|
|
||||||
|
- initWithFile:(NSString *)aFile;
|
||||||
|
- (NSString *)fileName;
|
||||||
|
- (NSString *)scriptName;
|
||||||
|
- (NSString *)localizedName;
|
||||||
|
- (NSString *)scriptDescription;
|
||||||
|
- (NSComparisonResult)compareByLocalizedName:(STScript *)aScript;
|
||||||
|
@end
|
192
Frameworks/StepTalk/STFileScript.m
Normal file
192
Frameworks/StepTalk/STFileScript.m
Normal file
|
@ -0,0 +1,192 @@
|
||||||
|
/**
|
||||||
|
STScript
|
||||||
|
|
||||||
|
Copyright (c) 2002 Stefan Urbanek
|
||||||
|
|
||||||
|
Written by: Stefan Urbanek <stefanurbanek@yahoo.fr>
|
||||||
|
Date: 2002 Mar 10
|
||||||
|
|
||||||
|
This file is part of the StepTalk project.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "STFileScript.h"
|
||||||
|
|
||||||
|
#import "STLanguage.h"
|
||||||
|
|
||||||
|
#import <Foundation/NSArray.h>
|
||||||
|
#import <Foundation/NSDictionary.h>
|
||||||
|
#import <Foundation/NSEnumerator.h>
|
||||||
|
#import <Foundation/NSFileManager.h>
|
||||||
|
#import <Foundation/NSUserDefaults.h>
|
||||||
|
|
||||||
|
@interface NSDictionary(LocalizedKey)
|
||||||
|
- (id)localizedObjectForKey:(NSString *)key;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSDictionary(LocalizedKey)
|
||||||
|
- (id)localizedObjectForKey:(NSString *)key
|
||||||
|
{
|
||||||
|
NSEnumerator *enumerator;
|
||||||
|
NSDictionary *dict;;
|
||||||
|
NSString *language;
|
||||||
|
NSArray *languages;
|
||||||
|
id obj = nil;
|
||||||
|
|
||||||
|
languages = [NSUserDefaults userLanguages];
|
||||||
|
|
||||||
|
enumerator = [languages objectEnumerator];
|
||||||
|
|
||||||
|
while( (language = [enumerator nextObject]) )
|
||||||
|
{
|
||||||
|
dict = [self objectForKey:language];
|
||||||
|
obj = [dict objectForKey:key];
|
||||||
|
|
||||||
|
if(obj)
|
||||||
|
{
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [[self objectForKey:@"Default"] objectForKey:key];
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation STFileScript
|
||||||
|
+ scriptWithFile:(NSString *)file
|
||||||
|
{
|
||||||
|
STFileScript *script;
|
||||||
|
|
||||||
|
script = [[STFileScript alloc] initWithFile:file];
|
||||||
|
|
||||||
|
return AUTORELEASE(script);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
Create a new script from file <var>aFile></var>. Script information will
|
||||||
|
be read from 'aFile.stinfo' file containing a dictionary property list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
- initWithFile:(NSString *)aFile
|
||||||
|
{
|
||||||
|
NSFileManager *manager = [NSFileManager defaultManager];
|
||||||
|
NSDictionary *info = nil;
|
||||||
|
NSString *infoFile;
|
||||||
|
NSString *lang;
|
||||||
|
BOOL isDir;
|
||||||
|
|
||||||
|
// infoFile = [aFile stringByDeletingPathExtension];
|
||||||
|
infoFile = [aFile stringByAppendingPathExtension: @"stinfo"];
|
||||||
|
|
||||||
|
if([manager fileExistsAtPath:infoFile isDirectory:&isDir] && !isDir )
|
||||||
|
{
|
||||||
|
info = [NSDictionary dictionaryWithContentsOfFile:infoFile];
|
||||||
|
}
|
||||||
|
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
fileName = RETAIN(aFile);
|
||||||
|
|
||||||
|
localizedName = [info localizedObjectForKey:@"Name"];
|
||||||
|
|
||||||
|
if(!localizedName)
|
||||||
|
{
|
||||||
|
localizedName = [[fileName lastPathComponent]
|
||||||
|
stringByDeletingPathExtension];
|
||||||
|
}
|
||||||
|
|
||||||
|
RETAIN(localizedName);
|
||||||
|
|
||||||
|
menuKey = RETAIN([info localizedObjectForKey:@"MenuKey"]);
|
||||||
|
description = RETAIN([info localizedObjectForKey:@"Description"]);
|
||||||
|
lang = [info localizedObjectForKey:@"Language"];
|
||||||
|
|
||||||
|
if(!lang)
|
||||||
|
{
|
||||||
|
lang = [STLanguage languageNameForFileType:[fileName pathExtension]];
|
||||||
|
}
|
||||||
|
if(!lang)
|
||||||
|
{
|
||||||
|
lang = @"Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
[self setLanguage:lang];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
RELEASE(fileName);
|
||||||
|
RELEASE(localizedName);
|
||||||
|
RELEASE(menuKey);
|
||||||
|
RELEASE(description);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return file name of the receiver. */
|
||||||
|
- (NSString *)fileName
|
||||||
|
{
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return menu item key equivalent for receiver. */
|
||||||
|
- (NSString *)menuKey
|
||||||
|
{
|
||||||
|
return menuKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns source string of the receiver script.*/
|
||||||
|
- (NSString *)source
|
||||||
|
{
|
||||||
|
/* FIXME
|
||||||
|
if(!source)
|
||||||
|
{
|
||||||
|
source = [[NSString alloc] initWithContentsOfFile:fileName];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return [[NSString alloc] initWithContentsOfFile:fileName];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a script name by which the script is identified */
|
||||||
|
- (NSString *)scriptName
|
||||||
|
{
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns localized name of the receiver script. */
|
||||||
|
- (NSString *)localizedName
|
||||||
|
{
|
||||||
|
return localizedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns localized description of the script. */
|
||||||
|
- (NSString *)scriptDescription
|
||||||
|
{
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
/** Returns language of the script. */
|
||||||
|
- (NSString *)language
|
||||||
|
{
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Compare scripts by localized name. */
|
||||||
|
- (NSComparisonResult)compareByLocalizedName:(STFileScript *)aScript
|
||||||
|
{
|
||||||
|
return [localizedName caseInsensitiveCompare:[aScript localizedName]];
|
||||||
|
}
|
||||||
|
@end
|
Loading…
Reference in a new issue