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