-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeyTulisarsip.h
259 lines (200 loc) · 7.93 KB
/
keyTulisarsip.h
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Bahasa Anak Indonesia untuk Komputer - BAIK
// Copyright Haris Hasanudin - 2005 - 2010
//
// Kupersembahkan untuk istriku tercinta Masako, anakku tersayang Takumi
// dan Tomoki serta seluruh putra putri Indonesia
void keyTulisarsip ()
{
int n=0;
char logMsg[MAX_STRING_LEN * 2],
tmpMsg[MAX_STRING_LEN * 2];
VAL_LABEL valdat, valdat2, tmpdat, valdat0;
long idx=0; // array index
FILE *tmpfile=NULL;
int isFileOpen=0;
char get_name[MAX_STRING_LEN];
// var list for class params
struct node_list tmpnode;
char class_tmpvar[MAX_STRING_LEN];
memset(&tmpdat, '\0', sizeof(tmpdat));
memset(&valdat, '\0', sizeof(valdat));
memset(&valdat2, '\0', sizeof(valdat2));
memset(&valdat0, '\0', sizeof(valdat0));
memset(&get_name, '\0', sizeof(get_name));
memset(&tmpMsg, '\0', sizeof(tmpMsg));
memset(&logMsg, '\0', sizeof(logMsg));;
memset(&tmpnode, '\0', sizeof(tmpnode));
memset(&class_tmpvar, '\0', sizeof(class_tmpvar));
memset(tmpMsg, '\0', sizeof(tmpMsg));
memset(tmpMsg, '\0', sizeof(tmpMsg));
memset(logMsg, '\0', sizeof(logMsg));
strcpy(logMsg, "");
n = 0;
do{
memset(tmpMsg, '\0', sizeof(tmpMsg));
getlex();
switch( lex.type )
{
case TYPE_NUM:
if(n >= 1) {
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(tmpMsg, sizeof(tmpMsg),"%li" , lex.detail.num );
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%li" , lex.detail.num );
#endif
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%li" , lex.detail.num );
#endif
strcat(logMsg, tmpMsg);
}
break;
case TYPE_DBL:
if(n >= 1) {
sprintf(tmpMsg, "%f", lex.detail.dblnum );
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(tmpMsg, sizeof(tmpMsg),"%f", lex.detail.dblnum );
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%f", lex.detail.dblnum );
#endif
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%f", lex.detail.dblnum );
#endif
strcat(logMsg, tmpMsg);
}
break;
case TYPE_STR:
if(n >= 1) {
strcpy(tmpMsg, lex.detail.string );
strcat(logMsg, tmpMsg);
}
break;
case TYPE_IDENT:
//printf(" DEBUG: TULIS_ARSIP\n");
ungetlex();
valdat = expression();
if(valdat.datatype == 0) {
if(n >= 1) {
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(tmpMsg, sizeof(tmpMsg),"%li" , valdat.val );
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%li" , valdat.val );
#endif
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%li" , valdat.val );
#endif
}
} else
if(valdat.datatype == 1) {
if(n >= 1) {
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(tmpMsg, sizeof(tmpMsg),"%f", valdat.floatdata);
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%f", valdat.floatdata);
#endif
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%f", valdat.floatdata);
#endif
}
} else
if(valdat.datatype == 2) {
if(n == 0) {
tmpfile = valdat.filedata;
isFileOpen = valdat.isFileOpen;
}
} else
if(valdat.datatype == 3) {
if(n >= 1) {
strcpy(tmpMsg, valdat.str);
}
}
strcat(logMsg, tmpMsg);
break;
case TYPE_ARRAY:
/* printf("write array\n"); */
if(strlen(lex.detail.array_str) > 0) {
strcpy(valdat.array_str, lex.detail.array_str);
getArrayName(lex.detail.array_str, (char *)&valdat.array_name);
getArrayIdx(lex.detail.array_str, (char *)&valdat.array_idx);
if(isdigit(valdat.array_idx[0])) {
/* printf("show digit\n"); */
idx = atoi (valdat.array_idx);
} else {
/* printf("show NOT digit\n"); */
/* Read index param */
tmpdat = ValLabel( valdat.array_idx, sub_deep, tmpdat, VAL_FLAG_SEARCH_R );
if(tmpdat.datatype==0)
idx = tmpdat.val;
else
Error("Untaian salah masukan");
}
valdat = ValLabel( valdat.array_name, sub_deep, valdat, VAL_FLAG_SEARCH_R );
//ltoa(idx, valdat.array_idx, 10);
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(valdat.array_idx, sizeof(valdat.array_idx),"%li", idx);
#else
snprintf(valdat.array_idx, sizeof(valdat.array_idx),"%li", idx);
#endif
#else
snprintf(valdat.array_idx, sizeof(valdat.array_idx),"%li", idx);
#endif
if(idx < 0 || idx > (valdat.array_max-1))
Error("ukuran Untaian tidak sesuai kapasitas");
if(n >= 1) {
if(valdat.datatype == 6 && valdat.array_i != '\0') {
if(valdat.array_i == '\0')
Error("ukuran Untaian belum terdefinisi");
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(tmpMsg, sizeof(tmpMsg),"%d", get_int_array(valdat, idx));
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%d", get_int_array(valdat, idx));
#endif
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%d", get_int_array(valdat, idx));
#endif
} else if (valdat.datatype == 7 && valdat.array_d != '\0') {
if(valdat.array_d == '\0')
Error("ukuran Untaian belum terdefinisi");
#ifdef WIN32
#ifndef S_SPLINT_S
sprintf_s(tmpMsg, sizeof(tmpMsg),"%f" , get_dbl_array(valdat, idx) );
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%f" , get_dbl_array(valdat, idx) );
#endif
#else
snprintf(tmpMsg, sizeof(tmpMsg),"%f" , get_dbl_array(valdat, idx) );
#endif
} else if (valdat.datatype == 8 && valdat.array_s != '\0') {
if(valdat.array_s == '\0')
Error("ukuran Untaian belum terdefinisi");
get_str_array(valdat, idx, (char *)&tmpMsg);
} else if (valdat.datatype == 10) {
strcpy(tmpMsg, valdat.long_str[idx]);
} else {
strcpy(tmpMsg, "Nil");
}
strcat(logMsg, tmpMsg);
}
}
break;
default:
Error("bentuk perintah TULIS_ARSIP salah");
}
n++;
getlex();
}while( lex.type == TYPE_SYM && lex.detail.symbol == ',');
/*
printf("tmpMsg : %s", tmpMsg);
printf("isOpen : %d\n", isFileOpen);
*/
if(isFileOpen == 1) {
fprintf(tmpfile, "%s", logMsg);
fflush( tmpfile );
}
ungetlex();
}