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