Commit d7300e1e authored by Alastair McKinstry's avatar Alastair McKinstry

Initial checkin

r1772
parents
- Not presented with question when "ps2" is selected.
(Help wanted on this one! something goes astray in cdebconf ?)
- keymap is not placed in /etc/console on /target yet.
- console-tools is not removed from required pkgs list when installing on a headless system.
-- amck, 2002-01-18
DESTDIR=
ifdef DEBUG
DEB_BUILD_OPTIONS := debug:${DEB_BUILD_OPTIONS}
endif
CFLAGS := -Wall -Os
ARCH := $(shell dpkg --print-architecture)
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
CFLAGS += -g -DDEBUG=1
STRIP= /bin/true
else
CFLAGS += -fomit-frame-pointer
STRIPTOOL=strip
STRIP= $(STRIPTOOL) --remove-section=.note --remove-section=.comment
endif
LDOPTS= -ldebconf -ldebian-installer
OBJS = loadkeys.o findfile.o ksyms.o getfd.o xmalloc.o
ifeq ($(ARCH),i386)
CFLAGS += -DAT_KBD -DPREFERRED_KEYBOARD="PS/2" -DUSB_KBD
OBJS += at-kbd.o usb-kbd.o
endif
ifeq ($(ARCH),sparc)
CFLAGS += -DSPARC -DPREFERRED_KEYBOARD="sparc"
OBJS += sparc-kbd.o
endif
ifeq ($(ARCH),powerpc)
CFLAGS += -DPOWERPC -DPREFERRED_KEYBOARD="mac"
OBJS += mac-kbd.o amiga-kbd.o
endif
all: kbd-chooser
kbd-chooser: ${OBJS} kbd-chooser.c
$(CC) $(CFLAGS) kbd-chooser.c -o $@ $(OBJS) $(LDOPTS)
$(STRIP) $@
# loadkeys.o: separate rule since the flex output does not permit -Wall
loadkeys.o: loadkeys.c analyze.c
$(CC) -c $(CFLAGS) $(DEFS) $<
clean:
rm -f *~ *.o kbd-chooser analyze.c loadkeys.c *#
install:
mkdir -p ${DESTDIR}/usr/bin
cp kbd-chooser ${DESTDIR}/usr/bin/kbd-chooser
This is not yet integrated into the debian-installer build.
To test:
- Add 'kbd-chooser', 'console-keymaps-ps2' and 'console-keymaps-usb' to debian-installer/build/pkg-lists/base
- run 'debuild -uc -us' in this directory
- copy ../kbd-chooser*.udeb to debian-installer/build/localudebs
--------------------------
Compile in support for various keyboards.
Note: its possible to have a variety of 'non-arch' keyboards, eg. it is possible to put a
Sun keyboard on a PC, using a serial adaptor. This is why all keymaps are present in
'console-data'. However this is unlikely (and I don't think you can boot off a serial keyboard),
so they are likely not to be compiled in on floppy versions (though maybe CD versions) of
the installer.
- alastair, 2003-01-16
- Add regression test to ensure data udebs are correct
(For space, no error checking done in this code)
- Add code to handle serial & ssh installs (not installing kbd where
not needed)
- Finish template & i18n code
- Trim loadkeys() code.
- Later in the install process, when /target is mounted, we should dump
a default keymap into place in /etc/console.
- Alastair, 2003-01-16
%{
#include <stdlib.h>
#include <linux/kd.h>
#include "ksyms.h"
#include "xmalloc.h"
extern int line_nr;
int yylval;
int rvalct;
struct kbsentry kbs_buf;
char *p, *pmax;
char *filename;
#undef yywrap
extern int yywrap(void);
extern int yyerror(const char *s);
extern void stringovfl(void);
extern void lkfatal(const char *s);
extern void lkfatal1(const char *s, const char *s2);
extern void open_include(char *s);
%}
%s RVALUE
%x STR
%x INCLSTR
Comment #|!
Continuation \\\n
Eol \n
Blank [ \t]
Include include[ \t]*
Decimal [1-9][0-9]*
Octal 0[0-7]*
Hex 0[xX][0-9a-fA-F]+
Unicode U\+([0-9a-fA-F]){4}
Literal [a-zA-Z][a-zA-Z_0-9]*
Octa ([0-7]){1,3}
Charset charset|Charset|CharSet|CHARSET
Keymaps keymaps|Keymaps|KeyMaps|KEYMAPS
Keycode keycode|Keycode|KeyCode|KEYCODE
String string|String|STRING
Equals =
Plain plain|Plain|PLAIN
Shift shift|Shift|SHIFT
Control control|Control|CONTROL
Alt alt|Alt|ALT
AltGr altgr|Altgr|AltGr|ALTGR
ShiftL shiftl|ShiftL|SHIFTL
ShiftR shiftr|ShiftR|SHIFTR
CtrlL ctrll|CtrlL|CTRLL
CtrlR ctrlr|CtrlR|CTRLR
AltIsMeta [aA][lL][tT][-_][iI][sS][-_][mM][eE][tT][aA]
Strings strings|Strings|STRINGS
Compose compose|Compose|COMPOSE
As as|As|AS
Usual usual|Usual|USUAL
For for|For|FOR
On on|On|ON
To to|To|TO
%%
{Include} {BEGIN(INCLSTR);}
<INCLSTR>\"[^"\n]+\" { int l; char *s;
l = strlen(yytext);
s = xmalloc(l);
strcpy(s, yytext+1);
s[l-2] = 0; /* wipe out " */
open_include(s);
BEGIN(0);
}
<INCLSTR>[^"]|\"\"|\"[^"\n]*{Eol} {
yyerror("expected filename between quotes");
BEGIN(0); }
{Continuation} {line_nr++;}
{Eol} {line_nr++;BEGIN(0);return(EOL);}
{Blank}+ ; /* do nothing */
{Comment}.*/{Eol} ; /* do nothing */
{Equals} {BEGIN(RVALUE);rvalct=0;return(EQUALS);}
\- {return(DASH);}
\, {return(COMMA);}
\+ {return(PLUS);}
{Unicode} {yylval=strtol(yytext+1,NULL,16);return(UNUMBER);}
{Decimal}|{Octal}|{Hex} {yylval=strtol(yytext,NULL,0);return(NUMBER);}
<RVALUE>{Literal} {return((yylval=ksymtocode(yytext))==-1?ERROR:LITERAL);}
{Charset} {return(CHARSET);}
{Keymaps} {return(KEYMAPS);}
{Keycode} {return(KEYCODE);}
{String} {BEGIN(RVALUE);return(STRING);}
{Plain} {return(PLAIN);}
{Shift} {return(SHIFT);}
{Control} {return(CONTROL);}
{Alt} {return(ALT);}
{AltGr} {return(ALTGR);}
{ShiftL} {return(SHIFTL);}
{ShiftR} {return(SHIFTR);}
{CtrlL} {return(CTRLL);}
{CtrlR} {return(CTRLR);}
{AltIsMeta} {return(ALT_IS_META);}
{Strings} {return(STRINGS);}
{Compose} {return(COMPOSE);}
{As} {return(AS);}
{Usual} {return(USUAL);}
{To} {BEGIN(RVALUE); return(TO);}
{On} {return(ON);}
{For} {return(FOR);}
'\\{Octa}' {yylval = strtol(yytext+2,NULL,8); return(CCHAR);}
'\\.' {yylval = yytext[2]; return(CCHAR);}
'.' {yylval = yytext[1]; return(CCHAR);}
\" {p=kbs_buf.kb_string;
pmax=p+sizeof(kbs_buf.kb_string)-1;
BEGIN(STR);}
<STR>\\{Octa} {if(p>=pmax)stringovfl();*p++=strtol(yytext+1,NULL,8);}
<STR>\\\" {if(p>=pmax)stringovfl();*p++='"';}
<STR>\\\\ {if(p>=pmax)stringovfl();*p++='\\';}
<STR>\\n {if(p>=pmax)stringovfl();*p++='\n';}
<STR>[^"\\]* {char *ptmp=p;p+=strlen(yytext);
if(p>pmax)stringovfl();strcpy(ptmp,yytext);}
<STR>\" {*p='\0';BEGIN(0);return(STRLITERAL);}
. {return(ERROR); /* report any unknown characters */}
%%
#include "ksyms.h"
#include <linux/keyboard.h>
void
stringovfl(void) {
lkfatal("string too long");
}
/* @file at-kbd.c
* @brief Report keyboards present on PC
*
* Copyright (C) 2002 Alastair McKinstry, <mckinstry@debian.org>
* Released under the GPL
*
* $Id: at-kbd.c,v 1.1 2003/01/19 11:37:56 mckinstry Exp $
*/
#include "config.h"
#include <cdebconf/common.h> // for NEW()
#include "kbd-chooser.h"
extern kbd_t *keyboards;
/**
* @brief list of keyboards present
*/
kbd_t *at_kbd_get ()
{
kbd_t *k = NEW (kbd_t);
#if defined (KERNEL_2_5)
/* In 2.5 series, we can detect keyboard via /proc/bus/input
*
* FIXME: Write this code
*/
#warning "Kernel 2.5 code not written yet"
free (k);
k = NULL;
#else
/* For 2.4, assume a PC keyboard is present
*/
k->name = "ps2"; // This must match the name "ps2" in console-keymaps-ps2
k->fd = -1;
k->present = UNKNOWN;
k->next = keyboards;
keyboards = k;
#endif
return k;
}
/*
* cp1250 symbols, aeb, 2000-12-29
* first half as usual; last quarter identical to latin-2 (iso 8859-2)
*
* No names have been introduced yet for the various quotation marks
*/
static sym cp1250_syms[] = { /* 128-255 */
{ 0x20ac, "euro"}, /* 0200 */
{ 0xfffd, ""},
{ 0x201a, ""}, /* SINGLE LOW-9 QUOTATION MARK */
{ 0xfffd, ""},
{ 0x201e, ""}, /* DOUBLE LOW-9 QUOTATION MARK */
{ 0x2026, "ellipsis"},
{ 0x2020, "dagger"},
{ 0x2021, "doubledagger"},
{ 0xfffd, ""}, /* 0210 */
{ 0x2030, "permille"},
{ 0x0160, "Scaron"},
{ 0x2039, ""}, /* SINGLE LEFT-POINTING ANGLE QUOTATION MARK */
{ 0x015a, "Sacute"},
{ 0x0164, "Tcaron"},
{ 0x017d, "Zcaron"},
{ 0x0179, "Zacute"},
{ 0xfffd, ""}, /* 0220 */
{ 0x2018, ""}, /* LEFT SINGLE QUOTATION MARK */
{ 0x2019, ""}, /* RIGHT SINGLE QUOTATION MARK */
{ 0x201c, ""}, /* LEFT DOUBLE QUOTATION MARK */
{ 0x201d, ""}, /* RIGHT DOUBLE QUOTATION MARK */
{ 0x2022, "bullet"},
{ 0x2013, "endash"},
{ 0x2014, "emdash"},
{ 0xfffd, ""}, /* 0230 */
{ 0x2122, "trademark"},
{ 0x0161, "scaron"},
{ 0x203a, ""}, /* SINGLE RIGHT-POINTING ANGLE QUOTATION MARK */
{ 0x015b, "sacute"},
{ 0x0165, "tcaron"},
{ 0x017e, "zcaron"},
{ 0x017a, "zacute"},
{ 0x00a0, ""}, /* 0240 */
{ 0x02c7, "caron"},
{ 0x02d8, "breve"},
{ 0x0141, "Lstroke"},
{ 0x00a4, ""},
{ 0x0104, "Aogonek"},
{ 0x00a6, ""},
{ 0x00a7, ""},
{ 0x00a8, ""}, /* 0250 */
{ 0x00a9, ""},
{ 0x015e, "Scedilla"},
{ 0x00ab, ""},
{ 0x00ac, ""},
{ 0x00ad, ""},
{ 0x00ae, ""},
{ 0x017b, "Zabovedot"},
{ 0x00b0, ""}, /* 0260 */
{ 0x00b1, ""},
{ 0x02db, "ogonek"},
{ 0x0142, "lstroke"},
{ 0x00b4, ""},
{ 0x00b5, ""},
{ 0x00b6, ""},
{ 0x00b7, ""},
{ 0x00b8, ""}, /* 0270 */
{ 0x0105, "aogonek"},
{ 0x015f, "scedilla"},
{ 0x00bb, ""},
{ 0x013d, "Lcaron"},
{ 0x02dd, "doubleacute"},
{ 0x013e, "lcaron"},
/* from here identical to latin-2 */
{ 0x017c, "zabovedot"},
{ 0x0154, "Racute"}, /* 0300 */
{ 0x00c1, "Aacute"},
{ 0x00c2, "Acircumflex"},
{ 0x0102, "Abreve"},
{ 0x00c4, "Adiaeresis"},
{ 0x0139, "Lacute"},
{ 0x0106, "Cacute"},
{ 0x00c7, "Ccedilla"},
{ 0x010c, "Ccaron"}, /* 0310 */
{ 0x00c9, "Eacute"},
{ 0x0118, "Eogonek"},
{ 0x00cb, "Ediaeresis"},
{ 0x011a, "Ecaron"},
{ 0x00cd, "Iacute"},
{ 0x00ce, "Icircumflex"},
{ 0x010e, "Dcaron"},
{ 0x0110, "Dstroke"}, /* 0320 */
{ 0x0143, "Nacute"},
{ 0x0147, "Ncaron"},
{ 0x00d3, "Oacute"},
{ 0x00d4, "Ocircumflex"},
{ 0x0150, "Odoubleacute"},
{ 0x00d6, "Odiaeresis"},
{ 0x00d7, "multiply"},
{ 0x0158, "Rcaron"}, /* 0330 */
{ 0x016e, "Uring"},
{ 0x00da, "Uacute"},
{ 0x0170, "Udoubleacute"},
{ 0x00dc, "Udiaeresis"},
{ 0x00dd, "Yacute"},
{ 0x0162, "Tcedilla"},
{ 0x00df, "ssharp"},
{ 0x0155, "racute"}, /* 0340 */
{ 0x00e1, "aacute"},
{ 0x00e2, "acircumflex"},
{ 0x0103, "abreve"},
{ 0x00e4, "adiaeresis"},
{ 0x013a, "lacute"},
{ 0x0107, "cacute"},
{ 0x00e7, "ccedilla"},
{ 0x010d, "ccaron"}, /* 0350 */
{ 0x00e9, "eacute"},
{ 0x0119, "eogonek"},
{ 0x00eb, "ediaeresis"},
{ 0x011b, "ecaron"},
{ 0x00ed, "iacute"},
{ 0x00ee, "icircumflex"},
{ 0x010f, "dcaron"},
{ 0x0111, "dstroke"}, /* 0360 */
{ 0x0144, "nacute"},
{ 0x0148, "ncaron"},
{ 0x00f3, "oacute"},
{ 0x00f4, "ocircumflex"},
{ 0x0151, "odoubleacute"},
{ 0x00f6, "odiaeresis"},
{ 0x00f7, "division"},
{ 0x0159, "rcaron"}, /* 0370 */
{ 0x016f, "uring"},
{ 0x00fa, "uacute"},
{ 0x0171, "udoubleacute"},
{ 0x00fc, "udiaeresis"},
{ 0x00fd, "yacute"},
{ 0x0163, "tcedilla"},
{ 0x02d9, "abovedot"},
};
kbd-chooser (0.1) unstable; urgency=low
* Initial Release.
-- Alastair McKinstry <mckinstry@debian.org> Wed, 18 Dec 2002 20:28:31 +1100
Local variables:
mode: debian-changelog
End:
Source: kbd-chooser
Section: debian-installer
Priority: standard
Maintainer: Alastair McKinstry <mckinstry@computer.org>
Build-Depends: debhelper (>= 4.1.13), libcdebconf-dev, libdebian-installer3-dev, po-debconf (>= 0.5.0)
Standards-Version: 3.5.8
Package: kbd-chooser
Architecture: any
XB-Installer-Menu-Item: 12
Depends: ${shlibs:Depends}
Description: Detect a keyboard and select layout
Try to auto-detect a keyboard, and select one for the user.
This module provides keyboard detection and configuration for the Debian/GNU Linux installer.
Author(s): Alastair McKinstry <mckinstry@computer.org>
Copyright (c) 2002,2003 Alastair McKinstry <mckinstry@computer.org>
The copyright of this package is GPL, version 2 or later.
#!/bin/sh
/usr/bin/kbd-chooser
exit 0
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1
PACKAGE=kbd-chooser
VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
ARCH=$(shell dpkg --print-architecture)
FILENAME=$(PACKAGE)_$(VERSION)_$(ARCH).udeb
# This is the debhelper compatability version to use.
export DH_COMPAT=3
configure: configure-stamp
configure-stamp:
dh_testdir
touch configure-stamp
build: configure-stamp build-stamp
build-stamp:
dh_testdir
$(MAKE)
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
-$(MAKE) clean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
$(MAKE) install DESTDIR=$(CURDIR)/debian/kbd-chooser
# Build architecture-independent files here.
binary-indep:
# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
dh_installdebconf
dh_link
dh_strip
dh_fixperms
dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol -- -n$(FILENAME)
dh_builddeb --filename=$(FILENAME)
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
Template: console-tools/archs
Type: select
Choices: ${choices}
_Description: Choose the type of keyboard to configure
Template: console-data/keymap/usb
Type: select
Choices: ${choices}
_Description: Select the keymap to use for a USB keyboard
Template: console-data/keymap/ps2
Type: select
Choices: ${choices}
_Description: Select the keymap to use for PC-style keyboard
Template: console-data/keymap/sparc
Type: select
Choices: ${choices}
_Description: Select the keymap to use
Template: console-data/keymap/amiga
Type: select
Choices: ${choices}
_Description: Select the keymap to use
Template: console-data/keymap/atari
Type: select
Choices: ${choices}
_Description: Select the keymap to use
Template: console-data/keymap/mac
Type: select
Choices: ${choices}
_Description: Select the keymap to use
This diff is collapsed.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include "xmalloc.h"
#include "findfile.h"
#include "nls.h"
char pathname[1024];
static int ispipe;
void fpclose(FILE *fp) {
if (ispipe)
pclose(fp);
else
fclose(fp);
}
#define SIZE(a) (sizeof(a)/sizeof(a[0]))
static struct decompressor {
char *ext; /* starts with `.', has no other dots */
char *cmd;
} decompressors[] = {
{ ".gz", "gzip -d -c" },
{ ".bz2", "bzip2 -d -c" },
{ 0, 0 }
};
static FILE *
pipe_open(struct decompressor *dc) {
char *pipe_cmd;
FILE *fp;
ispipe = 1;
pipe_cmd = xmalloc(strlen(dc->cmd) + strlen(pathname) + 2);
sprintf(pipe_cmd, "%s %s", dc->cmd, pathname);
fp = popen(pipe_cmd, "r");
if (fp == NULL)
fprintf(stderr, _("error executing %s\n"), pipe_cmd);
return fp;
}
/* If a file PATHNAME exists, then open it.
If is has a `compressed' extension, then open a pipe reading it */
static FILE *
maybe_pipe_open(void) {
FILE *fp;
char *t;
struct decompressor *dc;
if ((fp = fopen(pathname, "r")) != NULL) {
t = rindex(pathname, '.');
if (t) {
for (dc = &decompressors[0]; dc->cmd; dc++)
if (strcmp(t, dc->ext) == 0) {
fclose(fp);
return pipe_open(dc);
}
}
}
return fp;
}
static FILE *
findfile_in_dir(char *fnam, char *dir, int recdepth, char **suf) {
FILE *fp = NULL;
DIR *d;
struct dirent *de;
char *ff, *fdir, *p, *q, **sp;
struct decompressor *dc;
int secondpass = 0;
ispipe = 0;
ff = index(fnam, '/');
if (ff) {
fdir = xstrdup(fnam);
fdir[ff-fnam] = 0; /* caller guarantees fdir != "" */
} else
fdir = 0; /* just to please gcc */
/* Scan the directory twice: first for files, then
for subdirectories, so that we do never search
a subdirectory when the directory itself already
contains the file we are looking for. */
StartScan:
d = opendir(dir);
if (d == NULL)
return NULL;
while ((de = readdir(d)) != NULL) {
int okdir;
if (strcmp(de->d_name, ".") == 0 ||
strcmp(de->d_name, "..") == 0)
continue;
if (strlen(dir) + strlen(de->d_name) + 2 > sizeof(pathname))
continue;
okdir = (ff && strcmp(de->d_name, fdir) == 0);
if ((secondpass && recdepth) || okdir) {
struct stat statbuf;
char *a;
a = xmalloc(strlen(dir) + strlen(de->d_name) + 2);
sprintf(a, "%s/%s", dir, de->d_name);
if (stat(a, &statbuf) == 0 &&
S_ISDIR(statbuf.st_mode)) {
if (okdir)
fp = findfile_in_dir(ff+1, a, 0, suf);
if (!fp && recdepth)
fp = findfile_in_dir(fnam, a, recdepth-1, suf);
if (fp)
return fp;
}
free(a);
}
if (secondpass)
continue;
/* Should we be in a subdirectory? */
if (ff)
continue;
/* Does d_name start right? */
p = &de->d_name[0];
q = fnam;
while (*p && *p == *q) p++,q++;
if (*q)
continue;
sprintf(pathname, "%s/%s", dir, de->d_name);
/* Does tail consist of a known suffix and possibly
a compression suffix? */
for(sp = suf; *sp; sp++) {
int l;
if (!strcmp(p, *sp))
return maybe_pipe_open();
l = strlen(*sp);
if (strncmp(p,*sp,l) == 0) {
for (dc = &decompressors[0]; dc->cmd; dc++)
if (strcmp(p+l, dc->ext) == 0)
return pipe_open(dc);
}
}
}
closedir(d);
if (recdepth > 0 && !secondpass) {
secondpass = 1;
goto StartScan;
}
return NULL;
}
/* find input file; leave name in pathname[] */
FILE *findfile(char *fnam, char **dirpath, char **suffixes) {
char **dp, *dir, **sp;
FILE *fp;
int dl, recdepth;
struct decompressor *dc;
if (strlen(fnam) >= sizeof(pathname))
return NULL;
/* Try explicitly given name first */
strcpy(pathname, fnam);
fp = maybe_pipe_open();
if (fp)
return fp;
/* Test for full pathname - opening it failed, so need suffix */
/* (This is just nonsense, for backwards compatibility.) */
if (*fnam == '/') {
for (sp = suffixes; *sp; sp++) {
if (strlen(fnam) + strlen(*sp) + 1 > sizeof(pathname))
continue;
if (*sp == 0)
continue; /* we tried it already */
sprintf(pathname, "%s%s", fnam, *sp);
if((fp = fopen(pathname, "r")) != NULL)
return fp;
}
for (sp = suffixes; *sp; sp++) {
for (dc = &decompressors[0]; dc->cmd; dc++) {
if (strlen(fnam) + strlen(*sp)
+ strlen(dc->ext) + 1 > sizeof(pathname))
continue;
sprintf(pathname, "%s%s%s", fnam, *sp, dc->ext);
if ((fp = fopen(pathname, "r")) != NULL) {
fclose(fp);
return pipe_open(dc);
}
}
}
return NULL;
}
/* Search a list of directories and directory hierarchies */
for (dp = dirpath; *dp; dp++) {