]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/SplitFile/SplitFile.c
More moves for Tool Packages
[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 void
20 helpmsg (
21 void
22 )
23 /*++
24
25 Routine Description:
26
27 GC_TODO: Add function description
28
29 Arguments:
30
31
32 Returns:
33
34 GC_TODO: add return values
35
36 --*/
37 {
38 printf (
39 "SplitFile Filename Offset\n"" Filename = Input file to split\n"" Offset = offset at which to split file\n"
40 "\n\n""SplitFile will break a file in two pieces at the requested offset\n"
41 " outputting Filename1 and Filename2\n"
42 );
43 }
44
45 int
46 main (
47 int argc,
48 char*argv[]
49 )
50 /*++
51
52 Routine Description:
53
54 GC_TODO: Add function description
55
56 Arguments:
57
58 argc - GC_TODO: add argument description
59 ] - GC_TODO: add argument description
60
61 Returns:
62
63 GC_TODO: add return values
64
65 --*/
66 {
67 FILE *In;
68
69 FILE *Out1;
70
71 FILE *Out2;
72 char OutName1[512];
73 char OutName2[512];
74 unsigned long Index;
75 unsigned long splitpoint;
76 char CharC;
77
78 if (argc != 3) {
79 helpmsg ();
80 return -1;
81 }
82
83 In = fopen (argv[1], "rb");
84 if (In == NULL) {
85 printf ("Unable to open file \"%s\"\n", argv[1]);
86 return -1;
87 }
88
89 strncpy (OutName1, argv[1], 510);
90 strncpy (OutName2, argv[1], 510);
91 strcat (OutName1, "1");
92 strcat (OutName2, "2");
93
94 Out1 = fopen (OutName1, "wb");
95 if (Out1 == NULL) {
96 printf ("Unable to open file \"%s\"\n", OutName1);
97 return -1;
98 }
99
100 Out2 = fopen (OutName2, "wb");
101 if (Out2 == NULL) {
102 printf ("Unable to open file \"%s\"\n", OutName2);
103 return -1;
104 }
105
106 splitpoint = atoi (argv[2]);
107
108 for (Index = 0; Index < splitpoint; Index++) {
109 CharC = (char) fgetc (In);
110 if (feof (In)) {
111 break;
112 }
113
114 fputc (CharC, Out1);
115 }
116
117 for (;;) {
118 CharC = (char) fgetc (In);
119 if (feof (In)) {
120 break;
121 }
122
123 fputc (CharC, Out2);
124 }
125
126 fclose (In);
127 fclose (Out1);
128 fclose (Out2);
129
130 return 0;
131 }