3 Split a file into two pieces at the request offset.
5 Copyright (c) 1999 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 // GC_TODO: fix comment to start with /*++
27 #include "CommonLib.h"
28 #include "EfiUtilityMsgs.h"
32 #define UTILITY_NAME "Split"
35 // Utility version information
37 #define UTILITY_MAJOR_VERSION 0
38 #define UTILITY_MINOR_VERSION 1
48 Displays the standard utility information to SDTOUT
60 printf ("%s v%d.%d -Utility to break a file into two pieces at the request offset.\n", UTILITY_NAME
, UTILITY_MAJOR_VERSION
, UTILITY_MINOR_VERSION
);
61 printf ("Copyright (c) 1999-2010 Intel Corporation. All rights reserved.\n");
72 GC_TODO: Add function description
79 GC_TODO: add return values
86 -f, --filename inputFile to split\n\
87 -s, --split VALUE the number of bytes in the first file\n\
88 [-p, --prefix OutputDir]\n\
89 [-o, --firstfile Filename1]\n\
90 [-t, --secondfile Filename2]\n\
93 [-q, --quiet disable all messages except fatal errors]\n\
100 IN CONST CHAR8
* SplitValueString
,
101 OUT UINT64
*ReturnValue
104 UINT64 len
= strlen(SplitValueString
);
109 EFI_STATUS Status
= EFI_SUCCESS
;
115 Status
= AsciiStringToUint64 (SplitValueString
, FALSE
, ReturnValue
);
116 if (!EFI_ERROR (Status
)) {
120 if (SplitValueString
[0] == '0' && (SplitValueString
[1] == 'x' || SplitValueString
[1] == 'X')) {
121 Status
= AsciiStringToUint64 (SplitValueString
, TRUE
, ReturnValue
);
122 if (!EFI_ERROR (Status
)) {
127 lastCHAR
= (CHAR8
)toupper((int)SplitValueString
[len
- 1]);
129 if (lastCHAR
!= 'K' && lastCHAR
!= 'M' && lastCHAR
!= 'G') {
133 for (;index
< len
- 1; ++index
) {
134 if (!isdigit((int)SplitValueString
[index
])) {
139 number
= atol (SplitValueString
);
142 else if (lastCHAR
== 'M')
145 base
= 1024*1024*1024;
147 *ReturnValue
= number
*base
;
154 IN CONST CHAR8
* VerboseLevelString
,
155 IN CONST UINT64 Length
,
156 OUT UINT64
*ReturnValue
160 for (;i
< Length
; ++i
) {
161 if (VerboseLevelString
[i
] != 'v' && VerboseLevelString
[i
] != 'V') {
172 IN OUT CHAR8
** FullFileName
175 CHAR8
* temp
= *FullFileName
;
179 for (;index
< strlen(temp
); ++index
) {
180 if (temp
[index
] == '\\' || temp
[index
] == '/') {
183 if (mkdir(start
, S_IRWXU
| S_IRWXG
| S_IRWXO
) != 0) {
188 start
= temp
+ index
+ 1;
205 GC_TODO: Add function description
209 argc - GC_TODO: add argument description
210 ] - GC_TODO: add argument description
214 GC_TODO: add return values
218 EFI_STATUS Status
= EFI_SUCCESS
;
220 CHAR8
*InputFileName
= NULL
;
221 CHAR8
*OutputDir
= NULL
;
222 CHAR8
*OutFileName1
= NULL
;
223 CHAR8
*OutFileName2
= NULL
;
224 UINT64 SplitValue
= (UINT64
) -1;
227 CHAR8
*OutName1
= NULL
;
228 CHAR8
*OutName2
= NULL
;
229 CHAR8
*CurrentDir
= NULL
;
232 BOOLEAN QuietFlag
= TRUE
;
233 UINT64 DebugLevel
= 0;
234 UINT64 VerboseLevel
= 0;
236 SetUtilityName(UTILITY_NAME
);
245 if ((stricmp (argv
[0], "-h") == 0) || (stricmp (argv
[0], "--help") == 0)) {
247 return STATUS_SUCCESS
;
250 if (stricmp (argv
[0], "--version") == 0) {
252 return STATUS_SUCCESS
;
256 if ((stricmp (argv
[0], "-p") == 0) || (stricmp (argv
[0], "--prefix") == 0)) {
258 if (OutputDir
== NULL
) {
259 Warning (NULL
, 0, 0, "NO output directory specified.", NULL
);
267 if ((stricmp (argv
[0], "-f") == 0) || (stricmp (argv
[0], "--filename") == 0)) {
268 InputFileName
= argv
[1];
269 if (InputFileName
== NULL
) {
270 Error (NULL
, 0, 0x1001, "NO Input file specified.", NULL
);
278 if ((stricmp (argv
[0], "-s") == 0) || (stricmp (argv
[0], "--split") == 0)) {
279 Status
= GetSplitValue(argv
[1], &SplitValue
);
280 if (EFI_ERROR (Status
)) {
281 Error (NULL
, 0, 0x1003, "Input split value is not one valid integer.", NULL
);
289 if ((stricmp (argv
[0], "-o") == 0) || (stricmp (argv
[0], "--firstfile") == 0)) {
290 OutFileName1
= argv
[1];
291 if (OutFileName1
== NULL
) {
292 Warning (NULL
, 0, 0, NULL
, "No output file1 specified.");
299 if ((stricmp (argv
[0], "-t") == 0) || (stricmp (argv
[0], "--secondfile") == 0)) {
300 OutFileName2
= argv
[1];
301 if (OutFileName2
== NULL
) {
302 Warning (NULL
, 0, 0, NULL
, "No output file2 specified.");
309 if ((stricmp (argv
[0], "-q") == 0) || (stricmp (argv
[0], "--quiet") == 0)) {
316 if ((strlen(argv
[0]) >= 2 && argv
[0][0] == '-' && (argv
[0][1] == 'v' || argv
[0][1] == 'V')) || (stricmp (argv
[0], "--verbose") == 0)) {
318 if (strlen(argv
[0]) > 2) {
319 Status
= CountVerboseLevel (&argv
[0][2], strlen(argv
[0]) - 2, &VerboseLevel
);
320 if (EFI_ERROR (Status
)) {
321 Error (NULL
, 0, 0x1003, NULL
, "%s is invaild paramter!", argv
[0]);
331 if ((stricmp (argv
[0], "-d") == 0) || (stricmp (argv
[0], "--debug") == 0)) {
332 Status
= AsciiStringToUint64 (argv
[1], FALSE
, &DebugLevel
);
333 if (EFI_ERROR (Status
)) {
334 Error (NULL
, 0, 0x1003, "Input debug level is not one valid integrator.", NULL
);
342 // Don't recognize the paramter.
344 Error (NULL
, 0, 0x1003, NULL
, "%s is invaild paramter!", argv
[0]);
348 if (InputFileName
== NULL
) {
349 Error (NULL
, 0, 0x1001, "NO Input file specified.", NULL
);
353 In
= fopen (InputFileName
, "rb");
355 // ("Unable to open file \"%s\"\n", InputFileName);
356 Error (InputFileName
, 0, 1, "File open failure", NULL
);
360 if (OutFileName1
== NULL
) {
361 OutName1
= (CHAR8
*)malloc(strlen(InputFileName
) + 16);
362 if (OutName1
== NULL
) {
363 Warning (NULL
, 0, 0, NULL
, "Memory Allocation Fail.");
366 strcpy (OutName1
, InputFileName
);
367 strcat (OutName1
, "1");
368 OutFileName1
= OutName1
;
371 if (OutFileName2
== NULL
) {
372 OutName2
= (CHAR8
*)malloc(strlen(InputFileName
) + 16);
373 if (OutName2
== NULL
) {
374 Warning (NULL
, 0, 0, NULL
, "Memory Allocation Fail.");
377 strcpy (OutName2
, InputFileName
);
378 strcat (OutName2
, "2");
379 OutFileName2
= OutName2
;
383 if (OutputDir
!= NULL
) {
384 //OutputDirSpecified = TRUE;
385 if (chdir(OutputDir
) != 0) {
386 Warning (NULL
, 0, 0, NULL
, "Change dir to OutputDir Fail.");
391 CurrentDir
= (CHAR8
*)getcwd((CHAR8
*)0, 0);
392 if (EFI_ERROR(CreateDir(&OutFileName1
))) {
393 Error (OutFileName1
, 0, 5, "Create Dir for File1 Fail.", NULL
);
398 if (EFI_ERROR(CreateDir(&OutFileName2
))) {
399 Error (OutFileName2
, 0, 5, "Create Dir for File2 Fail.", NULL
);
405 Out1
= fopen (OutFileName1
, "wb");
407 // ("Unable to open file \"%s\"\n", OutFileName1);
408 Error (OutFileName1
, 0, 1, "File open failure", NULL
);
412 Out2
= fopen (OutFileName2
, "wb");
414 // ("Unable to open file \"%s\"\n", OutFileName2);
415 Error (OutFileName2
, 0, 1, "File open failure", NULL
);
419 for (Index
= 0; Index
< SplitValue
; Index
++) {
420 CharC
= (CHAR8
) fgetc (In
);
429 CharC
= (CHAR8
) fgetc (In
);
437 if (OutName1
!= NULL
) {
440 if (OutName2
!= NULL
) {
447 return STATUS_SUCCESS
;