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