summaryrefslogtreecommitdiff
path: root/lib/py_aes.c
blob: e221ba814a862b08ccd8a527ff49c2f9dd684a75 (plain)
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#include "ldg_Python.h"
#include <gem.h>
#include <macros.h>

extern PyObject *GEMError;

/* --- Application Library --- */
PyObject* __CDECL py_appl_init(PyObject *self, PyObject *args)
{
int ret;

    ret = appl_init();
    return Py_BuildValue("i",ret);
}

PyObject* __CDECL py_appl_exit(PyObject *self, PyObject *args)
{
int ret;

    ret = appl_exit();
    return Py_BuildValue("i",ret);
}

PyObject* __CDECL py_appl_write(PyObject *self, PyObject *args)
{
int ret;
int app_id;
char *message;
int buflen;
int msg_length;
    
    if(!PyArg_ParseTuple(args,"iis#",&app_id,&msg_length,&message,&buflen))
        return NULL;
    
    if(buflen < msg_length) {
        PyErr_SetString(GEMError,"Data length's are dangerously inconsistent in appl_write");
        return NULL;
    }
    
    ret = appl_write(app_id,msg_length,message);
    return Py_BuildValue("i",ret);
}

PyObject* __CDECL py_appl_read(PyObject *self, PyObject *args)
{
int ret;
int app_id;
char *message;
int msg_length;
PyObject *ret_obj;
    
    if(!PyArg_ParseTuple(args,"ii",&app_id,&msg_length))
        return NULL;
    
    if(msg_length <= 0) {
        PyErr_SetString(GEMError,"Data length of zero requested in appl_read");
        return NULL;
    }
    
    message = (char *)malloc(msg_length*sizeof(char));
    ret = appl_read(app_id,msg_length,message);
    
    if(ret == 0) {
        PyErr_SetString(GEMError,"Application read request failed");
        return NULL;
    }
    
#ifdef PYTHON_3_API
    ret_obj = Py_BuildValue("y#",ret_obj,msg_length);
#else
    ret_obj = Py_BuildValue("s#",ret_obj,msg_length);
#endif

    free(message);
    return ret_obj;
}

/* --- Forms Library --- */
PyObject* __CDECL py_form_alert(PyObject *self, PyObject *args)
{
char *text;
int x;
    
    if(!PyArg_ParseTuple(args,"is",&x,&text))
        return NULL;
        
    x = form_alert(x,text);
    return Py_BuildValue("i",x);
}

