]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/TianoTools/EfiCompress/EfiCompressMain.c
Porting several more tools to edk2.
[mirror_edk2.git] / Tools / Source / TianoTools / EfiCompress / EfiCompressMain.c
CommitLineData
d25c4bf0 1/*++\r
2\r
3Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved\r
4This software and associated documentation (if any) is furnished\r
5under a license and may only be used or copied in accordance\r
6with the terms of the license. Except as permitted by such\r
7license, no part of this software or documentation may be\r
8reproduced, stored in a retrieval system, or transmitted in any\r
9form or by any means without the express written consent of\r
10Intel Corporation.\r
11\r
12\r
13Module Name:\r
14 \r
15 EfiCompressMain.c\r
16\r
17Abstract:\r
18\r
19 The main function for the compression utility.\r
20 \r
21--*/\r
22\r
23#include <stdlib.h>\r
24#include <string.h>\r
25#include <ctype.h>\r
26#include <stdarg.h>\r
27#include <stdio.h>\r
51d48c26 28#include <UefiBaseTypes.h>\r
29#include <Base.h>\r
d25c4bf0 30#include "EfiCompress.h"\r
31\r
32int\r
33main (\r
34 INT32 argc,\r
35 CHAR8 *argv[]\r
36 )\r
37/*++\r
38\r
39Routine Description:\r
40\r
41 Compresses the input files\r
42\r
43Arguments:\r
44\r
45 argc - number of arguments passed into the command line.\r
46 argv[] - files to compress and files to output compressed data to.\r
47\r
48Returns:\r
49\r
50 int: 0 for successful execution of the function.\r
51\r
52--*/\r
53{\r
54 EFI_STATUS Status;\r
55 FILE *infile;\r
56 FILE *outfile;\r
57 UINT32 SrcSize;\r
58 UINT32 DstSize;\r
59 UINT8 *SrcBuffer;\r
60 UINT8 *DstBuffer;\r
61 UINT8 Buffer[8];\r
62\r
63 //\r
64 // Added for makefile debug - KCE\r
65 //\r
66 INT32 arg_counter;\r
67 printf ("\n\n");\r
68 for (arg_counter = 0; arg_counter < argc; arg_counter++) {\r
69 printf ("%s ", argv[arg_counter]);\r
70 }\r
71\r
72 printf ("\n\n");\r
73\r
74 SrcBuffer = DstBuffer = NULL;\r
75\r
76 infile = outfile = NULL;\r
77\r
78 if (argc != 3) {\r
79 printf ("Usage: EFICOMPRESS <infile> <outfile>\n");\r
80 goto Done;\r
81 }\r
82\r
83 if ((outfile = fopen (argv[2], "wb")) == NULL) {\r
84 printf ("Can't open output file\n");\r
85 goto Done;\r
86 }\r
87\r
88 if ((infile = fopen (argv[1], "rb")) == NULL) {\r
89 printf ("Can't open input file\n");\r
90 goto Done;\r
91 }\r
92 //\r
93 // Get the size of source file\r
94 //\r
95 SrcSize = 0;\r
96 while (fread (Buffer, 1, 1, infile)) {\r
97 SrcSize++;\r
98\r
99 }\r
100 //\r
101 // Read in the source data\r
102 //\r
103 if ((SrcBuffer = malloc (SrcSize)) == NULL) {\r
104 printf ("Can't allocate memory\n");\r
105 goto Done;\r
106 }\r
107\r
108 rewind (infile);\r
109 if (fread (SrcBuffer, 1, SrcSize, infile) != SrcSize) {\r
110 printf ("Can't read from source\n");\r
111 goto Done;\r
112 }\r
113 //\r
114 // Get destination data size and do the compression\r
115 //\r
116 DstSize = 0;\r
117 Status = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);\r
118 if (Status == EFI_BUFFER_TOO_SMALL) {\r
119 if ((DstBuffer = malloc (DstSize)) == NULL) {\r
120 printf ("Can't allocate memory\n");\r
121 goto Done;\r
122 }\r
123\r
124 Status = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);\r
125 }\r
126\r
127 if (EFI_ERROR (Status)) {\r
128 printf ("Compress Error\n");\r
129 goto Done;\r
130 }\r
131\r
132 printf ("\nOrig Size = %ld\n", SrcSize);\r
133 printf ("Comp Size = %ld\n", DstSize);\r
134\r
135 if (DstBuffer == NULL) {\r
136 printf ("No destination to write to.\n");\r
137 goto Done;\r
138 }\r
139 //\r
140 // Write out the result\r
141 //\r
142 if (fwrite (DstBuffer, 1, DstSize, outfile) != DstSize) {\r
143 printf ("Can't write to destination file\n");\r
144 }\r
145\r
146Done:\r
147 if (SrcBuffer) {\r
148 free (SrcBuffer);\r
149 }\r
150\r
151 if (DstBuffer) {\r
152 free (DstBuffer);\r
153 }\r
154\r
155 if (infile) {\r
156 fclose (infile);\r
157 }\r
158\r
159 if (outfile) {\r
160 fclose (outfile);\r
161 }\r
162\r
163 return 0;\r
164}\r