* Peter Novodvorsky <petya@logic.ru>
*/
-#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <assert.h>
#include <errno.h>
#include <signal.h>
+#include <sys/kd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
-#include <sys/kd.h>
+#include "busybox.h"
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);
+static int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
+static int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
+static unicode utf8_to_ucs2(char *buf);
+static int screen_map_load(int fd, FILE * fp);
int loadacm_main(int argc, char **argv)
{
int fd;
if (argc>=2 && *argv[1]=='-') {
- usage(loadacm_usage);
+ show_usage();
}
fd = open("/dev/tty", O_RDWR);
return EXIT_SUCCESS;
}
-int screen_map_load(int fd, FILE * fp)
+static int screen_map_load(int fd, FILE * fp)
{
struct stat stbuf;
unicode wbuf[E_TABSZ];
int is_unicode;
if (fstat(fileno(fp), &stbuf))
- perror("Cannot stat map file"), exit(1);
+ perror_msg_and_die("Cannot stat map file");
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
if (!
if (parse_failed) {
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
- error_msg("16bit screen-map MUST be a regular file.\n"),
- exit(1);
+ error_msg_and_die("16bit screen-map MUST be a regular file.");
else
- perror("fseek failed reading binary 16bit screen-map"),
- exit(1);
+ perror_msg_and_die("fseek failed reading binary 16bit screen-map");
}
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
- perror("Cannot read [new] map from file"), exit(1);
+ perror_msg_and_die("Cannot read [new] map from file");
#if 0
else
- error_msg("Input screen-map is binary.\n");
+ error_msg("Input screen-map is binary.");
#endif
}
/* 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);
+ perror_msg_and_die("PIO_UNISCRNMAP ioctl");
else
return 0;
}
/* rewind... */
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
- error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"),
+ error_msg("Assuming 8bit screen-map - MUST be a regular file."),
exit(1);
else
- perror("fseek failed assuming 8bit screen-map"), exit(1);
+ perror_msg_and_die("fseek failed assuming 8bit screen-map");
}
/* ... and try an old 8-bit screen-map */
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
/* should not - it succedeed above */
- error_msg("fseek() returned ESPIPE !\n"),
- exit(1);
+ error_msg_and_die("fseek() returned ESPIPE !");
else
- perror("fseek for binary 8bit screen-map"), exit(1);
+ perror_msg_and_die("fseek for binary 8bit screen-map");
}
if (fread(buf, E_TABSZ, 1, fp) != 1)
- perror("Cannot read [old] map from file"), exit(1);
+ perror_msg_and_die("Cannot read [old] map from file");
#if 0
else
- error_msg("Input screen-map is binary.\n");
+ error_msg("Input screen-map is binary.");
#endif
}
if (ioctl(fd, PIO_SCRNMAP, buf))
- perror("PIO_SCRNMAP ioctl"), exit(1);
+ perror_msg_and_die("PIO_SCRNMAP ioctl");
else
return 0;
}
- error_msg("Error parsing symbolic map\n");
+ error_msg("Error parsing symbolic map");
return(1);
}
*
* FIXME: ignores everything after second word
*/
-int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
+static 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 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;
+ sigset_t acmsigset, old_sigset;
assert(is_unicode);
buf[i] = 0xfffd;
/* block SIGCHLD */
- sigemptyset(&sigset);
- sigaddset(&sigset, SIGCHLD);
- sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
+ sigemptyset(&acmsigset);
+ sigaddset(&acmsigset, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &acmsigset, &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);
- }
+ else
+ perror_msg_and_die("uni_screen_map_read_ascii() can't read line");
}
/* get "charset-relative charcode", stripping leading spaces */
}
-int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
+static int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
{
char buffer[256];
int in, on;
*
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
*/
-long int ctoi(unsigned char *s, int *is_unicode)
+static long int ctoi(unsigned char *s, int *is_unicode)
{
int i;
size_t ls;
}
-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
-
- fp = xfopen(omfil, "w");
-#ifdef GIO_UNISCRNMAP
- 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);
-}
-
-unicode utf8_to_ucs2(char *buf)
+static unicode utf8_to_ucs2(char *buf)
{
int utf_count = 0;
long utf_char = 0;