Subversion Repositories Kolibri OS

Rev

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