Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My improvements #173

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d1796be
Initial pokes for re-doing how protocols are handled.
MaddTheSane Jan 29, 2025
0c163f1
Remove forward declarations for non-existent symbols.
MaddTheSane Jan 30, 2025
c932b83
Initial work on migrating to ObjC 2 properties.
MaddTheSane Jan 30, 2025
9b80595
Const-ify some NSStrings.
MaddTheSane Jan 30, 2025
c346c82
More Swift-friendly stuff, this time adding XADStringEncodingName and…
MaddTheSane Jan 31, 2025
8bcbf0a
Add XADForkStyle NS_ENUM.
MaddTheSane Jan 31, 2025
9b891eb
Fix oversights:
MaddTheSane Jan 31, 2025
fe11b8f
pokes
MaddTheSane Feb 1, 2025
fd00cc1
Convert some ints to NSInteger.
MaddTheSane Feb 1, 2025
bf1322f
Xcode project maintenance.
MaddTheSane Feb 1, 2025
dce2fca
Make an NSError domain for XADError. This makes any NSError with a XA…
MaddTheSane Feb 1, 2025
fed64c6
Implement the wrappers around throwing functions.
MaddTheSane Feb 2, 2025
da98dff
More files overlooked, more fixes.
MaddTheSane Feb 3, 2025
631a4e8
XADPlatformMacOSX: Replace usage of typeFSRef with typeFileURL
MaddTheSane Feb 3, 2025
fc6096e
Minor for-in migration.
MaddTheSane Feb 3, 2025
a05e642
More for-in syntax migration.
MaddTheSane Feb 3, 2025
020cfbb
More fixing, mostly related to XADArchive.
MaddTheSane Feb 3, 2025
ba91641
Adding NS_REQUIRES_NIL_TERMINATION to CSMultiHandle.
MaddTheSane Feb 6, 2025
bcc60ad
Fix some oversights noticed when trying to build on Linux.
MaddTheSane Feb 7, 2025
471270e
Remove NS_NONATOMIC_IOSONLY macro as gcc seems to hate macros in prop…
MaddTheSane Feb 7, 2025
c516f7b
Remove references to __autoreleasing and _Nullable
MaddTheSane Feb 7, 2025
df0b0d8
Still trying to get it to build on Linux.
MaddTheSane Feb 7, 2025
d6d6e06
More fixes for Linux.
MaddTheSane Feb 7, 2025
0350e8a
Quiet deprecation warnings in lsar and unar.
MaddTheSane Feb 7, 2025
5ddb236
Quiet a few more Linux warnings.
MaddTheSane Feb 7, 2025
3d7269b
Another rename.
MaddTheSane Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 28 additions & 42 deletions CSCommandLineParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@



static NSString *NamesKey=@"NamesKey";
static NSString *AllowedValuesKey=@"AllowedValuesKey";
static NSString *DefaultValueKey=@"DefaultValueKey";
static NSString *OptionTypeKey=@"OptionType";
static NSString *DescriptionKey=@"DescriptionKey";
static NSString *ArgumentDescriptionKey=@"ArgumentDescriptionKey";
static NSString *AliasTargetKey=@"AliasTargetKey";
static NSString *RequiredOptionsKey=@"RequiredOptionsKey";

static NSString *NumberValueKey=@"NumberValue";
static NSString *StringValueKey=@"StringValue";
static NSString *ArrayValueKey=@"ArrayValue";

static NSString *StringOptionType=@"StringOptionType";
static NSString *MultipleChoiceOptionType=@"MultipleChoiceOptionType";
static NSString *IntegerOptionType=@"IntegerOptionType";
static NSString *FloatingPointOptionType=@"FloatingPointOptionType";
static NSString *SwitchOptionType=@"SwitchOptionType";
static NSString *HelpOptionType=@"HelpOptionType";
static NSString *VersionOptionType=@"VersionOptionType";
static NSString *AliasOptionType=@"AliasOptionType";
static NSString *const NamesKey=@"NamesKey";
static NSString *const AllowedValuesKey=@"AllowedValuesKey";
static NSString *const DefaultValueKey=@"DefaultValueKey";
static NSString *const OptionTypeKey=@"OptionType";
static NSString *const DescriptionKey=@"DescriptionKey";
static NSString *const ArgumentDescriptionKey=@"ArgumentDescriptionKey";
static NSString *const AliasTargetKey=@"AliasTargetKey";
static NSString *const RequiredOptionsKey=@"RequiredOptionsKey";

