Some formatting updates (ran the code through indent)

-Erik
This commit is contained in:
Erik Andersen
2000-02-08 19:58:47 +00:00
parent c0bf817bbc
commit e49d5ecbbe
163 changed files with 27109 additions and 26607 deletions

View File

@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* chvt.c - aeb - 940227 - Change virtual terminal
*
@@ -13,24 +14,23 @@
extern int getfd(void);
int
chvt_main(int argc, char** argv)
int chvt_main(int argc, char **argv)
{
int fd, num;
int fd, num;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd,VT_ACTIVATE,num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd,VT_WAITACTIVE,num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
exit( TRUE);
if ((argc != 2) || (**(argv + 1) == '-')) {
usage
("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd, VT_ACTIVATE, num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd, VT_WAITACTIVE, num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
exit(TRUE);
}

View File

@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini clear implementation for busybox
*
@@ -25,9 +26,8 @@
#include <stdio.h>
extern int
clear_main(int argc, char** argv)
extern int clear_main(int argc, char **argv)
{
printf("\033[H\033[J");
exit( TRUE);
exit(TRUE);
}

View File

@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
* Renamed deallocvt.
@@ -13,38 +14,39 @@
extern int getfd(void);
char *progname;
int
deallocvt_main(int argc, char *argv[]) {
int fd, num, i;
int deallocvt_main(int argc, char *argv[])
{
int fd, num, i;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
progname = argv[0];
fd = get_console_fd("/dev/console");
if (argc == 1) {
/* deallocate all unused consoles */
if (ioctl(fd,VT_DISALLOCATE,0)) {
perror("VT_DISALLOCATE");
exit(1);
if ((argc != 2) || (**(argv + 1) == '-')) {
usage
("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
} else
for (i = 1; i < argc; i++) {
num = atoi(argv[i]);
if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
else
if (ioctl(fd,VT_DISALLOCATE,num)) {
perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num);
exit(1);
}
}
exit(0);
progname = argv[0];
fd = get_console_fd("/dev/console");
if (argc == 1) {
/* deallocate all unused consoles */
if (ioctl(fd, VT_DISALLOCATE, 0)) {
perror("VT_DISALLOCATE");
exit(1);
}
} else
for (i = 1; i < argc; i++) {
num = atoi(argv[i]);
if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
progname);
else if (ioctl(fd, VT_DISALLOCATE, num)) {
perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num);
exit(1);
}
}
exit(0);
}

View File

@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Derived from
* mapscrn.c - version 0.92
@@ -23,120 +24,115 @@
typedef unsigned short unicode;
static long int ctoi(unsigned char *s, int *is_unicode);
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[]);
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int* is_unicode);
unicode utf8_to_ucs2 (char* buf);
int screen_map_load(int fd, FILE *fp);
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
unicode utf8_to_ucs2(char *buf);
int screen_map_load(int fd, FILE * fp);
int loadacm_main(int argc, char **argv)
{
int fd;
fd = open("/dev/tty", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
return 1;
}
if (screen_map_load(fd, stdin))
{
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
return 1;
}
write(fd, "\033(K", 3);
return 0;
int fd;
fd = open("/dev/tty", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
return 1;
}
if (screen_map_load(fd, stdin)) {
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
return 1;
}
write(fd, "\033(K", 3);
return 0;
}
int screen_map_load(int fd, FILE *fp)
int screen_map_load(int fd, FILE * fp)
{
struct stat stbuf;
unicode wbuf[E_TABSZ];
unsigned char buf[E_TABSZ];
int parse_failed = 0;
int is_unicode;
struct stat stbuf;
unicode wbuf[E_TABSZ];
unsigned char buf[E_TABSZ];
int parse_failed = 0;
int is_unicode;
if (fstat(fp->_fileno, &stbuf))
perror("Cannot stat map file"), exit(1);
if (fstat(fp->_fileno, &stbuf))
perror("Cannot stat map file"), exit(1);
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
if (!(parse_failed = (-1 == uni_screen_map_read_ascii(fp,wbuf,&is_unicode))) ||
(S_ISREG(stbuf.st_mode) &&
(stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) /* test for binary UTF map by size */
{
if (parse_failed)
{
if (-1 == fseek (fp, 0, SEEK_SET))
{
if (errno == ESPIPE)
fprintf (stderr, "16bit screen-map MUST be a regular file.\n"), exit (1);
else
perror ("fseek failed reading binary 16bit screen-map"), exit (1);
}
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
perror("Cannot read [new] map from file"), exit(1);
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
if (!
(parse_failed =
(-1 == uni_screen_map_read_ascii(fp, wbuf, &is_unicode)))
|| (S_ISREG(stbuf.st_mode) && (stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) { /* test for binary UTF map by size */
if (parse_failed) {
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
fprintf(stderr,
"16bit screen-map MUST be a regular file.\n"),
exit(1);
else
perror("fseek failed reading binary 16bit screen-map"),
exit(1);
}
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
perror("Cannot read [new] map from file"), exit(1);
#if 0
else
fprintf(stderr, "Input screen-map is binary.\n");
else
fprintf(stderr, "Input screen-map is binary.\n");
#endif
}
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
/* same if it was binary, ie. if parse_failed */
if (parse_failed || is_unicode) {
if (ioctl(fd, PIO_UNISCRNMAP, wbuf))
perror("PIO_UNISCRNMAP ioctl"), exit(1);
else
return 0;
}
}
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
/* same if it was binary, ie. if parse_failed */
if (parse_failed || is_unicode)
{
if (ioctl(fd,PIO_UNISCRNMAP,wbuf))
perror("PIO_UNISCRNMAP ioctl"), exit(1);
else
return 0;
/* rewind... */
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
fprintf(stderr,
"Assuming 8bit screen-map - MUST be a regular file.\n"),
exit(1);
else
perror("fseek failed assuming 8bit screen-map"), exit(1);
}
}
/* rewind... */
if (-1 == fseek (fp, 0, SEEK_SET))
{
if (errno == ESPIPE)
fprintf (stderr, "Assuming 8bit screen-map - MUST be a regular file.\n"), exit (1);
else
perror ("fseek failed assuming 8bit screen-map"), exit (1);
}
/* ... and try an old 8-bit screen-map */
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp,buf))) ||
(S_ISREG(stbuf.st_mode) &&
(stbuf.st_size == E_TABSZ))) /* test for binary old 8-bit map by size */
{
if (parse_failed)
{
if (-1 == fseek (fp, 0, SEEK_SET))
{
if (errno == ESPIPE)
/* should not - it succedeed above */
fprintf (stderr, "fseek() returned ESPIPE !\n"), exit (1);
else
perror ("fseek for binary 8bit screen-map"), exit (1);
}
if (fread(buf,E_TABSZ,1,fp) != 1)
perror("Cannot read [old] map from file"), exit(1);
/* ... and try an old 8-bit screen-map */
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp, buf))) ||
(S_ISREG(stbuf.st_mode) && (stbuf.st_size == E_TABSZ))) { /* test for binary old 8-bit map by size */
if (parse_failed) {
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
/* should not - it succedeed above */
fprintf(stderr, "fseek() returned ESPIPE !\n"),
exit(1);
else
perror("fseek for binary 8bit screen-map"), exit(1);
}
if (fread(buf, E_TABSZ, 1, fp) != 1)
perror("Cannot read [old] map from file"), exit(1);
#if 0
else
fprintf(stderr, "Input screen-map is binary.\n");
else
fprintf(stderr, "Input screen-map is binary.\n");
#endif
}
if (ioctl(fd, PIO_SCRNMAP, buf))
perror("PIO_SCRNMAP ioctl"), exit(1);
else
return 0;
} else {
fprintf(stderr, "Error parsing symbolic map\n");
exit(1);
}
if (ioctl(fd,PIO_SCRNMAP,buf))
perror("PIO_SCRNMAP ioctl"), exit(1);
else
return 0;
}
else
{
fprintf(stderr, "Error parsing symbolic map\n");
exit(1);
}
}
@@ -149,116 +145,111 @@ int screen_map_load(int fd, FILE *fp)
*
* FIXME: ignores everything after second word
*/
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int *is_unicode)
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
{
char buffer[256]; /* line buffer reading file */
char *p, *q; /* 1st + 2nd words in line */
int in, on; /* the same, as numbers */
int tmp_is_unicode; /* tmp for is_unicode calculation */
int i; /* loop index - result holder */
int ret_code = 0; /* return code */
sigset_t sigset, old_sigset;
assert (is_unicode);
*is_unicode = 0;
/* first 128 codes defaults to ASCII */
for (i=0; i<128; i++) buf[i] = i;
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
for ( ; i<E_TABSZ; i++) buf[i] = 0xfffd;
/* block SIGCHLD */
sigemptyset (&sigset);
sigaddset (&sigset, SIGCHLD);
sigprocmask (SIG_BLOCK, &sigset, &old_sigset);
char buffer[256]; /* line buffer reading file */
char *p, *q; /* 1st + 2nd words in line */
int in, on; /* the same, as numbers */
int tmp_is_unicode; /* tmp for is_unicode calculation */
int i; /* loop index - result holder */
int ret_code = 0; /* return code */
sigset_t sigset, old_sigset;
do
{
if (NULL == fgets(buffer, sizeof(buffer),fp))
{
if (feof (fp))
break;
else
{
perror ("uni_screen_map_read_ascii() can't read line");
exit (2);
}
assert(is_unicode);
*is_unicode = 0;
/* first 128 codes defaults to ASCII */
for (i = 0; i < 128; i++)
buf[i] = i;
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
for (; i < E_TABSZ; i++)
buf[i] = 0xfffd;
/* block SIGCHLD */
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
do {
if (NULL == fgets(buffer, sizeof(buffer), fp)) {
if (feof(fp))
break;
else {
perror("uni_screen_map_read_ascii() can't read line");
exit(2);
}
}
/* get "charset-relative charcode", stripping leading spaces */
p = strtok(buffer, " \t\n");
/* skip empty lines and comments */
if (!p || *p == '#')
continue;
/* get unicode mapping */
q = strtok(NULL, " \t\n");
if (q) {
in = ctoi(p, NULL);
if (in < 0 || in > 255) {
ret_code = -1;
break;
}
on = ctoi(q, &tmp_is_unicode);
if (in < 0 && on > 65535) {
ret_code = -1;
break;
}
*is_unicode |= tmp_is_unicode;
buf[in] = on;
} else {
ret_code = -1;
break;
}
}
/* get "charset-relative charcode", stripping leading spaces */
p = strtok(buffer," \t\n");
while (1); /* terminated by break on feof() */
/* skip empty lines and comments */
if (!p || *p == '#')
continue;
/* restore sig mask */
sigprocmask(SIG_SETMASK, &old_sigset, NULL);
/* get unicode mapping */
q = strtok(NULL," \t\n");
if (q)
{
in = ctoi(p, NULL);
if (in < 0 || in > 255)
{
ret_code = -1;
break;
}
on = ctoi(q, &tmp_is_unicode);
if (in < 0 && on > 65535)
{
ret_code = -1;
break;
}
*is_unicode |= tmp_is_unicode;
buf[in] = on;
}
else
{
ret_code = -1;
break;
}
}
while (1); /* terminated by break on feof() */
/* restore sig mask */
sigprocmask (SIG_SETMASK, &old_sigset, NULL);
return ret_code;
return ret_code;
}
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
{
char buffer[256];
int in, on;
char *p, *q;
for (in=0; in<256; in++) buf[in]=in;
while (fgets(buffer,sizeof(buffer)-1,fp))
{
p = strtok(buffer," \t\n");
if (!p || *p == '#')
continue;
char buffer[256];
int in, on;
char *p, *q;
q = strtok(NULL," \t\n#");
if (q)
{
in = ctoi(p, NULL);
if (in < 0 || in > 255) return -1;
on = ctoi(q, NULL);
if (in < 0 && on > 255) return -1;
buf[in] = on;
for (in = 0; in < 256; in++)
buf[in] = in;
while (fgets(buffer, sizeof(buffer) - 1, fp)) {
p = strtok(buffer, " \t\n");
if (!p || *p == '#')
continue;
q = strtok(NULL, " \t\n#");
if (q) {
in = ctoi(p, NULL);
if (in < 0 || in > 255)
return -1;
on = ctoi(q, NULL);
if (in < 0 && on > 255)
return -1;
buf[in] = on;
} else
return -1;
}
else return -1;
}
return(0);
return (0);
}
@@ -270,172 +261,145 @@ int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
*
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
*/
long int ctoi(unsigned char *s, int *is_unicode)
long int ctoi(unsigned char *s, int *is_unicode)
{
int i;
size_t ls;
ls = strlen(s);
if (is_unicode) *is_unicode = 0;
/* hex-specified UCS2 */
if ((strncmp(s,"U+",2) == 0) &&
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
{
sscanf(s+2,"%x",&i);
if (is_unicode) *is_unicode = 1;
}
int i;
size_t ls;
/* hex-specified byte */
else if ((ls <= 4) && (strncmp(s,"0x",2) == 0) &&
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
sscanf(s+2,"%x",&i);
ls = strlen(s);
if (is_unicode)
*is_unicode = 0;
/* oct-specified number (byte) */
else if ((*s == '0') &&
(strspn(s,"01234567") == ls))
sscanf(s,"%o",&i);
/* dec-specified number (byte) */
else if (strspn(s,"0123456789") == ls)
sscanf(s,"%d",&i);
/* single-byte quoted char */
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
i=s[1];
/* multi-byte UTF8 quoted char */
else if ((s[0] == '\'') && (s[ls-1] == '\''))
{
s[ls-1] = 0; /* ensure we'll not "parse UTF too far" */
i = utf8_to_ucs2(s+1);
if (is_unicode) *is_unicode = 1;
}
else
return(-1);
return(i);
/* hex-specified UCS2 */
if ((strncmp(s, "U+", 2) == 0) &&
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2)) {
sscanf(s + 2, "%x", &i);
if (is_unicode)
*is_unicode = 1;
}
/* hex-specified byte */
else if ((ls <= 4) && (strncmp(s, "0x", 2) == 0) &&
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2))
sscanf(s + 2, "%x", &i);
/* oct-specified number (byte) */
else if ((*s == '0') && (strspn(s, "01234567") == ls))
sscanf(s, "%o", &i);
/* dec-specified number (byte) */
else if (strspn(s, "0123456789") == ls)
sscanf(s, "%d", &i);
/* single-byte quoted char */
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
i = s[1];
/* multi-byte UTF8 quoted char */
else if ((s[0] == '\'') && (s[ls - 1] == '\'')) {
s[ls - 1] = 0; /* ensure we'll not "parse UTF too far" */
i = utf8_to_ucs2(s + 1);
if (is_unicode)
*is_unicode = 1;
} else
return (-1);
return (i);
}
void saveoldmap(int fd, char *omfil)
void saveoldmap(int fd, char *omfil)
{
FILE *fp;
char buf[E_TABSZ];
#ifdef GIO_UNISCRNMAP
unicode xbuf[E_TABSZ];
int is_old_map = 0;
if (ioctl(fd,GIO_UNISCRNMAP,xbuf))
{
perror("GIO_UNISCRNMAP ioctl error");
#endif
if (ioctl(fd,GIO_SCRNMAP,buf))
{
perror("GIO_SCRNMAP ioctl error");
exit(1);
}
else
is_old_map = 1;
#ifdef GIO_UNISCRNMAP
}
#endif
if ((fp = fopen(omfil, "w")) == NULL)
{
perror(omfil);
exit(1);
}
FILE *fp;
char buf[E_TABSZ];
#ifdef GIO_UNISCRNMAP
if (is_old_map)
{
unicode xbuf[E_TABSZ];
int is_old_map = 0;
if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) {
perror("GIO_UNISCRNMAP ioctl error");
#endif
if (fwrite(buf,E_TABSZ,1,fp) != 1)
{
perror("Error writing map to file");
exit(1);
if (ioctl(fd, GIO_SCRNMAP, buf)) {
perror("GIO_SCRNMAP ioctl error");
exit(1);
} else
is_old_map = 1;
#ifdef GIO_UNISCRNMAP
}
#endif
if ((fp = fopen(omfil, "w")) == NULL) {
perror(omfil);
exit(1);
}
#ifdef GIO_UNISCRNMAP
}
else
if (fwrite(xbuf, sizeof(unicode) * E_TABSZ,1,fp) != 1)
{
perror("Error writing map to file");
exit(1);
if (is_old_map) {
#endif
if (fwrite(buf, E_TABSZ, 1, fp) != 1) {
perror("Error writing map to file");
exit(1);
}
#ifdef GIO_UNISCRNMAP
} else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) {
perror("Error writing map to file");
exit(1);
}
#endif
fclose(fp);
fclose(fp);
}
unicode utf8_to_ucs2 (char* buf)
unicode utf8_to_ucs2(char *buf)
{
int utf_count = 0;
long utf_char;
unicode tc;
unsigned char c;
int utf_count = 0;
long utf_char;
unicode tc;
unsigned char c;
do
{
c = *buf;
buf++;
do {
c = *buf;
buf++;
/* if byte should be part of multi-byte sequence */
if(c & 0x80)
{
/* if we have already started to parse a UTF8 sequence */
if (utf_count > 0 && (c & 0xc0) == 0x80)
{
utf_char = (utf_char << 6) | (c & 0x3f);
utf_count--;
if (utf_count == 0)
tc = utf_char;
else
continue;
}
else /* Possibly 1st char of a UTF8 sequence */
{
if ((c & 0xe0) == 0xc0)
{
utf_count = 1;
utf_char = (c & 0x1f);
}
else if ((c & 0xf0) == 0xe0)
{
utf_count = 2;
utf_char = (c & 0x0f);
}
else if ((c & 0xf8) == 0xf0)
{
utf_count = 3;
utf_char = (c & 0x07);
}
else if ((c & 0xfc) == 0xf8)
{
utf_count = 4;
utf_char = (c & 0x03);
}
else if ((c & 0xfe) == 0xfc)
{
utf_count = 5;
utf_char = (c & 0x01);
}
else
utf_count = 0;
continue;
}
}
else /* not part of multi-byte sequence - treat as ASCII
* this makes incomplete sequences to be ignored
*/
{
tc = c;
utf_count = 0;
}
}
while (utf_count);
/* if byte should be part of multi-byte sequence */
if (c & 0x80) {
/* if we have already started to parse a UTF8 sequence */
if (utf_count > 0 && (c & 0xc0) == 0x80) {
utf_char = (utf_char << 6) | (c & 0x3f);
utf_count--;
if (utf_count == 0)
tc = utf_char;
else
continue;
} else { /* Possibly 1st char of a UTF8 sequence */
return tc;
if ((c & 0xe0) == 0xc0) {
utf_count = 1;
utf_char = (c & 0x1f);
} else if ((c & 0xf0) == 0xe0) {
utf_count = 2;
utf_char = (c & 0x0f);
} else if ((c & 0xf8) == 0xf0) {
utf_count = 3;
utf_char = (c & 0x07);
} else if ((c & 0xfc) == 0xf8) {
utf_count = 4;
utf_char = (c & 0x03);
} else if ((c & 0xfe) == 0xfc) {
utf_count = 5;
utf_char = (c & 0x01);
} else
utf_count = 0;
continue;
}
} else { /* not part of multi-byte sequence - treat as ASCII
* this makes incomplete sequences to be ignored
*/
tc = c;
utf_count = 0;
}
}
while (utf_count);
return tc;
}

View File

@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* loadfont.c - Eugene Crosser & Andries Brouwer
*
@@ -30,72 +31,69 @@
#define PSF_SEPARATOR 0xFFFF
static const char loadfont_usage[] = "loadfont\n"
"\n"
"\tLoad a console font from standard input.\n"
"\n";
"\n" "\tLoad a console font from standard input.\n" "\n";
struct psf_header
{
unsigned char magic1, magic2; /* Magic number */
unsigned char mode; /* PSF font mode */
unsigned char charsize; /* Character size */
struct psf_header {
unsigned char magic1, magic2; /* Magic number */
unsigned char mode; /* PSF font mode */
unsigned char charsize; /* Character size */
};
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
static void loadnewfont(int fd);
extern int
loadfont_main(int argc, char **argv)
extern int loadfont_main(int argc, char **argv)
{
int fd;
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
}
loadnewfont(fd);
return 0;
}
static void
do_loadfont(int fd, char *inbuf, int unit, int fontsize) {
static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
{
char buf[16384];
int i;
memset(buf,0,sizeof(buf));
memset(buf, 0, sizeof(buf));
if (unit < 1 || unit > 32) {
fprintf(stderr, "Bad character size %d\n", unit);
exit(1);
fprintf(stderr, "Bad character size %d\n", unit);
exit(1);
}
for (i = 0; i < fontsize; i++)
memcpy(buf+(32*i), inbuf+(unit*i), unit);
memcpy(buf + (32 * i), inbuf + (unit * i), unit);
#if defined( PIO_FONTX ) && !defined( __sparc__ )
{
struct consolefontdesc cfd;
struct consolefontdesc cfd;
cfd.charcount = fontsize;
cfd.charheight = unit;
cfd.chardata = buf;
cfd.charcount = fontsize;
cfd.charheight = unit;
cfd.chardata = buf;
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
return; /* success */
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
return; /* success */
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
}
#endif
if (ioctl(fd, PIO_FONT, buf)) {
perror("PIO_FONT ioctl error");
exit(1);
perror("PIO_FONT ioctl error");
exit(1);
}
}
static void
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
{
struct unimapinit advice;
struct unimapdesc ud;
struct unipair *up;
@@ -103,23 +101,24 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
int glyph;
u_short unicode;
maxct = tailsz; /* more than enough */
maxct = tailsz; /* more than enough */
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
if (!up) {
fprintf(stderr, "Out of memory?\n");
exit(1);
fprintf(stderr, "Out of memory?\n");
exit(1);
}
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
tailsz -= 2;
inbuf += 2;
if (unicode == PSF_SEPARATOR)
break;
up[ct].unicode = unicode;
up[ct].fontpos = glyph;
ct++;
}
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
tailsz -= 2;
inbuf += 2;
if (unicode == PSF_SEPARATOR)
break;
up[ct].unicode = unicode;
up[ct].fontpos = glyph;
ct++;
}
}
/* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
@@ -128,33 +127,33 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
advice.advised_hashsize = 0;
advice.advised_hashstep = 0;
advice.advised_hashlevel = 0;
if(ioctl(fd, PIO_UNIMAPCLR, &advice)) {
if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
#ifdef ENOIOCTLCMD
if (errno == ENOIOCTLCMD) {
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
fprintf(stderr, "No Unicode mapping table loaded.\n");
} else
if (errno == ENOIOCTLCMD) {
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
fprintf(stderr, "No Unicode mapping table loaded.\n");
} else
#endif
perror("PIO_UNIMAPCLR");
exit(1);
perror("PIO_UNIMAPCLR");
exit(1);
}
ud.entry_ct = ct;
ud.entries = up;
if(ioctl(fd, PIO_UNIMAP, &ud)) {
if (ioctl(fd, PIO_UNIMAP, &ud)) {
#if 0
if (errno == ENOMEM) {
/* change advice parameters */
}
if (errno == ENOMEM) {
/* change advice parameters */
}
#endif
perror("PIO_UNIMAP");
exit(1);
perror("PIO_UNIMAP");
exit(1);
}
}
static void
loadnewfont(int fd) {
static void loadnewfont(int fd)
{
int unit;
char inbuf[32768]; /* primitive */
char inbuf[32768]; /* primitive */
int inputlth, offset;
/*
@@ -178,57 +177,58 @@ loadnewfont(int fd) {
/* test for psf first */
{
struct psf_header psfhdr;
int fontsize;
int hastable;
int head0, head;
struct psf_header psfhdr;
int fontsize;
int hastable;
int head0, head;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
psfhdr = * (struct psf_header *) &inbuf[0];
psfhdr = *(struct psf_header *) &inbuf[0];
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
if (psfhdr.mode > PSF_MAXMODE) {
fprintf(stderr, "Unsupported psf file mode\n");
exit(1);
}
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
if (psfhdr.mode > PSF_MAXMODE) {
fprintf(stderr, "Unsupported psf file mode\n");
exit(1);
}
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
#if !defined( PIO_FONTX ) || defined( __sparc__ )
if (fontsize != 256) {
fprintf(stderr, "Only fontsize 256 supported\n");
exit(1);
}
if (fontsize != 256) {
fprintf(stderr, "Only fontsize 256 supported\n");
exit(1);
}
#endif
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize*unit;
if (head > inputlth || (!hastable && head != inputlth)) {
fprintf(stderr, "Input file: bad length\n");
exit(1);
}
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth-head, fontsize);
return;
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize * unit;
if (head > inputlth || (!hastable && head != inputlth)) {
fprintf(stderr, "Input file: bad length\n");
exit(1);
}
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
return;
}
no_psf:
no_psf:
/* file with three code pages? */
if (inputlth == 9780) {
offset = 40;
unit = 16;
offset = 40;
unit = 16;
} else {
/* bare font */
if (inputlth & 0377) {
fprintf(stderr, "Bad input file size\n");
exit(1);
}
offset = 0;
unit = inputlth/256;
/* bare font */
if (inputlth & 0377) {
fprintf(stderr, "Bad input file size\n");
exit(1);
}
offset = 0;
unit = inputlth / 256;
}
do_loadfont(fd, inbuf+offset, unit, 256);
do_loadfont(fd, inbuf + offset, unit, 256);
}

