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