Rev 7942 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7942 | Rev 7994 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | * Author: JohnXenox aka Aleksandr Igorevich. |
- | |
3 | * |
- | |
4 | * Programme name: Backy |
2 | * Programme name: Backy |
5 | * Description: The programme for backing up a file. |
3 | * Description: The programme for backing up a file. |
6 | * |
4 | * |
- | 5 | * Backy.c |
|
- | 6 | * Author: JohnXenox aka Aleksandr Igorevich. |
|
- | 7 | * |
|
7 | * Works from command line, only! |
8 | * Works from command line, only! |
8 | */ |
9 | */ |
Line 9... | Line 10... | ||
9 | 10 | ||
Line 10... | Line 11... | ||
10 | #define CREATION_DATE "2020.05.17" |
11 | #define CREATION_DATE "2020.05.27" |
11 | - | ||
12 | #include |
12 | |
13 | //#include |
13 | #include |
Line -... | Line 14... | ||
- | 14 | #include |
|
14 | #include |
15 | #include |
Line 15... | Line 16... | ||
15 | #include |
16 | |
16 | 17 | #include "Backy_lang.h" |
|
Line 17... | Line 18... | ||
17 | #include "Backy-lib.h" |
18 | #include "Backy_lib.h" |
Line 39... | Line 40... | ||
39 | char ext[] = ".bak"; |
40 | char ext[] = ".bak"; |
40 | 41 | ||
Line 41... | Line 42... | ||
41 | char flag = 0; |
42 | char flag = 0; |
Line -... | Line 43... | ||
- | 43 | ||
Line 42... | Line 44... | ||
42 | 44 | char state; |
|
43 | 45 | ||
- | 46 | ||
- | 47 | int main(int argc, char** argv) |
|
- | 48 | { |
|
Line 44... | Line 49... | ||
44 | 49 | if (con_init_console_dll()) return 1; // init fail. |
|
45 | int main(int argc, char** argv) |
50 | |
46 | { |
51 | con_set_title("Backy"); |
47 | 52 | ||
Line 58... | Line 63... | ||
58 | // sprintf("Argv 1: %s\n\n", argv[1]); |
63 | // sprintf("Argv 1: %s\n\n", argv[1]); |
59 | 64 | ||
Line 60... | Line 65... | ||
60 | 65 | ||
61 | // ============================================================ // |
66 | // ============================================================ // |
Line 62... | Line 67... | ||
62 | // preprocess the command line arguments. ===================== // |
67 | // process the command line arguments. ======================== // |
63 | 68 | ||
64 | if (argc > 1) |
69 | if (argc > 1) |
65 | { |
70 | { |
Line 86... | Line 91... | ||
86 | break; |
91 | break; |
87 | } |
92 | } |
88 | } |
93 | } |
Line 89... | Line 94... | ||
89 | 94 | ||
90 | // if inut path is found, then copy it into the array "path_in". |
95 | // if input path is found, then copy it into the array "path_in". |
91 | if (*argv[i] == '/') |
96 | if (*argv[i] == '/') |
92 | { |
97 | { |
Line 93... | Line 98... | ||
93 | flag = 2; |
98 | flag = 2; |
Line 144... | Line 149... | ||
144 | } |
149 | } |
145 | } |
150 | } |
146 | else |
151 | else |
147 | { |
152 | { |
148 | //con_init_console_dll_param(-1, 23, -1, 23, "Backy"); |
153 | con_set_title("Useful info!"); |
- | 154 | ||
- | 155 | #if defined (lang_en) |
|
- | 156 | ||
- | 157 | con_printf("\n Name: Backy"); |
|
- | 158 | con_printf("\n Date: %s", CREATION_DATE); |
|
- | 159 | con_printf("\n Description: The programme for backing up a file.\n"); |
|
- | 160 | ||
- | 161 | con_printf("\n Author: JohnXenox\n"); |
|
- | 162 | ||
- | 163 | con_printf("\n Usage: backy |
|
- | 164 | con_printf(" path1 - path to a file to be backuped.\n"); |
|
149 | if (con_init_console_dll()) return 1; // init fail |
165 | con_printf(" -o path2 - path to the output directory without the name of a file.\n\n"); |
- | 166 | ||
- | 167 | con_printf(" Examples:\n"); |
|
- | 168 | con_printf(" backy test.c\n"); |
|
- | 169 | con_printf(" backy test.c -o /tmp0/1/\n"); |
|
150 | 170 | con_printf(" backy /hd0/1/test.c\n"); |
|
- | 171 | con_printf(" backy /hd0/1/test.c -o /tmp0/1/\n"); |
|
- | 172 | ||
Line 151... | Line 173... | ||
151 | printf("Useful info!"); |
173 | #elif defined (lang_ru) |
Line 152... | Line 174... | ||
152 | 174 | ||
153 | printf("\n Name: Backy"); |
175 | con_printf("\n •: Backy"); |
154 | printf("\n Date: %s", CREATION_DATE); |
176 | con_printf("\n â : %s", CREATION_DATE); |
Line 155... | Line 177... | ||
155 | printf("\n Description: The programme for backing up a file.\n"); |
177 | con_printf("\n ¯¨á ¨¥: à®£à ¬¬ ¤«ï ᮧ¤ ¨ï १¥à¢®© ª®¯¨¨ ä ©« .\n"); |
Line 156... | Line 178... | ||
156 | 178 | ||
157 | printf("\n Author: JohnXenox\n"); |
179 | con_printf("\n ¢â®à: JohnXenox\n"); |
158 | 180 | ||
Line 159... | Line 181... | ||
159 | printf("\n Usage: backy |
181 | con_printf("\n ᯮ«ì§®¢ ¨¥: backy |
160 | printf(" path1 - path to a file to be backuped.\n"); |
182 | con_printf(" path1 - ¯ãâì ª ä ©«ã, ª®â®àë© ¤® ᪮¯¨à®¢ âì.\n"); |
161 | printf(" -o path2 - path to the output directory without the name of a file.\n\n"); |
183 | con_printf(" -o path2 - ¯ãâì ª ¤¨à¥ªâ®à¨¨, ¢ ª®â®àãî ¡ã¤¥â ᪮¯¨à®¢ १¥à¢ ï ª®¯¨ï ä ©« .\n\n"); |
162 | 184 | ||
163 | printf(" Examples:\n"); |
185 | con_printf(" ਬ¥àë:\n"); |
Line 164... | Line 186... | ||
164 | printf(" backy test.c\n"); |
186 | con_printf(" backy test.c\n"); |
- | 187 | con_printf(" backy test.c -o /tmp0/1/\n"); |
|
165 | printf(" backy test.c -o /tmp0/1/\n"); |
188 | con_printf(" backy /hd0/1/test.c\n"); |
166 | printf(" backy /hd0/1/test.c\n"); |
189 | con_printf(" backy /hd0/1/test.c -o /tmp0/1/\n"); |
Line 167... | Line 190... | ||
167 | printf(" backy /hd0/1/test.c -o /tmp0/1/\n"); |
190 | |
168 | 191 | #endif |
|
Line 291... | Line 314... | ||
291 | 314 | ||
Line 292... | Line 315... | ||
292 | // ============================================================ // |
315 | // ============================================================ // |
293 | // adding the name of the input file to the output path. ====== // |
316 | // adding the name of the input file to the output path. ====== // |
Line 294... | Line -... | ||
294 | - | ||
295 | // searching the end of the path string. |
317 | |
296 | int i = 0; |
318 | int i = 0; |
Line 297... | Line 319... | ||
297 | int y = 0; |
319 | int y = 0; |
298 | 320 | ||
299 | // searching for zero terminator in the input path. |
321 | // searching for a zero terminator in the input path. |
300 | while (path_in[i] != 0) |
322 | while (path_in[i] != 0) |
301 | { |
323 | { |
Line 302... | Line 324... | ||
302 | i++; |
324 | i++; |
303 | } |
325 | } |
304 | 326 | ||
305 | // searching for slash in the input path. |
327 | // searching for a slash in the input path. |
306 | while (path_in[i] != '/') |
328 | while (path_in[i] != '/') |
Line 307... | Line 329... | ||
307 | { |
329 | { |
308 | i--; |
330 | i--; |
309 | } |
331 | } |
310 | 332 | ||
311 | // searching for zero terminator in the output path. |
333 | // searching for a zero terminator in the output path. |
Line 312... | Line 334... | ||
312 | while (path_out[y] != 0) |
334 | while (path_out[y] != 0) |
313 | { |
335 | { |
314 | y++; |
336 | y++; |
315 | } |
337 | } |
316 | 338 | ||
Line 327... | Line 349... | ||
327 | // adding the extension and full date to the path. ============ // |
349 | // adding the extension and full date to the path. ============ // |
328 | 350 | ||
Line 329... | Line 351... | ||
329 | i = 0; |
351 | i = 0; |
Line 330... | Line 352... | ||
330 | 352 | ||
331 | // searching for zero terminator in the output path. |
353 | // searching for a zero terminator in the output path. |
332 | while (path_out[i] != 0) |
354 | while (path_out[i] != 0) |
333 | { |
355 | { |
334 | i++; |
356 | i++; |
Line 341... | Line 363... | ||
341 | strcpy(&path_out[i], full_date); |
363 | strcpy(&path_out[i], full_date); |
342 | 364 | ||
Line 343... | Line 365... | ||
343 | i += strlen(full_date); |
365 | i += strlen(full_date); |
Line 344... | Line 366... | ||
344 | 366 | ||
345 | // adding the extension to path. |
367 | // adding the extension to a path. |
Line 346... | Line 368... | ||
346 | strncpy(&path_out[i], ext, 4); |
368 | strncpy(&path_out[i], ext, 4); |
347 | 369 | ||
Line 348... | Line 370... | ||
348 | //printf("Path_in: %s\n", path_in); |
370 | //printf("Path_in: %s\n", path_in); |
Line -... | Line 371... | ||
- | 371 | //printf("Path_out: %s\n", path_out); |
|
- | 372 | ||
349 | //printf("Path_out: %s\n", path_out); |
373 | data = openFile(&length, path_in); |
Line -... | Line 374... | ||
- | 374 | ||
Line -... | Line 375... | ||
- | 375 | if(data == 0) |
|
- | 376 | { |
|
- | 377 | #if defined (lang_en) |
|
- | 378 | ||
- | 379 | con_printf("\nThe file isn't found!\n"); |
|
- | 380 | ||
350 | 381 | #elif defined (lang_ru) |
|
- | 382 | ||
- | 383 | con_printf("\n ©« ¥ ©¤¥!\n"); |
|
- | 384 | ||
351 | data = openFile(&length, path_in); |
385 | #endif |