-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive_v0_0_2.cpp
79 lines (74 loc) · 2.16 KB
/
interactive_v0_0_2.cpp
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
/**
* This file is the sourse code of the INTERACTIVE project.
* argv[1]: get/set/delete, to assign the operation type to the iacache.
* argv[2]: the name of the dispatcher.
* argv[3]: the name of the reciever.
* argv[4]: the serial number.
* argv[5]: if argv[1] is not delete, it is to assign the outout/input file name.
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<direct.h>
#include<windows.h>
#include<io.h>
#define n "\n"
#define NEA_CHECK(x) if(argc<x) return NOT_ENOUGH_ARGUMENT
#define USER_ERROR 0xC0000000
#define NOT_ENOUGH_ARGUMENT 0xC0000001
#define INVALID_ARGUMENT 0xC0000002
#define FILE_NOT_FOUND 0xC0000003
#define OK 0x00000000
#define NO 0x00000001
#define YES 0x00000002
char target[1024];
char version[]="0.0.2";
char help[]="INTERACTIVE help document:"n
" This file is the sourse code of the INTERACTIVE project."n
" The argument values(argv) stands for:"n
" argv[1]: get/set/delete, to assign the operation type to the iacache."n
" argv[2]: the name of the dispatcher."n
" argv[3]: the name of the reciever."n
" argv[4]: the serial number."n
" argv[5]: if argv[1] is not delete, it is to assign the outout/input file name.";
int main(int argc,char* argv[]) {
if(argc==1) {
printf("For more information, type <%s help.>",argv[0]);
return NOT_ENOUGH_ARGUMENT;
}
if(access("iacache",0)==-1) mkdir("iacache");
NEA_CHECK(5);
sprintf(target,"iacache\\%s#%s#%s",argv[2],argv[3],argv[4]);
if(strcmp(argv[1],"version")==0) {
printf(version);
return OK;
}
else if(strcmp(argv[1],"help")==0) {
printf(help);
return OK;
}
else if(strcmp(argv[1],"get")==0) {
NEA_CHECK(6);
if(access(target,0)==-1) return FILE_NOT_FOUND;
CopyFile(target,argv[5],0);
return OK;
}
else if(strcmp(argv[1],"set")==0) {
NEA_CHECK(6);
if(access(argv[5],0)==-1) return FILE_NOT_FOUND;
CopyFile(argv[5],target,0);
return OK;
}
else if(strcmp(argv[1],"delete")==0) {
if(access(target,0)!=-1) remove(target);
return OK;
}
else if(strcmp(argv[1],"exist")==0) {
if(access(target,0)==-1) return YES;
else return NO;
}
else {
printf("Invalid function: %s",argv[1]);
return INVALID_ARGUMENT;
}
}