Subversion Repositories Kolibri OS

Rev

Rev 7927 | Rev 7994 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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