PyObject* __CDECL py_form_dial(PyObject *self, PyObject *args)
{
int id;
int lx, ly, lw, lh;
int bx, by, bw, bh;
int ret;
    
    if(!PyArg_ParseTuple(args,"i(iiii)(iiii)",&id,&lx,&ly,&lw,&lh,&bx,&by,&bw,&bh))
        return NULL;
    
    ret = form_dial(id, lx, ly, lw, lh, bx, by, bw, bh);
    
    if(ret == 0) {
        PyErr_SetString(GEMError,"Form dial call failed");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_form_do(PyObject *self, PyObject *args)
{
PyObject *obj;
int x;
int ret;
    
    if(!PyArg_ParseTuple(args,"Oi",&obj,&x))
        return NULL;
        
    ret = form_do(PyCapsule_GetPointer(obj,NULL),x);
    return Py_BuildValue("i",ret);
}

PyObject* __CDECL py_form_center(PyObject *self, PyObject *args)
{
PyObject *obj;
short x,y,w,h;
int ret;
    
    if(!PyArg_ParseTuple(args,"O",&obj))
        return NULL;
        
    form_center(PyCapsule_GetPointer(obj,NULL),&x,&y,&w,&h);
    
    return Py_BuildValue("(iiii)",(int)x,(int)y,(int)w,(int)h);
}

/* --- Graphics Library --- */
PyObject* __CDECL py_graf_handle(PyObject *self)
{
short wchar,hchar,wcell,hcell;
int ret;
    
    ret = graf_handle(&wchar, &hchar, &wcell, &hcell);
    return Py_BuildValue("i(iiii)",ret,(int)wchar,(int)hchar,(int)wcell,(int)hcell);
}

PyObject* __CDECL py_graf_mouse(PyObject self, PyObject *args)
{
int mouse;

    if(!PyArg_ParseTuple(args,"i",&mouse))
        return NULL;

    if(mouse == USER_DEF) {
        PyErr_SetString(GEMError,"User-defined mouse pointers not currently supported");
        return NULL;
    }
    
    if(graf_mouse(mouse,NULL) == 0) {
        PyErr_SetString(GEMError,"Mouse cursor setting failed");
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}

/* --- Resources Library --- */
PyObject* __CDECL py_rsrc_load(PyObject *self, PyObject *args)
{
char *file;
int x;
    
    if(!PyArg_ParseTuple(args,"s",&file))
        return NULL;
        
    if(rsrc_load(file) == 0) {
        PyErr_SetString(GEMError,"Resource failed to load");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_rsrc_gaddr(PyObject *self, PyObject *args)
{
char *file;
int type, index;
void *gaddr;
    
    if(!PyArg_ParseTuple(args,"ii",&type,&index))
        return NULL;
        
    if(rsrc_gaddr(type,index,&gaddr) == 0) {
        PyErr_SetString(GEMError,"Resource item was not found");
        return NULL;
    }
    
    return PyCapsule_New(gaddr,NULL,NULL);
}

/* --- Windows Library --- */
PyObject* __CDECL py_wind_create(PyObject *self, PyObject *args)
{
int type, x, y, w, h;
int ret;
    
    if(!PyArg_ParseTuple(args,"i(iiii)",&type,&x,&y,&w,&h))
        return NULL;
    
    return Py_BuildValue("i",wind_create(type,x,y,w,h));
}

PyObject* __CDECL py_wind_close(PyObject *self, PyObject *args)
{
int id;
    
    if(!PyArg_ParseTuple(args,"i",&id))
        return NULL;
    
    if(wind_close(id) == 0) {
        PyErr_SetString(GEMError,"Window failed to close");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_wind_delete(PyObject *self, PyObject *args)
{
int id;
    
    if(!PyArg_ParseTuple(args,"i",&id))
        return NULL;
    
    if(wind_delete(id) == 0) {
        PyErr_SetString(GEMError,"Window was not deleted");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_wind_open(PyObject *self, PyObject *args)
{
int id, x, y, w, h;
int ret;
    
    if(!PyArg_ParseTuple(args,"i(iiii)",&id,&x,&y,&w,&h))
        return NULL;
        
    ret = wind_open(id,x,y,w,h);
    if(ret == 0) {
        PyErr_SetString(GEMError,"Window could not be opened");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_wind_get(PyObject *self, PyObject *args)
{
int id, gp;
short p1, p2, p3, p4;
int w1, w2, w3, w4;
int ret;
    
    if(!PyArg_ParseTuple(args,"ii",&id,&gp))
        return NULL;
        
    ret = wind_get(id,gp,&p1,&p2,&p3,&p4);
    
    w1 = (int)p1;
    w2 = (int)p2;
    w3 = (int)p3;
    w4 = (int)p4;
    
    if(ret == 0) {
        PyErr_SetString(GEMError,"Window request failed");
        return NULL;
    }
    
    switch(gp) {
    
        case WF_WORKXYWH:
        case WF_WINXCFG:
        case WF_WINX:
        case WF_WIDGETS:
        case WF_UNICONIFY:
        case WF_TOP:
        case WF_PREVXYWH:
        case WF_OWNER:
        case WF_NTOOLBAR:
        case WF_NEXTXYWH:
        case WF_MINXYWH:
        case WF_FULLXYWH:
        case WF_FTOOLBAR:
        case WF_FIRSTXYWH:
        /* case WF_DDELAY: */
        case WF_CURRXYWH:
            return Py_BuildValue("(iiii)", w1, w2, w3, w4);
            break;
        case WF_DCOLOR:
        case WF_ICONIFY:
        case WF_NEWDESK:
            return Py_BuildValue("(iii)", w1, w2, w3);
            break;
        case WF_MENU:
        case WF_TOOLBAR:
        case WF_M_WINDLIST:
            return Py_BuildValue("(ii)", w1, w2);
            break;
        /* case XA:
         *   return Py_BuildValue("ii", ret, w1);
         *   break;
         */
        case WF_BEVENT:
        case WF_BOTTOM:
        case WF_HSLIDE:
        case WF_HSLSIZE:
        case WF_KIND:
        case WF_M_OWNER:
        case WF_SHADE:
        case WF_VSLIDE:
        case WF_VSLSIZE:
        default:
            return Py_BuildValue("i", w1);
            break;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_wind_update(PyObject *self, PyObject *args)
{
int op;
int ret;
    
    if(!PyArg_ParseTuple(args,"i",&op))
        return NULL;
    if(wind_update(op) == 0) {
        PyErr_SetString(GEMError,"Window update failed");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_wind_set_string(PyObject *self, PyObject *args)
{
int id, sp;
char *str;
short w1, w2;

    if(!PyArg_ParseTuple(args,"iiz",&id,&sp,&str))
        return NULL;

    wind_set_str(id,sp,str);
    
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject* __CDECL py_wind_set(PyObject *self, PyObject *args)
{
int id, sp;
int w1, w2, w3, w4;
int ret;
PyObject *tpl;

    if(!PyArg_ParseTuple(args,"ii|O",&id,&sp,&tpl))
        return NULL;
    
    w1 = 0; w2 = 0; w3 = 0; w4 = 0;
    
    switch(sp) {
        case WF_BEVENT:
        case WF_BOTTOMALL:
        case WF_HSLIDE:
        case WF_HSLSIZE:
        case WF_M_BACKDROP:
        case WF_SHADE:
        case WF_STACK:
        case WF_TOPALL:
        case WF_VSLIDE:
        case WF_VSLSIZE:
        case WF_WHEEL:
            PyArg_ParseTuple(tpl,"i",&w1);
            break;
        case WF_COLOR:
        case WF_INFO:
        case WF_MENU:
        case WF_NAME:
        case WF_OPTS:
            PyArg_ParseTuple(tpl,"ii",&w1,&w2);
            break;
        case WF_DCOLOR:
        case WF_NEWDESK:
            PyArg_ParseTuple(tpl,"iii",&w1,&w2,&w3);
            break;
        case WF_CURRXYWH:
        /* case WF_DDELAY: */
        case WF_FULLXYWH:
        case WF_ICONIFY:
        case WF_PREVXYWH:
        case WF_UNICONIFYXYWH:
        case WF_WIDGETS:
        case WF_WINXCFG:
            PyArg_ParseTuple(tpl,"iiii",&w1,&w2,&w3,&w4);
            break;
    }
    
    ret = wind_set(id,sp,w1,w2,w3,w4);
    if(ret == 0) {
        PyErr_SetString(GEMError,"Window set failed");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}


/* --- Event Library --- */
PyObject* __CDECL py_evnt_multi(PyObject *self, PyObject *args, PyObject *kwargs)
{

EVMULT_IN em_in;
EVMULT_OUT em_out;


/* Because this is possibly the ugliest call ever created in the C
 * language, we'll use the same variable names as the docs use.
 */
int ev_mflags, ev_mbclicks, ev_mbmask, ev_mbstate, ev_mm1flags, ev_mm1x, ev_mm1y, ev_mm1width, ev_mm1height, ev_mm2flags;
int ev_mm2x, ev_mm2y, ev_mm2width, ev_mm2height, ev_mtlocount, ev_mthicount, ev_mmox, ev_mmoy;
int ev_mmbutton, ev_mmokstate, ev_mkreturn, ev_mbreturn;

static char message[16];

int ret;

PyObject *mbuttons;
PyObject *mmovement;
long int timer;

static char *kwlist[] = {"mouse_buttons","mouse_movement","timer",NULL};

    mbuttons = NULL;
    mmovement = NULL;
    timer = 0l;

    if(!PyArg_ParseTupleAndKeywords(args, kwargs, "i|OOl", kwlist,
                                     &ev_mflags, &mbuttons, &mmovement, &timer))
    //if(!PyArg_ParseTuple(args,"i",&ev_mflags))
        return NULL;
            
    //form_alert(0,"[3][Args parsed][Ok]");
    em_in.emi_flags = (short)ev_mflags;
    
    /* Timer handling */
    em_in.emi_tlow = loword(timer);
    em_in.emi_thigh = hiword(timer);

    /* Mouse button handling */
    if(mbuttons != NULL) {
        PyArg_ParseTuple(mbuttons,"iii",&ev_mbclicks,&ev_mbmask,&ev_mbstate);
        em_in.emi_bclicks = (short)ev_mbclicks;
        em_in.emi_bmask = (short)ev_mbmask;
        em_in.emi_bstate = (short)ev_mbstate;
    }
    
    /* Mouse movement handling */
    if(mmovement != NULL) {
        PyArg_ParseTuple(mmovement,"iiiiiiiiii)",&ev_mm1flags,&ev_mm1x,&ev_mm1y,&ev_mm1width,ev_mm1height,
                                                        &ev_mm2flags,&ev_mm2x,&ev_mm2y,&ev_mm2width,ev_mm2height);
        em_in.emi_m1leave = (short)ev_mm1flags;
        em_in.emi_m1.g_x = (short)ev_mm1x;
        em_in.emi_m1.g_y = (short)ev_mm1y;
        em_in.emi_m1.g_w = (short)ev_mm1width;
        em_in.emi_m1.g_h = (short)ev_mm1height;
        
        em_in.emi_m2leave = (short)ev_mm2flags;
        em_in.emi_m2.g_x = (short)ev_mm2x;
        em_in.emi_m2.g_y = (short)ev_mm2y;
        em_in.emi_m2.g_w = (short)ev_mm2width;
        em_in.emi_m2.g_h = (short)ev_mm2height;
    }

    /* Use the not-so-portable fast multi call */
    ret = evnt_multi_fast(&em_in, message, &em_out);
    //form_alert(0,"[3][Args parsed][Ok]");
//#ifdef PYTHON_3_API
    //return Py_BuildValue("{s:i,s:y#,s:(ii),s:(ii),s:(ii)}", 
//#else
    return Py_BuildValue("{s:i,s:s#,s:(ii),s:(ii),s:(ii)}", 
//#endif
                            "events", ret, 
                            "message", message, 16, 
                            "mouse_position", (int)em_out.emo_mouse.p_x, (int)em_out.emo_mouse.p_y, 
                            "mouse_button", (int)em_out.emo_mbutton, (int)em_out.emo_mclicks,
                            "key", (int)em_out.emo_kreturn,(int)em_out.emo_kmeta);
}

/* Menu Library */
PyObject* __CDECL py_menu_bar(PyObject *self, PyObject *args)
{
PyObject *object;
int action;
int ret;

    if(!PyArg_ParseTuple(args,"Oi",&object, &action))
        return NULL;

    ret = menu_bar(PyCapsule_GetPointer(object,NULL),action);
    
    if(ret == 0) {
        PyErr_SetString(GEMError,"Menu bar failed to set properly");
        return NULL;
    }    
    Py_INCREF(Py_None);
    return Py_None;
}

/* Object Library */
PyObject* __CDECL py_objc_draw(PyObject *self, PyObject *args)
{
PyObject *object;
int id,depth;
int cx, cy, cw, ch;
int ret;
    
    if(!PyArg_ParseTuple(args,"Oii(iiii)",&object,&id,&depth,&cx,&cy,&cw,&ch))
        return NULL;
    
    ret = objc_draw(PyCapsule_GetPointer(object,NULL),id,depth,cx,cy,cw,ch);
    
    if(ret == 0) {
        PyErr_SetString(GEMError,"Object draw call failed");
        return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}