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