-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
114 lines (81 loc) · 3.09 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include"tag.h"
/*Main function routes to the correct file to edit view or help files
*
* take a look at line 23 , 37, 53
*/
int main(int argc, char *argv[]){
//Create a required variables in user defined structure
Name aud_info;
//check for required arguments
if(argc == 1 ){
//if argument count dosent meet the requirment then go to print error statement
goto l1;
}
//help section
else if(check_opr_type(argv)==HELP){
//help section for user.For further reference look at view.c
help();
return SUCCESS;
}
//edit section
else if(check_opr_type(argv)==EDIT){
//If the argument is above or below 5 then go to print error section
if(argc == 5){
//Acknoledge user that s(he) selected edit option
printf("----------------------------------------\n");
printf(" \t Selected edit option \t \n");
//go to function in do_mods.c
if(do_mods(argv,&aud_info)==SUCCESS){
if(remove(aud_info.f_name)== 0){
if(rename(aud_info.copy_fname,aud_info.f_name)==0){
printf("Done\n");
printf("----------------------------------------\n");
return SUCCESS;
}
}
}
remove(aud_info.copy_fname);
return FAILURE;
}
goto l1;
}
//if argc is above or below 3 then give error to the user
else if(check_opr_type(argv)==VIEW){
if(argc == 3){
//Acknoledge user that s(he) selected view option
printf("+---------------------------------------+\n");
printf("|\t Selected view option \t|\n");
//go to the view_info function in view.c
version_info(argv,&aud_info);
return SUCCESS;
}
goto l1;
}
//The l1: unconditional jump for any errors happened above cases
else{
l1:
printf("--------------------------------------------------\n");
printf("\t\tINVALID ARGUMENTS\n--------------------------------------------------\n");
printf("Usage : ./a.out -v filename.mp3\nFor more information try using --help or -h\n");
printf("--------------------------------------------------\n");
return FAILURE;
}
}
/*
* This function checks the operation type HELP , EDIT , or VIEW
* It takes the input from argv[1] i.e char*
* It gives output enum described as HELP , EDIT , VIEW anf FAILURE
*/
Status check_opr_type(char *argv[]){
//Compares the argv[1] and const literals and returns to the particular function
if(!strcmp(argv[1],"-h")||!strcmp(argv[1],"--help")){
return HELP;
}
if(!strcmp(argv[1],"-e")){
return EDIT;
}
if(!strcmp(argv[1],"-v")){
return VIEW;
}
return FAILURE;
}