-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorcagui.c
More file actions
313 lines (260 loc) · 9.88 KB
/
Copy pathorcagui.c
File metadata and controls
313 lines (260 loc) · 9.88 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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#define _CRT_SECURE_NO_WARNINGS
#define IUP_USE_STATIC
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iup.h>
#include <iupcontrols.h>
static unsigned char img_orca[] = {
// 32 satır, her satır 32 piksel
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,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6,6,5,5,5,5,6,6,5,5,6,6,5,5,6,6,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,6,6,5,5,5,5,6,6,5,5,6,6,5,5,6,6,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,6,6,5,5,5,5,6,6,5,5,6,6,5,5,6,6,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,6,6,5,5,5,5,6,6,5,5,6,6,5,5,6,6,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,6,6,6,6,6,6,5,5,6,6,6,6,6,6,5,5,6,6,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,6,6,6,6,6,6,5,5,5,6,6,6,6,5,5,5,6,6,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4,2,
1,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,
1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
};
static Ihandle *txt_log = NULL;
static Ihandle *lbl_status = NULL;
static Ihandle *txt_orca = NULL;
static Ihandle *txt_inp = NULL;
static PROCESS_INFORMATION g_pi;
static HANDLE g_hThread = NULL;
static volatile int g_running = 0;
static char g_out_path[MAX_PATH] = {0};
/* ------------------ yardımcı ------------------ */
static void log_append(const char* s)
{
if (!s) return;
IupSetAttribute(txt_log, "APPEND", s);
IupSetAttribute(txt_log, "APPEND", "\n");
IupFlush();
}
static void set_status(const char* s)
{
IupSetStrAttribute(lbl_status, "TITLE", s ? s : "");
}
static void make_out_path(const char* inp, char* out, int outsz)
{
strncpy(out, inp, outsz - 1);
out[outsz - 1] = 0;
char* dot = strrchr(out, '.');
if (dot) strcpy(dot, ".out");
else strncat(out, ".out", outsz - (int)strlen(out) - 1);
}
/* ------------------ CMD stdout okuyucu thread ------------------ */
DWORD WINAPI ReaderThread(LPVOID lpParam)
{
FILE* fout = NULL;
while (g_running && !fout)
{
fout = fopen(g_out_path, "rb");
if (!fout)
Sleep(200); // dosya oluşana kadar bekle
}
if (!fout) return 0;
char buffer[4096];
while (g_running)
{
size_t n = fread(buffer, 1, sizeof(buffer)-1, fout);
if (n > 0)
{
buffer[n] = 0;
IupSetAttribute(txt_log, "APPEND", buffer);
IupFlush();
}
else
Sleep(200);
}
fclose(fout);
return 0;
}
/* ------------------ ORCA çalıştır / durdur ------------------ */
static int orca_start(const char* orca_exe, const char* inp_file)
{
if (g_running) return 0;
make_out_path(inp_file, g_out_path, sizeof(g_out_path));
IupSetAttribute(txt_log, "VALUE", "");
log_append("=== ORCA STARTED ===");
log_append(orca_exe);
log_append(inp_file);
log_append(g_out_path);
log_append("");
char cmdline[4*MAX_PATH];
// start /B -> yeni pencere açmadan çalıştır
// "" -> window title placeholder
snprintf(cmdline, sizeof(cmdline),
"cmd /C start /B \"\" \"%s\" \"%s\" > \"%s\"",
orca_exe, inp_file, g_out_path);
STARTUPINFOA si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&g_pi, sizeof(g_pi));
g_running = 1;
if (!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &g_pi))
{
g_running = 0;
log_append("ERROR: ORCA process could not start.");
return 0;
}
g_hThread = CreateThread(NULL, 0, ReaderThread, NULL, 0, NULL);
set_status("RUNNING...");
return 1;
}
static void orca_stop(void)
{
if (!g_running) return;
g_running = 0;
TerminateProcess(g_pi.hProcess, 1);
if (g_hThread)
{
WaitForSingleObject(g_hThread, 1000);
CloseHandle(g_hThread);
g_hThread = NULL;
}
if (g_pi.hProcess) CloseHandle(g_pi.hProcess);
if (g_pi.hThread) CloseHandle(g_pi.hThread);
ZeroMemory(&g_pi, sizeof(g_pi));
set_status("STOPPED.");
log_append("=== STOPPED ===");
}
static int timer_cb(Ihandle* ih)
{
(void)ih;
if (g_running)
{
DWORD code = 0;
if (GetExitCodeProcess(g_pi.hProcess, &code) && code != STILL_ACTIVE)
{
g_running = 0;
if (g_hThread)
{
WaitForSingleObject(g_hThread, 1000);
CloseHandle(g_hThread);
g_hThread = NULL;
}
set_status("FINISHED.");
log_append("=== ORCA FINISHED ===");
}
}
return IUP_DEFAULT;
}
/* ------------------ GUI callback ------------------ */
static int btn_pick_orca_cb(Ihandle* ih)
{
(void)ih;
Ihandle* dlg = IupFileDlg();
IupSetAttribute(dlg, "DIALOGTYPE", "OPEN");
IupSetAttribute(dlg, "FILTER", "*.exe");
IupSetAttribute(dlg, "TITLE", "Select orca.exe");
IupPopup(dlg, IUP_CENTER, IUP_CENTER);
const char* val = IupGetAttribute(dlg, "VALUE");
const char* status = IupGetAttribute(dlg, "STATUS");
if (status && atoi(status) != -1 && val && val[0])
IupSetStrAttribute(txt_orca, "VALUE", val);
IupDestroy(dlg);
return IUP_DEFAULT;
}
static int btn_pick_inp_cb(Ihandle* ih)
{
(void)ih;
Ihandle* dlg = IupFileDlg();
IupSetAttribute(dlg, "DIALOGTYPE", "OPEN");
IupSetAttribute(dlg, "FILTER", "*.inp");
IupSetAttribute(dlg, "TITLE", "Select ORCA input (*.inp)");
IupPopup(dlg, IUP_CENTER, IUP_CENTER);
const char* val = IupGetAttribute(dlg, "VALUE");
const char* status = IupGetAttribute(dlg, "STATUS");
if (status && atoi(status) != -1 && val && val[0])
IupSetStrAttribute(txt_inp, "VALUE", val);
IupDestroy(dlg);
return IUP_DEFAULT;
}
static int btn_run_cb(Ihandle* ih)
{
(void)ih;
const char* orca = IupGetAttribute(txt_orca, "VALUE");
const char* inp = IupGetAttribute(txt_inp, "VALUE");
if (!orca || !orca[0]) { log_append("ERROR: orca.exe not selected"); return IUP_DEFAULT; }
if (!inp || !inp[0]) { log_append("ERROR: input .inp not selected"); return IUP_DEFAULT; }
orca_start(orca, inp);
return IUP_DEFAULT;
}
static int btn_stop_cb(Ihandle* ih)
{
(void)ih;
orca_stop();
return IUP_DEFAULT;
}
static int dlg_close_cb(Ihandle* ih)
{
(void)ih;
orca_stop();
return IUP_CLOSE;
}
/* ------------------ main ------------------ */
int main(int argc, char** argv)
{
IupOpen(&argc, &argv);
IupControlsOpen();
txt_orca = IupText(NULL); IupSetAttributes(txt_orca, "EXPAND=HORIZONTAL");
txt_inp = IupText(NULL); IupSetAttributes(txt_inp, "EXPAND=HORIZONTAL");
Ihandle* btn_orca = IupButton("orca.exe...", NULL); IupSetCallback(btn_orca, "ACTION", (Icallback)btn_pick_orca_cb);
Ihandle* btn_inp = IupButton("input.inp...", NULL); IupSetCallback(btn_inp, "ACTION", (Icallback)btn_pick_inp_cb);
Ihandle* btn_run = IupButton("RUN", NULL); IupSetAttributes(btn_run, "SIZE=60x"); IupSetCallback(btn_run, "ACTION", (Icallback)btn_run_cb);
Ihandle* btn_stop = IupButton("STOP", NULL); IupSetAttributes(btn_stop,"SIZE=60x"); IupSetCallback(btn_stop,"ACTION",(Icallback)btn_stop_cb);
lbl_status = IupLabel("IDLE."); IupSetAttributes(lbl_status,"EXPAND=HORIZONTAL");
txt_log = IupText(NULL);
IupSetAttributes(txt_log,
"MULTILINE=YES, EXPAND=YES, READONLY=YES, "
"SCROLLBAR=YES, WORDWRAP=NO, FONT=Courier, VISIBLELINES=20");
Ihandle* row1 = IupHbox(IupLabel("ORCA: "), txt_orca, btn_orca, NULL);
Ihandle* row2 = IupHbox(IupLabel("INP : "), txt_inp, btn_inp, NULL);
Ihandle* row3 = IupHbox(btn_run, btn_stop, IupFill(), lbl_status, NULL);
Ihandle* vbox = IupVbox(row1, row2, row3, txt_log, NULL);
IupSetAttributes(vbox, "MARGIN=10x10, GAP=6");
Ihandle* dlg = IupDialog(vbox);
IupSetAttribute(dlg,"TITLE","ORCA GUI (IUP + C)");
IupSetAttribute(dlg,"SIZE","600x300");
IupSetCallback(dlg,"CLOSE_CB",(Icallback)dlg_close_cb);
/* Timer: process finished check */
Ihandle* timer = IupTimer();
IupSetAttribute(timer,"TIME","500");
IupSetCallback(timer,"ACTION_CB",(Icallback)timer_cb);
IupSetAttribute(timer,"RUN","YES");
Ihandle* icon = IupImage(32, 32, img_orca);
IupSetAttributeHandle(dlg, "ICON", icon);
IupShow(dlg);
IupMainLoop();
IupDestroy(timer);
IupDestroy(dlg);
IupClose();
return 0;
}