diff options
author | Matt Kraai <kraai@debian.org> | 2001-04-18 16:05:34 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-04-18 16:05:34 +0000 |
commit | 53265546a69d5810d5e19b22d6a5095f04eca6be (patch) | |
tree | 6a920a60f2efdfbf4c34bea6542568d18aee9471 | |
parent | 96dcd19b8a8e9d6fc8c17c20c42d32665b68c141 (diff) | |
download | busybox-w32-53265546a69d5810d5e19b22d6a5095f04eca6be.tar.gz busybox-w32-53265546a69d5810d5e19b22d6a5095f04eca6be.tar.bz2 busybox-w32-53265546a69d5810d5e19b22d6a5095f04eca6be.zip |
Eliminate spurious warning, convert to getopt, and eliminate redundant check.
-rw-r--r-- | archival/gunzip.c | 4 | ||||
-rw-r--r-- | archival/gzip.c | 48 | ||||
-rw-r--r-- | gunzip.c | 4 | ||||
-rw-r--r-- | gzip.c | 48 |
4 files changed, 46 insertions, 58 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c index e6f6bdfc1..b4edb25ac 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
@@ -91,7 +91,7 @@ extern int gunzip_main(int argc, char **argv) | |||
91 | if (strcmp(applet_name, "zcat") == 0) | 91 | if (strcmp(applet_name, "zcat") == 0) |
92 | flags |= gunzip_to_stdout; | 92 | flags |= gunzip_to_stdout; |
93 | 93 | ||
94 | while ((opt = getopt(argc, argv, "ctfh")) != -1) { | 94 | while ((opt = getopt(argc, argv, "ctfhd")) != -1) { |
95 | switch (opt) { | 95 | switch (opt) { |
96 | case 'c': | 96 | case 'c': |
97 | flags |= gunzip_to_stdout; | 97 | flags |= gunzip_to_stdout; |
@@ -102,6 +102,8 @@ extern int gunzip_main(int argc, char **argv) | |||
102 | case 't': | 102 | case 't': |
103 | flags |= gunzip_test; | 103 | flags |= gunzip_test; |
104 | break; | 104 | break; |
105 | case 'd': /* Used to convert gzip to gunzip. */ | ||
106 | break; | ||
105 | case 'h': | 107 | case 'h': |
106 | default: | 108 | default: |
107 | show_usage(); /* exit's inside usage */ | 109 | show_usage(); /* exit's inside usage */ |
diff --git a/archival/gzip.c b/archival/gzip.c index ac503444e..f05ef95d0 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -1900,42 +1900,36 @@ int gzip_main(int argc, char **argv) | |||
1900 | int tostdout = 0; | 1900 | int tostdout = 0; |
1901 | int fromstdin = 0; | 1901 | int fromstdin = 0; |
1902 | int force = 0; | 1902 | int force = 0; |
1903 | int opt; | ||
1903 | 1904 | ||
1904 | /* Parse any options */ | 1905 | while ((opt = getopt(argc, argv, "cf123456789d")) != -1) { |
1905 | while (--argc > 0 && **(++argv) == '-') { | 1906 | switch (opt) { |
1906 | if (*((*argv) + 1) == '\0') { | 1907 | case 'c': |
1907 | tostdout = 1; | 1908 | tostdout = 1; |
1908 | } | 1909 | break; |
1909 | while (*(++(*argv))) { | 1910 | case 'f': |
1910 | switch (**argv) { | 1911 | force = 1; |
1911 | case 'c': | 1912 | break; |
1912 | tostdout = 1; | 1913 | /* Ignore 1-9 (compression level) options */ |
1913 | break; | 1914 | case '1': case '2': case '3': case '4': case '5': |
1914 | case 'f': | 1915 | case '6': case '7': case '8': case '9': |
1915 | force = 1; | 1916 | break; |
1916 | break; | ||
1917 | /* Ignore 1-9 (compression level) options */ | ||
1918 | case '1': case '2': case '3': case '4': case '5': | ||
1919 | case '6': case '7': case '8': case '9': | ||
1920 | break; | ||
1921 | #ifdef BB_GUNZIP | 1917 | #ifdef BB_GUNZIP |
1922 | case 'd': | 1918 | case 'd': |
1923 | exit(gunzip_main(argc, argv)); | 1919 | optind = 1; |
1920 | return gunzip_main(argc, argv); | ||
1924 | #endif | 1921 | #endif |
1925 | default: | 1922 | default: |
1926 | show_usage(); | 1923 | show_usage(); |
1927 | } | ||
1928 | } | 1924 | } |
1929 | } | 1925 | } |
1930 | if (argc <= 0 ) { | 1926 | if (optind == argc) { |
1931 | fromstdin = 1; | 1927 | fromstdin = 1; |
1932 | tostdout = 1; | 1928 | tostdout = 1; |
1933 | } | 1929 | } |
1934 | 1930 | ||
1935 | if (isatty(fileno(stdin)) && fromstdin==1 && force==0) | ||
1936 | error_msg_and_die( "data not read from terminal. Use -f to force it."); | ||
1937 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) | 1931 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) |
1938 | error_msg_and_die( "data not written to terminal. Use -f to force it."); | 1932 | error_msg_and_die( "compressed data not written to terminal. Use -f to force it."); |
1939 | 1933 | ||
1940 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | 1934 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; |
1941 | if (foreground) { | 1935 | if (foreground) { |
@@ -1975,9 +1969,7 @@ int gzip_main(int argc, char **argv) | |||
1975 | ifile_size = -1L; /* convention for unknown size */ | 1969 | ifile_size = -1L; /* convention for unknown size */ |
1976 | } else { | 1970 | } else { |
1977 | /* Open up the input file */ | 1971 | /* Open up the input file */ |
1978 | if (argc <= 0) | 1972 | strncpy(ifname, argv[optind], MAX_PATH_LEN); |
1979 | show_usage(); | ||
1980 | strncpy(ifname, *argv, MAX_PATH_LEN); | ||
1981 | 1973 | ||
1982 | /* Open input file */ | 1974 | /* Open input file */ |
1983 | inFileNum = open(ifname, O_RDONLY); | 1975 | inFileNum = open(ifname, O_RDONLY); |
@@ -91,7 +91,7 @@ extern int gunzip_main(int argc, char **argv) | |||
91 | if (strcmp(applet_name, "zcat") == 0) | 91 | if (strcmp(applet_name, "zcat") == 0) |
92 | flags |= gunzip_to_stdout; | 92 | flags |= gunzip_to_stdout; |
93 | 93 | ||
94 | while ((opt = getopt(argc, argv, "ctfh")) != -1) { | 94 | while ((opt = getopt(argc, argv, "ctfhd")) != -1) { |
95 | switch (opt) { | 95 | switch (opt) { |
96 | case 'c': | 96 | case 'c': |
97 | flags |= gunzip_to_stdout; | 97 | flags |= gunzip_to_stdout; |
@@ -102,6 +102,8 @@ extern int gunzip_main(int argc, char **argv) | |||
102 | case 't': | 102 | case 't': |
103 | flags |= gunzip_test; | 103 | flags |= gunzip_test; |
104 | break; | 104 | break; |
105 | case 'd': /* Used to convert gzip to gunzip. */ | ||
106 | break; | ||
105 | case 'h': | 107 | case 'h': |
106 | default: | 108 | default: |
107 | show_usage(); /* exit's inside usage */ | 109 | show_usage(); /* exit's inside usage */ |
@@ -1900,42 +1900,36 @@ int gzip_main(int argc, char **argv) | |||
1900 | int tostdout = 0; | 1900 | int tostdout = 0; |
1901 | int fromstdin = 0; | 1901 | int fromstdin = 0; |
1902 | int force = 0; | 1902 | int force = 0; |
1903 | int opt; | ||
1903 | 1904 | ||
1904 | /* Parse any options */ | 1905 | while ((opt = getopt(argc, argv, "cf123456789d")) != -1) { |
1905 | while (--argc > 0 && **(++argv) == '-') { | 1906 | switch (opt) { |
1906 | if (*((*argv) + 1) == '\0') { | 1907 | case 'c': |
1907 | tostdout = 1; | 1908 | tostdout = 1; |
1908 | } | 1909 | break; |
1909 | while (*(++(*argv))) { | 1910 | case 'f': |
1910 | switch (**argv) { | 1911 | force = 1; |
1911 | case 'c': | 1912 | break; |
1912 | tostdout = 1; | 1913 | /* Ignore 1-9 (compression level) options */ |
1913 | break; | 1914 | case '1': case '2': case '3': case '4': case '5': |
1914 | case 'f': | 1915 | case '6': case '7': case '8': case '9': |
1915 | force = 1; | 1916 | break; |
1916 | break; | ||
1917 | /* Ignore 1-9 (compression level) options */ | ||
1918 | case '1': case '2': case '3': case '4': case '5': | ||
1919 | case '6': case '7': case '8': case '9': | ||
1920 | break; | ||
1921 | #ifdef BB_GUNZIP | 1917 | #ifdef BB_GUNZIP |
1922 | case 'd': | 1918 | case 'd': |
1923 | exit(gunzip_main(argc, argv)); | 1919 | optind = 1; |
1920 | return gunzip_main(argc, argv); | ||
1924 | #endif | 1921 | #endif |
1925 | default: | 1922 | default: |
1926 | show_usage(); | 1923 | show_usage(); |
1927 | } | ||
1928 | } | 1924 | } |
1929 | } | 1925 | } |
1930 | if (argc <= 0 ) { | 1926 | if (optind == argc) { |
1931 | fromstdin = 1; | 1927 | fromstdin = 1; |
1932 | tostdout = 1; | 1928 | tostdout = 1; |
1933 | } | 1929 | } |
1934 | 1930 | ||
1935 | if (isatty(fileno(stdin)) && fromstdin==1 && force==0) | ||
1936 | error_msg_and_die( "data not read from terminal. Use -f to force it."); | ||
1937 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) | 1931 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) |
1938 | error_msg_and_die( "data not written to terminal. Use -f to force it."); | 1932 | error_msg_and_die( "compressed data not written to terminal. Use -f to force it."); |
1939 | 1933 | ||
1940 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | 1934 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; |
1941 | if (foreground) { | 1935 | if (foreground) { |
@@ -1975,9 +1969,7 @@ int gzip_main(int argc, char **argv) | |||
1975 | ifile_size = -1L; /* convention for unknown size */ | 1969 | ifile_size = -1L; /* convention for unknown size */ |
1976 | } else { | 1970 | } else { |
1977 | /* Open up the input file */ | 1971 | /* Open up the input file */ |
1978 | if (argc <= 0) | 1972 | strncpy(ifname, argv[optind], MAX_PATH_LEN); |
1979 | show_usage(); | ||
1980 | strncpy(ifname, *argv, MAX_PATH_LEN); | ||
1981 | 1973 | ||
1982 | /* Open input file */ | 1974 | /* Open input file */ |
1983 | inFileNum = open(ifname, O_RDONLY); | 1975 | inFileNum = open(ifname, O_RDONLY); |