#import "IExternalTable.h"
#import "INewsD.h"
#import "ILocalFileD.h"
#import <strings.h>
#import <appkit/Panel.h>
#import "errdebug.h"
#import "Localization.h"

#define LoStr(key)      doLocalString(NULL,key,NULL)

extern const char *externalClassNameTable[];
extern Class ExternalModuleTable[];

@implementation IExternalTable

+ initialize
{
    const char **externalClassNamePtr;
    Class *ExternalModulePtr;

    for (externalClassNamePtr = externalClassNameTable,
        ExternalModulePtr = ExternalModuleTable; *externalClassNamePtr != NULL;
        ++externalClassNamePtr, ++ExternalModulePtr) {
        if ((*ExternalModulePtr = (Class)objc_getClass(*externalClassNamePtr))
            == Nil) {
            NXRunAlertPanel(LoStr("NewsBase"), 
                LoStr("External Class for %s is not linked in NewsBase."),
                NULL, NULL, NULL, *externalClassNamePtr);
        }
    }
    *ExternalModulePtr = Nil;
    return(self);
}

+ (Class)externalModuleForDomain:(NXAtom)domain
{
    Class *ExternalModulePtr;

    for (ExternalModulePtr = ExternalModuleTable; *ExternalModulePtr != Nil &&
        [(id)*ExternalModulePtr domain] != domain; ++ExternalModulePtr);
    if (*ExternalModulePtr != Nil) {
        return(*ExternalModulePtr);
    } else {
        return(Nil);
    }
}

@end;
