---
git/buffer.ha | 5 +++--
git/error.ha | 9 +++++----
git/git.ha | 5 +++--
git/ref.ha | 5 +++--
git/repo.ha | 19 ++++++++++---------
git/status.ha | 3 ++-
mods/+clock.ha | 5 ++---
mods/+moon.ha | 9 ++++-----
mods/+path.ha | 24 ++++++++++++------------
mods/+project.ha | 31 +++++++++++++++++--------------
mods/+timer.ha | 1 -
11 files changed, 61 insertions(+), 55 deletions(-)
diff --git a/git/buffer.ha b/git/buffer.ha
index 2b038fa..a9b4245 100644
--- a/git/buffer.ha
+++ b/git/buffer.ha
@@ -5,9 +5,10 @@
// SPDX-License-Identifier: GPL-3.0-or-laterP
use strings;
use types;
+use types::c;
export type buf = struct {
- ptr: const *char,
+ ptr: const *c::char,
reserved: size,
s: size,
};
@@ -19,7 +20,7 @@ export fn get_out() *buf = {
const buffer = strings::padend("", '\0', 256);
const b = &buffer: *types::string;
return alloc(buf {
- ptr = b.data: const *char,
+ ptr = b.data: const *c::char,
reserved = b.capacity,
s = b.length,
});
diff --git a/git/error.ha b/git/error.ha
index 79155ae..9984ed3 100644
--- a/git/error.ha
+++ b/git/error.ha
@@ -5,24 +5,25 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use fmt;
use strings;
+use types::c;
// libgit2 returns errors as integers != 0
export type error = !int;
// details of an error, obtainable with error_last
export type git_error = struct {
- message: const *char,
+ message: const *c::char,
class: int,
};
export def ENOTFOUND: error = -3;
-export @symbol("git_error_set_str") fn error_set_str(class: int, err: const *char) int;
+export @symbol("git_error_set_str") fn error_set_str(class: int, err: const *c::char) int;
// If one of the functions returned an error, call this function to get the
// underlying message and error class. Call error_clear when you are done with
// the error message. If the information should survive error_clear, use
-// strings::dup(strings::fromc((ge: git_error).message)). You should only call
+// strings::dup(c::tostr((ge: git_error).message)). You should only call
// this function in case another function returned error.
export @symbol("git_error_last") fn error_last() const nullable *git_error;
@@ -70,7 +71,7 @@ export fn strerror(e: error) str = {
const ge: (str, int) = switch(ge) {
case null => yield ("", 0);
case =>
- yield (strings::fromc((ge: *git_error).message: *char)!,
+ yield (c::tostr((ge: *git_error).message: *c::char)!,
(ge: *git_error).class);
};
const res = fmt::asprintf(
diff --git a/git/git.ha b/git/git.ha
index 9d2ea14..4295dd1 100644
--- a/git/git.ha
+++ b/git/git.ha
@@ -4,6 +4,7 @@
// SPDX-FileCopyrightText: 2022 Tom Regner <tomte@tomsdiner.org>
// SPDX-License-Identifier: GPL-3.0-or-later
use strings;
+use types::c;
// You have to call this prior to using other functions of this library.
// Consider doing it in an @init function.
@@ -21,7 +22,7 @@ export fn branch(repo: *repository) (str | error) = {
case void =>
defer reference_free(ref: *reference);
yield strings::dup(
- strings::fromc(reference_shorthand(ref: *reference))!);
+ c::tostr(reference_shorthand(ref: *reference))!);
case let e: error=> yield e;
};
};
@@ -97,7 +98,7 @@ export type repo_state = struct {
cut_short: bool,
};
-fn update_repo_state(path: const *char, status_flags: uint,
+fn update_repo_state(path: const *c::char, status_flags: uint,
payload: *void) int = {
const state = payload: *repo_state;
if (status_flags & status_t::INDEX_NEW != 0 ||
diff --git a/git/ref.ha b/git/ref.ha
index 75d6b27..bf8fe9e 100644
--- a/git/ref.ha
+++ b/git/ref.ha
@@ -3,6 +3,7 @@
//
// SPDX-FileCopyrightText: 2022 Tom Regner <tomte@tomsdiner.org>
// SPDX-License-Identifier: GPL-3.0-or-later
+use types::c;
// Opaque pointer type representing a git reference
export type reference = void;
@@ -11,10 +12,10 @@ export type reference = void;
// Return the full name of REF (e.g. refs/heads/main). The pointer returned is
// valid as long as REF.
export @symbol("git_reference_name")
- fn reference_name(ref: *reference) const *char;
+ fn reference_name(ref: *reference) const *c::char;
// Return a short identifier for REF (e.g. main). The pointer returned is valid
// as long as REF.
export @symbol("git_reference_shorthand")
- fn reference_shorthand(ref: *reference) const *char;
+ fn reference_shorthand(ref: *reference) const *c::char;
// You have to call this when you are done with REF.
export @symbol("git_reference_free") fn reference_free(ref: *reference) void;
diff --git a/git/repo.ha b/git/repo.ha
index 412d59f..8cd1818 100644
--- a/git/repo.ha
+++ b/git/repo.ha
@@ -4,6 +4,7 @@
// SPDX-FileCopyrightText: 2022 Tom Regner <tomte@tomsdiner.org>
// SPDX-License-Identifier: GPL-3.0-or-later
use strings;
+use types::c;
export type repository_open_flag_t = enum uint {
NO_SEARCH = (1 << 0),
@@ -39,9 +40,9 @@ export @symbol("git_repository_free") fn repository_free(repo: *repository) void
// Open the repository at PATH, populate *REPO. Caller must call repository_free
// on *REPO if this call was successful.
@symbol("git_repository_open") fn _git_repository_open(repo: **repository,
- path: const *char) int;
+ path: const *c::char) int;
export fn repository_open(repo: **repository, path: str) (void | error) = {
- const path = strings::to_c(path);
+ const path = c::fromstr(path);
defer free(path);
const res: int = _git_repository_open(repo, path);
switch(res) {
@@ -52,18 +53,18 @@ export fn repository_open(repo: **repository, path: str) (void | error) = {
@symbol("git_repository_open_ext") fn _git_repository_open_ext(
repo: **repository,
- path: const *char,
+ path: const *c::char,
flags: uint,
- ceil: const *char) error;
+ ceil: const *c::char) error;
// Open the repository found in PATH. The repo will be searched upwards PATH,
// the search will stop once /tmp, /usr or /home are reached. It is the callers
// responsibility to call `repository_free(repo: *repository) on the pointer
// passed to *repo. void is returned if REPO could be populated.
export fn repository_open_ext(repo: **repository, path: str,
flags: uint, ceil: str) (void | error) = {
- const ceil = strings::to_c(ceil);
+ const ceil = c::fromstr(ceil);
defer free(ceil);
- const path = strings::to_c(path);
+ const path = c::fromstr(path);
defer free(path);
const res: int = _git_repository_open_ext(
repo,
@@ -147,19 +148,19 @@ export fn repository_item_path(repo: *repository, i: repository_item_t)
defer free_buf(b);
const res = _git_repository_item_path(b, repo, i);
switch(res) {
- case 0 => return strings::dup(strings::fromc(b.ptr)!);
+ case 0 => return strings::dup(c::tostr(b.ptr)!);
case ENOTFOUND => return void;
case => return res: error;
};
};
@symbol("git_repository_init") fn _git_repository_init(out: **repository,
- path: const *char, is_bare: uint) int;
+ path: const *c::char, is_bare: uint) int;
// Create, initialize and open a new repository at PATH; create it as bare if
// IS_BARE is true. The caller must free *OUT if this call is successful.
export fn repository_init(out: **repository,
path: str, is_bare: bool) (void | error) = {
- const path = strings::to_c(path);
+ const path = c::fromstr(path);
defer free(path);
const is_bare: uint = switch(is_bare) {
case false => yield 0;
diff --git a/git/status.ha b/git/status.ha
index 9e02b52..1bfc13e 100644
--- a/git/status.ha
+++ b/git/status.ha
@@ -5,6 +5,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use fmt;
use strings;
+use types::c;
def STATUS_OPTIONS_VERSION: uint = 1;
@@ -71,7 +72,7 @@ export fn status_foreach_ext(repo: *repository,
return res;
};
-export type status_cb = fn (path: const *char,
+export type status_cb = fn (path: const *c::char,
status_flags: uint, payload: *void) int;
export type status_t = enum uint {
diff --git a/mods/+clock.ha b/mods/+clock.ha
index f157046..1d6c86e 100644
--- a/mods/+clock.ha
+++ b/mods/+clock.ha
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use env;
use config;
-use datetime;
+use time::date;
@init fn register_clock() void = {
register("clock", &mod_clock);
@@ -13,6 +13,5 @@ use datetime;
export fn mod_clock(pe: *env::env) str = {
const layout = config::setting("clock.layout", "[%H:%M]");
- const now = datetime::now();
- return datetime::asformat(layout, &now): str;
+ return date::asformat(layout, &date::now()): str;
};
diff --git a/mods/+moon.ha b/mods/+moon.ha
index 3a01132..9e7e4ea 100644
--- a/mods/+moon.ha
+++ b/mods/+moon.ha
@@ -3,15 +3,14 @@
//
// SPDX-FileCopyrightText: 2023 Carlos Une <une@fastmail.fm>
// SPDX-License-Identifier: GPL-3.0-or-later
-use bufio;
use config;
-use datetime;
use env;
use fmt;
use math;
use strings;
use time;
use time::chrono;
+use time::date;
type hemisphere = enum {Southern, Northern};
@@ -19,9 +18,9 @@ type hemisphere = enum {Southern, Northern};
register("moon", &mod_moon);
};
-fn moon_phase(dt: datetime::datetime, hemisphere: hemisphere) str = {
+fn moon_phase(dt: date::date, hemisphere: hemisphere) str = {
// Use a known New Moon datetime as reference (January 21, 2023, 20:53 UTC)
- const ref_new_moon = datetime::new(time::chrono::UTC, 0, 2023, 1, 21, 20, 53, 0, 0)!;
+ const ref_new_moon = date::new(chrono::UTC, 0, 2023, 1, 21, 20, 53, 0, 0)!;
const secs = (chrono::diff(&ref_new_moon, &dt)! / time::SECOND): f64;
const T = 29.53059; // Average synodic period of the Moon
const Tsecs = T * 86400.0;
@@ -39,5 +38,5 @@ export fn mod_moon(pe: *env::env) str = {
case "N" => yield hemisphere::Northern;
case => return strings::dup("+moon.hemisphere:config error");
};
- return strings::dup(moon_phase(datetime::nowutc(), hemisphere));
+ return strings::dup(moon_phase(date::nowutc(), hemisphere));
};
diff --git a/mods/+path.ha b/mods/+path.ha
index ce93056..28fa966 100644
--- a/mods/+path.ha
+++ b/mods/+path.ha
@@ -16,11 +16,11 @@ use env;
// Returns the count of path-segemnts in PATH. For an absolute path, the root
// pathsep counts as segment.
-fn length(path: (str | *path::buffer)) size = {
+fn length(path: *path::buffer) size = {
let iter = path::iter(path);
let count = 0z;
for (true) {
- match(path::next(&iter)) {
+ match(path::nextiter(&iter)) {
case void => break;
case let s: str => count += 1;
};
@@ -32,11 +32,11 @@ fn shorten(p: str) str = {
static let pbuf: [4096]u8 = [0...];
switch(config::setting("path.shorten", "segments")) {
case "segments" =>
- let buf = path::init();
+ let buf = path::init()!;
match(path::set(&buf, p)) {
- case errors::overflow =>
- return strings::dup("buffer overflow");
- case => void;
+ case let e: path::error =>
+ return strings::dup(path::strerror(e));
+ case str => void;
};
const l = length(&buf);
if (l > 2) {
@@ -46,7 +46,7 @@ fn shorten(p: str) str = {
let iter = path::iter(&buf);
append(m, strings::toutf8("/")...);
for(true) {
- match(path::next(&iter)) {
+ match(path::nextiter(&iter)) {
case void => break;
case let s: str =>
ct += 1;
@@ -62,11 +62,11 @@ fn shorten(p: str) str = {
};
return p;
case "shorten" =>
- let buf = path::init();
+ let buf = path::init()!;
match(path::set(&buf, p)) {
- case errors::overflow =>
- return strings::dup("buffer overflow");
- case => void;
+ case let e: path::error =>
+ return strings::dup(path::strerror(e));
+ case str => void;
};
const l = length(&buf);
const limit = l - 2;
@@ -74,7 +74,7 @@ fn shorten(p: str) str = {
let iter = path::iter(&buf);
let m: []u8 = pbuf[..0];
for(true) {
- match(path::next(&iter)) {
+ match(path::nextiter(&iter)) {
case void => break;
case let s: str =>
ct += 1;
diff --git a/mods/+project.ha b/mods/+project.ha
index fd1bbb5..e06dcd6 100644
--- a/mods/+project.ha
+++ b/mods/+project.ha
@@ -20,31 +20,34 @@ let project_marker: str = ".projectile";
export fn mod_project(pe: *env::env) str = {
static let buf = path::buffer { ... };
- path::reset(&buf);
match (path::set(&buf, pe.pwd)) {
- case errors::overflow => return strings::dup("buffer overflow");
- case => void;
+ case let e: path::error =>
+ return strings::dup(path::strerror(e));
+ case str => void;
};
for (true) {
- match(path::add(&buf, config::setting("project.marker", project_marker))){
- case errors::overflow => return strings::dup("buffer overflow");
- case => void;
+ match(path::push(&buf, config::setting("project.marker", project_marker))){
+ case let e: path::error =>
+ return strings::dup(path::strerror(e));
+ case str => void;
};
match(os::stat(path::string(&buf))) {
case let e: fs::error =>
- match(path::set(&buf, path::dirname(&buf))) { // drop .projectile
- case errors::overflow => return strings::dup("buffer overflow");
- case => void;
+ match(path::set(&buf, path::parent(&buf)!)) { // drop .projectile
+ case let e: path::error =>
+ return strings::dup(path::strerror(e));
+ case str => void;
};
- match(path::set(&buf, path::dirname(&buf))) { // parent folder
- case errors::overflow => return strings::dup("buffer overflow");
- case => void;
+ match(path::set(&buf, path::parent(&buf)!)) { // parent folder
+ case let e: path::error =>
+ return strings::dup(path::strerror(e));
+ case str => void;
};
- if (path::string(&buf) == pathsepstr) {
+ if (path::isroot(&buf)) {
break;
};
case let s: fs::filestat => return strings::dup(
- path::basename(path::dirname(&buf)));
+ path::basename(path::parent(&buf)!));
};
};
return strings::dup("");
diff --git a/mods/+timer.ha b/mods/+timer.ha
index ceab068..bbf326f 100644
--- a/mods/+timer.ha
+++ b/mods/+timer.ha
@@ -5,7 +5,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use env;
use config;
-use datetime;
use strconv;
use strings;
use timer;
--
2.30.2