static NSString *const NumberValueKey=@"NumberValue";
static NSString *const StringValueKey=@"StringValue";
static NSString *const ArrayValueKey=@"ArrayValue";

static NSString *const StringOptionType=@"StringOptionType";
static NSString *const MultipleChoiceOptionType=@"MultipleChoiceOptionType";
static NSString *const IntegerOptionType=@"IntegerOptionType";
static NSString *const FloatingPointOptionType=@"FloatingPointOptionType";
static NSString *const SwitchOptionType=@"SwitchOptionType";
static NSString *const HelpOptionType=@"HelpOptionType";
static NSString *const VersionOptionType=@"VersionOptionType";
static NSString *const AliasOptionType=@"AliasOptionType";

#if MAC_OS_X_VERSION_MAX_ALLOWED<1050
@interface NSScanner (BuildKludge)
Expand Down Expand Up @@ -388,9 +388,7 @@ -(void)addRequiredOption:(NSString *)requiredoption

-(void)addRequiredOptionsArray:(NSArray *)requiredoptions
{
NSEnumerator *enumerator=[requiredoptions objectEnumerator];
NSString *requiredoption;
while((requiredoption=[enumerator nextObject])) [self addRequiredOption:requiredoption];
for(NSString *requiredoption in requiredoptions) [self addRequiredOption:requiredoption];
}

-(void)addRequiredOption:(NSString *)requiredoption forOption:(NSString *)option
Expand All @@ -409,9 +407,7 @@ -(void)addRequiredOption:(NSString *)requiredoption forOption:(NSString *)option

-(void)addRequiredOptionsArray:(NSArray *)requiredoptions forOption:(NSString *)option
{
NSEnumerator *enumerator=[requiredoptions objectEnumerator];
NSString *requiredoption;
while((requiredoption=[enumerator nextObject])) [self addRequiredOption:requiredoption forOption:option];
for(NSString *requiredoption in requiredoptions) [self addRequiredOption:requiredoption forOption:option];
}


Expand Down Expand Up @@ -620,9 +616,7 @@ -(void)_parseOptionWithDictionary:(NSMutableDictionary *)dict type:(NSString *)t

