[patch] setterm applet
Bernhard Fischer
rep.nop at aon.at
Wed Sep 27 14:15:07 PDT 2006
On Tue, Sep 26, 2006 at 10:41:47AM -0300, Alastor Santamaria wrote:
>hi, well I did the diff with the cvs snapshot now, and just in case I also
>put in a tar with the diff of config.in makefile.in usage.h and
>applet.hplus the
>setterm.h i hope it works now.
A few non-code comments while reading through..
>
>Sinceramente Alastor
>---
>Thanks for your attention.
>diff -urN b0/include/applets.h b1/include/applets.h
>--- b0/include/applets.h 2006-09-24 04:20:09.000000000 -0300
>+++ b1/include/applets.h 2006-09-25 07:24:03.000000000 -0300
>@@ -242,6 +242,7 @@
> USE_SETCONSOLE(APPLET(setconsole, _BB_DIR_SBIN, _BB_SUID_NEVER))
> USE_SETKEYCODES(APPLET(setkeycodes, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
> USE_SETLOGCONS(APPLET(setlogcons, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
>+USE_SETTERM(APPLET(setterm, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
> USE_SETSID(APPLET(setsid, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
> USE_FEATURE_SH_IS_ASH(APPLET_NOUSAGE(sh, ash, _BB_DIR_BIN, _BB_SUID_NEVER))
> USE_FEATURE_SH_IS_HUSH(APPLET_NOUSAGE(sh, hush, _BB_DIR_BIN, _BB_SUID_NEVER))
>diff -urN b0/include/usage.h b1/include/usage.h
>--- b0/include/usage.h 2006-09-24 04:20:09.000000000 -0300
>+++ b1/include/usage.h 2006-09-25 07:20:39.000000000 -0300
>@@ -2595,6 +2595,18 @@
> #define setlogcons_full_usage \
> "Redirects the kernel output to console N (0 for current)."
>
>+#define setterm_trivial_usage \
>+ "[-b COLOR] [-f COLOR] [-m blink|bold|dark|underline] [-s]\n" \
>+ "\tCOLOR: black|red|green|yellow|blue|magenta|cyan|white\n"
>+#define setterm_full_usage \
->+ "sets terminal settings\n\n" \
+set terminal attributes
>+ "Options:\n" \
>+ "\t-b:\t\tset background\n" \
>+ "\t-f:\t\tset foreground\n" \
->+ "\t-m:\t\tadd this modifier\n" \
+>+ "\t-m:\t\tset attribute\n" \
>+ "\t-s:\t\tstore\n" \
>+ "with no options it resets\n\n"
>+
> #define setsid_trivial_usage \
> "program [arg ...]"
> #define setsid_full_usage \
>diff -urN b0/util-linux/Config.in b1/util-linux/Config.in
>--- b0/util-linux/Config.in 2006-09-24 04:20:11.000000000 -0300
>+++ b1/util-linux/Config.in 2006-09-25 07:09:28.000000000 -0300
>@@ -433,6 +433,12 @@
> this util on a system that supports both 64bit and 32bit userland
> (like amd64/x86, ppc64/ppc, sparc64/sparc, etc...).
>
>+config CONFIG_SETTERM
>+ bool "setterm"
>+ default n
>+ help
->+ This program sets terminal settings.
+>+ This program sets terminal attributes.
>+
> config CONFIG_SWAPONOFF
> bool "swaponoff"
> default n
>diff -urN b0/util-linux/Makefile.in b1/util-linux/Makefile.in
>--- b0/util-linux/Makefile.in 2006-09-24 04:20:11.000000000 -0300
>+++ b1/util-linux/Makefile.in 2006-09-25 07:11:17.000000000 -0300
>@@ -33,6 +33,7 @@
> UTILLINUX-$(CONFIG_RDATE) +=rdate.o
> UTILLINUX-$(CONFIG_READPROFILE) +=readprofile.o
> UTILLINUX-$(CONFIG_SETARCH) +=setarch.o
>+UTILLINUX-$(CONFIG_SETTERM) +=setterm.o
> UTILLINUX-$(CONFIG_SWAPONOFF) +=swaponoff.o
> UTILLINUX-$(CONFIG_SWITCH_ROOT) +=switch_root.o
> UTILLINUX-$(CONFIG_UMOUNT) +=umount.o
>diff -urN b0/util-linux/setterm.c b1/util-linux/setterm.c
>--- b0/util-linux/setterm.c 1969-12-31 21:00:00.000000000 -0300
>+++ b1/util-linux/setterm.c 2006-09-25 07:38:57.000000000 -0300
>@@ -0,0 +1,108 @@
>+/* vi: set sw=4 ts=4: */
>+/*
>+ * setterm: set terminal settings
>+ *
>+ * Copyright (C) 2006 by Mario Santamaria <AlastorS at gmail.com>
>+ *
>+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
>+ */
>+/*
>+ *
>+ * This program manipulates the screen colors and other atributes,
attributes
>+ * with no options, it resets to stored defaults.
>+ *
>+ * less options than GNU counterpart to minimize code size
s/less/fewer/;# but i'm not a native speaker
>+ * and because I only use/need a small subset of GNU setterm functions.
>+ *
>+ * setterm
>+ * [ -b black|red|green|yellow|blue|magenta|cyan|white ]
>+ * sets the background
>+ * [ -f black|red|green|yellow|blue|magenta|cyan|white ]
>+ * sets the foreground
>+ * [ -m blink|bold|dark|underline|reverse ]
->+ * add this mod
+>+ * add this attribute
>+ * [ -s ]
>+ * store current settings as the new defaults
>+ *
>+ * example for green letters and black background, matrix style ;)
>+ * setterm -f green -b black -s
>+ *
>+ */
>+
>+#include <stdio.h>
>+#include <stdlib.h>
>+#include <string.h>
>+#include "busybox.h"
>+
>+/*
>+ * function parse_option
>+ *
>+ * opt_act: string, current option.
>+ * options_list: array of strings, all posible options.
>+ * result: string, making here the string.
>+ * base: int, this plus the value returned by compare_string_array is what we need to make the string.
>+ *
>+ * Returns
>+ *
>+ * n > 0 : number of caracters writen in result.
written
>+ *
>+ */
>+
static, as tito already pointed out.
>+int parse_option(const char *opt_act, const char *options_list[], char *result, int base) {
>+ int option;
>+
>+ option = compare_string_array(options_list, opt_act);
>+ if (option < 0)
>+ bb_show_usage();
>+ return sprintf(result, "%d;", option + base);
>+}
>+
->+/* main */
->+
>+int setterm_main(int argc, char **argv) {
>+ char settings[30] = "\033[0m";
>+ int opt;
>+ char *act, *back_opt, *fore_opt;
>+ llist_t *mods = NULL;
s/mods/attribs/
They really are attributes
>+ const char *bf_options_list[] = {
>+ "black",
>+ "red",
>+ "green",
>+ "yellow",
>+ "blue",
>+ "magenta",
>+ "cyan",
>+ "white",
->+ NULL
>+ };
>+ const char *m_options_list[] = {
>+ "bold",
>+ "dark",
>+ "\0",
>+ "underline",
>+ "blink",
->+ NULL
>+ };
>+
>+ bb_opt_complementally = "m::";
>+ opt = bb_getopt_ulflags(argc, argv, "b:f:m:s", &back_opt, &fore_opt, &mods);
>+
>+ act = settings;
>+
>+ if (opt & 0x07) { //change settings
>+ act += 2;
>+
>+ if (opt & 1)
>+ act += parse_option(back_opt, bf_options_list, act, 40);
Why don't you change act in parse_option() ?
>+ if (opt & 2)
>+ act += parse_option(fore_opt, bf_options_list, act, 30);
>+ for (; mods != NULL; mods = mods->link)
>+ act += parse_option(mods->data, m_options_list, act, 1);
>+
>+ *(act-1) = 'm'; //replace the last ';' which is surplus
>+ }
>+ if (opt & 8)
>+ sprintf(act, "\033[8]");
I would have to look it up, but isn't the closing ']' superfluous?
>+ printf("%s", settings);
>+ return 0;
didn't try, but perhaps bb_fflush_stdout_and_exit(EXIT_SUCCESS) is
smaller here..
>+}
hm. I'll have to try it out sometimes.. :)
More information about the busybox
mailing list