-
Notifications
You must be signed in to change notification settings - Fork 0
/
fjoin.c
executable file
·96 lines (86 loc) · 2.07 KB
/
fjoin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "fjoin.h"
void help()
{
fprintf(stdout,"Usage: fjoin [option] <filename>\n");
fprintf(stdout,"No specific option is required for joning of file. The filename, however, should be of form *.001\n");
fprintf(stdout,"Options can be\n");
fprintf(stdout," -split <N>\t To split the file. N is size, eg 200mb\n");
fprintf(stdout," --version\t Prints version of this software.\n");
fprintf(stdout," --help\t Prints this help.\n");
fprintf(stdout,"\nFor queries and bug reports contact [email protected]\n");
}
void version()
{
fprintf(stdout, "fjoin version 0.0.5\n");
}
int main(int argc, char *argv[])
{
unsigned long long ofsize, factr, spval;
char spfactr[3];
int i;
if(argc<2 || strcmp(argv[1],"--help")==0)
{
help();
exit(1);
}
else if(strcmp(argv[1],"--version")==0)
{
version();
exit(0);
}
else if(argc==2)
{
join(argv[1]);
exit(1);
}
else if(argc==4 && strcmp(argv[1],"-split")==0)
{
/* Copy the last two charaters into some other character array
*/
strcpy(spfactr, (argv[2]+strlen(argv[2])-2));
/* Generate number from the string form in argument.
*/
i=0;
spval = 0;
while(argv[2][i])
{
if(argv[2][i]<'0' || argv[2][i]>'9')
break;
spval = (10 * spval) + (argv[2][i] - '0');
i++;
}
if(i != strlen(argv[2])-2)
{
fprintf(stderr, "Invalid split size.\n");
}
/* Check the factor.
*/
for(i=0; i<2; i++)
spfactr[i] = toupper(spfactr[i]);
if(strcmp(spfactr, "KB")==0)
factr = 1024;
else if(strcmp(spfactr, "MB")==0)
factr = 1024 * 1024;
else if(strcmp(spfactr, "GB")==0)
factr = 1024 * 1024 * 1024;
else
{
fprintf(stdout, "Invalid split size.\n");
}
/*calcuate the size of each file.
*/
ofsize=0;
ofsize = spval * factr;
/****************temp********************/
fprintf(stdout, "factr = %lld, spval = %lld, ofsize = %lld\n",factr, spval, ofsize);
/****************************************/
/* Call the function to split the file.
*/
split(argv[3], ofsize);
}
return 0;
}