-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
81 lines (67 loc) · 1.12 KB
/
main.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
#include <stdlib.h>
#include <stdio.h>
#include "urldecode.h"
#include <string.h>
#define VERSION "0.0.1"
void printVersion();
void printHelp();
void decodeFileName(char*input);
int main(int argc,char**argv)
{
if(argc==1)
{
printf("NO input file(s)!\n");
printHelp();
return 0;
}
else if(argc==2)
{
if(strcmp(argv[1],"-v")==0||strcmp(argv[1],"--version")==0)
{
printVersion();
return 0;
}
else if(!strcmp(argv[1],"--help"))
{
printHelp();
return 0;
}
else if(argv[1][0]=='-')
{
printf("Unrecognized command line option\n");
printHelp();
return 0;
}
else
{
decodeFileName(argv[1]);
return 0;
}
}
for(int i=1;i<argc;i++)
{
decodeFileName(argv[i]);
}
return 0;
}
void decodeFileName(char*input)
{
char cmd[550];
char* out;
out = urlDecode(input);
printf("%s\n",out);
sprintf(cmd,"mv \"%s\" \"%s\"",input,out);
system(cmd);
}
void printHelp()
{
printf("fileNameDecode\t[file(s)...]\n");
printf("fileNameDecode\t--help\n");
printf("fileNameDecode\t-v/--version\n");
}
void printVersion()
{
printf("fileNameDecode ");
printf(VERSION);
printf("\n");
}