-(void)_setDefaultValues
{
NSEnumerator *enumerator=[options objectEnumerator];
NSMutableDictionary *dict;
while((dict=[enumerator nextObject]))
for(NSMutableDictionary *dict in [options objectEnumerator])
{
id defaultvalue=[dict objectForKey:DefaultValueKey];
if(!defaultvalue) continue;
Expand Down Expand Up @@ -660,9 +654,7 @@ -(void)_enforceRequirementsWithErrors:(NSMutableArray *)errors
{
if([alwaysrequiredoptions count]) [self _requireOptionsInArray:alwaysrequiredoptions when:@"" errors:errors];

NSEnumerator *enumerator=[options objectEnumerator];
NSDictionary *dict;
while((dict=[enumerator nextObject]))
for(NSDictionary *dict in [options objectEnumerator])
{
NSArray *names=[dict objectForKey:NamesKey];
NSString *name=[names objectAtIndex:0];
Expand All @@ -682,9 +674,7 @@ -(void)_requireOptionsInArray:(NSArray *)requiredoptions when:(NSString *)when e
{
NSMutableSet *set=[NSMutableSet set];

NSEnumerator *enumerator=[requiredoptions objectEnumerator];
NSString *requiredoption;
while((requiredoption=[enumerator nextObject]))
for(NSString *requiredoption in requiredoptions)
{
if(![self _isOptionDefined:requiredoption]) [set addObject:requiredoption];
}
Expand All @@ -693,9 +683,7 @@ -(void)_requireOptionsInArray:(NSArray *)requiredoptions when:(NSString *)when e

NSMutableArray *array=[NSMutableArray array];

enumerator=[optionordering objectEnumerator];
NSString *option;
while((option=[enumerator nextObject]))
for(NSString *option in optionordering)
{
if([set containsObject:option]) [array addObject:[self _describeOption:option]];
}
Expand Down Expand Up @@ -737,9 +725,7 @@ -(NSString *)_describeOptionAndArgument:(NSString *)name

-(void)_reportErrors:(NSArray *)errors
{
NSEnumerator *enumerator=[errors objectEnumerator];
NSString *error;
while((error=[enumerator nextObject]))
for(NSString *error in errors)
{
[error print];
[@"\n" print];
Expand Down
18 changes: 12 additions & 6 deletions CSFileHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

#define CSFileHandle XADFileHandle

extern NSString *CSCannotOpenFileException;
extern NSString *CSFileErrorException;
extern NSExceptionName const CSCannotOpenFileException;
extern NSExceptionName const CSFileErrorException;

@interface CSFileHandle:CSHandle
{
Expand All @@ -41,6 +41,12 @@ extern NSString *CSFileErrorException;
+(CSFileHandle *)fileHandleForReadingAtPath:(NSString *)path;
+(CSFileHandle *)fileHandleForWritingAtPath:(NSString *)path;
+(CSFileHandle *)fileHandleForPath:(NSString *)path modes:(NSString *)modes;
+(CSFileHandle *)fileHandleForReadingAtFileURL:(NSURL *)path NS_SWIFT_UNAVAILABLE("Use throwing methods instead");
+(CSFileHandle *)fileHandleForWritingAtFileURL:(NSURL *)path NS_SWIFT_UNAVAILABLE("Use throwing methods instead");
+(CSFileHandle *)fileHandleForFileURL:(NSURL *)path modes:(NSString *)modes NS_SWIFT_UNAVAILABLE("Use throwing methods instead");
+(CSFileHandle *)fileHandleForReadingAtFileURL:(NSURL *)path error:(NSError**)outErr;
+(CSFileHandle *)fileHandleForWritingAtFileURL:(NSURL *)path error:(NSError**)outErr;
+(CSFileHandle *)fileHandleForFileURL:(NSURL *)path modes:(NSString *)modes error:(NSError**)outErr;
+(CSFileHandle *)fileHandleForStandardInput;
+(CSFileHandle *)fileHandleForStandardOutput;
+(CSFileHandle *)fileHandleForStandardError;
Expand All @@ -52,12 +58,12 @@ extern NSString *CSFileErrorException;
-(void)close;

// Public methods
-(FILE *)filePointer;
@property (readonly) FILE *filePointer NS_RETURNS_INNER_POINTER;

// Implemented by this class
-(off_t)fileSize;
-(off_t)offsetInFile;
-(BOOL)atEndOfFile;
@property (readonly) off_t fileSize;
@property (readonly) off_t offsetInFile;
@property (readonly) BOOL atEndOfFile;

-(void)seekToFileOffset:(off_t)offs;
-(void)seekToEndOfFile;
Expand Down
79 changes: 77 additions & 2 deletions CSFileHandle.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,93 @@
* MA 02110-1301 USA
*/
#import "CSFileHandle.h"
#import "XADException.h"

#include <sys/stat.h>



NSString *CSCannotOpenFileException=@"CSCannotOpenFileException";
NSString *CSFileErrorException=@"CSFileErrorException";
NSString *const CSCannotOpenFileException=@"CSCannotOpenFileException";
NSString *const CSFileErrorException=@"CSFileErrorException";




@implementation CSFileHandle
@synthesize filePointer = fh;

+(CSFileHandle *)fileHandleForReadingAtFileURL:(NSURL *)path
{ return [self fileHandleForFileURL:path modes:@"rb"]; }

+(CSFileHandle *)fileHandleForWritingAtFileURL:(NSURL *)path
{ return [self fileHandleForFileURL:path modes:@"wb"]; }

+(CSFileHandle *)fileHandleForFileURL:(NSURL *)path modes:(NSString *)modes
{
if(!path) return nil;

#if defined(__COCOTRON__) // Cocotron
FILE *fileh=_wfopen([path fileSystemRepresentationW],
(const wchar_t *)[modes cStringUsingEncoding:NSUnicodeStringEncoding]);
#elif defined(__MINGW32__) // GNUstep under mingw32 - sort of untested
FILE *fileh=_wfopen((const wchar_t *)[path fileSystemRepresentation],
(const wchar_t *)[modes cStringUsingEncoding:NSUnicodeStringEncoding]);
#else // Cocoa or GNUstep under Linux
FILE *fileh=fopen([path fileSystemRepresentation],modes.UTF8String);
#endif

if(!fileh) [[NSException exceptionWithName:CSCannotOpenFileException
reason: [NSString stringWithFormat:@"Error attempting to open file \"%@\" in mode \"%@\" (%d).",path,modes, (int)errno]
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil], NSUnderlyingErrorKey, path, NSURLErrorKey, nil]] raise];

CSFileHandle *handle=[[CSFileHandle alloc] initWithFilePointer:fileh closeOnDealloc:YES path:path.path];
if(handle) return handle;

fclose(fileh);
return nil;
}

+(CSFileHandle *)fileHandleForReadingAtFileURL:(NSURL *)path error:(NSError **)outErr
{ return [self fileHandleForFileURL:path modes:@"rb" error:outErr]; }

+(CSFileHandle *)fileHandleForWritingAtFileURL:(NSURL *)path error:(NSError **)outErr
{ return [self fileHandleForFileURL:path modes:@"wb" error:outErr]; }

+(CSFileHandle *)fileHandleForFileURL:(NSURL *)path modes:(NSString *)modes error:(NSError **)outErr
{
if(!path) {
if (outErr) {
*outErr = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:nil];
}
return nil;
}

#if defined(__COCOTRON__) // Cocotron
FILE *fileh=_wfopen([path fileSystemRepresentationW],
(const wchar_t *)[modes cStringUsingEncoding:NSUnicodeStringEncoding]);
#elif defined(__MINGW32__) // GNUstep under mingw32 - sort of untested
FILE *fileh=_wfopen((const wchar_t *)[path fileSystemRepresentation],
(const wchar_t *)[modes cStringUsingEncoding:NSUnicodeStringEncoding]);
#else // Cocoa or GNUstep under Linux
FILE *fileh=fopen([path fileSystemRepresentation],modes.UTF8String);
#endif

if(!fileh) {
if (outErr) {
*outErr = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:[NSDictionary dictionaryWithObjectsAndKeys:path, NSURLErrorKey, nil]];
}
return nil;
}

CSFileHandle *handle=[[CSFileHandle alloc] initWithFilePointer:fileh closeOnDealloc:YES path:path.path];
if(handle) return handle;

fclose(fileh);
if (outErr) {
*outErr = [NSError errorWithDomain:XADErrorDomain code:XADErrorUnknown userInfo:[NSDictionary dictionaryWithObjectsAndKeys:path, NSURLErrorKey, nil]];
}
return nil;
}

+(CSFileHandle *)fileHandleForReadingAtPath:(NSString *)path
{ return [self fileHandleForPath:path modes:@"rb"]; }
Expand Down
14 changes: 9 additions & 5 deletions CSHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*/
#import <Foundation/Foundation.h>
#import <stdint.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
#import "XADTypes.h"
#pragma clang diagnostic pop



Expand All @@ -38,13 +42,13 @@
#endif


extern NSString *CSOutOfMemoryException;
extern NSString *CSEndOfFileException;
extern NSString *CSNotImplementedException;
extern NSString *CSNotSupportedException;

XADEXTERN NSExceptionName const CSOutOfMemoryException;
XADEXTERN NSExceptionName const CSEndOfFileException;
XADEXTERN NSExceptionName const CSNotImplementedException;
XADEXTERN NSExceptionName const CSNotSupportedException;


XADEXPORT
@interface CSHandle:NSObject <NSCopying>
{
CSHandle *parent;
Expand Down
8 changes: 4 additions & 4 deletions CSHandle.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#include <sys/stat.h>


NSString *CSOutOfMemoryException=@"CSOutOfMemoryException";
NSString *CSEndOfFileException=@"CSEndOfFileException";
NSString *CSNotImplementedException=@"CSNotImplementedException";
NSString *CSNotSupportedException=@"CSNotSupportedException";
NSString *const CSOutOfMemoryException=@"CSOutOfMemoryException";
NSString *const CSEndOfFileException=@"CSEndOfFileException";
NSString *const CSNotImplementedException=@"CSNotImplementedException";
NSString *const CSNotSupportedException=@"CSNotSupportedException";



Expand Down
Loading