From 5ce611c23e97059d4791e60c4eaf6ea2ee7d2fd1 Mon Sep 17 00:00:00 2001 From: Stefan Urbanek Date: Sat, 8 Nov 2003 01:29:17 +0000 Subject: [PATCH] Added missing files git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@18064 72102866-910b-0410-8b05-ffd578937521 --- Frameworks/StepTalk/STConversation.h | 52 ++++++++ Frameworks/StepTalk/STConversation.m | 119 +++++++++++++++++ Frameworks/StepTalk/STFileScript.h | 44 ++++++ Frameworks/StepTalk/STFileScript.m | 192 +++++++++++++++++++++++++++ 4 files changed, 407 insertions(+) create mode 100644 Frameworks/StepTalk/STConversation.h create mode 100644 Frameworks/StepTalk/STConversation.m create mode 100644 Frameworks/StepTalk/STFileScript.h create mode 100644 Frameworks/StepTalk/STFileScript.m diff --git a/Frameworks/StepTalk/STConversation.h b/Frameworks/StepTalk/STConversation.h new file mode 100644 index 0000000..7ccd933 --- /dev/null +++ b/Frameworks/StepTalk/STConversation.h @@ -0,0 +1,52 @@ +/** + STConversation + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + 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 + +@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 diff --git a/Frameworks/StepTalk/STConversation.m b/Frameworks/StepTalk/STConversation.m new file mode 100644 index 0000000..6a732a7 --- /dev/null +++ b/Frameworks/StepTalk/STConversation.m @@ -0,0 +1,119 @@ +/** + STConversation + + Copyright (c) 2002 Free Software Foundation + + Written by: Stefan Urbanek + 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 + +#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 langName. */ ++ 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 diff --git a/Frameworks/StepTalk/STFileScript.h b/Frameworks/StepTalk/STFileScript.h new file mode 100644 index 0000000..b68c3bc --- /dev/null +++ b/Frameworks/StepTalk/STFileScript.h @@ -0,0 +1,44 @@ +/** + STScript + + Copyright (c) 2002 Stefan Urbanek + + Written by: Stefan Urbanek + 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 + +@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 diff --git a/Frameworks/StepTalk/STFileScript.m b/Frameworks/StepTalk/STFileScript.m new file mode 100644 index 0000000..192654f --- /dev/null +++ b/Frameworks/StepTalk/STFileScript.m @@ -0,0 +1,192 @@ +/** + STScript + + Copyright (c) 2002 Stefan Urbanek + + Written by: Stefan Urbanek + 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 +#import +#import +#import +#import + +@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 aFile>. 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