ObjFW  Check-in [3f2b4a8941]

Overview
Comment:Localize ofhash
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3f2b4a89415c3bb6bc3d1de97c53d08f93d032b2872005a4ee1fe9889f89dfe9
User & Date: js on 2017-02-27 21:36:26
Other Links: manifest | tags
Context
2017-02-27
21:57
ofhttp: Move formatting out of localized strings check-in: 7ffbd24169 user: js tags: trunk
21:36
Localize ofhash check-in: 3f2b4a8941 user: js tags: trunk
2017-02-26
21:29
Localize ofzip check-in: ebf74827f6 user: js tags: trunk
Changes

Modified utils/ofhash/Makefile from [f80d36df3e] to [10e10c92fe].

1
2
3
4


5
6


7
8
9
10




11
12
13
include ../../extra.mk

PROG = ofhash${PROG_SUFFIX}
SRCS = OFHash.m



include ../../buildsys.mk



${PROG}: ${LIBOBJFW_DEP_LVL2}

CPPFLAGS += -I../../src -I../../src/runtime -I../../src/exceptions -I../..




LIBS := -L../../src -lobjfw ${LIBS}
LD = ${OBJC}
LDFLAGS += ${LDFLAGS_RPATH}




>
>


>
>



|
>
>
>
>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
include ../../extra.mk

PROG = ofhash${PROG_SUFFIX}
SRCS = OFHash.m
DATA = lang/de.json		\
       lang/languages.json

include ../../buildsys.mk

PACKAGE_NAME = ofhash

${PROG}: ${LIBOBJFW_DEP_LVL2}

CPPFLAGS += -I../../src					\
	    -I../../src/runtime				\
	    -I../../src/exceptions			\
	    -I../..					\
	    -DLANGUAGE_DIR=\"${datadir}/ofhash/lang\"
LIBS := -L../../src -lobjfw ${LIBS}
LD = ${OBJC}
LDFLAGS += ${LDFLAGS_RPATH}

Modified utils/ofhash/OFHash.m from [aa7d967739] to [3f3d3563e3].

23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#import "OFRIPEMD160Hash.h"
#import "OFSHA1Hash.h"
#import "OFSHA224Hash.h"
#import "OFSHA256Hash.h"
#import "OFSHA384Hash.h"
#import "OFSHA512Hash.h"
#import "OFStdIOStream.h"


#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"

@interface OFHash: OFObject
@end

OF_APPLICATION_DELEGATE(OFHash)

static void
help(void)
{
	[of_stderr writeFormat:
	    @"Usage: %@ [md5|rmd160|sha1|sha224|sha256|sha384|sha512] "
	    @"file1 [file2 ...]\n",
	    [OFApplication programName]];

	[OFApplication terminateWithStatus: 1];
}

static id <OFCryptoHash>
hashForName(OFString *name)
{







>












|
|
|
|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#import "OFRIPEMD160Hash.h"
#import "OFSHA1Hash.h"
#import "OFSHA224Hash.h"
#import "OFSHA256Hash.h"
#import "OFSHA384Hash.h"
#import "OFSHA512Hash.h"
#import "OFStdIOStream.h"
#import "OFLocalization.h"

#import "OFOpenItemFailedException.h"
#import "OFReadFailedException.h"

@interface OFHash: OFObject
@end

OF_APPLICATION_DELEGATE(OFHash)

static void
help(void)
{
	[of_stderr writeLine: OF_LOCALIZED(@"usage",
	    @"Usage: %[prog] [md5|rmd160|sha1|sha224|sha256|sha384|sha512] "
	    @"file1 [file2 ...]",
	    @"prog", [OFApplication programName])];

	[OFApplication terminateWithStatus: 1];
}

static id <OFCryptoHash>
hashForName(OFString *name)
{
72
73
74
75
76
77
78


79
80
81
82
83
84
85
- (void)applicationDidFinishLaunching
{
	OFArray OF_GENERIC(OFString*) *arguments = [OFApplication arguments];
	id <OFCryptoHash> hash;
	bool first = true;
	int exitStatus = 0;



	if ([arguments count] < 2)
		help();

	if ((hash = hashForName([arguments firstObject])) == nil)
		help();

	for (OFString *path in arguments) {







>
>







73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
- (void)applicationDidFinishLaunching
{
	OFArray OF_GENERIC(OFString*) *arguments = [OFApplication arguments];
	id <OFCryptoHash> hash;
	bool first = true;
	int exitStatus = 0;

	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];

	if ([arguments count] < 2)
		help();

	if ((hash = hashForName([arguments firstObject])) == nil)
		help();

	for (OFString *path in arguments) {
98
99
100
101
102
103
104





105

106
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123





124

125
126

127
128
129
130
131
132
133
		if ([path isEqual: @"-"])
			file = of_stdin;
		else {
			@try {
				file = [OFFile fileWithPath: path
						       mode: @"rb"];
			} @catch (OFOpenItemFailedException *e) {





				[of_stderr writeFormat:

				    @"Failed to open file %@: %s\n",
				    [e path], strerror([e errNo])];


				exitStatus = 1;
				goto outer_loop_end;
			}
		}

		[hash reset];

		while (![file isAtEndOfStream]) {
			uint8_t buffer[1024];
			size_t length;

			@try {
				length = [file readIntoBuffer: buffer
						       length: 1024];
			} @catch (OFReadFailedException *e) {





				[of_stderr writeFormat:

				    @"Failed to read %@: %s\n",
				    path, strerror([e errNo])];


				exitStatus = 1;
				goto outer_loop_end;
			}

			[hash updateWithBuffer: buffer
					length: length];







>
>
>
>
>
|
>
|
|
>
















>
>
>
>
>
|
>
|
|
>







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
		if ([path isEqual: @"-"])
			file = of_stdin;
		else {
			@try {
				file = [OFFile fileWithPath: path
						       mode: @"rb"];
			} @catch (OFOpenItemFailedException *e) {
				OFString *error = [OFString
				    stringWithCString: strerror([e errNo])
					     encoding: [OFLocalization
							   encoding]];

				[of_stderr writeLine: OF_LOCALIZED(
				    @"failed_to_open_file",
				    @"Failed to open file %[file]: %[error]",
				    @"file", [e path],
				    @"error", error)];

				exitStatus = 1;
				goto outer_loop_end;
			}
		}

		[hash reset];

		while (![file isAtEndOfStream]) {
			uint8_t buffer[1024];
			size_t length;

			@try {
				length = [file readIntoBuffer: buffer
						       length: 1024];
			} @catch (OFReadFailedException *e) {
				OFString *error = [OFString
				    stringWithCString: strerror([e errNo])
					     encoding: [OFLocalization
							   encoding]];

				[of_stderr writeLine: OF_LOCALIZED(
				    @"failed_to_read_file",
				    @"Failed to read %[file]: %[error]",
				    @"file", path,
				    @"error", error)];

				exitStatus = 1;
				goto outer_loop_end;
			}

			[hash updateWithBuffer: buffer
					length: length];

Added utils/ofhash/lang/de.json version [c22df5828c].

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
{
    "usage": [
        "Benutzung: %[prog] [md5|rmd160|sha1|sha224|sha256|sha384|sha512] ",
	"datei1 [datei2 ...]"
    ],
    "failed_to_open_file": "Fehler beim Öffnen der Datei %[file]: %[error]",
    "failed_to_read_file": "Fehler beim Lesen der Datei %[file]: %[error]"
}

Added utils/ofhash/lang/languages.json version [59396279d5].

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
{
    "de": {
        "": "de"
    },
    "german": {
        "": "de"
    }
}