~sircmpwn/powerctl

9614dbff937f9b90f28c85ce7fdee06a45dc0649 — Drew DeVault 8 months ago 64efe1d master
all: updates for for-each

Signed-off-by: Drew DeVault <sir@cmpwn.com>
3 files changed, 7 insertions(+), 28 deletions(-)

M group.ha
M main.ha
M sysfs.ha
M group.ha => group.ha +2 -2
@@ 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;
		};
	};

M main.ha => main.ha +2 -2
@@ 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' =>

M sysfs.ha => sysfs.ha +3 -24
@@ 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 =>