-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmsgid_define.cpp
More file actions
69 lines (61 loc) · 1.48 KB
/
msgid_define.cpp
File metadata and controls
69 lines (61 loc) · 1.48 KB
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
#include "msgid_define.h"
MsgId_Define::MsgId_Define(char *name):
msgidName_(name),
msgName_(),
msgId_(),
comment_(),
buff_()
{
}
MsgId_Define::~MsgId_Define()
{
}
int MsgId_Define::readAttr(FILE *fp){
fgets(buff_, 256, fp);
while(strncmp(EOSTRUCT, buff_, 2)){
setAttr();
memset(buff_, 0, 256);
fgets(buff_, 256, fp);
}
return 0;
}
int MsgId_Define::setAttr(){
char temp[128] = {};
char slip[8] = "\x20\t\n,={";
char *str;
if((str = get_string_field(temp, buff_, 1, slip)) == NULL)
return -1;
std::string msgname = str;
std::string msgid = get_string_field(temp, buff_, 2, slip);
std::string comt = "";
if((str = get_string_field(temp, buff_, 3, slip)) != NULL)
comt = str;
msgName_.push_back(msgname);
msgId_.push_back(msgid);
comment_.push_back(comt);
return 0;
}
int MsgId_Define::write_to_h(FILE *fp){
char temp[256] = {};
sprintf(temp, ENUM_H_HEAD, msgidName_.c_str());
fputs(temp, fp);
write_to_h_msg(temp, fp);
sprintf(temp, STRUCT_END);
fputs(temp, fp);
return 0;
}
int MsgId_Define::write_to_h_msg(char *temp, FILE *fp){
for(uint i = 0; i < msgName_.size(); i++){
sprintf(temp, ENUM_H_BODY, msgName_[i].c_str(), msgId_[i].c_str(), comment_[i].c_str());
fputs(temp, fp);
}
return 0;
}
int MsgId_Define::write_to_js(std::string js_name, FILE *fp){
char temp[256] = {};
for(uint i = 0; i < msgName_.size(); i++){
sprintf(temp, ENUM_JS_BODY, js_name.c_str(), msgName_[i].c_str(), msgId_[i].c_str(), comment_[i].c_str());
fputs(temp, fp);
}
return 0;
}