File: util.ha

package info (click to toggle)
hare 0.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,948 kB
  • sloc: asm: 1,264; makefile: 123; sh: 114; lisp: 101
file content (53 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download
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
// SPDX-License-Identifier: GPL-3.0-only
// (c) Hare authors <https://harelang.org>

use ascii;
use dirs;
use hare::module;
use os;
use strings;

def HAREPATH: str = ".";

fn merge_tags(current: *[]str, new: str) (void | module::error) = {
	let trimmed = strings::ltrim(new, '^');
	if (trimmed != new) {
		free(*current);
		*current = [];
	};
	let newtags = module::parse_tags(trimmed)?;
	defer free(newtags);
	for :new (let newtag .. newtags) {
		for (let i = 0z; i < len(current); i += 1) {
			if (newtag.name == current[i]) {
				if (!newtag.include) {
					static delete(current[i]);
				};
				continue :new;
			};
		};
		if (newtag.include) {
			append(current, newtag.name)!;
		};
	};
};

fn harepath() str = os::tryenv("HAREPATH", HAREPATH);

fn harecache() str = {
	match (os::getenv("HARECACHE")) {
	case let s: str =>
		return s;
	case void =>
		return dirs::cache("hare");
	};
};

// contents of slice shouldn't be freed
fn default_tags() []str = {
	let arch = os::arch_name(os::architecture());
	static let platform: [7]u8 = [0...];
	let platform = ascii::strlower_buf(os::sysname(), platform[..0])!;
	let tags: []str = alloc([arch, platform])!;
	return tags;
};