Index: utils/ofarc/GZIPArchive.m ================================================================== --- utils/ofarc/GZIPArchive.m +++ utils/ofarc/GZIPArchive.m @@ -46,11 +46,11 @@ @implementation GZIPArchive + (void)initialize { if (self == [GZIPArchive class]) - app = (OFArc *)[[OFApplication sharedApplication] delegate]; + app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (of_string_encoding_t)encoding @@ -94,20 +94,20 @@ - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFString *fileName; OFFile *output; - if ([files count] != 0) { + if (files.count != 0) { [of_stderr writeLine: OF_LOCALIZED(@"cannot_extract_specific_file_from_gz", @"Cannot extract a specific file of a .gz archive!")]; app->_exitStatus = 1; return; } - fileName = [[app->_archivePath lastPathComponent] - stringByDeletingPathExtension]; + fileName = app->_archivePath.lastPathComponent + .stringByDeletingPathExtension; if (app->_outputLevel >= 0) [of_stdout writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; @@ -118,11 +118,11 @@ output = [OFFile fileWithPath: fileName mode: @"w"]; setPermissions(fileName, app->_archivePath); - while (![_stream isAtEndOfStream]) { + while (!_stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: _stream toStream: output fileName: fileName]; if (length < 0) { @@ -139,22 +139,22 @@ } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files { - OFString *fileName = [[app->_archivePath lastPathComponent] - stringByDeletingPathExtension]; + OFString *fileName = app->_archivePath.lastPathComponent + .stringByDeletingPathExtension; - if ([files count] > 0) { + if (files.count > 0) { [of_stderr writeLine: OF_LOCALIZED( @"cannot_print_specific_file_from_gz", @"Cannot print a specific file of a .gz archive!")]; app->_exitStatus = 1; return; } - while (![_stream isAtEndOfStream]) { + while (!_stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: _stream toStream: of_stdout fileName: fileName]; if (length < 0) { Index: utils/ofarc/LHAArchive.m ================================================================== --- utils/ofarc/LHAArchive.m +++ utils/ofarc/LHAArchive.m @@ -40,11 +40,11 @@ static void setPermissions(OFString *path, OFLHAArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS - OFNumber *mode = [entry mode]; + OFNumber *mode = entry.mode; if (mode == nil) return; of_file_attributes_t attributes = [OFDictionary @@ -58,11 +58,11 @@ @implementation LHAArchive + (void)initialize { if (self == [LHAArchive class]) - app = (OFArc *)[[OFApplication sharedApplication] delegate]; + app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (of_string_encoding_t)encoding @@ -81,11 +81,11 @@ @try { _archive = [[OFLHAArchive alloc] initWithStream: stream mode: mode]; if (encoding != OF_STRING_ENCODING_AUTODETECT) - [_archive setEncoding: encoding]; + _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } @@ -104,21 +104,21 @@ OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); - [of_stdout writeLine: [entry fileName]]; + [of_stdout writeLine: entry.fileName]; if (app->_outputLevel >= 1) { - OFString *date = [[entry date] + OFString *date = [entry.date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: - @"%" PRIu32, [entry compressedSize]]; + @"%" PRIu32, entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: - @"%" PRIu32, [entry uncompressedSize]]; + @"%" PRIu32, entry.uncompressedSize]; OFString *CRC16 = [OFString stringWithFormat: - @"%04" PRIX16, [entry CRC16]]; + @"%04" PRIX16, entry.CRC16]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", @"Compressed: %[size] bytes", @@ -130,84 +130,84 @@ @"size", uncompressedSize)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", - @"method", [entry compressionMethod])]; + @"method", entry.compressionMethod)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_date", @"Date: %[date]", @"date", date)]; - if ([entry mode] != nil) { + if (entry.mode != nil) { OFString *modeString = [OFString stringWithFormat: - @"%" PRIo16, [[entry mode] uInt16Value]]; + @"%" PRIo16, entry.mode.uInt16Value]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_mode", @"Mode: %[mode]", @"mode", modeString)]; } - if ([entry UID] != nil) { + if (entry.UID != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_uid", @"UID: %[uid]", - @"uid", [entry UID])]; + @"uid", entry.UID)]; } - if ([entry GID] != nil) { + if (entry.GID != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_gid", @"GID: %[gid]", - @"gid", [entry GID])]; + @"gid", entry.GID)]; } - if ([entry owner] != nil) { + if (entry.owner != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_owner", @"Owner: %[owner]", - @"owner", [entry owner])]; + @"owner", entry.owner)]; } - if ([entry group] != nil) { + if (entry.group != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_group", @"Group: %[group]", - @"group", [entry group])]; + @"group", entry.group)]; } if (app->_outputLevel >= 2) { OFString *headerLevel = [OFString stringWithFormat: @"%" PRIu8, - [entry headerLevel]]; + entry.headerLevel]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_header_level", @"Header level: %[level]", @"level", headerLevel)]; - if ([entry operatingSystemIdentifier] != '\0') { + if (entry.operatingSystemIdentifier != '\0') { OFString *OSID = [OFString stringWithFormat: @"%c", - [entry operatingSystemIdentifier]]; + entry.operatingSystemIdentifier]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_osid", @"Operating system identifier: " "%[osid]", @"osid", OSID)]; } - if ([entry modificationDate] != nil) { - OFString *modificationDate = [[entry - modificationDate] description]; + if (entry.modificationDate != nil) { + OFString *modificationDate = + entry.modificationDate.description; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @@ -214,12 +214,12 @@ @"date", modificationDate)]; } } if (app->_outputLevel >= 3) { - OFString *extensions = indent([[entry - extensions] description]); + OFString *extensions = + indent(entry.extensions.description); [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_extensions", @"Extensions: %[extensions]", @@ -232,22 +232,22 @@ } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - bool all = ([files count] == 0); + bool all = (files.count == 0); OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); - OFString *fileName = [entry fileName]; + OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFFile *output; OFStream *stream; - uint64_t written = 0, size = [entry uncompressedSize]; + uint64_t written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; @@ -283,11 +283,11 @@ } goto outer_loop_end; } - directory = [outFileName stringByDeletingLastPathComponent]; + directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName @@ -297,11 +297,11 @@ stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { @@ -339,11 +339,11 @@ outer_loop_end: objc_autoreleasePoolPop(pool); } - if ([missing count] > 0) { + if (missing.count > 0) { for (OFString *file in missing) [of_stderr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; @@ -355,29 +355,29 @@ - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFLHAArchiveEntry *entry; - if ([files_ count] < 1) { + if (files_.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { - OFString *fileName = [entry fileName]; + OFString *fileName = entry.fileName; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: of_stdout fileName: fileName]; if (length < 0) { @@ -387,11 +387,11 @@ } [files removeObject: fileName]; [stream close]; - if ([files count] == 0) + if (files.count == 0) break; } for (OFString *file in files) { [of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive", @@ -398,15 +398,16 @@ @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } + - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - if ([files count] < 1) { + if (files.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } @@ -422,41 +423,41 @@ [of_stdout writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; - type = [attributes fileType]; + type = attributes.fileType; entry = [OFMutableLHAArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS - [entry setMode: [OFNumber numberWithUInt16: - [attributes filePOSIXPermissions]]]; + entry.mode = [OFNumber numberWithUInt16: + attributes.filePOSIXPermissions]; #endif - [entry setDate: [attributes fileModificationDate]]; + entry.date = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER - [entry setUID: [OFNumber numberWithUInt16: - [attributes filePOSIXUID]]]; - [entry setGID: [OFNumber numberWithUInt16: - [attributes filePOSIXGID]]]; - [entry setOwner: [attributes fileOwner]]; - [entry setGroup: [attributes fileGroup]]; + entry.UID = + [OFNumber numberWithUInt16: attributes.filePOSIXUID]; + entry.GID = + [OFNumber numberWithUInt16: attributes.filePOSIXGID]; + entry.owner = attributes.fileOwner; + entry.group = attributes.fileGroup; #endif if ([type isEqual: of_file_type_directory]) - [entry setCompressionMethod: @"-lhd-"]; + entry.compressionMethod = @"-lhd-"; output = [_archive streamForWritingEntry: entry]; if ([type isEqual: of_file_type_regular]) { - uintmax_t written = 0, size = [attributes fileSize]; + uintmax_t written = 0, size = attributes.fileSize; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; - while (![input isAtEndOfStream]) { + while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; Index: utils/ofarc/OFArc.m ================================================================== --- utils/ofarc/OFArc.m +++ utils/ofarc/OFArc.m @@ -174,18 +174,18 @@ OFArray OF_GENERIC(OFString *) *remainingArguments, *files; id archive; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; - [sandbox setAllowsStdIO: true]; - [sandbox setAllowsReadingFiles: true]; - [sandbox setAllowsWritingFiles: true]; - [sandbox setAllowsCreatingFiles: true]; - [sandbox setAllowsChangingFileAttributes: true]; - [sandbox setAllowsUserDatabaseReading: true]; + sandbox.allowsStdIO = true; + sandbox.allowsReadingFiles = true; + sandbox.allowsWritingFiles = true; + sandbox.allowsCreatingFiles = true; + sandbox.allowsChangingFileAttributes = true; + sandbox.allowsUserDatabaseReading = true; /* Dropped after parsing options */ - [sandbox setAllowsUnveil: true]; + sandbox.allowsUnveil = true; [OFApplication activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS @@ -246,26 +246,26 @@ case '=': [of_stderr writeLine: OF_LOCALIZED( @"option_takes_no_argument", @"%[prog]: Option --%[opt] takes no argument", @"prog", [OFApplication programName], - @"opt", [optionsParser lastLongOption])]; + @"opt", optionsParser.lastLongOption)]; [OFApplication terminateWithStatus: 1]; break; case ':': - if ([optionsParser lastLongOption] != nil) + if (optionsParser.lastLongOption != nil) [of_stderr writeLine: OF_LOCALIZED( @"long_option_requires_argument", @"%[prog]: Option --%[opt] requires an " @"argument", @"prog", [OFApplication programName], - @"opt", [optionsParser lastLongOption])]; + @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", - [optionsParser lastOption]]; + optionsParser.lastOption]; [of_stderr writeLine: OF_LOCALIZED( @"option_requires_argument", @"%[prog]: Option -%[opt] requires an " @"argument", @"prog", [OFApplication programName], @@ -273,20 +273,20 @@ } [OFApplication terminateWithStatus: 1]; break; case '?': - if ([optionsParser lastLongOption] != nil) + if (optionsParser.lastLongOption != nil) [of_stderr writeLine: OF_LOCALIZED( @"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], - @"opt", [optionsParser lastLongOption])]; + @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", - [optionsParser lastOption]]; + optionsParser.lastOption]; [of_stderr writeLine: OF_LOCALIZED( @"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; @@ -307,94 +307,94 @@ @"encoding", encodingString)]; [OFApplication terminateWithStatus: 1]; } - remainingArguments = [optionsParser remainingArguments]; + remainingArguments = optionsParser.remainingArguments; switch (mode) { case 'a': case 'c': - if ([remainingArguments count] < 1) + if (remainingArguments.count < 1) help(of_stderr, false, 1); files = [remainingArguments objectsInRange: - of_range(1, [remainingArguments count] - 1)]; + of_range(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX - [sandbox unveilPath: [remainingArguments firstObject] + [sandbox unveilPath: remainingArguments.firstObject permissions: (mode == 'a' ? @"rwc" : @"wc")]; for (OFString *path in files) [sandbox unveilPath: path permissions: @"r"]; - [sandbox setAllowsUnveil: false]; + sandbox.allowsUnveil = false; [OFApplication activateSandbox: sandbox]; #endif archive = [self - openArchiveWithPath: [remainingArguments firstObject] + openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; [archive addFiles: files]; break; case 'l': - if ([remainingArguments count] != 1) + if (remainingArguments.count != 1) help(of_stderr, false, 1); #ifdef OF_HAVE_SANDBOX - [sandbox unveilPath: [remainingArguments firstObject] + [sandbox unveilPath: remainingArguments.firstObject permissions: @"r"]; - [sandbox setAllowsUnveil: false]; + sandbox.allowsUnveil = false; [OFApplication activateSandbox: sandbox]; #endif archive = [self - openArchiveWithPath: [remainingArguments firstObject] + openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; [archive listFiles]; break; case 'p': - if ([remainingArguments count] < 1) + if (remainingArguments.count < 1) help(of_stderr, false, 1); #ifdef OF_HAVE_SANDBOX - [sandbox unveilPath: [remainingArguments firstObject] + [sandbox unveilPath: remainingArguments.firstObject permissions: @"r"]; - [sandbox setAllowsUnveil: false]; + sandbox.allowsUnveil = false; [OFApplication activateSandbox: sandbox]; #endif files = [remainingArguments objectsInRange: - of_range(1, [remainingArguments count] - 1)]; + of_range(1, remainingArguments.count - 1)]; archive = [self - openArchiveWithPath: [remainingArguments firstObject] + openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; [archive printFiles: files]; break; case 'x': - if ([remainingArguments count] < 1) + if (remainingArguments.count < 1) help(of_stderr, false, 1); files = [remainingArguments objectsInRange: - of_range(1, [remainingArguments count] - 1)]; + of_range(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX - [sandbox unveilPath: [remainingArguments firstObject] + [sandbox unveilPath: remainingArguments.firstObject permissions: @"r"]; - if ([files count] > 0) + if (files.count > 0) for (OFString *path in files) [sandbox unveilPath: path permissions: @"wc"]; else { OFString *path = (outputDir != nil @@ -402,16 +402,16 @@ /* We need 'r' to change the directory to it. */ [sandbox unveilPath: path permissions: @"rwc"]; } - [sandbox setAllowsUnveil: false]; + sandbox.allowsUnveil = false; [OFApplication activateSandbox: sandbox]; #endif archive = [self - openArchiveWithPath: [remainingArguments firstObject] + openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; if (outputDir != nil) @@ -420,28 +420,28 @@ @try { [archive extractFiles: files]; } @catch (OFCreateDirectoryFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stderr writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_create_directory", @"Failed to create directory %[dir]: %[error]", - @"dir", [[e URL] fileSystemRepresentation], + @"dir", e.URL.fileSystemRepresentation, @"error", error)]; _exitStatus = 1; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stderr writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", - @"file", [e path], + @"file", e.path, @"error", error)]; _exitStatus = 1; } break; @@ -488,17 +488,17 @@ @try { file = [OFFile fileWithPath: path mode: fileModeString]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stderr writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", - @"file", [e path], + @"file", e.path, @"error", error)]; [OFApplication terminateWithStatus: 1]; } if (type == nil || [type isEqual: @"auto"]) { @@ -546,30 +546,29 @@ @"Unknown archive type: %[type]", @"type", type)]; goto error; } } @catch (OFNotImplementedException *e) { - if ((mode == 'a' || mode == 'c') && - sel_isEqual([e selector], + if ((mode == 'a' || mode == 'c') && sel_isEqual(e.selector, @selector(initWithStream:mode:))) { writingNotSupported(type); goto error; } @throw e; } @catch (OFReadFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", path, @"error", error)]; goto error; } @catch (OFSeekFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file", @"Failed to seek in file %[file]: %[error]", @"file", path, @"error", error)]; @@ -666,11 +665,11 @@ @try { length = [input readIntoBuffer: buffer length: BUFFER_SIZE]; } @catch (OFReadFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stdout writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", fileName, @@ -681,11 +680,11 @@ @try { [output writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stdout writeString: @"\r"]; [of_stderr writeLine: OF_LOCALIZED(@"failed_to_write_file", @"Failed to write file %[file]: %[error]", @"file", fileName, @@ -698,11 +697,11 @@ - (OFString *)safeLocalPathForPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - path = [path stringByStandardizingPath]; + path = path.stringByStandardizingPath; #if defined(OF_WINDOWS) || defined(OF_MSDOS) if ([path containsString: @":"] || [path hasPrefix: @"\\"]) { #elif defined(OF_AMIGAOS) if ([path containsString: @":"] || [path hasPrefix: @"/"]) { @@ -711,11 +710,11 @@ #endif objc_autoreleasePoolPop(pool); return nil; } - if ([path length] == 0) { + if (path.length == 0) { objc_autoreleasePoolPop(pool); return nil; } /* @@ -722,15 +721,15 @@ * After -[stringByStandardizingPath], everything representing parent * directory should be at the beginning, so in theory checking the * first component should be enough. But it does not hurt being * paranoid and checking all components, just in case. */ - for (OFString *component in [path pathComponents]) { + for (OFString *component in path.pathComponents) { #ifdef OF_AMIGAOS - if ([component length] == 0 || [component isEqual: @"/"]) { + if (component.length == 0 || [component isEqual: @"/"]) { #else - if ([component length] == 0 || [component isEqual: @".."]) { + if (component.length == 0 || [component isEqual: @".."]) { #endif objc_autoreleasePoolPop(pool); return nil; } } Index: utils/ofarc/TarArchive.m ================================================================== --- utils/ofarc/TarArchive.m +++ utils/ofarc/TarArchive.m @@ -34,11 +34,11 @@ static void setPermissions(OFString *path, OFTarArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS of_file_attributes_t attributes = [OFDictionary - dictionaryWithObject: [OFNumber numberWithUInt16: [entry mode]] + dictionaryWithObject: [OFNumber numberWithUInt16: entry.mode] forKey: of_file_attribute_key_posix_permissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; #endif @@ -46,11 +46,11 @@ @implementation TarArchive + (void)initialize { if (self == [TarArchive class]) - app = (OFArc *)[[OFApplication sharedApplication] delegate]; + app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (of_string_encoding_t)encoding @@ -69,11 +69,11 @@ @try { _archive = [[OFTarArchive alloc] initWithStream: stream mode: mode]; if (encoding != OF_STRING_ENCODING_AUTODETECT) - [_archive setEncoding: encoding]; + _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } @@ -92,23 +92,23 @@ OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); - [of_stdout writeLine: [entry fileName]]; + [of_stdout writeLine: entry.fileName]; if (app->_outputLevel >= 1) { - OFString *date = [[entry modificationDate] + OFString *date = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *size = [OFString stringWithFormat: - @"%" PRIu64, [entry size]]; + @"%" PRIu64, entry.size]; OFString *mode = [OFString stringWithFormat: - @"%06o", [entry mode]]; + @"%06o", entry.mode]; OFString *UID = [OFString stringWithFormat: - @"%u", [entry UID]]; + @"%u", entry.UID]; OFString *GID = [OFString stringWithFormat: - @"%u", [entry GID]]; + @"%u", entry.GID]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_size", @"Size: %[size] bytes", @"size", size)]; @@ -123,23 +123,23 @@ [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_gid", @"GID: %[gid]", @"gid", GID)]; - if ([entry owner] != nil) { + if (entry.owner != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_owner", @"Owner: %[owner]", - @"owner", [entry owner])]; + @"owner", entry.owner)]; } - if ([entry group] != nil) { + if (entry.group != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_group", @"Group: %[group]", - @"group", [entry group])]; + @"group", entry.group)]; } [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_modification_date", @@ -148,11 +148,11 @@ } if (app->_outputLevel >= 2) { [of_stdout writeString: @"\t"]; - switch ([entry type]) { + switch (entry.type) { case OF_TAR_ARCHIVE_ENTRY_TYPE_FILE: [of_stdout writeLine: OF_LOCALIZED( @"list_type_normal", @"Type: Normal file")]; break; @@ -162,29 +162,27 @@ @"Type: Hard link")]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_link_target", @"Target file name: %[target]", - @"target", [entry targetFileName])]; + @"target", entry.targetFileName)]; break; case OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK: [of_stdout writeLine: OF_LOCALIZED( @"list_type_symlink", @"Type: Symbolic link")]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_link_target", @"Target file name: %[target]", - @"target", [entry targetFileName])]; + @"target", entry.targetFileName)]; break; case OF_TAR_ARCHIVE_ENTRY_TYPE_CHARACTER_DEVICE: { OFString *majorString = [OFString - stringWithFormat: @"%d", - [entry deviceMajor]]; + stringWithFormat: @"%d", entry.deviceMajor]; OFString *minorString = [OFString - stringWithFormat: @"%d", - [entry deviceMinor]]; + stringWithFormat: @"%d", entry.deviceMinor]; [of_stdout writeLine: OF_LOCALIZED( @"list_type_character_device", @"Type: Character device")]; [of_stdout writeString: @"\t"]; @@ -199,15 +197,13 @@ @"minor", minorString)]; break; } case OF_TAR_ARCHIVE_ENTRY_TYPE_BLOCK_DEVICE: { OFString *majorString = [OFString - stringWithFormat: @"%d", - [entry deviceMajor]]; + stringWithFormat: @"%d", entry.deviceMajor]; OFString *minorString = [OFString - stringWithFormat: @"%d", - [entry deviceMinor]]; + stringWithFormat: @"%d", entry.deviceMinor]; [of_stdout writeLine: OF_LOCALIZED( @"list_type_block_device", @"Type: Block device")]; [of_stdout writeString: @"\t"]; @@ -250,23 +246,23 @@ } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - bool all = ([files count] == 0); + bool all = (files.count == 0); OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); - OFString *fileName = [entry fileName]; - of_tar_archive_entry_type_t type = [entry type]; + OFString *fileName = entry.fileName; + of_tar_archive_entry_type_t type = entry.type; OFString *outFileName, *directory; OFFile *output; OFStream *stream; - uint64_t written = 0, size = [entry size]; + uint64_t written = 0, size = entry.size; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; @@ -314,11 +310,11 @@ } goto outer_loop_end; } - directory = [outFileName stringByDeletingLastPathComponent]; + directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName @@ -328,11 +324,11 @@ stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { @@ -370,11 +366,11 @@ outer_loop_end: objc_autoreleasePoolPop(pool); } - if ([missing count] > 0) { + if (missing.count > 0) { for (OFString *file in missing) [of_stderr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; @@ -386,29 +382,29 @@ - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFTarArchiveEntry *entry; - if ([files_ count] < 1) { + if (files_.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { - OFString *fileName = [entry fileName]; + OFString *fileName = entry.fileName; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: of_stdout fileName: fileName]; if (length < 0) { @@ -418,11 +414,11 @@ } [files removeObject: fileName]; [stream close]; - if ([files count] == 0) + if (files.count == 0) break; } for (OFString *file in files) { [of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive", @@ -434,11 +430,11 @@ - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - if ([files count] < 1) { + if (files.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } @@ -454,50 +450,50 @@ [of_stdout writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; - type = [attributes fileType]; + type = attributes.fileType; entry = [OFMutableTarArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS - [entry setMode: [attributes filePOSIXPermissions]]; + entry.mode = attributes.filePOSIXPermissions; #endif - [entry setSize: [attributes fileSize]]; - [entry setModificationDate: [attributes fileModificationDate]]; + entry.size = attributes.fileSize; + entry.modificationDate = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER - [entry setUID: [attributes filePOSIXUID]]; - [entry setGID: [attributes filePOSIXGID]]; - [entry setOwner: [attributes fileOwner]]; - [entry setGroup: [attributes fileGroup]]; + entry.UID = attributes.filePOSIXUID; + entry.GID = attributes.filePOSIXGID; + entry.owner = attributes.fileOwner; + entry.group = attributes.fileGroup; #endif if ([type isEqual: of_file_type_regular]) - [entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_FILE]; + entry.type = OF_TAR_ARCHIVE_ENTRY_TYPE_FILE; else if ([type isEqual: of_file_type_directory]) { - [entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY]; - [entry setSize: 0]; + entry.type = OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY; + entry.size = 0; } else if ([type isEqual: of_file_type_symbolic_link]) { - [entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK]; - [entry setTargetFileName: - [attributes fileSymbolicLinkDestination]]; - [entry setSize: 0]; + entry.type = OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK; + entry.targetFileName = + attributes.fileSymbolicLinkDestination; + entry.size = 0; } [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; - if ([entry type] == OF_TAR_ARCHIVE_ENTRY_TYPE_FILE) { - uint64_t written = 0, size = [entry size]; + if (entry.type == OF_TAR_ARCHIVE_ENTRY_TYPE_FILE) { + uint64_t written = 0, size = entry.size; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; - while (![input isAtEndOfStream]) { + while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; Index: utils/ofarc/ZIPArchive.m ================================================================== --- utils/ofarc/ZIPArchive.m +++ utils/ofarc/ZIPArchive.m @@ -18,10 +18,11 @@ #include "config.h" #include #import "OFApplication.h" +#import "OFData.h" #import "OFDate.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFSet.h" @@ -39,13 +40,13 @@ static void setPermissions(OFString *path, OFZIPArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS - if (([entry versionMadeBy] >> 8) == + if ((entry.versionMadeBy >> 8) == OF_ZIP_ARCHIVE_ENTRY_ATTR_COMPAT_UNIX) { - uint16_t mode = [entry versionSpecificAttributes] >> 16; + uint16_t mode = entry.versionSpecificAttributes >> 16; of_file_attribute_key_t key = of_file_attribute_key_posix_permissions; of_file_attributes_t attributes = [OFDictionary dictionaryWithObject: [OFNumber numberWithUInt16: mode] forKey: key]; @@ -58,11 +59,11 @@ @implementation ZIPArchive + (void)initialize { if (self == [ZIPArchive class]) - app = (OFArc *)[[OFApplication sharedApplication] delegate]; + app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (of_string_encoding_t)encoding @@ -96,28 +97,28 @@ [super dealloc]; } - (void)listFiles { - for (OFZIPArchiveEntry *entry in [_archive entries]) { + for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); - [of_stdout writeLine: [entry fileName]]; + [of_stdout writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu64, - [entry compressedSize]]; + entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu64, - [entry uncompressedSize]]; + entry.uncompressedSize]; OFString *compressionMethod = of_zip_archive_entry_compression_method_to_string( - [entry compressionMethod]); + entry.compressionMethod); OFString *CRC32 = [OFString - stringWithFormat: @"%08" PRIX32, [entry CRC32]]; - OFString *modificationDate = [[entry modificationDate] + stringWithFormat: @"%08" PRIX32, entry.CRC32]; + OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", @@ -142,11 +143,11 @@ @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; if (app->_outputLevel >= 2) { - uint16_t versionMadeBy = [entry versionMadeBy]; + uint16_t versionMadeBy = entry.versionMadeBy; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_version_made_by", @"Version made by: %[version]", @@ -157,16 +158,16 @@ [of_stdout writeLine: OF_LOCALIZED( @"list_min_version_needed", @"Minimum version needed: %[version]", @"version", of_zip_archive_entry_version_to_string( - [entry minVersionNeeded]))]; + entry.minVersionNeeded))]; if ((versionMadeBy >> 8) == OF_ZIP_ARCHIVE_ENTRY_ATTR_COMPAT_UNIX) { - uint32_t mode = [entry - versionSpecificAttributes] >> 16; + uint32_t mode = entry + .versionSpecificAttributes >> 16; OFString *modeString = [OFString stringWithFormat: @"%06o", mode]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_mode", @@ -175,34 +176,34 @@ } } if (app->_outputLevel >= 3) { OFString *GPBF = [OFString stringWithFormat: - @"%04" PRIx16, - [entry generalPurposeBitFlag]]; + @"%04" PRIx16, entry.generalPurposeBitFlag]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_general_purpose_bit_flag", @"General purpose bit flag: %[gpbf]", @"gpbf", GPBF)]; - if ([entry extraField] != nil) { + if (entry.extraField != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_extra_field", @"Extra field: %[extra]", - @"extra", [entry extraField])]; + @"extra", + entry.extraField.description)]; } } - if ([[entry fileComment] length] > 0) { + if (entry.fileComment.length > 0) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_comment", @"Comment: %[comment]", - @"comment", [entry fileComment])]; + @"comment", entry.fileComment)]; } } objc_autoreleasePoolPop(pool); } @@ -209,21 +210,21 @@ } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - bool all = ([files count] == 0); + bool all = (files.count == 0); OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; - for (OFZIPArchiveEntry *entry in [_archive entries]) { + for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); - OFString *fileName = [entry fileName]; + OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFStream *stream; OFFile *output; - uint64_t written = 0, size = [entry uncompressedSize]; + uint64_t written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; @@ -259,11 +260,11 @@ } goto outer_loop_end; } - directory = [outFileName stringByDeletingLastPathComponent]; + directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName @@ -273,11 +274,11 @@ stream = [_archive streamForReadingFile: fileName]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { @@ -315,11 +316,11 @@ outer_loop_end: objc_autoreleasePoolPop(pool); } - if ([missing count] > 0) { + if (missing.count > 0) { for (OFString *file in missing) [of_stderr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; @@ -330,11 +331,11 @@ - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files { OFStream *stream; - if ([files count] < 1) { + if (files.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } @@ -341,23 +342,23 @@ for (OFString *path in files) { @try { stream = [_archive streamForReadingFile: path]; } @catch (OFOpenItemFailedException *e) { - if ([e errNo] == ENOENT) { + if (e.errNo == ENOENT) { [of_stderr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", - @"file", [e path])]; + @"file", e.path)]; app->_exitStatus = 1; continue; } @throw e; } - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: of_stdout fileName: path]; if (length < 0) { @@ -372,11 +373,11 @@ - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - if ([files count] < 1) { + if (files.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } @@ -389,17 +390,17 @@ bool isDirectory = false; OFMutableZIPArchiveEntry *entry; uintmax_t size; OFStream *output; - components = [localFileName pathComponents]; + components = localFileName.pathComponents; fileName = [components componentsJoinedByString: @"/"]; attributes = [fileManager attributesOfItemAtPath: localFileName]; - if ([[attributes fileType] isEqual: of_file_type_directory]) { + if ([attributes.fileType isEqual: of_file_type_directory]) { isDirectory = true; fileName = [fileName stringByAppendingString: @"/"]; } if (app->_outputLevel >= 0) @@ -407,24 +408,20 @@ @"Adding %[file]...", @"file", fileName)]; entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName]; - if (isDirectory) - size = 0; - else - size = [attributes fileSize]; - + size = (isDirectory ? 0 : attributes.fileSize); if (size > INT64_MAX) @throw [OFOutOfRangeException exception]; - [entry setCompressedSize: (int64_t)size]; - [entry setUncompressedSize: (int64_t)size]; + entry.compressedSize = (int64_t)size; + entry.uncompressedSize = (int64_t)size; - [entry setCompressionMethod: - OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE]; - [entry setModificationDate: [attributes fileModificationDate]]; + entry.compressionMethod = + OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE; + entry.modificationDate = attributes.fileModificationDate; [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; @@ -433,11 +430,11 @@ int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; - while (![input isAtEndOfStream]) { + while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; Index: utils/ofdns/OFDNS.m ================================================================== --- utils/ofdns/OFDNS.m +++ utils/ofdns/OFDNS.m @@ -61,43 +61,43 @@ OFDNSResolver *resolver; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [[OFSandbox alloc] init]; @try { - [sandbox setAllowsStdIO: true]; - [sandbox setAllowsDNS: true]; + sandbox.allowsStdIO = true; + sandbox.allowsDNS = true; [OFApplication activateSandbox: sandbox]; } @finally { [sandbox release]; } #endif - if ([arguments count] < 1 || [arguments count] > 4) { + if (arguments.count < 1 || arguments.count > 4) { [of_stderr writeFormat: @"Usage: %@ host [type [class [server]]]\n", [OFApplication programName]]; [OFApplication terminateWithStatus: 1]; } resolver = [OFDNSResolver resolver]; - if ([arguments count] >= 2) + if (arguments.count >= 2) recordType = of_dns_resource_record_type_parse( [arguments objectAtIndex: 1]); - if ([arguments count] >= 3) + if (arguments.count >= 3) recordClass = of_dns_resource_record_class_parse( [arguments objectAtIndex: 2]); - if ([arguments count] >= 4) { - [resolver setConfigReloadInterval: 0]; - [resolver setNameServers: - [OFArray arrayWithObject: [arguments objectAtIndex: 3]]]; + if (arguments.count >= 4) { + resolver.configReloadInterval = 0; + resolver.nameServers = + [arguments objectsInRange: of_range(3, 1)]; } [resolver asyncResolveHost: [arguments objectAtIndex: 0] recordClass: recordClass recordType: recordType delegate: self]; } @end Index: utils/ofhash/OFHash.m ================================================================== --- utils/ofhash/OFHash.m +++ utils/ofhash/OFHash.m @@ -90,13 +90,13 @@ [OFSecureData preallocateMemoryWithSize: class_getInstanceSize([OFSHA512Hash class])]; sandbox = [[OFSandbox alloc] init]; @try { - [sandbox setAllowsStdIO: true]; - [sandbox setAllowsReadingFiles: true]; - [sandbox setAllowsUserDatabaseReading: true]; + sandbox.allowsStdIO = true; + sandbox.allowsReadingFiles = true; + sandbox.allowsUserDatabaseReading = true; for (OFString *path in arguments) { if (first) { first = false; continue; @@ -120,14 +120,14 @@ [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; #else [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"]; #endif - if ([arguments count] < 2) + if (arguments.count < 2) help(); - if ((hash = hashForName([arguments firstObject])) == nil) + if ((hash = hashForName(arguments.firstObject)) == nil) help(); for (OFString *path in arguments) { void *pool; OFStream *file; @@ -147,36 +147,36 @@ @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", - @"file", [e path], + @"file", e.path, @"error", error)]; exitStatus = 1; goto outer_loop_end; } } [hash reset]; - while (![file isAtEndOfStream]) { + while (!file.atEndOfStream) { uint8_t buffer[1024]; size_t length; @try { length = [file readIntoBuffer: buffer length: 1024]; } @catch (OFReadFailedException *e) { OFString *error = [OFString - stringWithCString: strerror([e errNo]) + stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [of_stderr writeLine: OF_LOCALIZED( @"failed_to_read_file", @"Failed to read %[file]: %[error]", @@ -191,12 +191,12 @@ length: length]; } [file close]; - digest = [hash digest]; - digestSize = [[hash class] digestSize]; + digest = hash.digest; + digestSize = hash.digestSize; for (size_t i = 0; i < digestSize; i++) [of_stdout writeFormat: @"%02x", digest[i]]; [of_stdout writeFormat: @" %@\n", path]; Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -141,12 +141,12 @@ if (contentDisposition == nil) return nil; pool = objc_autoreleasePoolPush(); - UTF8String = [contentDisposition UTF8String]; - UTF8StringLength = [contentDisposition UTF8StringLength]; + UTF8String = contentDisposition.UTF8String; + UTF8StringLength = contentDisposition.UTF8StringLength; state = DISPOSITION_TYPE; params = [OFMutableDictionary dictionary]; last = 0; for (size_t i = 0; i < UTF8StringLength; i++) { @@ -230,11 +230,11 @@ (fileName = [params objectForKey: @"filename"]) == nil) { objc_autoreleasePoolPop(pool); return nil; } - fileName = [fileName lastPathComponent]; + fileName = fileName.lastPathComponent; [fileName retain]; objc_autoreleasePoolPop(pool); return [fileName autorelease]; } @@ -250,11 +250,11 @@ _clientHeaders = [[OFMutableDictionary alloc] initWithObject: @"OFHTTP" forKey: @"User-Agent"]; _HTTPClient = [[OFHTTPClient alloc] init]; - [_HTTPClient setDelegate: self]; + _HTTPClient.delegate = self; _buffer = [self allocMemoryWithSize: [OFSystemInfo pageSize]]; } @catch (id e) { [self release]; @throw e; @@ -274,15 +274,15 @@ @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } name = [header substringWithRange: of_range(0, pos)]; - name = [name stringByDeletingEnclosingWhitespaces]; + name = name.stringByDeletingEnclosingWhitespaces; value = [header substringWithRange: - of_range(pos + 1, [header length] - pos - 1)]; - value = [value stringByDeletingEnclosingWhitespaces]; + of_range(pos + 1, header.length - pos - 1)]; + value = value.stringByDeletingEnclosingWhitespaces; [_clientHeaders setObject: value forKey: name]; } @@ -292,21 +292,21 @@ [_body release]; _body = [[OFFile alloc] initWithPath: path mode: @"r"]; - bodySize = [[[OFFileManager defaultManager] - attributesOfItemAtPath: path] fileSize]; + bodySize = [[OFFileManager defaultManager] attributesOfItemAtPath: path] + .fileSize; [_clientHeaders setObject: [OFString stringWithFormat: @"%ju", bodySize] forKey: @"Content-Length"]; } - (void)setMethod: (OFString *)method { void *pool = objc_autoreleasePoolPush(); - method = [method uppercaseString]; + method = method.uppercaseString; if ([method isEqual: @"GET"]) _method = OF_HTTP_REQUEST_METHOD_GET; else if ([method isEqual: @"HEAD"]) _method = OF_HTTP_REQUEST_METHOD_HEAD; @@ -340,12 +340,12 @@ if (pos == OF_NOT_FOUND) @throw [OFInvalidFormatException exception]; host = [proxy substringWithRange: of_range(0, pos)]; - port = [[proxy substringWithRange: - of_range(pos + 1, [proxy length] - pos - 1)] decimalValue]; + port = [proxy substringWithRange: + of_range(pos + 1, proxy.length - pos - 1)].decimalValue; if (port > UINT16_MAX) @throw [OFOutOfRangeException exception]; [OFTCPSocket setSOCKS5Host: host]; @@ -379,20 +379,20 @@ OFOptionsParser *optionsParser; of_unichar_t option; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; - [sandbox setAllowsStdIO: true]; - [sandbox setAllowsReadingFiles: true]; - [sandbox setAllowsWritingFiles: true]; - [sandbox setAllowsCreatingFiles: true]; - [sandbox setAllowsIPSockets: true]; - [sandbox setAllowsDNS: true]; - [sandbox setAllowsUserDatabaseReading: true]; - [sandbox setAllowsTTY: true]; + sandbox.allowsStdIO = true; + sandbox.allowsReadingFiles = true; + sandbox.allowsWritingFiles = true; + sandbox.allowsCreatingFiles = true; + sandbox.allowsIPSockets = true; + sandbox.allowsDNS = true; + sandbox.allowsUserDatabaseReading = true; + sandbox.allowsTTY = true; /* Dropped after parsing options */ - [sandbox setAllowsUnveil: true]; + sandbox.allowsUnveil = true; [OFApplication activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS @@ -403,36 +403,36 @@ optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'b': - [self setBody: [optionsParser argument]]; + self.body = optionsParser.argument; break; case 'h': help(of_stdout, true, 0); break; case 'H': - [self addHeader: [optionsParser argument]]; + [self addHeader: optionsParser.argument]; break; case 'm': - [self setMethod: [optionsParser argument]]; + self.method = optionsParser.argument; break; case 'P': - [self setProxy: [optionsParser argument]]; + self.proxy = optionsParser.argument; break; case ':': - if ([optionsParser lastLongOption] != nil) + if (optionsParser.lastLongOption != nil) [of_stderr writeLine: OF_LOCALIZED(@"long_argument_missing", @"%[prog]: Argument for option --%[opt] " @"missing" @"prog", [OFApplication programName], - @"opt", [optionsParser lastLongOption])]; + @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%c", - [optionsParser lastOption]]; + optionsParser.lastOption]; [of_stderr writeLine: OF_LOCALIZED(@"argument_missing", @"%[prog]: Argument for option -%[opt] " @"missing", @"prog", [OFApplication programName], @@ -444,25 +444,25 @@ case '=': [of_stderr writeLine: OF_LOCALIZED(@"option_takes_no_argument", @"%[prog]: Option --%[opt] takes no argument", @"prog", [OFApplication programName], - @"opt", [optionsParser lastLongOption])]; + @"opt", optionsParser.lastLongOption)]; [OFApplication terminateWithStatus: 1]; break; case '?': - if ([optionsParser lastLongOption] != nil) + if (optionsParser.lastLongOption != nil) [of_stderr writeLine: OF_LOCALIZED(@"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], - @"opt", [optionsParser lastLongOption])]; + @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%c", - [optionsParser lastOption]]; + optionsParser.lastOption]; [of_stderr writeLine: OF_LOCALIZED(@"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; @@ -479,18 +479,18 @@ permissions: @"wc"]; /* In case we use ObjOpenSSL for https later */ [sandbox unveilPath: @"/etc/ssl" permissions: @"r"]; - [sandbox setAllowsUnveil: false]; + sandbox.allowsUnveil = false; [OFApplication activateSandbox: sandbox]; #endif _outputPath = [outputPath copy]; - _URLs = [[optionsParser remainingArguments] retain]; + _URLs = [optionsParser.remainingArguments copy]; - if ([_URLs count] < 1) + if (_URLs.count < 1) help(of_stderr, false, 1); if (_quiet && _verbose) { [of_stderr writeLine: OF_LOCALIZED(@"quiet_xor_verbose", @"%[prog]: -q / --quiet and -v / --verbose are mutually " @@ -497,21 +497,21 @@ @"exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } - if (_outputPath != nil && [_URLs count] > 1) { + if (_outputPath != nil && _URLs.count > 1) { [of_stderr writeLine: OF_LOCALIZED(@"output_only_with_one_url", @"%[prog]: Cannot use -o / --output when more than one URL " @"has been specified!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_insecure) - [_HTTPClient setInsecureRedirectsAllowed: true]; + _HTTPClient.insecureRedirectsAllowed = true; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } @@ -527,11 +527,11 @@ - (void)client: (OFHTTPClient *)client wantsRequestBody: (OFStream *)body request: (OFHTTPRequest *)request { /* TODO: Do asynchronously and print status */ - while (![_body isAtEndOfStream]) { + while (!_body.atEndOfStream) { char buffer[4096]; size_t length; length = [_body readIntoBuffer: buffer length: 4096]; @@ -547,14 +547,13 @@ response: (OFHTTPResponse *)response { if (_verbose) { void *pool = objc_autoreleasePoolPush(); OFDictionary OF_GENERIC(OFString *, OFString *) *headers = - [response headers]; + response.headers; OFEnumerator *keyEnumerator = [headers keyEnumerator]; - OFEnumerator *objectEnumerator = - [headers objectEnumerator]; + OFEnumerator *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [of_stdout writeFormat: @" %@: %@\n", @@ -562,11 +561,11 @@ objc_autoreleasePoolPop(pool); } if (!_quiet) - [of_stdout writeFormat: @"☇ %@", [URL string]]; + [of_stdout writeFormat: @"☇ %@", URL.string]; return true; } - (void)client: (OFHTTPClient *)client @@ -580,11 +579,11 @@ [of_stderr writeLine: OF_LOCALIZED(@"download_failed_resolve_host_failed", @"%[prog]: Failed to download <%[url]>!\n" @" Failed to resolve host: %[exception]", @"prog", [OFApplication programName], - @"url", [[request URL] string], + @"url", request.URL.string, @"exception", e)]; } else if ([e isKindOfClass: [OFConnectionFailedException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; @@ -591,11 +590,11 @@ [of_stderr writeLine: OF_LOCALIZED(@"download_failed_connection_failed", @"%[prog]: Failed to download <%[url]>!\n" @" Connection failed: %[exception]", @"prog", [OFApplication programName], - @"url", [[request URL] string], + @"url", request.URL.string, @"exception", e)]; } else if ([e isKindOfClass: [OFInvalidServerReplyException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; @@ -602,11 +601,11 @@ [of_stderr writeLine: OF_LOCALIZED(@"download_failed_invalid_server_reply", @"%[prog]: Failed to download <%[url]>!\n" @" Invalid server reply!", @"prog", [OFApplication programName], - @"url", [[request URL] string])]; + @"url", request.URL.string)]; } else if ([e isKindOfClass: [OFUnsupportedProtocolException class]]) { if (!_quiet) [of_stdout writeString: @"\n"]; [of_stderr writeLine: OF_LOCALIZED(@"no_ssl_library", @@ -635,18 +634,18 @@ [of_stderr writeLine: OF_LOCALIZED(@"download_failed_read_or_write_failed", @"%[prog]: Failed to download <%[url]>!\n" @" %[error]: %[exception]", @"prog", [OFApplication programName], - @"url", [[request URL] string], + @"url", request.URL.string, @"error", error, @"exception", e)]; } else if ([e isKindOfClass: [OFHTTPRequestFailedException class]]) { [of_stderr writeLine: OF_LOCALIZED(@"download_failed", @"%[prog]: Failed to download <%[url]>!", @"prog", [OFApplication programName], - @"url", [[request URL] string])]; + @"url", request.URL.string)]; } else @throw e; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; @@ -685,14 +684,13 @@ _received += length; [_output writeBuffer: buffer length: length]; - [_progressBar setReceived: _received]; + _progressBar.received = _received; - if ([response isAtEndOfStream] || - (_length >= 0 && _received >= _length)) { + if (response.atEndOfStream || (_length >= 0 && _received >= _length)) { [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; @@ -724,11 +722,11 @@ if (type == nil) type = OF_LOCALIZED(@"type_unknown", @"unknown"); if (lengthString != nil) - _length = [lengthString decimalValue]; + _length = lengthString.decimalValue; if (_length >= 0) { if (_resumedFrom + _length >= GIBIBYTE) { lengthString = [OFString stringWithFormat: @"%,.2f", @@ -804,11 +802,11 @@ didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if (_detectFileNameRequest) { _currentFileName = [fileNameFromContentDisposition( - [[response headers] objectForKey: @"Content-Disposition"]) + [response.headers objectForKey: @"Content-Disposition"]) copy]; _detectedFileName = true; /* Handle this URL on the next -[downloadNextURL] call */ _URLIndex--; @@ -833,11 +831,11 @@ goto next; } @try { OFString *mode = - ([response statusCode] == 206 ? @"a" : @"w"); + (response.statusCode == 206 ? @"a" : @"w"); _output = [[OFFile alloc] initWithPath: _currentFileName mode: mode]; } @catch (OFOpenItemFailedException *e) { [of_stderr writeLine: OF_LOCALIZED(@"failed_to_open_output", @@ -854,18 +852,18 @@ if (!_quiet) { _progressBar = [[ProgressBar alloc] initWithLength: _length resumedFrom: _resumedFrom]; - [_progressBar setReceived: _received]; + _progressBar.received = _received; [_progressBar draw]; } [_currentFileName release]; _currentFileName = nil; - [response setDelegate: self]; + response.delegate = self; [response asyncReadIntoBuffer: _buffer length: [OFSystemInfo pageSize]]; return; next: @@ -888,11 +886,11 @@ if (_output != of_stdout) [_output release]; _output = nil; - if (_URLIndex >= [_URLs count]) + if (_URLIndex >= _URLs.count) [OFApplication terminateWithStatus: _errorCode]; @try { URLString = [_URLs objectAtIndex: _URLIndex++]; URL = [OFURL URLWithString: URLString]; @@ -904,12 +902,11 @@ _errorCode = 1; goto next; } - if (![[URL scheme] isEqual: @"http"] && - ![[URL scheme] isEqual: @"https"]) { + if (![URL.scheme isEqual: @"http"] && ![URL.scheme isEqual: @"https"]) { [of_stderr writeLine: OF_LOCALIZED(@"invalid_scheme", @"%[prog]: Invalid scheme: <%[url]>!", @"prog", [OFApplication programName], @"url", URLString)]; @@ -919,15 +916,15 @@ clientHeaders = [[_clientHeaders mutableCopy] autorelease]; if (_detectFileName && !_detectedFileName) { if (!_quiet) - [of_stdout writeFormat: @"⠒ %@", [URL string]]; + [of_stdout writeFormat: @"⠒ %@", URL.string]; request = [OFHTTPRequest requestWithURL: URL]; - [request setHeaders: clientHeaders]; - [request setMethod: OF_HTTP_REQUEST_METHOD_HEAD]; + request.headers = clientHeaders; + request.method = OF_HTTP_REQUEST_METHOD_HEAD; _detectFileNameRequest = true; [_HTTPClient asyncPerformRequest: request]; return; } @@ -935,22 +932,22 @@ [_currentFileName release]; _currentFileName = nil; _detectedFileName = false; if (!_quiet) - [of_stdout writeFormat: @"⇣ %@", [URL string]]; + [of_stdout writeFormat: @"⇣ %@", URL.string]; if (_outputPath != nil) _currentFileName = [_outputPath copy]; if (_currentFileName == nil) - _currentFileName = [[[URL path] lastPathComponent] copy]; + _currentFileName = [URL.path.lastPathComponent copy]; if (_continue) { @try { - uintmax_t size = [[[OFFileManager defaultManager] - attributesOfItemAtPath: _currentFileName] fileSize]; + uintmax_t size = [[OFFileManager defaultManager] + attributesOfItemAtPath: _currentFileName].fileSize; OFString *range; if (size > INTMAX_MAX) @throw [OFOutOfRangeException exception]; @@ -963,12 +960,12 @@ } @catch (OFRetrieveItemAttributesFailedException *e) { } } request = [OFHTTPRequest requestWithURL: URL]; - [request setHeaders: clientHeaders]; - [request setMethod: _method]; + request.headers = clientHeaders; + request.method = _method; _detectFileNameRequest = false; [_HTTPClient asyncPerformRequest: request]; return; Index: utils/ofhttp/ProgressBar.m ================================================================== --- utils/ofhttp/ProgressBar.m +++ utils/ofhttp/ProgressBar.m @@ -86,11 +86,11 @@ - (void)_drawProgress { float bars, percent; int columns, barWidth; - if ((columns = [of_stdout columns]) >= 0) { + if ((columns = of_stdout.columns) >= 0) { if (columns > 37) barWidth = columns - 37; else barWidth = 0; } else @@ -130,11 +130,11 @@ } [of_stdout writeFormat: @"▏ %,6.2f%% ", percent]; if (percent == 100) { - double timeInterval = -[_startDate timeIntervalSinceNow]; + double timeInterval = -_startDate.timeIntervalSinceNow; _BPS = (float)_received / (float)timeInterval; _ETA = timeInterval; } @@ -210,11 +210,11 @@ [of_stdout writeString: @" "]; if (_stopped) _BPS = (float)_received / - -(float)[_startDate timeIntervalSinceNow]; + -(float)_startDate.timeIntervalSinceNow; if (_BPS >= GIBIBYTE) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / GIBIBYTE]; [of_stdout writeString: OF_LOCALIZED(@"progress_gibs", @@ -250,11 +250,11 @@ } - (void)calculateBPSAndETA { _BPS = (float)(_received - _lastReceived) / - -(float)[_lastReceivedDate timeIntervalSinceNow]; + -(float)_lastReceivedDate.timeIntervalSinceNow; _ETA = (double)(_length - _received) / _BPS; _lastReceived = _received; [_lastReceivedDate release]; _lastReceivedDate = [[OFDate alloc] init];