Support for tar -z option for uncompressing only
[oweals/busybox.git] / console-tools / loadacm.c
index 072562f6bef28090f597ce52e40bd03ff4f1436b..a69664031e729165a47c39337528a37f3915b4dc 100644 (file)
@@ -7,6 +7,7 @@
  * Peter Novodvorsky <petya@logic.ru>
  */
 
+#include "busybox.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <memory.h>
@@ -17,7 +18,6 @@
 #include <errno.h>
 #include <signal.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/kd.h>
 
@@ -33,20 +33,24 @@ int loadacm_main(int argc, char **argv)
 {
        int fd;
 
+       if (argc>=2 && *argv[1]=='-') {
+               usage(loadacm_usage);
+       }
+
        fd = open("/dev/tty", O_RDWR);
        if (fd < 0) {
-               fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
-               return 1;
+               error_msg("Error opening /dev/tty1: %s\n", strerror(errno));
+               return EXIT_FAILURE;
        }
 
        if (screen_map_load(fd, stdin)) {
-               fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
-               return 1;
+               error_msg("Error loading acm: %s\n", strerror(errno));
+               return EXIT_FAILURE;
        }
 
        write(fd, "\033(K", 3);
 
-       return 0;
+       return EXIT_SUCCESS;
 }
 
 int screen_map_load(int fd, FILE * fp)
@@ -57,7 +61,7 @@ int screen_map_load(int fd, FILE * fp)
        int parse_failed = 0;
        int is_unicode;
 
-       if (fstat(fp->_fileno, &stbuf))
+       if (fstat(fileno(fp), &stbuf))
                perror("Cannot stat map file"), exit(1);
 
        /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
@@ -68,8 +72,7 @@ int screen_map_load(int fd, FILE * fp)
                if (parse_failed) {
                        if (-1 == fseek(fp, 0, SEEK_SET)) {
                                if (errno == ESPIPE)
-                                       fprintf(stderr,
-                                                       "16bit screen-map MUST be a regular file.\n"),
+                                       error_msg("16bit screen-map MUST be a regular file.\n"),
                                                exit(1);
                                else
                                        perror("fseek failed reading binary 16bit screen-map"),
@@ -80,7 +83,7 @@ int screen_map_load(int fd, FILE * fp)
                                perror("Cannot read [new] map from file"), exit(1);
 #if 0
                        else
-                               fprintf(stderr, "Input screen-map is binary.\n");
+                               error_msg("Input screen-map is binary.\n");
 #endif
                }
 
@@ -97,8 +100,7 @@ int screen_map_load(int fd, FILE * fp)
        /* rewind... */
        if (-1 == fseek(fp, 0, SEEK_SET)) {
                if (errno == ESPIPE)
-                       fprintf(stderr,
-                                       "Assuming 8bit screen-map - MUST be a regular file.\n"),
+                       error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"),
                                exit(1);
                else
                        perror("fseek failed assuming 8bit screen-map"), exit(1);
@@ -111,7 +113,7 @@ int screen_map_load(int fd, FILE * fp)
                        if (-1 == fseek(fp, 0, SEEK_SET)) {
                                if (errno == ESPIPE)
                                        /* should not - it succedeed above */
-                                       fprintf(stderr, "fseek() returned ESPIPE !\n"),
+                                       error_msg("fseek() returned ESPIPE !\n"),
                                                exit(1);
                                else
                                        perror("fseek for binary 8bit screen-map"), exit(1);
@@ -121,7 +123,7 @@ int screen_map_load(int fd, FILE * fp)
                                perror("Cannot read [old] map from file"), exit(1);
 #if 0
                        else
-                               fprintf(stderr, "Input screen-map is binary.\n");
+                               error_msg("Input screen-map is binary.\n");
 #endif
                }
 
@@ -129,10 +131,9 @@ int screen_map_load(int fd, FILE * fp)
                        perror("PIO_SCRNMAP ioctl"), exit(1);
                else
                        return 0;
-       } else {
-               fprintf(stderr, "Error parsing symbolic map\n");
-               exit(1);
        }
+       error_msg("Error parsing symbolic map\n");
+       return(1);
 }
 
 
@@ -329,10 +330,7 @@ void saveoldmap(int fd, char *omfil)
        }
 #endif
 
-       if ((fp = fopen(omfil, "w")) == NULL) {
-               perror(omfil);
-               exit(1);
-       }
+       fp = xfopen(omfil, "w");
 #ifdef GIO_UNISCRNMAP
        if (is_old_map) {
 #endif
@@ -353,8 +351,8 @@ void saveoldmap(int fd, char *omfil)
 unicode utf8_to_ucs2(char *buf)
 {
        int utf_count = 0;
-       long utf_char;
-       unicode tc;
+       long utf_char = 0;
+       unicode tc = 0;
        unsigned char c;
 
        do {