1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/*
* Copyright (c) 2008-2025 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3.0 only,
* as published by the Free Software Foundation.
*
* This program 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
* version 3.0 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3.0 along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#import "OFArray.h"
#import "OFXMLAttribute.h"
#import "FuncArrayGenerator.h"
#import "OFInvalidFormatException.h"
#import "OFUnsupportedVersionException.h"
#import "copyright.h"
@implementation FuncArrayGenerator
- (instancetype)initWithLibrary: (OFXMLElement *)library
include: (OFStream *)include
{
self = [super init];
@try {
OFXMLAttribute *version;
if (![library.name isEqual: @"amiga-library"] ||
library.namespace != nil)
@throw [OFInvalidFormatException exception];
if ((version = [library attributeForName: @"version"]) == nil)
@throw [OFInvalidFormatException exception];
if (![version.stringValue isEqual: @"1.0"])
@throw [OFUnsupportedVersionException
exceptionWithVersion: version.stringValue];
_library = objc_retain(library);
_include = objc_retain(include);
} @catch (id e) {
objc_release(self);
@throw e;
}
return self;
}
- (void)dealloc
{
objc_release(_library);
objc_release(_include);
[super dealloc];
}
- (void)generate
{
[_include writeString: COPYRIGHT];
[_include writeString:
@"/* This file is automatically generated from amiga-library.xml */"
@"\n\n"];
for (OFXMLElement *function in [_library elementsForName: @"function"])
[_include writeFormat:
@"(CONST_APTR)glue_%@,\n",
[function attributeForName: @"name"].stringValue];
}
@end
|