Pavel Roskin <proski@gnu.org> just found a nasty memory
[oweals/busybox.git] / loadacm.c
index 66f79092c26e1555eadd656623dae528b3a5fbbc..cf393d92ddf495e6fc0cba52700dce844cf8de4b 100644 (file)
--- a/loadacm.c
+++ b/loadacm.c
@@ -7,6 +7,7 @@
  * Peter Novodvorsky <petya@logic.ru>
  */
 
+#include "internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <memory.h>
 #include <sys/ioctl.h>
 #include <sys/kd.h>
 
+static const char loadacm_usage[] = "loadacm\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nLoads an acm from standard input.\n"
+#endif
+       ;
+
 typedef unsigned short unicode;
 
 static long int ctoi(unsigned char *s, int *is_unicode);
@@ -33,20 +40,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;
+               return( FALSE);
        }
 
        if (screen_map_load(fd, stdin)) {
                fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
-               return 1;
+               return( FALSE);
        }
 
        write(fd, "\033(K", 3);
 
-       return 0;
+       return( TRUE);
 }
 
 int screen_map_load(int fd, FILE * fp)
@@ -129,10 +140,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);
        }
+       fprintf(stderr, "Error parsing symbolic map\n");
+       return(1);
 }