usage.c: remove reference to busybox.h
[oweals/busybox.git] / coreutils / uudecode.c
index 921d29af0cc18e075f947be78daa06eb260d36cc..779710edda07e6e6ad2c6edc0d6997e914f15e89 100644 (file)
  */
 
 
-#include "busybox.h"
+#include "libbb.h"
 
-static int read_stduu(FILE *src_stream, FILE *dst_stream)
+static void read_stduu(FILE *src_stream, FILE *dst_stream)
 {
        char *line;
 
-       while ((line = bb_get_chomped_line_from_file(src_stream)) != NULL) {
+       while ((line = xmalloc_getline(src_stream)) != NULL) {
                int length;
                char *line_ptr = line;
 
                if (strcmp(line, "end") == 0) {
-                       return(EXIT_SUCCESS);
+                       return;
                }
                length = ((*line_ptr - 0x20) & 0x3f)* 4 / 3;
 
@@ -32,13 +32,13 @@ static int read_stduu(FILE *src_stream, FILE *dst_stream)
                        continue;
                }
                if (length > 60) {
-                       bb_error_msg_and_die("Line too long");
+                       bb_error_msg_and_die("line too long");
                }
 
                line_ptr++;
                /* Tolerate an overly long line to accomodate a possible exta '`' */
                if (strlen(line_ptr) < (size_t)length) {
-                       bb_error_msg_and_die("Short file");
+                       bb_error_msg_and_die("short file");
                }
 
                while (length > 0) {
@@ -63,14 +63,14 @@ static int read_stduu(FILE *src_stream, FILE *dst_stream)
                }
                free(line);
        }
-       bb_error_msg_and_die("Short file");
+       bb_error_msg_and_die("short file");
 }
 
-static int read_base64(FILE *src_stream, FILE *dst_stream)
+static void read_base64(FILE *src_stream, FILE *dst_stream)
 {
        static const char base64_table[] =
                "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n";
-       char term_count = 0;
+       int term_count = 0;
 
        while (1) {
                char translated[4];
@@ -84,7 +84,7 @@ static int read_base64(FILE *src_stream, FILE *dst_stream)
                        do {
                                ch = fgetc(src_stream);
                                if (ch == EOF) {
-                                       bb_error_msg_and_die("Short file");
+                                       bb_error_msg_and_die("short file");
                                }
                        } while ((table_ptr = strchr(base64_table, ch)) == NULL);
 
@@ -101,7 +101,7 @@ static int read_base64(FILE *src_stream, FILE *dst_stream)
                        else if (*table_ptr == '\n') {
                                /* Check for terminating line */
                                if (term_count == 5) {
-                                       return(EXIT_SUCCESS);
+                                       return;
                                }
                                term_count = 1;
                                continue;
@@ -123,6 +123,7 @@ static int read_base64(FILE *src_stream, FILE *dst_stream)
        }
 }
 
+int uudecode_main(int argc, char **argv);
 int uudecode_main(int argc, char **argv)
 {
        FILE *src_stream;
@@ -140,13 +141,12 @@ int uudecode_main(int argc, char **argv)
        }
 
        /* Search for the start of the encoding */
-       while ((line = bb_get_chomped_line_from_file(src_stream)) != NULL) {
-               int (*decode_fn_ptr)(FILE * src, FILE * dst);
+       while ((line = xmalloc_getline(src_stream)) != NULL) {
+               void (*decode_fn_ptr)(FILE * src, FILE * dst);
                char *line_ptr;
                FILE *dst_stream;
                int mode;
-               int ret;
-               
+
                if (strncmp(line, "begin-base64 ", 13) == 0) {
                        line_ptr = line + 13;
                        decode_fn_ptr = read_base64;
@@ -166,16 +166,16 @@ int uudecode_main(int argc, char **argv)
                        }
                        outname++;
                }
-               if (strcmp(outname, "-") == 0) {
+               if (LONE_DASH(outname)) {
                        dst_stream = stdout;
                } else {
                        dst_stream = xfopen(outname, "w");
                        chmod(outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO));
                }
                free(line);
-               ret = decode_fn_ptr(src_stream, dst_stream);
-               bb_fclose_nonstdin(src_stream);
-               return(ret);
+               decode_fn_ptr(src_stream, dst_stream);
+               fclose_if_not_stdin(src_stream);
+               return EXIT_SUCCESS;
        }
-       bb_error_msg_and_die("No `begin' line");
+       bb_error_msg_and_die("no 'begin' line");
 }