mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-06-08 08:44:32 +02:00
98 lines
2.7 KiB
Diff
98 lines
2.7 KiB
Diff
From 9614dbff937f9b90f28c85ce7fdee06a45dc0649 Mon Sep 17 00:00:00 2001
|
|
From: Drew DeVault <sir@cmpwn.com>
|
|
Date: Mon, 1 Apr 2024 16:05:39 +0200
|
|
Subject: [PATCH] all: updates for for-each
|
|
Patch-Source: https://git.sr.ht/~sircmpwn/powerctl/commit/9614dbff937f9b90f28c85ce7fdee06a45dc0649
|
|
|
|
Signed-off-by: Drew DeVault <sir@cmpwn.com>
|
|
---
|
|
group.ha | 4 ++--
|
|
main.ha | 4 ++--
|
|
sysfs.ha | 27 +++------------------------
|
|
3 files changed, 7 insertions(+), 28 deletions(-)
|
|
|
|
diff --git a/group.ha b/group.ha
|
|
index 0ac5df0..6ed8332 100644
|
|
--- a/group.ha
|
|
+++ b/group.ha
|
|
@@ -23,8 +23,8 @@ fn checkgroup() bool = {
|
|
defer passwd::grent_finish(&group);
|
|
|
|
const gids = unix::getgroups();
|
|
- for (let i = 0z; i < len(gids); i += 1) {
|
|
- if (gids[i] == group.gid) {
|
|
+ for (const gid .. gids) {
|
|
+ if (gid == group.gid) {
|
|
return true;
|
|
};
|
|
};
|
|
diff --git a/main.ha b/main.ha
|
|
index 0a59752..cafaf37 100644
|
|
--- a/main.ha
|
|
+++ b/main.ha
|
|
@@ -27,8 +27,8 @@ export fn main() void = {
|
|
defer getopt::finish(&cmd);
|
|
|
|
let op = operation::SET_SLEEP;
|
|
- for (let i = 0z; i < len(cmd.opts); i += 1) {
|
|
- switch (cmd.opts[i].0) {
|
|
+ for (const (opt, _) .. cmd.opts) {
|
|
+ switch (opt) {
|
|
case 'q' =>
|
|
op = operation::QUERY;
|
|
case 'D' =>
|
|
diff --git a/sysfs.ha b/sysfs.ha
|
|
index df7f373..dbd507f 100644
|
|
--- a/sysfs.ha
|
|
+++ b/sysfs.ha
|
|
@@ -56,14 +56,7 @@ fn read_sleep_states() (sleep_state | fs::error | io::error) = {
|
|
const tok = read_states("/sys/power/state")?;
|
|
|
|
let states: sleep_state = 0;
|
|
- for (true) {
|
|
- const tok = match (strings::next_token(&tok)) {
|
|
- case let s: str =>
|
|
- yield s;
|
|
- case void =>
|
|
- break;
|
|
- };
|
|
-
|
|
+ for (const tok => strings::next_token(&tok)) {
|
|
match (sleep_state_parse(tok)) {
|
|
case let s: sleep_state =>
|
|
states |= s;
|
|
@@ -119,14 +112,7 @@ fn read_mem_states() ((mem_state, mem_state) | fs::error | io::error) = {
|
|
const tok = read_states("/sys/power/mem_sleep")?;
|
|
|
|
let states: mem_state = 0, active: mem_state = 0;
|
|
- for (true) {
|
|
- let tok = match (strings::next_token(&tok)) {
|
|
- case let s: str =>
|
|
- yield s;
|
|
- case void =>
|
|
- break;
|
|
- };
|
|
-
|
|
+ for (const tok => strings::next_token(&tok)) {
|
|
const trimmed = strings::trim(tok, '[', ']');
|
|
match (mem_state_parse(trimmed)) {
|
|
case let s: mem_state =>
|
|
@@ -180,14 +166,7 @@ fn read_disk_states() ((disk_state, disk_state) | fs::error | io::error) = {
|
|
const tok = read_states("/sys/power/disk")?;
|
|
|
|
let states: disk_state = 0, active: disk_state = 0;
|
|
- for (true) {
|
|
- let tok = match (strings::next_token(&tok)) {
|
|
- case let s: str =>
|
|
- yield s;
|
|
- case void =>
|
|
- break;
|
|
- };
|
|
-
|
|
+ for (const tok => strings::next_token(&tok)) {
|
|
const trimmed = strings::trim(tok, '[', ']');
|
|
match (disk_state_parse(trimmed)) {
|
|
case let s: disk_state =>
|
|
--
|
|
2.45.3
|
|
|