-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputd.c
651 lines (594 loc) · 10.7 KB
/
inputd.c
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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#include <string.h>
#include <stdio.h>
#include <time.h>
#include "input.h"
#include "icons.h"
#include "text.h"
#include "io.h"
#include "gfx.h"
#include "pngw.h"
#define xbrd scale2res(25)
#define ybrd scale2res(25)
#define exsz scale2res(23)
#define eysz scale2res(38)
#define bxsz scale2res(60)
#define bysz scale2res(60)
#define hsz scale2res(50)
#define tys scale2res(30)
#define NUM '#'
#define ANUM '@'
#define HEX '^'
#define ndelay 2
#define REPEAT_TIMER 2
char rstr[512]={0},tstr[512]={0}, *format=NULL, *estr=NULL;
unsigned int kpos=0;
int epos=-1,cpos=0,cnt,first=1,hex=0;
const char kcod[10][13]={"0 _.:,;$@()#","1-+*/", "2abcä", "3def", "4ghi", "5jkl", "6mnoö", "7pqrsß", "8tuvü", "9wxyz"};
const char hcod[10][13]={"0","1", "2abc", "3def", "4", "5", "6", "7", "8", "9"};
unsigned rc;
extern int radius;
extern int rcvalue;
const char INST_FILE[]="/tmp/rc.locked";
int instance=0;
int rclocked=0;
int rcvalue=0;
int get_instance(void)
{
FILE *fh;
int rval=0;
if((fh=fopen(INST_FILE,"r"))!=NULL)
{
rval=fgetc(fh);
fclose(fh);
}
return rval;
}
void put_instance(int pval)
{
FILE *fh;
if(pval)
{
if (!rclocked) {
rclocked=1;
system("pzapit -lockrc > /dev/null");
}
if((fh=fopen(INST_FILE,"w"))!=NULL)
{
fputc(pval,fh);
fclose(fh);
}
}
else
{
remove(INST_FILE);
system("pzapit -unlockrc > /dev/null");
}
}
int IsAlpha(char ch)
{
const char uml[]="ÄÖÜäöü";
return (((ch>='A')&&(ch<='Z')) || ((ch>='a')&&(ch<='z')) || strchr(uml,ch));
}
int IsNum(char ch)
{
return ((ch>='0')&&(ch<='9'));
}
int IsInput(char ch)
{
if((ch==NUM) || (ch==ANUM))
{
hex=0;
return 1;
}
if (ch==HEX)
{
hex=1;
return 1;
}
return 0;
}
void FindCode(char ch)
{
if(!hex)
{
for(cpos=0; cpos<10; cpos++)
{
for(kpos=0; kpos<strlen(kcod[cpos]); kpos++)
{
if(ch==kcod[cpos][kpos])
{
return;
}
}
}
}
else
{
for(cpos=0; cpos<10; cpos++)
{
for(kpos=0; kpos<strlen(hcod[cpos]); kpos++)
{
if(ch==hcod[cpos][kpos])
{
return;
}
}
}
}
}
void NextPos(void)
{
do
{
epos++;
if(epos>=cnt)
{
epos=0;
}
}
while(!IsInput(format[epos]));
FindCode(estr[epos]);
first=1;
}
void PrevPos(void)
{
do
{
epos--;
if(epos<0)
{
epos=cnt-1;
}
}
while(!IsInput(format[epos]));
FindCode(estr[epos]);
first=1;
}
void SetCode(int code)
{
if(format[epos]==NUM)
{
hex=0;
cpos=code;
kpos=0;
estr[epos]=kcod[cpos][kpos];
NextPos();
}
else
{
if(format[epos]==HEX)
{
hex=1;
if(strlen(hcod[code])>1)
{
if(!first)
{
if(cpos==code)
{
if(++kpos>=strlen(hcod[cpos]))
{
kpos=0;
}
}
else
{
NextPos();
cpos=code;
kpos=0;
first=0;
}
estr[epos]=hcod[cpos][kpos];
}
else
{
cpos=code;
kpos=0;
estr[epos]=hcod[cpos][kpos];
first=0;
}
}
else
{
cpos=code;
kpos=0;
estr[epos]=hcod[cpos][kpos];
NextPos();
}
}
else
{
hex=0;
if(!first)
{
if(cpos==code)
{
if(++kpos>=strlen(kcod[cpos]))
{
kpos=0;
}
}
else
{
NextPos();
cpos=code;
kpos=1;
first=0;
}
estr[epos]=kcod[cpos][kpos];
}
else
{
cpos=code;
kpos=1;
estr[epos]=kcod[cpos][kpos];
first=0;
}
}
}
}
int ReTransform_Msg(char *msg)
{
unsigned i;
int found=0;
char *sptr=msg, *tptr=tstr;
*tptr=0;
while(*sptr)
{
found=0;
for(i=0; i<sizeof(tc)/sizeof(tc[0]) && !found; i++)
{
rc=*sptr;
if(rc==tc[i])
{
rc=sc[i];
*(tptr++)='~';
found=1;
}
}
*tptr=rc;
++sptr;
++tptr;
}
*tptr=0;
return strlen(rstr);
}
char *inputd(char *form, char *title, char *defstr, int keys, int frame, int mask, int bhelp, int cols, int tmo)
{
int iw, ih, xsize=0, ysize=0, icon_w=0, icon_h=0;
int i, j, tlen;
int exs, eys, wxs, wxw, wys, wyw, xp, yp;
char trnd[2]={0,0}, tch;
int act_key=-1, last_key=-1, run=1, ipos=0, count=0;
time_t t1, t2, tm1;
// only for num block
const char knum[12][2]={"1","2","3","4","5","6","7","8","9"," ","0"};
const char kalp[12][6]={"+-*/","abcä","def","ghi","jkl","mnoö","pqrsß","tuvü","wxyz","","_,.;"};
epos=-1;
cpos=0;
kpos=0;
first=1;
time(&tm1);
if(cols>25)
{
cols=25;
}
if(cols<1)
{
cols=1;
}
format=form;
estr=strdup(form);
cnt=strlen(form);
tlen=i=GetStringLen(title, BIG)+OFFSET_MED;
j=((cnt>cols)?cols:cnt)*exsz;
if(j>i)
{
i=j;
}
if(keys)
{
j=3*bxsz;
if(j>i)
{
i=j;
}
}
wxw=i+2*xbrd;
wxw=(keys==1 && wxw < scale2res(265)) ? scale2res(265) : wxw;
i=(((cnt-1)/cols)+1)*eysz;
if(keys)
{
i+=4*bysz;
}
wyw=((keys)?4:2)*ybrd+i;
wxs=((ex-sx)-wxw)/2;
wys=(((ey-sy)-wyw)+hsz)/2;
exs=wxs+(wxw-((cnt>cols)?cols:cnt)*exsz)/2;
eys=wys+ybrd;
*estr=0;
*rstr=0;
j=0;
for(i=0; i<(int)strlen(format); i++)
{
tch=format[i];
if(IsInput(tch))
{
if(epos==-1)
{
epos=i;
}
if(defstr && j<(int)strlen(defstr))
{
estr[i]=defstr[j++];
}
else
{
estr[i]=' ';
}
}
else
{
estr[i]=format[i];
}
}
estr[i]=0;
// icon & title
RenderBox(wxs+OFFSET_SMALL, wys-hsz+OFFSET_SMALL, wxs+wxw+OFFSET_SMALL, wys+wyw+OFFSET_SMALL, radius, COL_SHADOW_PLUS_0);
RenderBox(wxs, wys-hsz, wxs+wxw, wys+wyw, radius, CMC);
RenderBox(wxs, wys-hsz, wxs+wxw, wys, radius, CMH);
png_getsize(ICON_KEYS, &icon_w, &icon_h);
if(icon_w > 40 || icon_h > 40)
icon_w = icon_h = xsize = ysize = 40;
int offw = OFFSET_SMALL+OFFSET_MIN;
paintIcon(ICON_KEYS, wxs+offw, wys-hsz/2-icon_h/2, xsize, ysize, &iw, &ih);
int tstart, twide;
if(wxs+offw+iw >= wxs+wxw-offw-iw-tlen ) {
tstart = wxs+offw+iw;
twide = wxw-offw-iw;
}
else {
tstart = wxs;
twide = wxw;
}
RenderString(title, tstart, wys-7, twide, CENTER, BIG, CMHT);
int bxs=wxs+(wxw-(3*bxsz))/2;
int bys=((wys+wyw)-2*ybrd)-4*bysz;
if(keys == 1)
{
png_getsize(ICON_NUMERIC_PAD, &icon_w, &icon_h);
paintIcon(ICON_NUMERIC_PAD, wxs+wxw/2-scale2res(icon_w)/2, bys+OFFSET_MED, scale2res(icon_w), scale2res(icon_h), &iw, &ih);
}
if(keys == 2)
{
for(i=0; i<11; i++)
{
if(i!=9) //num fields
{
RenderBox(bxs+(i%3)*bxsz, bys+(i/3)*bysz, bxs+((i%3)+1)*bxsz, bys+((i/3)+1)*bysz, radius, CMS);
RenderBox(bxs+(i%3)*bxsz+2, bys+(i/3)*bysz+2, bxs+((i%3)+1)*bxsz-2, bys+((i/3)+1)*bysz-2, radius, CMC);
RenderString(knum[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz/2+8, bxsz, CENTER, MED, CMCIT);
RenderString(kalp[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz-2, bxsz, CENTER, SMALL, CMCIT);
}
}
}
if(keys)
{
png_getsize(ICON_BUTTON_RED, &icon_w, &icon_h);
paintIcon(ICON_BUTTON_RED, bxs-icon_w/2, wys+wyw-ybrd-2-icon_h/2, 0, 0, &iw, &ih);
RenderString("Groß/Klein", bxs+icon_w/2+OFFSET_SMALL/*5*/,wys+wyw-ybrd+OFFSET_MED/*10*/, 2*bxsz, LEFT, SMALL, CMCIT);
paintIcon(ICON_BUTTON_YELLOW, bxs+scale2res(125)-icon_w/2, wys+wyw-ybrd-2-icon_h/2, 0, 0, &iw, &ih);
RenderString("löschen", bxs+scale2res(125)+icon_w/2+OFFSET_SMALL,wys+wyw-ybrd+OFFSET_MED, bxsz, LEFT, SMALL, CMCIT);
}
while(run)
{
for(i=0; i<cnt; i++)
{
xp=i%cols;
yp=i/cols;
if(frame && IsInput(format[i]))
{
RenderBox(exs+xp*exsz, eys+OFFSET_SMALL+yp*eysz, exs+(xp+1)*exsz, eys+(yp+1)*eysz, 0/*radius*/, CMS);
}
RenderBox(exs+xp*exsz+1, eys+OFFSET_SMALL+yp*eysz+1, exs+(xp+1)*exsz-1, eys+(yp+1)*eysz-1, 0/*radius*/, (epos==i)?CMCS:CMC);
*trnd=(mask && format[i]==NUM && IsNum(estr[i]))?'*':estr[i];
RenderString(trnd, exs+xp*exsz, eys+yp*eysz+tys+OFFSET_SMALL/*7*/, exsz, CENTER, MED, (epos==i)?CMCST:(IsInput(format[i]))?CMCT:CMCIT);
}
memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
time(&t1);
i=-1;
while(i==-1)
{
i=GetRCCode(1000);
if (i != KEY_UP && i != KEY_DOWN && i != KEY_LEFT && i != KEY_RIGHT)
{
if (rcvalue == 2 && count < 3)
{
count++;
i = -1;
}
}
time(&t2);
if(tmo)
{
//printf("t2-t1 = %f %i\n", difftime(t2, t1), tmo);
if((t2-t1)>=tmo)
{
i=KEY_EXIT;
}
}
if((((format[epos]!=NUM) && (format[epos]!=HEX)) || ((format[epos]==HEX)&&(strlen(hcod[cpos])>1))) && ((t2-t1)>=ndelay) && last_key>=0)
{
act_key=i=-2;
NextPos();
}
}
count=0;
act_key=i;
switch(act_key)
{
case KEY_0:
SetCode(0);
break;
case KEY_1:
SetCode(1);
break;
case KEY_2:
SetCode(2);
break;
case KEY_3:
SetCode(3);
break;
case KEY_4:
SetCode(4);
break;
case KEY_5:
SetCode(5);
break;
case KEY_6:
SetCode(6);
break;
case KEY_7:
SetCode(7);
break;
case KEY_8:
SetCode(8);
break;
case KEY_9:
SetCode(9);
break;
case KEY_RIGHT:
NextPos();
act_key=-2;
break;
case KEY_LEFT:
PrevPos();
act_key=-2;
break;
case KEY_VOLUMEUP:
ipos=epos;
while(IsInput(format[ipos+1]) && ((ipos+1)<cnt))
{
++ipos;
}
while(ipos>epos)
{
estr[ipos]=estr[ipos-1];
--ipos;
}
estr[epos]=' ';
// estr[epos]=((format[epos]=='#')||(format[epos]=='^'))?'0':' ';
act_key=-1;
break;
case KEY_VOLUMEDOWN:
ipos=epos+1;
while(IsInput(format[ipos]) && (ipos<cnt))
{
estr[ipos-1]=estr[ipos];
++ipos;
}
estr[ipos-1]=' ';
// estr[ipos-1]=(format[ipos-1]=='#')?'0':' ';
act_key=-1;
break;
case KEY_OK:
run=0;
break;
case KEY_MUTE:
memset(lfb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
while(GetRCCode(300)!=KEY_MUTE);
break;
case KEY_UP:
if(epos>=cols)
{
epos-=cols;
if(!IsInput(format[epos]))
{
NextPos();
}
}
else
{
epos=cnt-1;
if(!IsInput(format[epos]))
{
PrevPos();
}
}
act_key=-2;
break;
case KEY_DOWN:
if(epos<=(cnt-cols))
{
epos+=cols;
if(!IsInput(format[epos]))
{
NextPos();
}
}
else
{
epos=0;
if(!IsInput(format[epos]))
{
NextPos();
}
}
act_key=-2;
break;
case KEY_EXIT:
free(estr);
estr=NULL;
*rstr=0;
run=0;
break;
case KEY_RED:
if(IsAlpha(estr[epos]))
{
estr[epos]^=0x20;
}
act_key=-2;
break;
case KEY_YELLOW:
epos=-1;
for(i=0; i<(int)strlen(format); i++)
{
if(IsInput(format[i]))
{
if(epos==-1)
{
epos=i;
}
estr[i]=' ';
}
}
act_key=-2;
break;
case KEY_HELP:
if(bhelp)
{
sprintf(estr,"?");
run=0;
}
break;
default:
act_key=-2;
break;
}
last_key=act_key;
}
if(estr)
{
j=0;
for(i=0; i<(int)strlen(format); i++)
{
if(IsInput(format[i]))
{
rstr[j++]=estr[i];
}
}
rstr[j]=0;
free(estr);
}
ReTransform_Msg(rstr);
return rstr;
}