Move messages.c to libbb. Make each string in messages.c be its own .o file.
[oweals/busybox.git] / loadacm.c
index a69664031e729165a47c39337528a37f3915b4dc..5dbf03e362d65215820beb91641c1c308521f0bc 100644 (file)
--- a/loadacm.c
+++ b/loadacm.c
@@ -7,7 +7,6 @@
  * 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);
        if (fd < 0) {
-               error_msg("Error opening /dev/tty1: %s\n", strerror(errno));
-               return EXIT_FAILURE;
+               perror_msg_and_die("Error opening /dev/tty1");
        }
 
        if (screen_map_load(fd, stdin)) {
-               error_msg("Error loading acm: %s\n", strerror(errno));
-               return EXIT_FAILURE;
+               perror_msg_and_die("Error loading acm");
        }
 
        write(fd, "\033(K", 3);
@@ -53,7 +51,7 @@ int loadacm_main(int argc, char **argv)
        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];
@@ -62,7 +60,7 @@ int screen_map_load(int fd, FILE * fp)
        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 (!
@@ -72,18 +70,16 @@ int screen_map_load(int fd, FILE * fp)
                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
                }
 
@@ -91,7 +87,7 @@ int screen_map_load(int fd, FILE * fp)
                /* 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;
                }
@@ -100,10 +96,10 @@ int screen_map_load(int fd, FILE * fp)
        /* 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 */
@@ -113,26 +109,25 @@ int screen_map_load(int fd, FILE * fp)
                        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);
 }
 
@@ -146,7 +141,7 @@ 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)
+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 */
@@ -154,7 +149,7 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
        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);
 
@@ -168,18 +163,16 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *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 */
@@ -220,7 +213,7 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
 }
 
 
-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;
@@ -262,7 +255,7 @@ 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)
+static long int ctoi(unsigned char *s, int *is_unicode)
 {
        int i;
        size_t ls;
@@ -309,46 +302,7 @@ long int ctoi(unsigned char *s, int *is_unicode)
 }
 
 
-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;