]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/Split/Split.c
3 Split a file into two pieces at the request offset.
5 Copyright (c) 1999-2008 Intel Corporation. All rights reserved
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 /*++
25 #include "CommonLib.h"
26 #include "EfiUtilityMsgs.h"
30 #define UTILITY_NAME "Split"
33 // Utility version information
35 #define UTILITY_MAJOR_VERSION 0
36 #define UTILITY_MINOR_VERSION 1
46 Displays the standard utility information to SDTOUT
58 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
);
59 printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");
70 GC_TODO: Add function description
77 GC_TODO: add return values
84 -f, --filename inputFile to split\n\
85 -s, --split VALUE the number of bytes in the first file\n\
86 [-p, --prefix OutputDir]\n\
87 [-o, --firstfile Filename1]\n\
88 [-t, --secondfile Filename2]\n\
91 [-q, --quiet disable all messages except fatal errors]\n\
98 IN CONST CHAR8
* SplitValueString
,
99 OUT UINT64
*ReturnValue
102 UINT64 len
= strlen(SplitValueString
);
107 EFI_STATUS Status
= EFI_SUCCESS
;
113 Status
= AsciiStringToUint64 (SplitValueString
, FALSE
, ReturnValue
);
114 if (!EFI_ERROR (Status
)) {
118 if (SplitValueString
[0] == '0' && (SplitValueString
[1] == 'x' || SplitValueString
[1] == 'X')) {
119 Status
= AsciiStringToUint64 (SplitValueString
, TRUE
, ReturnValue
);
120 if (!EFI_ERROR (Status
)) {
125 lastCHAR
= (CHAR8
)toupper(SplitValueString
[len
- 1]);
127 if (lastCHAR
!= 'K' && lastCHAR
!= 'M' && lastCHAR
!= 'G') {
131 for (;index
< len
- 1; ++index
) {
132 if (!isdigit(SplitValueString
[index
])) {
137 number
= atol (SplitValueString
);
140 else if (lastCHAR
== 'M')
143 base
= 1024*1024*1024;
145 *ReturnValue
= number
*base
;
152 IN CONST CHAR8
* VerboseLevelString
,
153 IN CONST UINT64 Length
,
154 OUT UINT64
*ReturnValue
158 for (;i
< Length
; ++i
) {
159 if (VerboseLevelString
[i
] != 'v' && VerboseLevelString
[i
] != 'V') {
170 IN OUT CHAR8
** FullFileName
173 CHAR8
* temp
= *FullFileName
;
177 for (;index
< strlen(temp
); ++index
) {
178 if (temp
[index
] == '\\' || temp
[index
] == '/') {
181 if (mkdir(start
, S_IRWXU
| S_IRWXG
| S_IRWXO
) != 0) {
186 start
= temp
+ index
+ 1;
203 GC_TODO: Add function description
207 argc - GC_TODO: add argument description
208 ] - GC_TODO: add argument description
212 GC_TODO: add return values
216 EFI_STATUS Status
= EFI_SUCCESS
;
218 CHAR8
*InputFileName
= NULL
;
219 CHAR8
*OutputDir
= NULL
;
220 CHAR8
*OutFileName1
= NULL
;
221 CHAR8
*OutFileName2
= NULL
;
222 UINT64 SplitValue
= -1;
225 CHAR8
*OutName1
= NULL
;
226 CHAR8
*OutName2
= NULL
;
227 CHAR8
*CurrentDir
= NULL
;
230 BOOLEAN QuietFlag
= TRUE
;
231 UINT64 DebugLevel
= 0;
232 UINT64 VerboseLevel
= 0;
234 SetUtilityName(UTILITY_NAME
);
243 if ((stricmp (argv
[0], "-h") == 0) || (stricmp (argv
[0], "--help") == 0)) {
245 return STATUS_SUCCESS
;
248 if (stricmp (argv
[0], "--version") == 0) {
250 return STATUS_SUCCESS
;
254 if ((stricmp (argv
[0], "-p") == 0) || (stricmp (argv
[0], "--prefix") == 0)) {
256 if (OutputDir
== NULL
) {
257 Warning (NULL
, 0, 0, "NO output directory specified.", NULL
);
265 if ((stricmp (argv
[0], "-f") == 0) || (stricmp (argv
[0], "--filename") == 0)) {
266 InputFileName
= argv
[1];
267 if (InputFileName
== NULL
) {
268 Error (NULL
, 0, 0x1001, "NO Input file specified.", NULL
);
276 if ((stricmp (argv
[0], "-s") == 0) || (stricmp (argv
[0], "--split") == 0)) {
277 Status
= GetSplitValue(argv
[1], &SplitValue
);
278 if (EFI_ERROR (Status
)) {
279 Error (NULL
, 0, 0x1003, "Input split value is not one valid integer.", NULL
);
287 if ((stricmp (argv
[0], "-o") == 0) || (stricmp (argv
[0], "--firstfile") == 0)) {
288 OutFileName1
= argv
[1];
289 if (OutFileName1
== NULL
) {
290 Warning (NULL
, 0, 0, NULL
, "No output file1 specified.");
297 if ((stricmp (argv
[0], "-t") == 0) || (stricmp (argv
[0], "--secondfile") == 0)) {
298 OutFileName2
= argv
[1];
299 if (OutFileName2
== NULL
) {
300 Warning (NULL
, 0, 0, NULL
, "No output file2 specified.");
307 if ((stricmp (argv
[0], "-q") == 0) || (stricmp (argv
[0], "--quiet") == 0)) {
314 if ((strlen(argv
[0]) >= 2 && argv
[0][0] == '-' && (argv
[0][1] == 'v' || argv
[0][1] == 'V')) || (stricmp (argv
[0], "--verbose") == 0)) {
316 if (strlen(argv
[0]) > 2) {
317 Status
= CountVerboseLevel (&argv
[0][2], strlen(argv
[0]) - 2, &VerboseLevel
);
318 if (EFI_ERROR (Status
)) {
319 Error (NULL
, 0, 0x1003, NULL
, "%s is invaild paramter!", argv
[0]);
329 if ((stricmp (argv
[0], "-d") == 0) || (stricmp (argv
[0], "--debug") == 0)) {
330 Status
= AsciiStringToUint64 (argv
[1], FALSE
, &DebugLevel
);
331 if (EFI_ERROR (Status
)) {
332 Error (NULL
, 0, 0x1003, "Input debug level is not one valid integrator.", NULL
);
340 // Don't recognize the paramter.
342 Error (NULL
, 0, 0x1003, NULL
, "%s is invaild paramter!", argv
[0]);
346 if (InputFileName
== NULL
) {
347 Error (NULL
, 0, 0x1001, "NO Input file specified.", NULL
);
351 In
= fopen (InputFileName
, "rb");
353 // ("Unable to open file \"%s\"\n", InputFileName);
354 Error (InputFileName
, 0, 1, "File open failure", NULL
);
358 if (OutFileName1
== NULL
) {
359 OutName1
= (CHAR8
*)malloc(strlen(InputFileName
) + 16);
360 if (OutName1
== NULL
) {
361 Warning (NULL
, 0, 0, NULL
, "Memory Allocation Fail.");
364 strcpy (OutName1
, InputFileName
);
365 strcat (OutName1
, "1");
366 OutFileName1
= OutName1
;
369 if (OutFileName2
== NULL
) {
370 OutName2
= (CHAR8
*)malloc(strlen(InputFileName
) + 16);
371 if (OutName2
== NULL
) {
372 Warning (NULL
, 0, 0, NULL
, "Memory Allocation Fail.");
375 strcpy (OutName2
, InputFileName
);
376 strcat (OutName2
, "2");
377 OutFileName2
= OutName2
;
381 if (OutputDir
!= NULL
) {
382 //OutputDirSpecified = TRUE;
383 if (chdir(OutputDir
) != 0) {
384 Warning (NULL
, 0, 0, NULL
, "Change dir to OutputDir Fail.");
389 CurrentDir
= (CHAR8
*)getcwd((CHAR8
*)0, 0);
390 if (EFI_ERROR(CreateDir(&OutFileName1
))) {
391 Error (OutFileName1
, 0, 5, "Create Dir for File1 Fail.", NULL
);
396 if (EFI_ERROR(CreateDir(&OutFileName2
))) {
397 Error (OutFileName2
, 0, 5, "Create Dir for File2 Fail.", NULL
);
403 Out1
= fopen (OutFileName1
, "wb");
405 // ("Unable to open file \"%s\"\n", OutFileName1);
406 Error (OutFileName1
, 0, 1, "File open failure", NULL
);
410 Out2
= fopen (OutFileName2
, "wb");
412 // ("Unable to open file \"%s\"\n", OutFileName2);
413 Error (OutFileName2
, 0, 1, "File open failure", NULL
);
417 for (Index
= 0; Index
< SplitValue
; Index
++) {
418 CharC
= (CHAR8
) fgetc (In
);
427 CharC
= (CHAR8
) fgetc (In
);
435 if (OutName1
!= NULL
) {
438 if (OutName2
!= NULL
) {
445 return STATUS_SUCCESS
;