View File

@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini loadkmap implementation for busybox
*
@@ -29,61 +30,63 @@
static const char loadkmap_usage[] = "loadkmap\n"
"\n"
"\tLoad a binary keyboard translation table from standard input.\n"
"\n";
"\n"
"\tLoad a binary keyboard translation table from standard input.\n"
"\n";
int
loadkmap_main(int argc, char * * argv)
{
struct kbentry ke;
u_short *ibuff;
int i,j,fd,readsz,pos,ibuffsz=NR_KEYS * sizeof(u_short);
char flags[MAX_NR_KEYMAPS],magic[]="bkeymap",buff[7];
int loadkmap_main(int argc, char **argv)
{
struct kbentry ke;
u_short *ibuff;
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7];
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
}
read(0,buff,7);
if (0 != strncmp(buff,magic,7)) {
fprintf(stderr, "This is not a valid binary keymap.\n");
return 1;
}
if ( MAX_NR_KEYMAPS != read(0,flags,MAX_NR_KEYMAPS) ) {
fprintf(stderr, "Error reading keymap flags: %s\n", strerror(errno));
return 1;
}
ibuff=(u_short *) malloc(ibuffsz);
if (!ibuff) {
fprintf(stderr, "Out of memory.\n");
return 1;
}
for(i=0; i<MAX_NR_KEYMAPS; i++) {
if (flags[i]==1){
pos=0;
while (pos < ibuffsz) {
if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) {
fprintf(stderr, "Error reading keymap: %s\n",
strerror(errno));
return 1;
}
pos += readsz;
}
for(j=0; j<NR_KEYS; j++) {
ke.kb_index = j;
ke.kb_table = i;
ke.kb_value = ibuff[j];
ioctl(fd, KDSKBENT, &ke);
}
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
}
}
close (fd);
return 0;
read(0, buff, 7);
if (0 != strncmp(buff, magic, 7)) {
fprintf(stderr, "This is not a valid binary keymap.\n");
return 1;
}
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
fprintf(stderr, "Error reading keymap flags: %s\n",
strerror(errno));
return 1;
}
ibuff = (u_short *) malloc(ibuffsz);
if (!ibuff) {
fprintf(stderr, "Out of memory.\n");
return 1;
}
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
pos = 0;
while (pos < ibuffsz) {
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
< 0) {
fprintf(stderr, "Error reading keymap: %s\n",
strerror(errno));
return 1;
}
pos += readsz;
}
for (j = 0; j < NR_KEYS; j++) {
ke.kb_index = j;
ke.kb_table = i;
ke.kb_value = ibuff[j];
ioctl(fd, KDSKBENT, &ke);
}
}
}
close(fd);
return 0;
}