Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (8 years ago)
Author:
bruno
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
Location:
branches/2.2.9/mindi-busybox/console-tools
Files:
5 added
14 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/console-tools/Config.in

    r1765 r2725  
     1# DO NOT EDIT. This file is generated from Config.src
    12#
    23# For a description of the syntax of this configuration file,
     
    67menu "Console Utilities"
    78
     9
     10
    811config CHVT
    912    bool "chvt"
    10     default n
     13    default y
     14    depends on PLATFORM_LINUX
    1115    help
    1216      This program is used to change to another terminal.
    1317      Example: chvt 4 (change to terminal /dev/tty4)
    1418
     19config FGCONSOLE
     20    bool "fgconsole"
     21    default y
     22    depends on PLATFORM_LINUX
     23    help
     24      This program prints active (foreground) console number.
     25
    1526config CLEAR
    1627    bool "clear"
    17     default n
     28    default y
    1829    help
    1930      This program clears the terminal screen.
     
    2132config DEALLOCVT
    2233    bool "deallocvt"
    23     default n
     34    default y
     35    depends on PLATFORM_LINUX
    2436    help
    2537      This program deallocates unused virtual consoles.
     
    2739config DUMPKMAP
    2840    bool "dumpkmap"
    29     default n
     41    default y
     42    depends on PLATFORM_LINUX
    3043    help
    3144      This program dumps the kernel's keyboard translation table to
    3245      stdout, in binary format. You can then use loadkmap to load it.
    3346
     47config KBD_MODE
     48    bool "kbd_mode"
     49    default y
     50    depends on PLATFORM_LINUX
     51    help
     52      This program reports and sets keyboard mode.
     53
    3454config LOADFONT
    3555    bool "loadfont"
    36     default n
     56    default y
     57    depends on PLATFORM_LINUX
    3758    help
    3859      This program loads a console font from standard input.
     
    4061config LOADKMAP
    4162    bool "loadkmap"
    42     default n
     63    default y
     64    depends on PLATFORM_LINUX
    4365    help
    4466      This program loads a keyboard translation table from
     
    4769config OPENVT
    4870    bool "openvt"
    49     default n
     71    default y
     72    depends on PLATFORM_LINUX
    5073    help
    5174      This program is used to start a command on an unused
     
    5477config RESET
    5578    bool "reset"
    56     default n
     79    default y
    5780    help
    5881      This program is used to reset the terminal screen, if it
     
    6184config RESIZE
    6285    bool "resize"
    63     default n
     86    default y
    6487    help
    6588      This program is used to (re)set the width and height of your current
     
    6790
    6891config FEATURE_RESIZE_PRINT
    69     bool "print environment variables"
    70     default n
     92    bool "Print environment variables"
     93    default y
    7194    depends on RESIZE
    7295    help
     
    78101config SETCONSOLE
    79102    bool "setconsole"
    80     default n
     103    default y
     104    depends on PLATFORM_LINUX
    81105    help
    82106      This program redirects the system console to another device,
     
    85109config FEATURE_SETCONSOLE_LONG_OPTIONS
    86110    bool "Enable long options"
    87     default n
    88     depends on SETCONSOLE && GETOPT_LONG
     111    default y
     112    depends on SETCONSOLE && LONG_OPTS
    89113    help
    90114      Support long options for the setconsole applet.
    91115
     116config SETFONT
     117    bool "setfont"
     118    default y
     119    depends on PLATFORM_LINUX
     120    help
     121      Allows to load console screen map. Useful for i18n.
     122
     123config FEATURE_SETFONT_TEXTUAL_MAP
     124    bool "Support reading textual screen maps"
     125    default y
     126    depends on SETFONT
     127    help
     128      Support reading textual screen maps.
     129
     130config DEFAULT_SETFONT_DIR
     131    string "Default directory for console-tools files"
     132    default ""
     133    depends on SETFONT
     134    help
     135      Directory to use if setfont's params are simple filenames
     136      (not /path/to/file or ./file). Default is "" (no default directory).
     137
    92138config SETKEYCODES
    93139    bool "setkeycodes"
    94     default n
     140    default y
     141    depends on PLATFORM_LINUX
    95142    help
    96143      This program loads entries into the kernel's scancode-to-keycode
     
    99146config SETLOGCONS
    100147    bool "setlogcons"
    101     default n
     148    default y
     149    depends on PLATFORM_LINUX
    102150    help
    103151      This program redirects the output console of kernel messages.
    104152
     153config SHOWKEY
     154    bool "showkey"
     155    default y
     156    depends on PLATFORM_LINUX
     157    help
     158      Shows keys pressed.
     159
     160comment "Common options for loadfont and setfont"
     161    depends on LOADFONT || SETFONT
     162
     163config FEATURE_LOADFONT_PSF2
     164    bool "Support for PSF2 console fonts"
     165    default y
     166    depends on LOADFONT || SETFONT
     167    help
     168      Support PSF2 console fonts.
     169
     170config FEATURE_LOADFONT_RAW
     171    bool "Support for old (raw) console fonts"
     172    default y
     173    depends on LOADFONT || SETFONT
     174    help
     175      Support old (raw) console fonts.
     176
    105177endmenu
  • branches/2.2.9/mindi-busybox/console-tools/Kbuild

    r1765 r2725  
     1# DO NOT EDIT. This file is generated from Kbuild.src
    12# Makefile for busybox
    23#
    34# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
    45#
    5 # Licensed under the GPL v2, see the file LICENSE in this tarball.
     6# Licensed under GPLv2, see file LICENSE in this source tree.
    67
    78lib-y:=
     9
     10
    811lib-$(CONFIG_CHVT)      += chvt.o
     12lib-$(CONFIG_FGCONSOLE)     += fgconsole.o
    913lib-$(CONFIG_CLEAR)     += clear.o
    1014lib-$(CONFIG_DEALLOCVT)     += deallocvt.o
    1115lib-$(CONFIG_DUMPKMAP)      += dumpkmap.o
    1216lib-$(CONFIG_SETCONSOLE)    += setconsole.o
     17lib-$(CONFIG_KBD_MODE)      += kbd_mode.o
    1318lib-$(CONFIG_LOADFONT)      += loadfont.o
    1419lib-$(CONFIG_LOADKMAP)      += loadkmap.o
     
    1621lib-$(CONFIG_RESET)     += reset.o
    1722lib-$(CONFIG_RESIZE)        += resize.o
     23lib-$(CONFIG_SETFONT)       += loadfont.o
    1824lib-$(CONFIG_SETKEYCODES)   += setkeycodes.o
    1925lib-$(CONFIG_SETLOGCONS)    += setlogcons.o
     26lib-$(CONFIG_SHOWKEY)       += showkey.o
  • branches/2.2.9/mindi-busybox/console-tools/chvt.c

    r1765 r2725  
    55 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
    9 
    109#include "libbb.h"
    1110
    12 /* From <linux/vt.h> */
    13 enum {
    14     VT_ACTIVATE = 0x5606,   /* make vt active */
    15     VT_WAITACTIVE = 0x5607  /* wait for vt active */
    16 };
    17 
    18 int chvt_main(int argc, char **argv);
    19 int chvt_main(int argc, char **argv)
     11int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     12int chvt_main(int argc UNUSED_PARAM, char **argv)
    2013{
    21     int fd, num;
    22 
    23     if (argc != 2) {
    24         bb_show_usage();
    25     }
    26 
    27     fd = get_console_fd();
    28     num = xatou_range(argv[1], 1, 63);
    29     /* double cast suppresses "cast to ptr from int of different size */
    30     xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)num);
    31     xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)num);
     14    int num = xatou_range(single_argv(argv), 1, 63);
     15    console_make_active(get_console_fd_or_die(), num);
    3216    return EXIT_SUCCESS;
    3317}
  • branches/2.2.9/mindi-busybox/console-tools/clear.c

    r1765 r2725  
    55 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    8  *
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    98 */
    10 
    11 /* no options, no getopt */
    12 
    139#include "libbb.h"
    1410
    15 int clear_main(int argc, char **argv);
    16 int clear_main(int argc, char **argv)
     11int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     12int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
    1713{
    18     return printf("\033[H\033[J") != 6;
     14    /* home; clear to the end of screen */
     15    return full_write1_str("\033[H""\033[J") != 6;
    1916}
  • branches/2.2.9/mindi-busybox/console-tools/deallocvt.c

    r1765 r2725  
    66 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    77 *
    8  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
    1010
     
    1616enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
    1717
    18 int deallocvt_main(int argc, char **argv);
    19 int deallocvt_main(int argc, char **argv)
     18int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     19int deallocvt_main(int argc UNUSED_PARAM, char **argv)
    2020{
    2121    /* num = 0 deallocate all unused consoles */
    2222    int num = 0;
    2323
    24     switch (argc) {
    25     case 2:
     24    if (argv[1]) {
     25        if (argv[2])
     26            bb_show_usage();
    2627        num = xatou_range(argv[1], 1, 63);
    27         /* Fallthrough */
    28     case 1:
    29         break;
    30     default:
    31         bb_show_usage();
    3228    }
    3329
    34     /* double cast suppresses "cast to ptr from int of different size */
    35     xioctl(get_console_fd(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
     30    /* double cast suppresses "cast to ptr from int of different size" */
     31    xioctl(get_console_fd_or_die(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
    3632    return EXIT_SUCCESS;
    3733}
  • branches/2.2.9/mindi-busybox/console-tools/dumpkmap.c

    r1765 r2725  
    55 * Copyright (C) Arne Bernin <arne@matrix.loopback.org>
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 *
    99 */
     10/* no options, no getopt */
    1011
    1112#include "libbb.h"
     
    2324#define MAX_NR_KEYMAPS 256
    2425
    25 int dumpkmap_main(int argc, char **argv);
    26 int dumpkmap_main(int argc, char **argv)
     26int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     27int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
    2728{
    2829    struct kbentry ke;
    2930    int i, j, fd;
    30     char flags[MAX_NR_KEYMAPS];
     31    RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
    3132
    32     if (argc >= 2 && argv[1][0] == '-')
     33    /* When user accidentally runs "dumpkmap FILE"
     34     * instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
     35     * Let's prevent it: */
     36    if (argv[1])
    3337        bb_show_usage();
     38/*  bb_warn_ignoring_args(argv[1]);*/
    3439
    35     fd = xopen(CURRENT_VC, O_RDWR);
     40    fd = get_console_fd_or_die();
    3641
    37     write(1, "bkeymap", 7);
     42    write(STDOUT_FILENO, "bkeymap", 7);
    3843
    3944    /* Here we want to set everything to 0 except for indexes:
     
    4449
    4550    /* dump flags */
    46     write(1, flags, MAX_NR_KEYMAPS);
     51    write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
    4752
    4853    for (i = 0; i < MAX_NR_KEYMAPS; i++) {
     
    5762                        &ke.kb_value)
    5863                ) {
    59                     write(1, (void*)&ke.kb_value, 2);
     64                    write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
    6065                }
    6166            }
    6267        }
    6368    }
    64     close(fd);
     69    if (ENABLE_FEATURE_CLEAN_UP) {
     70        close(fd);
     71        RELEASE_CONFIG_BUFFER(flags);
     72    }
    6573    return EXIT_SUCCESS;
    6674}
  • branches/2.2.9/mindi-busybox/console-tools/loadfont.c

    r1765 r2725  
    77 * Loads the console font, and possibly the corresponding screen map(s).
    88 * (Adapted for busybox by Matej Vela.)
     9 *
     10 * Licensed under GPLv2, see file LICENSE in this source tree.
    911 */
    1012#include "libbb.h"
    1113#include <sys/kd.h>
    1214
     15#ifndef KDFONTOP
     16# define KDFONTOP 0x4B72
     17struct console_font_op {
     18    unsigned op;            /* KD_FONT_OP_* */
     19    unsigned flags;         /* KD_FONT_FLAG_* */
     20    unsigned width, height;
     21    unsigned charcount;
     22    unsigned char *data;    /* font data with height fixed to 32 */
     23};
     24# define KD_FONT_OP_SET          0  /* Set font */
     25# define KD_FONT_OP_GET          1  /* Get font */
     26# define KD_FONT_OP_SET_DEFAULT  2  /* Set font to default, data points to name / NULL */
     27# define KD_FONT_OP_COPY         3  /* Copy from another console */
     28# define KD_FONT_FLAG_OLD        0x80000000 /* Invoked via old interface */
     29# define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */
     30                                   /* (Used internally for PIO_FONT support) */
     31#endif /* KDFONTOP */
     32
     33
    1334enum {
    14     PSF_MAGIC1 = 0x36,
    15     PSF_MAGIC2 = 0x04,
    16 
    17     PSF_MODE512 = 0x01,
    18     PSF_MODEHASTAB = 0x02,
    19     PSF_MAXMODE = 0x03,
    20     PSF_SEPARATOR = 0xFFFF
     35    PSF1_MAGIC0 = 0x36,
     36    PSF1_MAGIC1 = 0x04,
     37    PSF1_MODE512 = 0x01,
     38    PSF1_MODEHASTAB = 0x02,
     39    PSF1_MODEHASSEQ = 0x04,
     40    PSF1_MAXMODE = 0x05,
     41    PSF1_STARTSEQ = 0xfffe,
     42    PSF1_SEPARATOR = 0xffff,
    2143};
    2244
    23 struct psf_header {
    24     unsigned char magic1, magic2;   /* Magic number */
     45struct psf1_header {
     46    unsigned char magic[2];         /* Magic number */
    2547    unsigned char mode;             /* PSF font mode */
    2648    unsigned char charsize;         /* Character size */
    2749};
    2850
    29 #define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
    30 
    31 static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
    32 {
    33     char *buf;
     51#define psf1h(x) ((struct psf1_header*)(x))
     52
     53#define PSF1_MAGIC_OK(x) ( \
     54     (x)->magic[0] == PSF1_MAGIC0 \
     55  && (x)->magic[1] == PSF1_MAGIC1 \
     56)
     57
     58#if ENABLE_FEATURE_LOADFONT_PSF2
     59enum {
     60    PSF2_MAGIC0 = 0x72,
     61    PSF2_MAGIC1 = 0xb5,
     62    PSF2_MAGIC2 = 0x4a,
     63    PSF2_MAGIC3 = 0x86,
     64    PSF2_HAS_UNICODE_TABLE = 0x01,
     65    PSF2_MAXVERSION = 0,
     66    PSF2_STARTSEQ = 0xfe,
     67    PSF2_SEPARATOR = 0xff
     68};
     69
     70struct psf2_header {
     71    unsigned char magic[4];
     72    unsigned int version;
     73    unsigned int headersize;    /* offset of bitmaps in file */
     74    unsigned int flags;
     75    unsigned int length;        /* number of glyphs */
     76    unsigned int charsize;      /* number of bytes for each character */
     77    unsigned int height;        /* max dimensions of glyphs */
     78    unsigned int width;         /* charsize = height * ((width + 7) / 8) */
     79};
     80
     81#define psf2h(x) ((struct psf2_header*)(x))
     82
     83#define PSF2_MAGIC_OK(x) ( \
     84     (x)->magic[0] == PSF2_MAGIC0 \
     85  && (x)->magic[1] == PSF2_MAGIC1 \
     86  && (x)->magic[2] == PSF2_MAGIC2 \
     87  && (x)->magic[3] == PSF2_MAGIC3 \
     88)
     89#endif /* ENABLE_FEATURE_LOADFONT_PSF2 */
     90
     91
     92static void do_loadfont(int fd, unsigned char *inbuf, int height, int width, int charsize, int fontsize)
     93{
     94    unsigned char *buf;
     95    int charwidth = 32 * ((width+7)/8);
    3496    int i;
    3597
    36     if (unit < 1 || unit > 32)
    37         bb_error_msg_and_die("bad character size %d", unit);
    38 
    39     buf = xzalloc(16 * 1024);
    40     /*memset(buf, 0, 16 * 1024);*/
     98    if (height < 1 || height > 32 || width < 1 || width > 32)
     99        bb_error_msg_and_die("bad character size %dx%d", height, width);
     100
     101    buf = xzalloc(charwidth * ((fontsize < 128) ? 128 : fontsize));
    41102    for (i = 0; i < fontsize; i++)
    42         memcpy(buf + (32 * i), inbuf + (unit * i), unit);
    43 
    44 #if defined(PIO_FONTX) && !defined(__sparc__)
    45     {
    46         struct consolefontdesc cfd;
    47 
    48         cfd.charcount = fontsize;
    49         cfd.charheight = unit;
    50         cfd.chardata = buf;
    51 
    52         if (!ioctl_or_perror(fd, PIO_FONTX, &cfd, "PIO_FONTX ioctl failed (will try PIO_FONT)"))
    53             goto ret;           /* success */
    54     }
    55 #endif
    56     xioctl(fd, PIO_FONT, buf);
    57  ret:
     103        memcpy(buf + (i*charwidth), inbuf + (i*charsize), charsize);
     104
     105    { /* KDFONTOP */
     106        struct console_font_op cfo;
     107        cfo.op = KD_FONT_OP_SET;
     108        cfo.flags = 0;
     109        cfo.width = width;
     110        cfo.height = height;
     111        cfo.charcount = fontsize;
     112        cfo.data = buf;
     113        xioctl(fd, KDFONTOP, &cfo);
     114    }
     115
    58116    free(buf);
    59117}
    60118
    61 static void
    62 do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
    63 {
     119/*
     120 * Format of the Unicode information:
     121 *
     122 * For each font position <uc>*<seq>*<term>
     123 * where <uc> is a 2-byte little endian Unicode value (PSF1)
     124 * or an UTF-8 coded value (PSF2),
     125 * <seq> = <ss><uc><uc>*, <ss> = psf1 ? 0xFFFE : 0xFE,
     126 * <term> = psf1 ? 0xFFFF : 0xFF.
     127 * and * denotes zero or more occurrences of the preceding item.
     128 *
     129 * Semantics:
     130 * The leading <uc>* part gives Unicode symbols that are all
     131 * represented by this font position. The following sequences
     132 * are sequences of Unicode symbols - probably a symbol
     133 * together with combining accents - also represented by
     134 * this font position.
     135 *
     136 * Example:
     137 * At the font position for a capital A-ring glyph, we
     138 * may have:
     139 *   00C5,212B,FFFE,0041,030A,FFFF
     140 * Some font positions may be described by sequences only,
     141 * namely when there is no precomposed Unicode value for the glyph.
     142 */
     143#if !ENABLE_FEATURE_LOADFONT_PSF2
     144#define do_loadtable(fd, inbuf, tailsz, fontsize, psf2) \
     145    do_loadtable(fd, inbuf, tailsz, fontsize)
     146#endif
     147static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize, int psf2)
     148{
     149#if !ENABLE_FEATURE_LOADFONT_PSF2
     150/* gcc 4.3.1 code size: */
     151# define psf2 0 /* +0 bytes */
     152//  const int psf2 = 0; /* +8 bytes */
     153//  enum { psf2 = 0 }; /* +13 bytes */
     154#endif
    64155    struct unimapinit advice;
    65156    struct unimapdesc ud;
     
    69160    uint16_t unicode;
    70161
    71     maxct = tailsz;             /* more than enough */
    72     up = xmalloc(maxct * sizeof(struct unipair));
     162    maxct = tailsz; /* more than enough */
     163    up = xmalloc(maxct * sizeof(*up));
    73164
    74165    for (glyph = 0; glyph < fontsize; glyph++) {
    75         while (tailsz >= 2) {
    76             unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
    77             tailsz -= 2;
    78             inbuf += 2;
    79             if (unicode == PSF_SEPARATOR)
    80                 break;
     166        while (tailsz > 0) {
     167            if (!psf2) { /* PSF1 */
     168                unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
     169                tailsz -= 2;
     170                inbuf += 2;
     171                if (unicode == PSF1_SEPARATOR)
     172                    break;
     173            } else { /* PSF2 */
     174#if ENABLE_FEATURE_LOADFONT_PSF2
     175                --tailsz;
     176                unicode = *inbuf++;
     177                if (unicode == PSF2_SEPARATOR) {
     178                    break;
     179                } else if (unicode == PSF2_STARTSEQ) {
     180                    bb_error_msg_and_die("unicode sequences not implemented");
     181                } else if (unicode >= 0xC0) {
     182                    if (unicode >= 0xFC)
     183                        unicode &= 0x01, maxct = 5;
     184                    else if (unicode >= 0xF8)
     185                        unicode &= 0x03, maxct = 4;
     186                    else if (unicode >= 0xF0)
     187                        unicode &= 0x07, maxct = 3;
     188                    else if (unicode >= 0xE0)
     189                        unicode &= 0x0F, maxct = 2;
     190                    else
     191                        unicode &= 0x1F, maxct = 1;
     192                    do {
     193                        if (tailsz <= 0 || *inbuf < 0x80 || *inbuf > 0xBF)
     194                            bb_error_msg_and_die("illegal UTF-8 character");
     195                        --tailsz;
     196                        unicode = (unicode << 6) + (*inbuf++ & 0x3F);
     197                    } while (--maxct > 0);
     198                } else if (unicode >= 0x80) {
     199                    bb_error_msg_and_die("illegal UTF-8 character");
     200                }
     201#else
     202                return;
     203#endif
     204            }
    81205            up[ct].unicode = unicode;
    82206            up[ct].fontpos = glyph;
     
    95219    ud.entries = up;
    96220    xioctl(fd, PIO_UNIMAP, &ud);
    97 }
    98 
    99 static void loadnewfont(int fd)
    100 {
    101     enum { INBUF_SIZE = 32*1024 + 1 };
    102 
    103     int unit;
    104     unsigned inputlth, offset;
    105     /* Was on stack, but 32k is a bit too much: */
    106     unsigned char *inbuf = xmalloc(INBUF_SIZE);
     221#undef psf2
     222}
     223
     224static void do_load(int fd, unsigned char *buffer, size_t len)
     225{
     226    int height;
     227    int width = 8;
     228    int charsize;
     229    int fontsize = 256;
     230    int has_table = 0;
     231    unsigned char *font = buffer;
     232    unsigned char *table;
     233
     234    if (len >= sizeof(struct psf1_header) && PSF1_MAGIC_OK(psf1h(buffer))) {
     235        if (psf1h(buffer)->mode > PSF1_MAXMODE)
     236            bb_error_msg_and_die("unsupported psf file mode");
     237        if (psf1h(buffer)->mode & PSF1_MODE512)
     238            fontsize = 512;
     239        if (psf1h(buffer)->mode & PSF1_MODEHASTAB)
     240            has_table = 1;
     241        height = charsize = psf1h(buffer)->charsize;
     242        font += sizeof(struct psf1_header);
     243    } else
     244#if ENABLE_FEATURE_LOADFONT_PSF2
     245    if (len >= sizeof(struct psf2_header) && PSF2_MAGIC_OK(psf2h(buffer))) {
     246        if (psf2h(buffer)->version > PSF2_MAXVERSION)
     247            bb_error_msg_and_die("unsupported psf file version");
     248        fontsize = psf2h(buffer)->length;
     249        if (psf2h(buffer)->flags & PSF2_HAS_UNICODE_TABLE)
     250            has_table = 2;
     251        charsize = psf2h(buffer)->charsize;
     252        height = psf2h(buffer)->height;
     253        width = psf2h(buffer)->width;
     254        font += psf2h(buffer)->headersize;
     255    } else
     256#endif
     257#if ENABLE_FEATURE_LOADFONT_RAW
     258    if (len == 9780) {  /* file with three code pages? */
     259        charsize = height = 16;
     260        font += 40;
     261    } else if ((len & 0377) == 0) {  /* bare font */
     262        charsize = height = len / 256;
     263    } else
     264#endif
     265    {
     266        bb_error_msg_and_die("input file: bad length or unsupported font type");
     267    }
     268
     269#if !defined(PIO_FONTX) || defined(__sparc__)
     270    if (fontsize != 256)
     271        bb_error_msg_and_die("only fontsize 256 supported");
     272#endif
     273
     274    table = font + fontsize * charsize;
     275    buffer += len;
     276
     277    if (table > buffer || (!has_table && table != buffer))
     278        bb_error_msg_and_die("input file: bad length");
     279
     280    do_loadfont(fd, font, height, width, charsize, fontsize);
     281
     282    if (has_table)
     283        do_loadtable(fd, table, buffer - table, fontsize, has_table - 1);
     284}
     285
     286
     287#if ENABLE_LOADFONT
     288int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     289int loadfont_main(int argc UNUSED_PARAM, char **argv)
     290{
     291    size_t len;
     292    unsigned char *buffer;
     293
     294    // no arguments allowed!
     295    opt_complementary = "=0";
     296    getopt32(argv, "");
    107297
    108298    /*
     
    111301     * just read the entire file.
    112302     */
    113     inputlth = full_read(STDIN_FILENO, inbuf, INBUF_SIZE);
    114     if (inputlth < 0)
     303    len = 32*1024; // can't be larger
     304    buffer = xmalloc_read(STDIN_FILENO, &len);
     305    // xmalloc_open_zipped_read_close(filename, &len);
     306    if (!buffer)
    115307        bb_perror_msg_and_die("error reading input font");
    116     if (inputlth >= INBUF_SIZE)
    117         bb_error_msg_and_die("font too large");
    118 
    119     /* test for psf first */
    120     {
    121         struct psf_header psfhdr;
    122         int fontsize;
    123         int hastable;
    124         unsigned head0, head;
    125 
    126         if (inputlth < sizeof(struct psf_header))
    127             goto no_psf;
    128 
    129         psfhdr = *(struct psf_header *) &inbuf[0];
    130 
    131         if (!PSF_MAGIC_OK(psfhdr))
    132             goto no_psf;
    133 
    134         if (psfhdr.mode > PSF_MAXMODE)
    135             bb_error_msg_and_die("unsupported psf file mode");
    136         fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
    137 #if !defined(PIO_FONTX) || defined(__sparc__)
    138         if (fontsize != 256)
    139             bb_error_msg_and_die("only fontsize 256 supported");
    140 #endif
    141         hastable = (psfhdr.mode & PSF_MODEHASTAB);
    142         unit = psfhdr.charsize;
    143         head0 = sizeof(struct psf_header);
    144 
    145         head = head0 + fontsize * unit;
    146         if (head > inputlth || (!hastable && head != inputlth))
    147             bb_error_msg_and_die("input file: bad length");
    148         do_loadfont(fd, inbuf + head0, unit, fontsize);
    149         if (hastable)
    150             do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
    151         return;
    152     }
    153 
    154  no_psf:
    155     /* file with three code pages? */
    156     if (inputlth == 9780) {
    157         offset = 40;
    158         unit = 16;
    159     } else {
    160         /* bare font */
    161         if (inputlth & 0377)
    162             bb_error_msg_and_die("bad input file size");
    163         offset = 0;
    164         unit = inputlth / 256;
    165     }
    166     do_loadfont(fd, inbuf + offset, unit, 256);
    167 }
    168 
    169 int loadfont_main(int argc, char **argv);
    170 int loadfont_main(int argc, char **argv)
    171 {
     308    do_load(get_console_fd_or_die(), buffer, len);
     309
     310    return EXIT_SUCCESS;
     311}
     312#endif
     313
     314#if ENABLE_SETFONT
     315
     316/*
     317kbd-1.12:
     318
     319setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
     320[-ou umap.orig] [-N] [font.new ...] [-m cmap] [-u umap] [-C console]
     321[-hNN] [-v] [-V]
     322
     323-h NN  Override font height
     324-o file
     325       Save previous font in file
     326-O file
     327       Save previous font and Unicode map in file
     328-om file
     329       Store console map in file
     330-ou file
     331       Save previous Unicode map in file
     332-m file
     333       Load console map or Unicode console map from file
     334-u file
     335       Load Unicode table describing the font from file
     336       Example:
     337       # cp866
     338       0x00-0x7f       idem
     339       #
     340       0x80    U+0410  # CYRILLIC CAPITAL LETTER A
     341       0x81    U+0411  # CYRILLIC CAPITAL LETTER BE
     342       0x82    U+0412  # CYRILLIC CAPITAL LETTER VE
     343-C console
     344       Set the font for the indicated console
     345-v     Verbose
     346-V     Version
     347*/
     348
     349#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
     350static int ctoi(char *s)
     351{
     352    if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
     353        return s[1];
     354    // U+ means 0x
     355    if (s[0] == 'U' && s[1] == '+') {
     356        s[0] = '0';
     357        s[1] = 'x';
     358    }
     359    if (!isdigit(s[0]))
     360        return -1;
     361    return xstrtoul(s, 0);
     362}
     363#endif
     364
     365int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     366int setfont_main(int argc UNUSED_PARAM, char **argv)
     367{
     368    size_t len;
     369    unsigned opts;
    172370    int fd;
    173 
    174     if (argc != 1)
    175         bb_show_usage();
    176 
    177     fd = xopen(CURRENT_VC, O_RDWR);
    178     loadnewfont(fd);
     371    unsigned char *buffer;
     372    char *mapfilename;
     373    const char *tty_name = CURRENT_TTY;
     374
     375    opt_complementary = "=1";
     376    opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
     377    argv += optind;
     378
     379    fd = xopen_nonblocking(tty_name);
     380
     381    if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
     382        if (*argv[0] != '/') {
     383            // goto default fonts location. don't die if doesn't exist
     384            chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts");
     385        }
     386    }
     387    // load font
     388    len = 32*1024; // can't be larger
     389    buffer = xmalloc_open_zipped_read_close(*argv, &len);
     390    if (!buffer)
     391        bb_simple_perror_msg_and_die(*argv);
     392    do_load(fd, buffer, len);
     393
     394    // load the screen map, if any
     395    if (opts & 1) { // -m
     396        unsigned mode = PIO_SCRNMAP;
     397        void *map;
     398
     399        if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
     400            if (mapfilename[0] != '/') {
     401                // goto default keymaps location
     402                chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans");
     403            }
     404        }
     405        // fetch keymap
     406        map = xmalloc_open_zipped_read_close(mapfilename, &len);
     407        if (!map)
     408            bb_simple_perror_msg_and_die(mapfilename);
     409        // file size is 256 or 512 bytes? -> assume binary map
     410        if (len == E_TABSZ || len == 2*E_TABSZ) {
     411            if (len == 2*E_TABSZ)
     412                mode = PIO_UNISCRNMAP;
     413        }
     414#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
     415        // assume textual Unicode console maps:
     416        // 0x00 U+0000  #  NULL (NUL)
     417        // 0x01 U+0001  #  START OF HEADING (SOH)
     418        // 0x02 U+0002  #  START OF TEXT (STX)
     419        // 0x03 U+0003  #  END OF TEXT (ETX)
     420        else {
     421            int i;
     422            char *token[2];
     423            parser_t *parser;
     424
     425            if (ENABLE_FEATURE_CLEAN_UP)
     426                free(map);
     427            map = xmalloc(E_TABSZ * sizeof(unsigned short));
     428
     429#define unicodes ((unsigned short *)map)
     430            // fill vanilla map
     431            for (i = 0; i < E_TABSZ; i++)
     432                unicodes[i] = 0xf000 + i;
     433
     434            parser = config_open(mapfilename);
     435            while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) {
     436                // parse code/value pair
     437                int a = ctoi(token[0]);
     438                int b = ctoi(token[1]);
     439                if (a < 0 || a >= E_TABSZ
     440                 || b < 0 || b > 65535
     441                ) {
     442                    bb_error_msg_and_die("map format");
     443                }
     444                // patch map
     445                unicodes[a] = b;
     446                // unicode character is met?
     447                if (b > 255)
     448                    mode = PIO_UNISCRNMAP;
     449            }
     450            if (ENABLE_FEATURE_CLEAN_UP)
     451                config_close(parser);
     452
     453            if (mode != PIO_UNISCRNMAP) {
     454#define asciis ((unsigned char *)map)
     455                for (i = 0; i < E_TABSZ; i++)
     456                    asciis[i] = unicodes[i];
     457#undef asciis
     458            }
     459#undef unicodes
     460        }
     461#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
     462
     463        // do set screen map
     464        xioctl(fd, mode, map);
     465
     466        if (ENABLE_FEATURE_CLEAN_UP)
     467            free(map);
     468    }
    179469
    180470    return EXIT_SUCCESS;
    181471}
     472#endif
  • branches/2.2.9/mindi-busybox/console-tools/loadkmap.c

    r1765 r2725  
    55 * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    8  *
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    98 */
    10 
    119#include "libbb.h"
    1210
     
    2624#define MAX_NR_KEYMAPS  256
    2725
    28 int loadkmap_main(int argc, char **argv);
    29 int loadkmap_main(int argc, char **argv)
     26int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     27int loadkmap_main(int argc UNUSED_PARAM, char **argv)
    3028{
    3129    struct kbentry ke;
    3230    int i, j, fd;
    3331    uint16_t ibuff[NR_KEYS];
    34     char flags[MAX_NR_KEYMAPS];
    35     char buff[7];
     32/*  const char *tty_name = CURRENT_TTY; */
     33    RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
    3634
    37     if (argc != 1)
     35    /* When user accidentally runs "loadkmap FILE"
     36     * instead of "loadkmap <FILE", we end up waiting for input from tty.
     37     * Let's prevent it: */
     38    if (argv[1])
    3839        bb_show_usage();
     40/* bb_warn_ignoring_args(argv[1]); */
     41    fd = get_console_fd_or_die();
     42/* or maybe:
     43    opt = getopt32(argv, "C:", &tty_name);
     44    fd = xopen_nonblocking(tty_name);
     45*/
    3946
    40     fd = xopen(CURRENT_VC, O_RDWR);
     47    xread(STDIN_FILENO, flags, 7);
     48    if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
     49        bb_error_msg_and_die("not a valid binary keymap");
    4150
    42     xread(0, buff, 7);
    43     if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
    44         bb_error_msg_and_die("this is not a valid binary keymap");
    45 
    46     xread(0, flags, MAX_NR_KEYMAPS);
     51    xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
    4752
    4853    for (i = 0; i < MAX_NR_KEYMAPS; i++) {
    4954        if (flags[i] == 1) {
    50             xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
     55            xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
    5156            for (j = 0; j < NR_KEYS; j++) {
    5257                ke.kb_index = j;
     
    5863    }
    5964
    60     if (ENABLE_FEATURE_CLEAN_UP) close(fd);
    61     return 0;
     65    if (ENABLE_FEATURE_CLEAN_UP) {
     66        close(fd);
     67        RELEASE_CONFIG_BUFFER(flags);
     68    }
     69    return EXIT_SUCCESS;
    6270}
  • branches/2.2.9/mindi-busybox/console-tools/openvt.c

    r1765 r2725  
    66 *  hacked by Tito <farmatito@tiscali.it>
    77 *
    8  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
    1010
    11 /* getopt not needed */
    12 
     11#include <linux/vt.h>
    1312#include "libbb.h"
    1413
    15 int openvt_main(int argc, char **argv);
    16 int openvt_main(int argc, char **argv)
     14/* "Standard" openvt's man page (we do not support all of this):
     15
     16openvt [-c NUM] [-fsulv] [--] [command [args]]
     17
     18Find the first available VT, and run command on it. Stdio is directed
     19to that VT. If no command is specified then $SHELL is used.
     20
     21-c NUM
     22    Use the given VT number, not the first free one.
     23-f
     24    Force opening a VT: don't try to check if VT is already in use.
     25-s
     26    Switch to the new VT when starting the command.
     27    The VT of the new command will be made the new current VT.
     28-u
     29    Figure out the owner of the current VT, and run login as that user.
     30    Suitable to be called by init. Shouldn't be used with -c or -l.
     31-l
     32    Make the command a login shell: a "-" is prepended to the argv[0]
     33    when command is executed.
     34-v
     35    Verbose.
     36-w
     37    Wait for command to complete. If -w and -s are used together,
     38    switch back to the controlling terminal when the command completes.
     39
     40bbox:
     41-u: not implemented
     42-f: always in effect
     43-l: not implemented, ignored
     44-v: ignored
     45-ws: does NOT switch back
     46*/
     47
     48/* Helper: does this fd understand VT_xxx? */
     49static int not_vt_fd(int fd)
    1750{
    18     char vtname[sizeof(VC_FORMAT) + 2];
     51    struct vt_stat vtstat;
     52    return ioctl(fd, VT_GETSTATE, &vtstat); /* !0: error, it's not VT fd */
     53}
    1954
    20     if (argc < 3)
    21         bb_show_usage();
     55/* Helper: get a fd suitable for VT_xxx */
     56static int get_vt_fd(void)
     57{
     58    int fd;
    2259
    23     /* check for illegal vt number: < 1 or > 63 */
    24     sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
     60    /* Do we, by chance, already have it? */
     61    for (fd = 0; fd < 3; fd++)
     62        if (!not_vt_fd(fd))
     63            return fd;
     64    fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
     65    if (fd >= 0 && !not_vt_fd(fd))
     66        return fd;
     67    bb_error_msg_and_die("can't find open VT");
     68}
    2569
    26     bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
    27     /* grab new one */
    28     close(0);
     70static int find_free_vtno(void)
     71{
     72    int vtno;
     73    int fd = get_vt_fd();
     74
     75    errno = 0;
     76    /*xfunc_error_retval = 3; - do we need compat? */
     77    if (ioctl(fd, VT_OPENQRY, &vtno) != 0 || vtno <= 0)
     78        bb_perror_msg_and_die("can't find open VT");
     79// Not really needed, grep for DAEMON_ONLY_SANITIZE
     80//  if (fd > 2)
     81//      close(fd);
     82    return vtno;
     83}
     84
     85/* vfork scares gcc, it generates bigger code.
     86 * Keep it away from main program.
     87 * TODO: move to libbb; or adapt existing libbb's spawn().
     88 */
     89static NOINLINE void vfork_child(char **argv)
     90{
     91    if (vfork() == 0) {
     92        /* CHILD */
     93        /* Try to make this VT our controlling tty */
     94        setsid(); /* lose old ctty */
     95        ioctl(STDIN_FILENO, TIOCSCTTY, 0 /* 0: don't forcibly steal */);
     96        //bb_error_msg("our sid %d", getsid(0));
     97        //bb_error_msg("our pgrp %d", getpgrp());
     98        //bb_error_msg("VT's sid %d", tcgetsid(0));
     99        //bb_error_msg("VT's pgrp %d", tcgetpgrp(0));
     100        BB_EXECVP_or_die(argv);
     101    }
     102}
     103
     104int openvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     105int openvt_main(int argc UNUSED_PARAM, char **argv)
     106{
     107    char vtname[sizeof(VC_FORMAT) + sizeof(int)*3];
     108    struct vt_stat vtstat;
     109    char *str_c;
     110    int vtno;
     111    int flags;
     112    enum {
     113        OPT_c = (1 << 0),
     114        OPT_w = (1 << 1),
     115        OPT_s = (1 << 2),
     116        OPT_l = (1 << 3),
     117        OPT_f = (1 << 4),
     118        OPT_v = (1 << 5),
     119    };
     120
     121    /* "+" - stop on first non-option */
     122    flags = getopt32(argv, "+c:wslfv", &str_c);
     123    argv += optind;
     124
     125    if (flags & OPT_c) {
     126        /* Check for illegal vt number: < 1 or > 63 */
     127        vtno = xatou_range(str_c, 1, 63);
     128    } else {
     129        vtno = find_free_vtno();
     130    }
     131
     132    /* Grab new VT */
     133    sprintf(vtname, VC_FORMAT, vtno);
     134    /* (Try to) clean up stray open fds above fd 2 */
     135    bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL);
     136    close(STDIN_FILENO);
     137    /*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
    29138    xopen(vtname, O_RDWR);
    30     dup2(0, STDOUT_FILENO);
    31     dup2(0, STDERR_FILENO);
     139    xioctl(STDIN_FILENO, VT_GETSTATE, &vtstat);
    32140
    33     BB_EXECVP(argv[2], &argv[2]);
    34     _exit(1);
     141    if (flags & OPT_s) {
     142        console_make_active(STDIN_FILENO, vtno);
     143    }
     144
     145    if (!argv[0]) {
     146        argv--;
     147        argv[0] = getenv("SHELL");
     148        if (!argv[0])
     149            argv[0] = (char *) DEFAULT_SHELL;
     150        /*argv[1] = NULL; - already is */
     151    }
     152
     153    xdup2(STDIN_FILENO, STDOUT_FILENO);
     154    xdup2(STDIN_FILENO, STDERR_FILENO);
     155
     156#ifdef BLOAT
     157    {
     158    /* Handle -l (login shell) option */
     159    const char *prog = argv[0];
     160    if (flags & OPT_l)
     161        argv[0] = xasprintf("-%s", argv[0]);
     162    }
     163#endif
     164
     165    vfork_child(argv);
     166    if (flags & OPT_w) {
     167        /* We have only one child, wait for it */
     168        safe_waitpid(-1, NULL, 0); /* loops on EINTR */
     169        if (flags & OPT_s) {
     170            console_make_active(STDIN_FILENO, vtstat.v_active);
     171            // Compat: even with -c N (try to) disallocate:
     172            // # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5
     173            // openvt: could not deallocate console 9
     174            xioctl(STDIN_FILENO, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno);
     175        }
     176    }
     177    return EXIT_SUCCESS;
    35178}
  • branches/2.2.9/mindi-busybox/console-tools/reset.c

    r1765 r2725  
    66 * Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
    77 *
    8  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
    1010
    11 /* no options, no getopt */
     11/* BTW, which "standard" package has this utility? It doesn't seem
     12 * to be ncurses, coreutils, console-tools... then what? */
    1213
    1314#include "libbb.h"
    1415
    15 int reset_main(int argc, char **argv);
    16 int reset_main(int argc, char **argv)
     16#define ESC "\033"
     17
     18#if ENABLE_STTY
     19int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     20#endif
     21
     22int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     23int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
    1724{
    18     if (isatty(1)) {
     25    static const char *const args[] = {
     26        "stty", "sane", NULL
     27    };
     28
     29    /* no options, no getopt */
     30
     31    if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) {
    1932        /* See 'man 4 console_codes' for details:
    20          * "ESC c"          -- Reset
    21          * "ESC ( K"        -- Select user mapping
    22          * "ESC [ J"        -- Erase display
    23          * "ESC [ 0 m"      -- Reset all display attributes
    24          * "ESC [ ? 25 h"   -- Make cursor visible.
     33         * "ESC c"        -- Reset
     34         * "ESC ( K"      -- Select user mapping
     35         * "ESC [ 0 m"    -- Reset all display attributes
     36         * "ESC [ J"      -- Erase to the end of screen
     37         * "ESC [ ? 25 h" -- Make cursor visible
    2538         */
    26         printf("\033c\033(K\033[J\033[0m\033[?25h");
     39        printf(ESC"c" ESC"(K" ESC"[0m" ESC"[J" ESC"[?25h");
     40        /* http://bugs.busybox.net/view.php?id=1414:
     41         * people want it to reset echo etc: */
     42#if ENABLE_STTY
     43        return stty_main(2, (char**)args);
     44#else
     45        execvp("stty", (char**)args);
     46#endif
    2747    }
    2848    return EXIT_SUCCESS;
    2949}
    30 
  • branches/2.2.9/mindi-busybox/console-tools/resize.c

    r1765 r2725  
    33 * resize - set terminal width and height.
    44 *
    5  * Copyright 2006 Bernhard Fischer
     5 * Copyright 2006 Bernhard Reutner-Fischer
    66 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
    99/* no options, no getopt */
     
    1212#define ESC "\033"
    1313
    14 #define old_termios (*(struct termios*)&bb_common_bufsiz1)
     14#define old_termios_p ((struct termios*)&bb_common_bufsiz1)
    1515
    1616static void
    17 onintr(int sig ATTRIBUTE_UNUSED)
     17onintr(int sig UNUSED_PARAM)
    1818{
    19     tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
    20     exit(1);
     19    tcsetattr(STDERR_FILENO, TCSANOW, old_termios_p);
     20    _exit(EXIT_FAILURE);
    2121}
    2222
    23 int resize_main(int argc, char **argv);
    24 int resize_main(int argc, char **argv)
     23int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     24int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
    2525{
    2626    struct termios new;
    27     struct winsize w = { 0,0,0,0 };
     27    struct winsize w = { 0, 0, 0, 0 };
    2828    int ret;
    2929
     
    3434     */
    3535
    36     tcgetattr(STDERR_FILENO, &old_termios); /* fiddle echo */
    37     new = old_termios;
     36    tcgetattr(STDERR_FILENO, old_termios_p); /* fiddle echo */
     37    memcpy(&new, old_termios_p, sizeof(new));
    3838    new.c_cflag |= (CLOCAL | CREAD);
    3939    new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
    40     signal(SIGINT, onintr);
    41     signal(SIGQUIT, onintr);
    42     signal(SIGTERM, onintr);
    43     signal(SIGALRM, onintr);
     40    bb_signals(0
     41        + (1 << SIGINT)
     42        + (1 << SIGQUIT)
     43        + (1 << SIGTERM)
     44        + (1 << SIGALRM)
     45        , onintr);
    4446    tcsetattr(STDERR_FILENO, TCSANOW, &new);
    4547
     
    6062    ret = ioctl(STDERR_FILENO, TIOCSWINSZ, &w);
    6163
    62     tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
     64    tcsetattr(STDERR_FILENO, TCSANOW, old_termios_p);
    6365
    6466    if (ENABLE_FEATURE_RESIZE_PRINT)
  • branches/2.2.9/mindi-busybox/console-tools/setconsole.c

    r1765 r2725  
    44 *
    55 *  Copyright (C) 2004,2005  Enrik Berkhan <Enrik.Berkhan@inka.de>
     6 *  Copyright (C) 2008 Bernhard Reutner-Fischer
    67 *
    7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    89 */
    910
    10 #include <getopt.h>
    1111#include "libbb.h"
    1212
    13 #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
    14 static const char setconsole_longopts[] ALIGN1 =
    15     "reset\0" No_argument "r"
    16     ;
    17 #endif
    18 
    19 #define OPT_SETCONS_RESET 1
    20 
    21 int setconsole_main(int argc, char **argv);
    22 int setconsole_main(int argc, char **argv)
     13int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     14int setconsole_main(int argc UNUSED_PARAM, char **argv)
    2315{
    24     unsigned long flags;
    2516    const char *device = CURRENT_TTY;
     17    bool reset;
    2618
    2719#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
     20    static const char setconsole_longopts[] ALIGN1 =
     21        "reset\0" No_argument "r"
     22        ;
    2823    applet_long_options = setconsole_longopts;
    2924#endif
    30     flags = getopt32(argv, "r");
     25    /* at most one non-option argument */
     26    opt_complementary = "?1";
     27    reset = getopt32(argv, "r");
    3128
    32     if (argc - optind > 1)
    33         bb_show_usage();
    34 
    35     if (argc - optind == 1) {
    36         if (flags & OPT_SETCONS_RESET)
    37             bb_show_usage();
    38         device = argv[optind];
     29    argv += 1 + reset;
     30    if (*argv) {
     31        device = *argv;
    3932    } else {
    40         if (flags & OPT_SETCONS_RESET)
     33        if (reset)
    4134            device = DEV_CONSOLE;
    4235    }
  • branches/2.2.9/mindi-busybox/console-tools/setkeycodes.c

    r1765 r2725  
    77 * Adjusted for BusyBox by Erik Andersen <andersen@codepoet.org>
    88 *
    9  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1010 */
    11 
    12 //#include <sys/ioctl.h>
    1311#include "libbb.h"
    1412
    1513/* From <linux/kd.h> */
    1614struct kbkeycode {
    17     unsigned int scancode, keycode;
     15    unsigned scancode, keycode;
    1816};
    1917enum {
     
    2119};
    2220
    23 int setkeycodes_main(int argc, char** argv);
    24 int setkeycodes_main(int argc, char** argv)
     21int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     22int setkeycodes_main(int argc, char **argv)
    2523{
    26     int fd, sc;
     24    int fd;
    2725    struct kbkeycode a;
    2826
    29     if (argc % 2 != 1 || argc < 2) {
     27    if (!(argc & 1) /* if even */ || argc < 2) {
    3028        bb_show_usage();
    3129    }
    3230
    33     fd = get_console_fd();
     31    fd = get_console_fd_or_die();
    3432
    35     while (argc > 2) {
    36         a.keycode = xatoul_range(argv[2], 0, 127);
    37         a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
    38         if (a.scancode > 127) {
    39             a.scancode -= 0xe000;
    40             a.scancode += 128;
     33    while (argv[1]) {
     34        int sc = xstrtoul_range(argv[1], 16, 0, 0xe07f);
     35        if (sc >= 0xe000) {
     36            sc -= 0xe000;
     37            sc += 0x0080;
    4138        }
     39        a.scancode = sc;
     40        a.keycode = xatou_range(argv[2], 0, 255);
    4241        ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
    43             "failed to set SCANCODE %x to KEYCODE %d",
     42            "can't set SCANCODE %x to KEYCODE %d",
    4443            sc, a.keycode);
    45         argc -= 2;
    4644        argv += 2;
    4745    }
  • branches/2.2.9/mindi-busybox/console-tools/setlogcons.c

    r1765 r2725  
    77 * Based on setlogcons (kbd-1.12) by Andries E. Brouwer
    88 *
    9  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1010 */
    1111
    1212#include "libbb.h"
    1313
    14 int setlogcons_main(int argc, char **argv);
    15 int setlogcons_main(int argc, char **argv)
     14int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     15int setlogcons_main(int argc UNUSED_PARAM, char **argv)
    1616{
    1717    struct {
    1818        char fn;
    1919        char subarg;
    20     } arg;
     20    } arg = { 11, /* redirect kernel messages */
     21              0   /* to specified console (current as default) */
     22            };
    2123
    22     arg.fn = 11;    /* redirect kernel messages */
    23     arg.subarg = 0; /* to specified console (current as default) */
    24 
    25     if (argc == 2)
    26         arg.subarg = xatoul_range(argv[1], 0, 63);
     24    if (argv[1])
     25        arg.subarg = xatou_range(argv[1], 0, 63);
    2726
    2827    xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
    2928
    30     return 0;
     29    return EXIT_SUCCESS;
    3130}
Note: See TracChangeset for help on using the changeset viewer.