]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/SplitFile/SplitFile.c
remove unnecessary check for NULL pointer.
[mirror_edk2.git] / Tools / CCode / Source / SplitFile / SplitFile.c
1 /*
2
3 Copyright (c) 1999-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 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 */
13
14 // GC_TODO: fix comment to start with /*++
15 #include "stdio.h"
16 #include "string.h"
17 #include "stdlib.h"
18
19 //
20 // Utility Name
21 //
22 #define UTILITY_NAME "SplitFile"
23
24 //
25 // Utility version information
26 //
27 #define UTILITY_MAJOR_VERSION 0
28 #define UTILITY_MINOR_VERSION 1
29
30 void
31 Version (
32 void
33 )
34 /*++
35
36 Routine Description:
37
38 Displays the standard utility information to SDTOUT
39
40 Arguments:
41
42 None
43
44 Returns:
45
46 None
47
48 --*/
49 {
50 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);
51 printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");
52 }
53
54 void
55 Usage (
56 void
57 )
58 /*++
59
60 Routine Description:
61
62 GC_TODO: Add function description
63
64 Arguments:
65
66
67 Returns:
68
69 GC_TODO: add return values
70
71 --*/
72 {
73 Version();
74 printf ("\nUsage: \n\
75 SplitFile Filename Offset\n\
76 where:\n\
77 Filename: Input file to split\n\
78 Offset: offset at which to split file\n\
79 The output files will be named <Filename>1 and <Filename>2 with \n\
80 <Filename> being given as the input file name.\n");
81 }
82
83 int
84 main (
85 int argc,
86 char*argv[]
87 )
88 /*++
89
90 Routine Description:
91
92 GC_TODO: Add function description
93
94 Arguments:
95
96 argc - GC_TODO: add argument description
97 ] - GC_TODO: add argument description
98
99 Returns:
100
101 GC_TODO: add return values
102
103 --*/
104 {
105 FILE *In;
106
107 FILE *Out1;
108
109 FILE *Out2;
110 char OutName1[512];
111 char OutName2[512];
112 unsigned long Index;
113 unsigned long splitpoint;
114 char CharC;
115
116 if (argc == 1) {
117 Usage();
118 return -1;
119 }
120
121 if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0) ||
122 (strcmp(argv[1], "-?") == 0) || (strcmp(argv[1], "/?") == 0)) {
123 Usage();
124 return -1;
125 }
126
127 if ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0)) {
128 Version();
129 return -1;
130 }
131
132 if (argc != 3) {
133 Usage ();
134 return -1;
135 }
136
137 In = fopen (argv[1], "rb");
138 if (In == NULL) {
139 printf ("Unable to open file \"%s\"\n", argv[1]);
140 return -1;
141 }
142
143 strncpy (OutName1, argv[1], 510);
144 strncpy (OutName2, argv[1], 510);
145 strcat (OutName1, "1");
146 strcat (OutName2, "2");
147
148 Out1 = fopen (OutName1, "wb");
149 if (Out1 == NULL) {
150 printf ("Unable to open file \"%s\"\n", OutName1);
151 return -1;
152 }
153
154 Out2 = fopen (OutName2, "wb");
155 if (Out2 == NULL) {
156 printf ("Unable to open file \"%s\"\n", OutName2);
157 return -1;
158 }
159
160 splitpoint = atoi (argv[2]);
161
162 for (Index = 0; Index < splitpoint; Index++) {
163 CharC = (char) fgetc (In);
164 if (feof (In)) {
165 break;
166 }
167
168 fputc (CharC, Out1);
169 }
170
171 for (;;) {
172 CharC = (char) fgetc (In);
173 if (feof (In)) {
174 break;
175 }
176
177 fputc (CharC, Out2);
178 }
179
180 fclose (In);
181 fclose (Out1);
182 fclose (Out2);
183
184 return 0;
185 }