Index: .fossil-settings/clean-glob ================================================================== --- .fossil-settings/clean-glob +++ .fossil-settings/clean-glob @@ -48,9 +48,10 @@ tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config +utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -53,9 +53,10 @@ tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config +utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp Index: .gitignore ================================================================== --- .gitignore +++ .gitignore @@ -53,9 +53,10 @@ tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config +utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1225,10 +1225,11 @@ AC_ARG_ENABLE(files, AS_HELP_STRING([--disable-files], [disable file support])) AS_IF([test x"$enable_files" != x"no"], [ AC_DEFINE(OF_HAVE_FILES, 1, [Whether we have files]) AC_SUBST(USE_SRCS_FILES, '${SRCS_FILES}') + AC_SUBST(OBJFW_NEW, "objfw-new") AC_SUBST(OFARC, "ofarc") AC_SUBST(OFHASH, "ofhash") case "$host_os" in msdosdjgpp*) Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -41,10 +41,11 @@ LOOKUP_ASM_A = @LOOKUP_ASM_A@ LOOKUP_ASM_AMIGALIB_A = @LOOKUP_ASM_AMIGALIB_A@ LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@ MAP_LDFLAGS = @MAP_LDFLAGS@ OBJC_SYNC = @OBJC_SYNC@ +OBJFW_NEW = @OBJFW_NEW@ OFARC = @OFARC@ OFDNS = @OFDNS@ OFHASH = @OFHASH@ OFHTTP = @OFHTTP@ OFHTTP_LIBS = @OFHTTP_LIBS@ Index: utils/Makefile ================================================================== --- utils/Makefile +++ utils/Makefile @@ -1,8 +1,9 @@ include ../extra.mk -SUBDIRS += ${OFARC} \ +SUBDIRS += ${OBJFW_NEW} \ + ${OFARC} \ ${OFDNS} \ ${OFHASH} \ ${OFHTTP} \ completions ADDED utils/objfw-new/Makefile Index: utils/objfw-new/Makefile ================================================================== --- /dev/null +++ utils/objfw-new/Makefile @@ -0,0 +1,20 @@ +include ../../extra.mk + +PROG = objfw-new${PROG_SUFFIX} +SRCS = NewApp.m \ + NewClass.m \ + ObjFWNew.m + +include ../../buildsys.mk + +${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} + +CPPFLAGS += -I../../src \ + -I../../src/runtime \ + -I../../src/exceptions \ + -I../.. +LIBS := -L../../src -lobjfw \ + -L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \ + ${LIBS} +LD = ${OBJC} +LDFLAGS += ${LDFLAGS_RPATH} ADDED utils/objfw-new/NewApp.m Index: utils/objfw-new/NewApp.m ================================================================== --- /dev/null +++ utils/objfw-new/NewApp.m @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFApplication.h" +#import "OFFile.h" +#import "OFStdIOStream.h" +#import "OFString.h" + +#import "OFOpenItemFailedException.h" + +void +newApp(OFString *name) +{ + OFString *path = [name stringByAppendingPathExtension: @"m"]; + OFFile *file; + @try { + file = [OFFile fileWithPath: path mode: @"wx"]; + } @catch (OFOpenItemFailedException *e) { + if (e.errNo != EEXIST) + @throw e; + + [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", + e.path]; + [OFApplication terminateWithStatus: 1]; + } + + [file writeFormat: @"#import \n" + @"\n" + @"@interface %@: OFObject \n" + @"@end\n" + @"\n" + @"OF_APPLICATION_DELEGATE(%@)\n" + @"\n" + @"@implementation %@\n" + @"- (void)applicationDidFinishLaunching\n" + @"{\n" + @" [OFApplication terminate];\n" + @"}\n" + @"@end\n", + name, name, name]; + + [file close]; +} ADDED utils/objfw-new/NewClass.m Index: utils/objfw-new/NewClass.m ================================================================== --- /dev/null +++ utils/objfw-new/NewClass.m @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFApplication.h" +#import "OFFile.h" +#import "OFStdIOStream.h" +#import "OFString.h" + +#import "OFOpenItemFailedException.h" + +void +newClass(OFString *name) +{ + OFString *headerPath = [name stringByAppendingPathExtension: @"h"]; + OFString *implPath = [name stringByAppendingPathExtension: @"m"]; + OFFile *headerFile, *implFile; + @try { + headerFile = [OFFile fileWithPath: headerPath mode: @"wx"]; + implFile = [OFFile fileWithPath: implPath mode: @"wx"]; + } @catch (OFOpenItemFailedException *e) { + if (e.errNo != EEXIST) + @throw e; + + [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", + e.path]; + [OFApplication terminateWithStatus: 1]; + } + + [headerFile writeFormat: @"#import \n" + @"\n" + @"@interface %@: OFObject\n" + @"@end\n", + name]; + + [implFile writeFormat: @"#import \"%@\"\n" + @"\n" + @"@implementation %@\n" + @"@end\n", + headerPath, name]; + + [headerFile close]; + [implFile close]; +} ADDED utils/objfw-new/ObjFWNew.m Index: utils/objfw-new/ObjFWNew.m ================================================================== --- /dev/null +++ utils/objfw-new/ObjFWNew.m @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFApplication.h" +#import "OFArray.h" +#import "OFObject.h" +#import "OFStdIOStream.h" +#import "OFString.h" + +@interface ObjFWNew: OFObject +@end + +extern void newApp(OFString *); +extern void newClass(OFString *); + +OF_APPLICATION_DELEGATE(ObjFWNew) + +static void +showUsage(void) +{ + [OFStdErr writeFormat: @"Usage: %@ app|class name [properties]\n", + [OFApplication programName]]; + + [OFApplication terminateWithStatus: 1]; +} + +@implementation ObjFWNew +- (void)applicationDidFinishLaunching +{ + OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments]; + OFString *type, *name; + + if (arguments.count != 2) + showUsage(); + + type = [arguments objectAtIndex: 0]; + name = [arguments objectAtIndex: 1]; + + if ([type isEqual: @"app"]) + newApp(name); + else if ([type isEqual: @"class"]) + newClass(name); + else + showUsage(); + + [OFApplication terminate]; +} +@end