ObjFW  Check-in [156b850131]

Overview
Comment:Remove OF_PATH_* macros

These were way too simplistic, as paths differ in more than just that on
various operating systems.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 156b8501310bb9860c14bc7c9a67de5360fc3e36087ee61697938e4977abee1f
User & Date: js on 2018-03-11 12:55:20
Other Links: manifest | tags
Context
2018-03-11
14:26
OFSystemInfo: Path-related methods require files check-in: 953421ce9d user: js tags: trunk
12:55
Remove OF_PATH_* macros check-in: 156b850131 user: js tags: trunk
12:35
OFString+PathAdditions: Split into per-type files check-in: c6930c5141 user: js tags: trunk
Changes

Modified generators/TableGenerator.m from [f4a7b8e070] to [faffa6159e].

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
			}
		}
	} while (!done);
}

- (void)writeFiles
{
	OFString *path;

	[of_stdout writeString: @"Writing files…"];

	path = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.m", nil]];
	[self writeTablesToFile: path];

	path = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.h", nil]];
	[self writeHeaderToFile: path];

	[of_stdout writeLine: @" done"];

	[OFApplication terminate];
}

- (void)writeTablesToFile: (OFString *)path







|



<
|
|

<
|
|







267
268
269
270
271
272
273
274
275
276
277

278
279
280

281
282
283
284
285
286
287
288
289
			}
		}
	} while (!done);
}

- (void)writeFiles
{
	OFURL *URL;

	[of_stdout writeString: @"Writing files…"];


	URL = [OFURL fileURLWithPath: @"../src/unicode.m"];
	[self writeTablesToFile: [URL fileSystemRepresentation]];


	URL = [OFURL fileURLWithPath: @"../src/unicode.h"];
	[self writeHeaderToFile: [URL fileSystemRepresentation]];

	[of_stdout writeLine: @" done"];

	[OFApplication terminate];
}

- (void)writeTablesToFile: (OFString *)path

Modified src/OFString+PathAdditions_UNIX.m from [7650af811e] to [12cda0c8c7].

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

			return [ret autorelease];
		}
	}

	objc_autoreleasePoolPop(pool);

	return OF_PATH_CURRENT_DIRECTORY;
}

- (OFString *)stringByDeletingPathExtension
{
	void *pool;
	OFMutableArray OF_GENERIC(OFString *) *components;
	OFString *ret, *fileName;







|







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

			return [ret autorelease];
		}
	}

	objc_autoreleasePoolPop(pool);

	return @".";
}

