@@ -72,18 +72,19 @@ OF_APPLICATION_DELEGATE(OFHTTP) static void help(OFStream *stream, bool full, int status) { - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"usage", - @"Usage: %[prog] -[cehHmoOPqv] url1 [url2 ...]\n", + @"Usage: %[prog] -[cehHmoOPqv] url1 [url2 ...]", @"prog", [OFApplication programName])]; - if (full) - [stream writeString: OF_LOCALIZED(@"full_usage", - @"\nOptions:\n " + if (full) { + [stream writeString: @"\n"]; + [stream writeLine: OF_LOCALIZED(@"full_usage", + @"Options:\n " @"-b --body " @" Specify the file to send as body\n " @"-c --continue " @" Continue download of existing file\n " @"-f --force " @@ -103,11 +104,12 @@ @"-q --quiet " @" Quiet mode (no output, except errors)\n " @"-v --verbose " @" Verbose mode (print headers)\n " @" --insecure " - @" Ignore TLS errors\n")]; + @" Ignore TLS errors")]; + } [OFApplication terminateWithStatus: status]; } @implementation OFHTTP @@ -138,12 +140,12 @@ { size_t pos = [header rangeOfString: @":"].location; OFString *name, *value; if (pos == OF_NOT_FOUND) { - [of_stderr writeString: OF_LOCALIZED(@"invalid_input_header", - @"%[prog]: Headers must to be in format name:value!\n", + [of_stderr writeLine: OF_LOCALIZED(@"invalid_input_header", + @"%[prog]: Headers must to be in format name:value!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } name = [header substringWithRange: of_range(0, pos)]; @@ -188,12 +190,12 @@ else if ([method isEqual: @"DELETE"]) _method = OF_HTTP_REQUEST_METHOD_DELETE; else if ([method isEqual: @"TRACE"]) _method = OF_HTTP_REQUEST_METHOD_TRACE; else { - [of_stderr writeString: OF_LOCALIZED(@"invalid_input_method", - @"%[prog]: Invalid request method %[method]!\n", + [of_stderr writeLine: OF_LOCALIZED(@"invalid_input_method", + @"%[prog]: Invalid request method %[method]!", @"prog", [OFApplication programName], @"method", method)]; [OFApplication terminateWithStatus: 1]; } @@ -220,12 +222,12 @@ @throw [OFOutOfRangeException exception]; [OFTCPSocket setSOCKS5Host: host]; [OFTCPSocket setSOCKS5Port: (uint16_t)port]; } @catch (OFInvalidFormatException *e) { - [of_stderr writeString: OF_LOCALIZED(@"invalid_input_proxy", - @"%[prog]: Proxy must to be in format host:port!\n", + [of_stderr writeLine: OF_LOCALIZED(@"invalid_input_proxy", + @"%[prog]: Proxy must to be in format host:port!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } } @@ -270,53 +272,53 @@ case 'P': [self setProxy: [optionsParser argument]]; break; case ':': if ([optionsParser lastLongOption] != nil) - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"long_argument_missing", @"%[prog]: Argument for option --%[opt] " - "missing\n" + @"missing" @"prog", [OFApplication programName], @"opt", [optionsParser lastLongOption])]; else { OFString *optStr = [OFString stringWithFormat: @"%c", [optionsParser lastOption]]; - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"argument_missing", @"%[prog]: Argument for option -%[opt] " - "missing\n", + @"missing", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; case '=': - [of_stderr writeString: - OF_LOCALIZED(@"takes_no_argument", - @"%[prog]: Option --%[opt] takes no argument\n", + [of_stderr writeLine: + OF_LOCALIZED(@"option_takes_no_argument", + @"%[prog]: Option --%[opt] takes no argument", @"prog", [OFApplication programName], @"opt", [optionsParser lastLongOption])]; [OFApplication terminateWithStatus: 1]; break; case '?': if ([optionsParser lastLongOption] != nil) - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"unknown_long_option", - @"%[prog]: Unknown option: --%[opt]\n", + @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", [optionsParser lastLongOption])]; else { OFString *optStr = [OFString stringWithFormat: @"%c", [optionsParser lastOption]]; - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"unknown_option", - @"%[prog]: Unknown option: -%[opt]\n", + @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; @@ -329,22 +331,22 @@ if ([_URLs count] < 1) help(of_stderr, false, 1); if (_quiet && _verbose) { - [of_stderr writeString: OF_LOCALIZED(@"quiet_xor_verbose", + [of_stderr writeLine: OF_LOCALIZED(@"quiet_xor_verbose", @"%[prog]: -q / --quiet and -v / --verbose are mutually " - @"exclusive!\n", + @"exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_outputPath != nil && [_URLs count] > 1) { - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"output_only_with_one_url", @"%[prog]: Cannot use -o / --output when more than one URL " - @"has been specified!\n", + @"has been specified!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } [self performSelector: @selector(downloadNextURL) @@ -400,47 +402,47 @@ response = [_HTTPClient performRequest: request]; } @catch (OFAddressTranslationFailedException *e) { if (!_quiet) [of_stdout writeString: @"\n"]; - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"download_failed_address_translation", @"%[prog]: Failed to download <%[url]>!\n" - @" Address translation failed: %[exception]\n", + @" Address translation failed: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"exception", e)]; } @catch (OFConnectionFailedException *e) { if (!_quiet) [of_stdout writeString: @"\n"]; - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"download_failed_connection_failed", @"%[prog]: Failed to download <%[url]>!\n" - @" Connection failed: %[exception]\n", + @" Connection failed: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"exception", e)]; } @catch (OFInvalidServerReplyException *e) { if (!_quiet) [of_stdout writeString: @"\n"]; - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"download_failed_invalid_server_reply", @"%[prog]: Failed to download <%[url]>!\n" - @" Invalid server reply!\n", + @" Invalid server reply!", @"prog", [OFApplication programName], @"url", [[request URL] string])]; } @catch (OFUnsupportedProtocolException *e) { if (!_quiet) [of_stdout writeString: @"\n"]; - [of_stderr writeString: OF_LOCALIZED(@"no_ssl_library", + [of_stderr writeLine: OF_LOCALIZED(@"no_ssl_library", @"%[prog]: No TLS library loaded!\n" @" In order to download via https, you need to preload an " @"TLS library for ObjFW\n" - "such as ObjOpenSSL!\n", + @" such as ObjOpenSSL!", @"prog", [OFApplication programName])]; } @catch (OFReadOrWriteFailedException *e) { OFString *error = OF_LOCALIZED( @"download_failed_read_or_write_failed_any", @"Read or write failed"); @@ -455,25 +457,25 @@ else if ([e isKindOfClass: [OFWriteFailedException class]]) error = OF_LOCALIZED( @"download_failed_read_or_write_failed_write", @"Write failed"); - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"download_failed_read_or_write_failed", @"%[prog]: Failed to download <%[url]>!\n" - @" %[error]: %[exception]\n", + @" %[error]: %[exception]", @"prog", [OFApplication programName], @"url", [[request URL] string], @"error", error, @"exception", e)]; } @catch (OFHTTPRequestFailedException *e) { if (!_quiet) [of_stdout writeFormat: @" ➜ %d\n", [[e response] statusCode]]; - [of_stderr writeString: OF_LOCALIZED(@"download_failed", - @"%[prog]: Failed to download <%[url]>!\n", + [of_stderr writeLine: OF_LOCALIZED(@"download_failed", + @"%[prog]: Failed to download <%[url]>!", @"prog", [OFApplication programName], @"url", [[request URL] string])]; } if (!_quiet && response != nil) @@ -617,13 +619,13 @@ if (!_quiet) [of_stdout writeString: @"\n Error!\n"]; URL = [_URLs objectAtIndex: _URLIndex - 1]; - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"download_failed_exception", - @"%[prog]: Failed to download <%[url]>: %[exception]\n", + @"%[prog]: Failed to download <%[url]>: %[exception]", @"prog", [OFApplication programName], @"url", URL, @"exception", e)]; _errorCode = 1; @@ -642,13 +644,15 @@ [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; - if (!_quiet) - [of_stdout writeString: - OF_LOCALIZED(@"download_done", @"\n Done!\n")]; + if (!_quiet) { + [of_stdout writeString: @"\n "]; + [of_stdout writeLine: + OF_LOCALIZED(@"download_done", @"Done!")]; + } goto next; } return true; @@ -682,23 +686,23 @@ @try { URLString = [_URLs objectAtIndex: _URLIndex++]; URL = [OFURL URLWithString: URLString]; } @catch (OFInvalidFormatException *e) { - [of_stderr writeString: OF_LOCALIZED(@"invalid_url", - @"%[prog]: Invalid URL: <%[url]>!\n", + [of_stderr writeLine: OF_LOCALIZED(@"invalid_url", + @"%[prog]: Invalid URL: <%[url]>!", @"prog", [OFApplication programName], @"url", URLString)]; _errorCode = 1; goto next; } if (![[URL scheme] isEqual: @"http"] && ![[URL scheme] isEqual: @"https"]) { - [of_stderr writeString: OF_LOCALIZED(@"invalid_scheme", - @"%[prog]: Invalid scheme: <%[scheme]:>!\n", + [of_stderr writeLine: OF_LOCALIZED(@"invalid_scheme", + @"%[prog]: Invalid scheme: <%[scheme]:>!", @"prog", [OFApplication programName], @"scheme", URLString)]; _errorCode = 1; goto next; @@ -812,41 +816,46 @@ OFEnumerator *keyEnumerator = [headers keyEnumerator]; OFEnumerator *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; - [of_stdout writeString: OF_LOCALIZED(@"info_name_nopad", - @" Name: %[name]\n", + [of_stdout writeString: @" "]; + [of_stdout writeLine: OF_LOCALIZED( + @"info_name_unaligned", + @"Name: %[name]", @"name", fileName)]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [of_stdout writeFormat: @" %@: %@\n", key, object]; objc_autoreleasePoolPop(pool); } else { - [of_stdout writeString: OF_LOCALIZED(@"info_name", - @" Name: %[name]\n", + [of_stdout writeString: @" "]; + [of_stdout writeLine: OF_LOCALIZED(@"info_name", + @"Name: %[name]", @"name", fileName)]; - [of_stdout writeString: OF_LOCALIZED(@"info_type", - @" Type: %[type]\n", + [of_stdout writeString: @" "]; + [of_stdout writeLine: OF_LOCALIZED(@"info_type", + @"Type: %[type]", @"type", type)]; - [of_stdout writeString: OF_LOCALIZED(@"info_size", - @" Size: %[size]\n", + [of_stdout writeString: @" "]; + [of_stdout writeLine: OF_LOCALIZED(@"info_size", + @"Size: %[size]", @"size", lengthString)]; } } if ([_outputPath isEqual: @"-"]) _output = of_stdout; else { if (!_continue && !_force && [fileManager fileExistsAtPath: fileName]) { - [of_stderr writeString: - OF_LOCALIZED(@"ouput_already_exists", - @"%[prog]: File %[filename] already exists!\n", + [of_stderr writeLine: + OF_LOCALIZED(@"output_already_exists", + @"%[prog]: File %[filename] already exists!", @"prog", [OFApplication programName], @"filename", fileName)]; _errorCode = 1; goto next; @@ -856,14 +865,14 @@ OFString *mode = ([response statusCode] == 206 ? @"ab" : @"wb"); _output = [[OFFile alloc] initWithPath: fileName mode: mode]; } @catch (OFOpenItemFailedException *e) { - [of_stderr writeString: + [of_stderr writeLine: OF_LOCALIZED(@"failed_to_open_output", @"%[prog]: Failed to open file %[filename]: " - @"%[exception]\n", + @"%[exception]", @"prog", [OFApplication programName], @"filename",fileName, @"exception", e)]; _errorCode = 1;