OLD | NEW |
1 /////////////////////////////////////////////////////////////////////////////// | 1 /////////////////////////////////////////////////////////////////////////////// |
2 // | 2 // |
3 /// \file lzmainfo.c | 3 /// \file lzmainfo.c |
4 /// \brief lzmainfo tool for compatibility with LZMA Utils | 4 /// \brief lzmainfo tool for compatibility with LZMA Utils |
5 // | 5 // |
6 // Author: Lasse Collin | 6 // Author: Lasse Collin |
7 // | 7 // |
8 // This file has been put into the public domain. | 8 // This file has been put into the public domain. |
9 // You can do whatever you want with this file. | 9 // You can do whatever you want with this file. |
10 // | 10 // |
11 /////////////////////////////////////////////////////////////////////////////// | 11 /////////////////////////////////////////////////////////////////////////////// |
12 | 12 |
13 #include "sysdefs.h" | 13 #include "sysdefs.h" |
14 #include <stdio.h> | 14 #include <stdio.h> |
15 #include <errno.h> | 15 #include <errno.h> |
16 | 16 |
17 #include "lzma.h" | 17 #include "lzma.h" |
18 #include "getopt.h" | 18 #include "getopt.h" |
19 #include "tuklib_gettext.h" | 19 #include "tuklib_gettext.h" |
20 #include "tuklib_progname.h" | 20 #include "tuklib_progname.h" |
21 #include "tuklib_exit.h" | 21 #include "tuklib_exit.h" |
22 | 22 |
| 23 #ifdef TUKLIB_DOSLIKE |
| 24 # include <fcntl.h> |
| 25 # include <io.h> |
| 26 #endif |
23 | 27 |
24 static void lzma_attribute((noreturn)) | 28 |
| 29 static void lzma_attribute((__noreturn__)) |
25 help(void) | 30 help(void) |
26 { | 31 { |
27 printf( | 32 printf( |
28 _("Usage: %s [--help] [--version] [FILE]...\n" | 33 _("Usage: %s [--help] [--version] [FILE]...\n" |
29 "Show information stored in the .lzma file header"), progname); | 34 "Show information stored in the .lzma file header"), progname); |
30 | 35 |
31 printf(_( | 36 printf(_( |
32 "\nWith no FILE, or when FILE is -, read standard input.\n")); | 37 "\nWith no FILE, or when FILE is -, read standard input.\n")); |
33 printf("\n"); | 38 printf("\n"); |
34 | 39 |
35 printf(_("Report bugs to <%s> (in English or Finnish).\n"), | 40 printf(_("Report bugs to <%s> (in English or Finnish).\n"), |
36 PACKAGE_BUGREPORT); | 41 PACKAGE_BUGREPORT); |
37 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL); | 42 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL); |
38 | 43 |
39 tuklib_exit(EXIT_SUCCESS, EXIT_FAILURE, true); | 44 tuklib_exit(EXIT_SUCCESS, EXIT_FAILURE, true); |
40 } | 45 } |
41 | 46 |
42 | 47 |
43 static void lzma_attribute((noreturn)) | 48 static void lzma_attribute((__noreturn__)) |
44 version(void) | 49 version(void) |
45 { | 50 { |
46 » puts("lzmainfo (" PACKAGE_NAME ") " PACKAGE_VERSION); | 51 » puts("lzmainfo (" PACKAGE_NAME ") " LZMA_VERSION_STRING); |
47 tuklib_exit(EXIT_SUCCESS, EXIT_FAILURE, true); | 52 tuklib_exit(EXIT_SUCCESS, EXIT_FAILURE, true); |
48 } | 53 } |
49 | 54 |
50 | 55 |
51 /// Parse command line options. | 56 /// Parse command line options. |
52 static void | 57 static void |
53 parse_args(int argc, char **argv) | 58 parse_args(int argc, char **argv) |
54 { | 59 { |
55 enum { | 60 enum { |
56 OPT_HELP, | 61 OPT_HELP, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 printf("Unknown"); | 148 printf("Unknown"); |
144 else | 149 else |
145 printf("%" PRIu64 " MB (%" PRIu64 " bytes)", | 150 printf("%" PRIu64 " MB (%" PRIu64 " bytes)", |
146 (uncompressed_size + 512 * 1024) | 151 (uncompressed_size + 512 * 1024) |
147 / (1024 * 1024), | 152 / (1024 * 1024), |
148 uncompressed_size); | 153 uncompressed_size); |
149 | 154 |
150 lzma_options_lzma *opt = filter.options; | 155 lzma_options_lzma *opt = filter.options; |
151 | 156 |
152 printf("\nDictionary size: " | 157 printf("\nDictionary size: " |
153 » » » "%u MB (2^%u bytes)\n" | 158 » » » "%" PRIu32 " MB (2^%" PRIu32 " bytes)\n" |
154 "Literal context bits (lc): %" PRIu32 "\n" | 159 "Literal context bits (lc): %" PRIu32 "\n" |
155 "Literal pos bits (lp): %" PRIu32 "\n" | 160 "Literal pos bits (lp): %" PRIu32 "\n" |
156 "Number of pos bits (pb): %" PRIu32 "\n", | 161 "Number of pos bits (pb): %" PRIu32 "\n", |
157 (opt->dict_size + 512 * 1024) / (1024 * 1024), | 162 (opt->dict_size + 512 * 1024) / (1024 * 1024), |
158 my_log2(opt->dict_size), opt->lc, opt->lp, opt->pb); | 163 my_log2(opt->dict_size), opt->lc, opt->lp, opt->pb); |
159 | 164 |
160 free(opt); | 165 free(opt); |
161 | 166 |
162 return false; | 167 return false; |
163 } | 168 } |
164 | 169 |
165 | 170 |
166 extern int | 171 extern int |
167 main(int argc, char **argv) | 172 main(int argc, char **argv) |
168 { | 173 { |
169 tuklib_progname_init(argv); | 174 tuklib_progname_init(argv); |
170 tuklib_gettext_init(PACKAGE, LOCALEDIR); | 175 tuklib_gettext_init(PACKAGE, LOCALEDIR); |
171 | 176 |
172 parse_args(argc, argv); | 177 parse_args(argc, argv); |
173 | 178 |
| 179 #ifdef TUKLIB_DOSLIKE |
| 180 setmode(fileno(stdin), O_BINARY); |
| 181 #endif |
| 182 |
174 int ret = EXIT_SUCCESS; | 183 int ret = EXIT_SUCCESS; |
175 | 184 |
176 // We print empty lines around the output only when reading from | 185 // We print empty lines around the output only when reading from |
177 // files specified on the command line. This is due to how | 186 // files specified on the command line. This is due to how |
178 // LZMA Utils did it. | 187 // LZMA Utils did it. |
179 if (optind == argc) { | 188 if (optind == argc) { |
180 if (lzmainfo("(stdin)", stdin)) | 189 if (lzmainfo("(stdin)", stdin)) |
181 ret = EXIT_FAILURE; | 190 ret = EXIT_FAILURE; |
182 } else { | 191 } else { |
183 printf("\n"); | 192 printf("\n"); |
(...skipping 17 matching lines...) Expand all Loading... |
201 ret = EXIT_FAILURE; | 210 ret = EXIT_FAILURE; |
202 | 211 |
203 printf("\n"); | 212 printf("\n"); |
204 fclose(f); | 213 fclose(f); |
205 } | 214 } |
206 } while (++optind < argc); | 215 } while (++optind < argc); |
207 } | 216 } |
208 | 217 |
209 tuklib_exit(ret, EXIT_FAILURE, true); | 218 tuklib_exit(ret, EXIT_FAILURE, true); |
210 } | 219 } |
OLD | NEW |