summaryrefslogtreecommitdiff
path: root/samus/sa_misc.c
blob: 0f71b4a297401f0ae6fd928d92bdbdeb3c90f450 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
54
55
#include "fitz.h"
#include "samus.h"

/*
 * Create a new canonical absolute path given both
 * a base url (current directory) and a relative or absolute name.
 */
char *
sa_resolvepath(char *dst, char *baseurl, char *parturl, int dstlen)
{
	char *end;

	if (parturl[0] == '/')
	{
		strlcpy(dst, parturl, dstlen);
	}
	else
	{
		strlcpy(dst, baseurl, dstlen);
		end = strrchr(dst, '/');
		if (end)
			end[1] = 0;
		strlcat(dst, parturl, dstlen);
		cleanname(dst);
	}

	return dst;
}

/*
 * Test part names for equivalence.
 *
 * What we *should* do here (according to the spec) is...
 * - Convert part name to a Unicode string by un-escaping UTF-8 octets.
 * - Convert this to upper case.
 * - Normalize to NFC.
 *
 * But all we do is a case insensitive ASCII string comparison.
 */

static inline int toupper(int c)
{
	if (c >= 'a' && c <= 'z')
		return c + 'A' - 'a';
	return c;
}

int sa_strcmp(char *a, char *b)
{
	while (toupper(*a) == toupper(*b++))
		if (*a++ == 0)
			return 0;
	return toupper(*a) - toupper(*(b-1));
}