- (OFString *)stringByDeletingPathExtension
{
	void *pool;
	OFMutableArray OF_GENERIC(OFString *) *components;
	OFString *ret, *fileName;

Modified src/OFURL.m from [bb7c13caac] to [13457e7f1d].

601
602
603
604
605
606
607

608

609




610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
- (instancetype)initFileURLWithPath: (OFString *)path
{
	bool isDirectory;

	@try {
		void *pool = objc_autoreleasePoolPush();


		isDirectory = ([path hasSuffix: OF_PATH_DELIMITER_STRING] ||

		    [OFURLHandler_file of_directoryExistsAtPath: path]);





		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initFileURLWithPath: path
			     isDirectory: isDirectory];

	return self;
}

- (instancetype)initFileURLWithPath: (OFString *)path
			isDirectory: (bool)isDirectory
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
# if OF_PATH_DELIMITER != '/' || defined(OF_WINDOWS) || defined(OF_DJGPP)
		OFArray OF_GENERIC(OFString *) *pathComponents =
		    [path pathComponents];
# endif

# if OF_PATH_DELIMITER != '/'
		path = [pathComponents componentsJoinedByString: @"/"];
# endif

# if defined(OF_WINDOWS) || defined(OF_DJGPP)
		if ([[pathComponents firstObject] hasSuffix: @":"])
			path = [path stringByPrependingString: @"/"];
# endif

		if (isDirectory && ![path hasSuffix: OF_PATH_DELIMITER_STRING])
			path = [path stringByAppendingString: @"/"];

		_URLEncodedScheme = @"file";

		if (![path hasPrefix: @"/"]) {
			OFString *currentDirectoryPath = [[OFFileManager
			    defaultManager] currentDirectoryPath];

# if OF_PATH_DELIMITER != '/'
			currentDirectoryPath = [[currentDirectoryPath
			    pathComponents] componentsJoinedByString: @"/"];
# endif
# if defined(OF_WINDOWS) || defined(OF_DJGPP)
			currentDirectoryPath = [currentDirectoryPath
			    stringByPrependingString: @"/"];
# endif

			path = [currentDirectoryPath
			    stringByAppendingURLPathComponent: path];
			path = [path stringByStandardizingURLPath];







>
|
>

>
>
>
>




















|


<

<

<

<




|








|


<
<







601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

639

640

641

642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657


658
659
660
661
662
663
664
- (instancetype)initFileURLWithPath: (OFString *)path
{
	bool isDirectory;

	@try {
		void *pool = objc_autoreleasePoolPush();

#if defined(OF_WINDOWS) || defined(OF_MSDOS)
		isDirectory = ([path hasSuffix: @"\\"] ||
		    [path hasSuffix: @"/"] ||
		    [OFURLHandler_file of_directoryExistsAtPath: path]);
#else
		isDirectory = ([path hasSuffix: @"/"] ||
		    [OFURLHandler_file of_directoryExistsAtPath: path]);
#endif

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initFileURLWithPath: path
			     isDirectory: isDirectory];

	return self;
}

- (instancetype)initFileURLWithPath: (OFString *)path
			isDirectory: (bool)isDirectory
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
# if defined(OF_WINDOWS) || defined(OF_DJGPP)
		OFArray OF_GENERIC(OFString *) *pathComponents =
		    [path pathComponents];



		path = [pathComponents componentsJoinedByString: @"/"];



		if ([[pathComponents firstObject] hasSuffix: @":"])
			path = [path stringByPrependingString: @"/"];
# endif

		if (isDirectory && ![path hasSuffix: @"/"])
			path = [path stringByAppendingString: @"/"];

		_URLEncodedScheme = @"file";

		if (![path hasPrefix: @"/"]) {
			OFString *currentDirectoryPath = [[OFFileManager
			    defaultManager] currentDirectoryPath];

# if defined(OF_WINDOWS) || defined(OF_DJGPP)
			currentDirectoryPath = [[currentDirectoryPath
			    pathComponents] componentsJoinedByString: @"/"];


			currentDirectoryPath = [currentDirectoryPath
			    stringByPrependingString: @"/"];
# endif

			path = [currentDirectoryPath
			    stringByAppendingURLPathComponent: path];
			path = [path stringByStandardizingURLPath];
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989

	path = [self path];

	if ([path hasSuffix: @"/"])
		path = [path substringWithRange:
		    of_range(0, [path length] - 1)];

#ifndef OF_PATH_STARTS_WITH_SLASH
	path = [path substringWithRange: of_range(1, [path length] - 1)];
#endif

#if OF_PATH_DELIMITER != '/'
	path = [OFString pathWithComponents:
	    [path componentsSeparatedByString: @"/"]];
#endif

	[path retain];

	objc_autoreleasePoolPop(pool);







|

<
<
<







971
972
973
974
975
976
977
978
979



980
981
982
983
984
985
986

	path = [self path];

	if ([path hasSuffix: @"/"])
		path = [path substringWithRange:
		    of_range(0, [path length] - 1)];

#if defined(OF_WINDOWS) || defined(OF_MSDOS)
	path = [path substringWithRange: of_range(1, [path length] - 1)];



	path = [OFString pathWithComponents:
	    [path componentsSeparatedByString: @"/"]];
#endif

	[path retain];

	objc_autoreleasePoolPop(pool);

Modified src/macros.h from [0a54ffbbce] to [9420a38fbf].

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#  endif
# endif
#endif

#define OF_RETAIN_COUNT_MAX UINT_MAX
#define OF_NOT_FOUND SIZE_MAX

#if !defined(OF_WINDOWS) && !defined(OF_MSDOS)
# define OF_PATH_DELIMITER '/'
# define OF_PATH_DELIMITER_STRING @"/"
# define OF_IS_PATH_DELIMITER(c) (c == '/')
# define OF_PATH_STARTS_WITH_SLASH
#else
# define OF_PATH_DELIMITER '\\'
# define OF_PATH_DELIMITER_STRING @"\\"
# define OF_IS_PATH_DELIMITER(c) (c == '\\' || c == '/')
#endif
#define OF_PATH_CURRENT_DIRECTORY @"."
#define OF_PATH_PARENT_DIRECTORY @".."

#define OF_ENSURE(cond)							\
	do {								\
		if (!(cond)) {						\
			fprintf(stderr, "Failed to ensure condition "	\
			    "in " __FILE__ ":%d:\n" #cond "\n",		\
			    __LINE__);					\
			abort();					\







<
<
<
<
<
<
<
<
<
<
<
<
<







352
353
354
355
356
357
358













359
360
361
362
363
364
365
#  endif
# endif
#endif

#define OF_RETAIN_COUNT_MAX UINT_MAX
#define OF_NOT_FOUND SIZE_MAX














#define OF_ENSURE(cond)							\
	do {								\
		if (!(cond)) {						\
			fprintf(stderr, "Failed to ensure condition "	\
			    "in " __FILE__ ":%d:\n" #cond "\n",		\
			    __LINE__);					\
			abort();					\

Modified tests/OFStringTests.m from [e113d97e23] to [bb51e4a860].

549
550
551
552
553
554
555

556



557
558

559



560
561
562
563
564
565
566
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

#ifdef OF_HAVE_FILES
	s[0] = [mutableStringClass stringWithString: @"foo"];

	[s[0] appendString: OF_PATH_DELIMITER_STRING];



	[s[0] appendString: @"bar"];
	s[1] = [mutableStringClass stringWithString: s[0]];

	[s[1] appendString: OF_PATH_DELIMITER_STRING];



	is = [stringClass stringWithString: s[1]];
	[s[1] appendString: @"baz"];
	TEST(@"-[stringByAppendingPathComponent:]",
	    [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] &&
	    [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]])
#endif








>
|
>
>
>


>
|
>
>
>







549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

#ifdef OF_HAVE_FILES
	s[0] = [mutableStringClass stringWithString: @"foo"];
# if defined(OF_WINDOWS) || defined(OF_MSDOS)
	[s[0] appendString: @"\\"];
# else
	[s[0] appendString: @"/"];
# endif
	[s[0] appendString: @"bar"];
	s[1] = [mutableStringClass stringWithString: s[0]];
# if defined(OF_WINDOWS) || defined(OF_MSDOS)
	[s[1] appendString: @"\\"];
# else
	[s[1] appendString: @"/"];
# endif
	is = [stringClass stringWithString: s[1]];
	[s[1] appendString: @"baz"];
	TEST(@"-[stringByAppendingPathComponent:]",
	    [[s[0] stringByAppendingPathComponent: @"baz"] isEqual: s[1]] &&
	    [[is stringByAppendingPathComponent: @"baz"] isEqual: s[1]])
#endif

Modified utils/ofzip/TarArchive.m from [00b90bedb9] to [4c9cd970e5].

292
293
294
295
296
297
298

299
300
301
302
303
304
305
306

			app->_exitStatus = 1;
			goto outer_loop_end;
		}

		pathComponents = [outFileName pathComponents];
		for (OFString *component in pathComponents) {

			if ([component isEqual: OF_PATH_PARENT_DIRECTORY]) {
				[of_stderr writeLine: OF_LOCALIZED(
				    @"refusing_to_extract_file",
				    @"Refusing to extract %[file]!",
				    @"file", fileName)];

				app->_exitStatus = 1;
				goto outer_loop_end;







>
|







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

			app->_exitStatus = 1;
			goto outer_loop_end;
		}

		pathComponents = [outFileName pathComponents];
		for (OFString *component in pathComponents) {
			if ([component length] == 0 ||
			    [component isEqual: @".."]) {
				[of_stderr writeLine: OF_LOCALIZED(
				    @"refusing_to_extract_file",
				    @"Refusing to extract %[file]!",
				    @"file", fileName)];

				app->_exitStatus = 1;
				goto outer_loop_end;

Modified utils/ofzip/ZIPArchive.m from [dc39ebe128] to [f8793bebd7].

233
234
235
236
237
238
239

240
241
242
243
244
245
246
247

			app->_exitStatus = 1;
			goto outer_loop_end;
		}

		pathComponents = [outFileName pathComponents];
		for (OFString *component in pathComponents) {

			if ([component isEqual: OF_PATH_PARENT_DIRECTORY]) {
				[of_stderr writeLine: OF_LOCALIZED(
				    @"refusing_to_extract_file",
				    @"Refusing to extract %[file]!",
				    @"file", fileName)];

				app->_exitStatus = 1;
				goto outer_loop_end;







>
|







233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

			app->_exitStatus = 1;
			goto outer_loop_end;
		}

		pathComponents = [outFileName pathComponents];
		for (OFString *component in pathComponents) {
			if ([component length] == 0 ||
			    [component isEqual: @".."]) {
				[of_stderr writeLine: OF_LOCALIZED(
				    @"refusing_to_extract_file",
				    @"Refusing to extract %[file]!",
				    @"file", fileName)];

				app->_exitStatus = 1;
				goto outer_loop_end;