Plan 9 from Bell Labs’s /usr/web/sources/contrib/rog/sh-examples/rgb2tkcol.b

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


implement Rgb2tkcol;
include "sys.m";
	sys: Sys;
include "draw.m";
include "bufio.m";
	bufio: Bufio;
	Iobuf: import bufio;

Rgb2tkcol: module {
	init: fn(nil: ref Draw->Context, argv: list of string);
};

init(nil: ref Draw->Context, nil: list of string)
{
	sys = load Sys Sys->PATH;
	stderr := sys->fildes(2);
	bufio = load Bufio Bufio->PATH;
	stdin := bufio->fopen(sys->fildes(0), Bufio->OREAD);

	while ((s := stdin.gets('\n')) != nil) {
		(n, toks) := sys->tokenize(s, " \n");
		if (n != 3) {
			sys->fprint(stderr, "bad rgb line: %q", s);
		} else {
			(r, g, b) := (int hd toks, int hd tl toks, int hd tl tl toks);
			sys->print("#%.2x%.2x%.2x\n", r, g, b);
		}
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.