Rev 7994 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7883 | leency | 1 | |
2 | * Programme name: Backy |
||
7942 | leency | 3 | * Description: The programme for backing up a file. |
4 | * |
||
5 | * Backy.c |
||
7994 | leency | 6 | * Author: JohnXenox aka Aleksandr Igorevich. |
7 | * |
||
8 | * Works from command line, only! |
||
7942 | leency | 9 | */ |
10 | |||
7883 | leency | 11 | |
7994 | leency | 12 | |
7883 | leency | 13 | |
7942 | leency | 14 | #include |
7883 | leency | 15 | #include |
16 | |||
17 | |||
7994 | leency | 18 | #include "Backy_lib.h" |
19 | |||
7883 | leency | 20 | |
21 | int time = 0; |
||
22 | |||
23 | |||
24 | char months = 0; |
||
25 | char days = 0; |
||
26 | |||
27 | |||
28 | char minutes = 0; |
||
29 | char seconds = 0; |
||
30 | |||
31 | |||
32 | int length = 0; |
||
33 | |||
34 | |||
35 | char path_out[4096] = {0}; |
||
36 | |||
37 | |||
38 | |||
39 | |||
40 | char ext[] = ".bak"; |
||
41 | |||
42 | |||
43 | |||
44 | |||
7994 | leency | 45 | |
7883 | leency | 46 | |
47 | |||
48 | { |
||
49 | |||
50 | |||
51 | // preprocessing arguments from the command line. ============= // |
||
52 | // |
||
53 | // 0 argument - name of the programme. |
||
54 | // 1 argument - path to the file with name that need to be backup. |
||
55 | // 2 argument - the key (-o). |
||
56 | // 3 argument - path to the output directory without the name of the file. |
||
57 | |||
58 | |||
59 | // printf("Argv 0: %s\n", argv[0]); |
||
60 | // sprintf("Argv 1: %s\n\n", argv[1]); |
||
61 | |||
62 | |||
63 | |||
64 | // process the command line arguments. ======================== // |
||
7994 | leency | 65 | |
7883 | leency | 66 | |
67 | { |
||
68 | for (int i = 1; i < argc; i++) |
||
69 | { |
||
70 | // if found the key "-o", then copy output path into the array "path_out". |
||
71 | if (*argv[i] == '-') // && (*(argv[i] + 1) == 'o')) |
||
72 | { |
||
73 | // printf("Key -o is found!\n"); |
||
74 | |||
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
80 | { |
||
81 | // copying of a current path into the array "path_out". |
||
82 | strcpy(path_out, argv[i]); |
||
83 | |||
84 | |||
85 | |||
86 | |||
87 | |||
88 | |||
89 | } |
||
90 | } |
||
91 | |||
92 | |||
7994 | leency | 93 | if (*argv[i] == '/') |
7883 | leency | 94 | { |
95 | flag = 2; |
||
96 | |||
97 | |||
98 | strcpy(path_in, argv[i]); |
||
99 | |||
100 | |||
101 | { |
||
102 | int idx = strlen(path_in); |
||
103 | while (path_in[idx] != '/') |
||
104 | { |
||
105 | idx--; |
||
106 | } |
||
107 | |||
108 | |||
109 | } |
||
110 | |||
111 | |||
112 | } |
||
113 | |||
114 | |||
115 | if ( (*argv[i] > '0') && (*argv[i] < '9') || \ |
||
116 | (*argv[i] > 'A') && (*argv[i] < 'Z') || \ |
||
117 | (*argv[i] > 'a') && (*argv[i] < 'z') ) |
||
118 | { |
||
119 | flag = 3; |
||
120 | |||
121 | |||
122 | // printf("Arg 0 is copyed!\n"); |
||
123 | |||
124 | |||
125 | |||
126 | |||
127 | { |
||
128 | path_in[idx] = 0; |
||
129 | idx--; |
||
130 | } |
||
131 | |||
132 | |||
133 | strcpy(path_out, path_in); |
||
134 | strcpy(&path_in[idx], argv[1]); |
||
135 | // printf("Arg 1 is added!\n"); |
||
136 | |||
137 | |||
138 | } |
||
139 | |||
140 | |||
141 | if ((flag == 0) && (flag != 2) && (flag != 3)) |
||
142 | { |
||
143 | // copying the input path into the output path, |
||
144 | strcpy(path_out, path_in); |
||
145 | //printf("Path input is copyed into the path output!\n"); |
||
146 | } |
||
147 | } |
||
148 | else |
||
149 | { |
||
150 | if (con_init_console_dll()) return 1; // init fail. |
||
8583 | leency | 151 | |
152 | |||
7994 | leency | 153 | |
7883 | leency | 154 | |
7994 | leency | 155 | |
7942 | leency | 156 | |
7994 | leency | 157 | con_printf("\n Date: %s", CREATION_DATE); |
158 | con_printf("\n Description: The programm for backing up a file.\n"); |
||
8583 | leency | 159 | |
7942 | leency | 160 | |
7994 | leency | 161 | |
7883 | leency | 162 | |
7994 | leency | 163 | con_printf(" path1 - path to a file to be backuped.\n"); |
164 | con_printf(" -o path2 - path to the output directory without the name of a file.\n\n"); |
||
165 | |||
7883 | leency | 166 | |
7994 | leency | 167 | con_printf(" backy test.c\n"); |
168 | con_printf(" backy test.c -o /tmp0/1/\n"); |
||
169 | con_printf(" backy /hd0/1/test.c\n"); |
||
170 | con_printf(" backy /hd0/1/test.c -o /tmp0/1/\n"); |
||
171 | |||
7883 | leency | 172 | |
7994 | leency | 173 | |
174 | |||
175 | con_printf("\n Дата: %s", CREATION_DATE); |
||
176 | con_printf("\n Описание: Программа для создания резервной копии файла.\n"); |
||
177 | |||
178 | |||
179 | |||
180 | |||
181 | con_printf(" path1 - путь к файлу, который надо скопировать.\n"); |
||
182 | con_printf(" -o path2 - путь к директории, в которую будет скопирована резервная копия файла.\n\n"); |
||
183 | |||
184 | |||
185 | con_printf(" backy test.c\n"); |
||
186 | con_printf(" backy test.c -o /tmp0/1/\n"); |
||
187 | con_printf(" backy /hd0/1/test.c\n"); |
||
188 | con_printf(" backy /hd0/1/test.c -o /tmp0/1/\n"); |
||
189 | |||
190 | |||
191 | |||
192 | |||
193 | } |
||
7883 | leency | 194 | |
195 | |||
196 | //printf("Path_out: %s\n", path_out); |
||
197 | |||
198 | |||
199 | |||
200 | // getting the time in BCD. =================================== // |
||
201 | |||
202 | |||
203 | |||
204 | |||
205 | minutes = (char)(time >> 8); |
||
206 | seconds = (char)(time >> 16); |
||
207 | |||
208 | |||
209 | // getting the date in BCD. =================================== // |
||
210 | |||
211 | |||
212 | |||
213 | |||
214 | months = (char)(date >> 8); |
||
215 | days = (char)(date >> 16); |
||
216 | |||
217 | |||
218 | // fills the array with the date in ASCII. ==================== // |
||
219 | |||
220 | |||
221 | char *dta = 0; |
||
222 | |||
223 | |||
224 | { |
||
225 | if (i == 0) |
||
226 | { |
||
227 | dta = &years; |
||
228 | full_date[ofs] = '2'; |
||
229 | ofs++; |
||
230 | full_date[ofs] = '0'; |
||
231 | ofs++; |
||
232 | } |
||
233 | if (i == 1) |
||
234 | { |
||
235 | dta = &months; |
||
236 | } |
||
237 | if (i == 2) |
||
238 | { |
||
239 | dta = &days; |
||
240 | } |
||
241 | |||
242 | |||
243 | |||
7942 | leency | 244 | |
7883 | leency | 245 | |
246 | { |
||
247 | full_date[ofs] = '0'; |
||
248 | ofs++; |
||
249 | full_date[ofs] = num[0]; |
||
250 | } |
||
251 | else |
||
252 | { |
||
253 | full_date[ofs] = num[0]; |
||
254 | ofs++; |
||
255 | full_date[ofs] = num[1]; |
||
256 | } |
||
257 | |||
258 | |||
259 | |||
260 | |||
261 | { |
||
262 | full_date[ofs] = '.'; |
||
263 | ofs++; |
||
264 | } |
||
265 | } |
||
266 | |||
267 | |||
268 | ofs++; |
||
269 | |||
270 | |||
271 | // fills the array with the time in ASCII. ==================== // |
||
272 | |||
273 | |||
274 | dta = 0; |
||
275 | |||
276 | |||
277 | { |
||
278 | if (i == 0) |
||
279 | dta = &hours; |
||
280 | if (i == 1) |
||
281 | dta = &minutes; |
||
282 | if (i == 2) |
||
283 | dta = &seconds; |
||
284 | |||
285 | |||
7942 | leency | 286 | |
7883 | leency | 287 | |
288 | { |
||
289 | full_date[ofs] = '0'; |
||
290 | ofs++; |
||
291 | full_date[ofs] = num[0]; |
||
292 | } |
||
293 | else |
||
294 | { |
||
295 | full_date[ofs] = num[0]; |
||
296 | ofs++; |
||
297 | full_date[ofs] = num[1]; |
||
298 | } |
||
299 | |||
300 | |||
301 | |||
302 | |||
303 | { |
||
304 | full_date[ofs] = '.'; |
||
305 | } |
||
306 | //else |
||
307 | //{ |
||
308 | // full_date[ofs] = '_'; |
||
309 | //} |
||
310 | |||
311 | |||
312 | } |
||
313 | |||
314 | |||
315 | // adding the name of the input file to the output path. ====== // |
||
316 | |||
317 | |||
318 | int y = 0; |
||
319 | |||
320 | |||
7994 | leency | 321 | while (path_in[i] != 0) |
7883 | leency | 322 | { |
323 | i++; |
||
324 | } |
||
325 | |||
326 | |||
7994 | leency | 327 | while (path_in[i] != '/') |
7883 | leency | 328 | { |
329 | i--; |
||
330 | } |
||
331 | |||
332 | |||
7994 | leency | 333 | while (path_out[y] != 0) |
7883 | leency | 334 | { |
335 | y++; |
||
336 | } |
||
337 | |||
338 | |||
7994 | leency | 339 | if (path_out[y - 1] == '/') |
7883 | leency | 340 | { |
341 | y--; |
||
342 | } |
||
343 | |||
344 | |||
345 | strcpy(&path_out[y], &path_in[i]); |
||
346 | |||
347 | |||
348 | // adding the extension and full date to the path. ============ // |
||
349 | |||
350 | |||
351 | |||
352 | |||
7994 | leency | 353 | while (path_out[i] != 0) |
7883 | leency | 354 | { |
355 | i++; |
||
356 | } |
||
357 | |||
358 | |||
359 | i++; |
||
360 | |||
361 | |||
362 | strcpy(&path_out[i], full_date); |
||
363 | |||
364 | |||
365 | |||
366 | |||
7994 | leency | 367 | strncpy(&path_out[i], ext, 4); |
7883 | leency | 368 | |
369 | |||
370 | //printf("Path_out: %s\n", path_out); |
||
371 | |||
372 | |||
373 | |||
374 | |||
7994 | leency | 375 | { |
376 | if (con_init_console_dll()) return 1; // init fail. |
||
8583 | leency | 377 | con_set_title("Backy"); |
378 | |||
379 | |||
7994 | leency | 380 | |
7883 | leency | 381 | |
7994 | leency | 382 | |
7883 | leency | 383 | |
7994 | leency | 384 | |
385 | |||
386 | |||
387 | |||
388 | |||
389 | |||
390 | } |
||
391 | |||
392 | |||
393 | }>>>-o>-o>>>>=>> |
||
7883 | leency | 394 |