]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/SplitFile/splitfile.c
Sync all bug fixes between EDK1.04 and EDK1.06 into EdkCompatibilityPkg.
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / SplitFile / splitfile.c
1 /*++
2
3 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 splitfile.c
15
16 Abstract:
17
18 --*/
19
20 #include "stdio.h"
21 #include "string.h"
22 #include "stdlib.h"
23
24 #define UTILITY_NAME "SplitFile"
25 #define UTILITY_VERSION "v1.0"
26
27 void
28 helpmsg (
29 void
30 )
31 /*++
32
33 Routine Description:
34
35 GC_TODO: Add function description
36
37 Arguments:
38
39
40 Returns:
41
42 GC_TODO: add return values
43
44 --*/
45 {
46 int Index;
47 const char *Str[] = {
48 UTILITY_NAME" "UTILITY_VERSION" - Intel Split File Utility",
49 " Copyright (C), 2006 - 2008 Intel Corporation",
50
51 #if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )
52 " Built from "UTILITY_BUILD", project of "UTILITY_VENDOR,
53 #endif
54 "",
55 "Usage:",
56 " "UTILITY_NAME" FILE OFFSET",
57 "Description:",
58 " Break the FILE in two pieces FILE1 and FILE2 at the requested OFFSET.",
59 NULL
60 };
61 for (Index = 0; Str[Index] != NULL; Index++) {
62 fprintf (stdout, "%s\n", Str[Index]);
63 }
64 }
65
66 int
67 main (
68 int argc,
69 char*argv[]
70 )
71 /*++
72
73 Routine Description:
74
75 GC_TODO: Add function description
76
77 Arguments:
78
79 argc - GC_TODO: add argument description
80 argv - GC_TODO: add argument description
81
82 Returns:
83
84 GC_TODO: add return values
85
86 --*/
87 {
88 FILE *In;
89
90 FILE *Out1;
91
92 FILE *Out2;
93 char OutName1[512];
94 char OutName2[512];
95 unsigned long Index;
96 unsigned long splitpoint;
97 char CharC;
98
99 if (argc != 3) {
100 helpmsg ();
101 return -1;
102 }
103
104 In = fopen (argv[1], "rb");
105 if (In == NULL) {
106 printf ("Unable to open file \"%s\"\n", argv[1]);
107 return -1;
108 }
109
110 strncpy (OutName1, argv[1], 510);
111 strncpy (OutName2, argv[1], 510);
112 strcat (OutName1, "1");
113 strcat (OutName2, "2");
114
115 Out1 = fopen (OutName1, "wb");
116 if (Out1 == NULL) {
117 printf ("Unable to open file \"%s\"\n", OutName1);
118 return -1;
119 }
120
121 Out2 = fopen (OutName2, "wb");
122 if (Out2 == NULL) {
123 printf ("Unable to open file \"%s\"\n", OutName2);
124 return -1;
125 }
126
127 splitpoint = atoi (argv[2]);
128
129 for (Index = 0; Index < splitpoint; Index++) {
130 CharC = (char) fgetc (In);
131 if (feof (In)) {
132 break;
133 }
134
135 fputc (CharC, Out1);
136 }
137
138 for (;;) {
139 CharC = (char) fgetc (In);
140 if (feof (In)) {
141 break;
142 }
143
144 fputc (CharC, Out2);
145 }
146
147 fclose (In);
148 fclose (Out1);
149 fclose (Out2);
150
151 return 0;
152 }