-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
899 lines (805 loc) · 23.5 KB
/
Main.cpp
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
// ============================================================================
//
// This file are where the Conditions/Actions/Expressions are defined.
// You can manually enter these, or use CICK (recommended)
// See the Extension FAQ in this SDK for more info and where to download it
//
// ============================================================================
// Common Include
#include "common.h"
// Quick memo: content of the eventInformations arrays
// ---------------------------------------------------
// Menu ID
// String ID
// Code
// Flags
// Number_of_parameters
// Parameter_type [Number_of_parameters]
// Parameter_TitleString [Number_of_parameters]
// Definitions of parameters for each condition
short conditionsInfos[]=
{
0
};
// Definitions of parameters for each action
short actionsInfos[]=
{
0
};
// Definitions of parameters for each expression
short expressionsInfos[]=
{
EID_GetTodayStamp, EID_GetTodayStamp, 7, 0, 0,
EID_GetTimeStamp, EID_GetTimeStamp, 0, 0, 6, EXPPARAM_LONG, EXPPARAM_LONG, EXPPARAM_LONG, EXPPARAM_LONG, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_GetTimeStamp, EP1ID_GetTimeStamp, EP2ID_GetTimeStamp, EP3ID_GetTimeStamp, EP4ID_GetTimeStamp, EP5ID_GetTimeStamp,
EID_GetTimezone, EID_GetTimezone, 17, 0, 0,
EID_GetYearDiff, EID_GetYearDiff, 20, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_GetYearDiff, EP1ID_GetYearDiff,
EID_GetMonthDiff, EID_GetMonthDiff, 21, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_GetMonthDiff, EP1ID_GetMonthDiff,
EID_GetDayDiff, EID_GetDayDiff, 22, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_GetDayDiff, EP1ID_GetDayDiff,
EID_GetHoursDiff, EID_GetHoursDiff, 23, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_GetHoursDiff, EP1ID_GetHoursDiff,
EID_GetMinutesDiff, EID_GetMinutesDiff, 24, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_GetMinutesDiff, EP1ID_GetMinutesDiff,
EID_GetSecondsDiff, EID_GetSecondsDiff, 25, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_GetSecondsDiff, EP1ID_GetSecondsDiff,
EID_GetYear, EID_GetYear, 1, 0, 1, EXPPARAM_LONG, EP0ID_GetYear,
EID_GetMonth, EID_GetMonth, 2, 0, 1, EXPPARAM_LONG, EP0ID_GetMonth,
EID_GetDay, EID_GetDay, 3, 0, 1, EXPPARAM_LONG, EP0ID_GetDay,
EID_GetHours, EID_GetHours, 4, 0, 1, EXPPARAM_LONG, EP0ID_GetHours,
EID_GetMinutes, EID_GetMinutes, 5, 0, 1, EXPPARAM_LONG, EP0ID_GetMinutes,
EID_GetSeconds, EID_GetSeconds, 6, 0, 1, EXPPARAM_LONG, EP0ID_GetSeconds,
EID_GetDayofWeek, EID_GetDayofWeek, 8, 0, 1, EXPPARAM_LONG, EP0ID_GetDayofWeek,
EID_AddYears, EID_AddYears, 10, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_AddYears, EP1ID_AddYears,
EID_AddMonths, EID_AddMonths, 11, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_AddMonths, EP1ID_AddMonths,
EID_AddWeeks, EID_AddWeeks, 12, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_AddWeeks, EP1ID_AddWeeks,
EID_AddDays, EID_AddDays, 13, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_AddDays, EP1ID_AddDays,
EID_AddHours, EID_AddHours, 14, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_AddHours, EP1ID_AddHours,
EID_AddMinutes, EID_AddMinutes, 15, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_AddMinutes, EP1ID_AddMinutes,
EID_AddSeconds, EID_AddSeconds, 16, 0, 2, EXPPARAM_LONG, EXPPARAM_LONG, EP0ID_AddSeconds, EP1ID_AddSeconds,
EID_GetFullString, EID_GetFullString, 9, EXPFLAG_STRING, 1, EXPPARAM_LONG, EP0ID_GetFullString,
EID_GetYYYYMMDD, EID_GetYYYYMMDD, 18, EXPFLAG_STRING, 1, EXPPARAM_LONG, EP0ID_GetYYYYMMDD,
EID_GetHHMMSS, EID_GetHHMMSS, 19, EXPFLAG_STRING, 1, EXPPARAM_LONG, EP0ID_GetHHMMSS,
EID_GetAsText, EID_GetAsText, 26, EXPFLAG_STRING, 1, EXPPARAM_LONG, EP0ID_GetAsText,
EID_GetVal, EID_GetVal, 27, 0, 1, EXPPARAM_STRING, EP0ID_GetVal,
};
// ============================================================================
//
// CONDITION ROUTINES
//
// ============================================================================
// ============================================================================
//
// ACTIONS ROUTINES
//
// ============================================================================
// ============================================================================
//
// EXPRESSIONS ROUTINES
//
// ============================================================================
long WINAPI DLLExport GetTodayStamp(LPRDATA rdPtr, long param1)
{
__time64_t timestamp=_time64(0);
if(timestamp>4294967294 || timestamp==-1)
return -1;
else
return (long)timestamp;
}
long WINAPI DLLExport GetTimeStamp(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
long p3=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
long p4=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
long p5=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
long p6=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
tm datetime;
datetime.tm_year=p1-1900;
datetime.tm_mon=p2-1;
datetime.tm_mday=p3;
datetime.tm_hour=p4;
datetime.tm_min=p5;
datetime.tm_sec=p6;
datetime.tm_isdst=-1;
datetime.tm_wday=0;
datetime.tm_yday=0;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport GetTimezone(LPRDATA rdPtr, long param1)
{
rdPtr->rHo.hoFlags |= HOF_FLOAT;
_tzset();
float timezone=-_timezone/3600.0f;
return *(long*)&timezone;
}
long WINAPI DLLExport GetYear(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return temptime->tm_year+1900;
}
return rdPtr->datetime.tm_year+1900;
}
long WINAPI DLLExport GetMonth(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return temptime->tm_mon+1;
}
return rdPtr->datetime.tm_mon+1;
}
long WINAPI DLLExport GetDay(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return temptime->tm_mday;
}
return rdPtr->datetime.tm_mday;
}
long WINAPI DLLExport GetHours(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return temptime->tm_hour;
}
return rdPtr->datetime.tm_hour;
}
long WINAPI DLLExport GetMinutes(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return temptime->tm_min;
}
return rdPtr->datetime.tm_min;
}
long WINAPI DLLExport GetSeconds(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return temptime->tm_sec;
}
return rdPtr->datetime.tm_sec;
}
long WINAPI DLLExport GetDayofWeek(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return temptime->tm_wday;
}
return rdPtr->datetime.tm_wday;
}
long WINAPI DLLExport AddYears(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *datetime=_localtime64(×tamp);
if(datetime==0)
return -1;
datetime->tm_year+=p2;
datetime->tm_isdst=-1;
timestamp=_mktime64(datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=*datetime;
rdPtr->timestamp=p1;
return (time_t)timestamp;
}
tm datetime;
datetime=rdPtr->datetime;
datetime.tm_year+=p2;
//datetime.tm_isdst=-1;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport AddMonths(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
temptime->tm_mon+=p2;
temptime->tm_isdst=-1;
timestamp=_mktime64(temptime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return (time_t)timestamp;
}
tm datetime;
datetime=rdPtr->datetime;
datetime.tm_mon+=p2;
//datetime.tm_isdst=-1;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport AddWeeks(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
temptime->tm_mday+=7*p2;
temptime->tm_isdst=-1;
timestamp=_mktime64(temptime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return (time_t)timestamp;
}
tm datetime;
datetime=rdPtr->datetime;
datetime.tm_mday+=7*p2;
//datetime.tm_isdst=-1;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport AddDays(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
temptime->tm_mday+=p2;
temptime->tm_isdst=-1;
timestamp=_mktime64(temptime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return (time_t)timestamp;
}
tm datetime;
datetime=rdPtr->datetime;
datetime.tm_mday+=p2;
//datetime.tm_isdst=-1;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport AddHours(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
temptime->tm_hour+=p2;
temptime->tm_isdst=-1;
timestamp=_mktime64(temptime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return (time_t)timestamp;
}
tm datetime;
datetime=rdPtr->datetime;
datetime.tm_hour+=p2;
// datetime.tm_isdst=-1;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport AddMinutes(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
temptime->tm_min+=p2;
temptime->tm_isdst=-1;
timestamp=_mktime64(temptime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return (time_t)timestamp;
}
tm datetime;
datetime=rdPtr->datetime;
datetime.tm_min+=p2;
// datetime.tm_isdst=-1;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport AddSeconds(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1)
return -1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
temptime->tm_sec+=p2;
temptime->tm_isdst=-1;
timestamp=_mktime64(temptime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
return (time_t)timestamp;
}
tm datetime;
datetime=rdPtr->datetime;
datetime.tm_sec+=p2;
// datetime.tm_isdst=-1;
__time64_t timestamp=_mktime64(&datetime);
if(timestamp>4294967294 || timestamp==-1)
return -1;
rdPtr->datetime=datetime;
rdPtr->timestamp=(time_t)timestamp;
return (time_t)timestamp;
}
long WINAPI DLLExport GetFullString(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
rdPtr->rHo.hoFlags |= HOF_STRING;
if(p1==-1)
return (long)"Error: Invalid TimeStamp";
__time64_t timestamp=(unsigned)p1;
char* temp;
if((temp=_ctime64(×tamp))==0)
return (long)"Error: Invalid TimeStamp";
else
return (long)temp;
}
long WINAPI DLLExport GetYYYYMMDD(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
rdPtr->rHo.hoFlags |= HOF_STRING;
if(p1==-1)
return (long)"Error: Invalid TimeStamp";
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return (long)"Error: Invalid TimeStamp";
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
}
static char temp[9]="YYYYMMDD";
temp[0]=(rdPtr->datetime.tm_year>=100)?'2':'1';//(rdPtr->datetime.tm_year+1900>=2000)
temp[1]='0'+(rdPtr->datetime.tm_year/100+9)%10;
temp[2]='0'+(rdPtr->datetime.tm_year/10)%10;
temp[3]='0'+rdPtr->datetime.tm_year%10;
temp[4]='0'+(rdPtr->datetime.tm_mon+1)/10;
temp[5]='0'+(rdPtr->datetime.tm_mon+1)%10;
temp[6]='0'+rdPtr->datetime.tm_mday/10;
temp[7]='0'+rdPtr->datetime.tm_mday%10;
return (long)temp;
}
long WINAPI DLLExport GetAsText(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
rdPtr->rHo.hoFlags |= HOF_STRING;
if(p1==-1)
return (long)"Error: Invalid TimeStamp";
static char temp[66]=""; //_i64toa docs say that it can never write more than 65 chars + null
_i64toa((unsigned)p1, temp, 10);
return (long)temp;
}
long WINAPI DLLExport GetVal(LPRDATA rdPtr, long param1)
{
char* p1=(char*)CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_STRING);
unsigned int temp = -1;
temp = (unsigned int)_atoi64(p1);
return (long)temp;
}
long WINAPI DLLExport GetHHMMSS(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
rdPtr->rHo.hoFlags |= HOF_STRING;
if(p1==-1)
return (long)"Error: Invalid TimeStamp";
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return (long)"Error: Invalid TimeStamp";
rdPtr->datetime=*temptime;
rdPtr->timestamp=p1;
}
static char temp[7]="HHMMSS";
temp[0]='0'+rdPtr->datetime.tm_hour/10;
temp[1]='0'+rdPtr->datetime.tm_hour%10;
temp[2]='0'+rdPtr->datetime.tm_min/10;
temp[3]='0'+rdPtr->datetime.tm_min%10;
temp[4]='0'+rdPtr->datetime.tm_sec/10;
temp[5]='0'+rdPtr->datetime.tm_sec%10;
return (long)temp;
}
long WINAPI DLLExport GetYearDiff(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1 || p2==-1)
return -1;
if(p1==p2)
return 0;
tm datetime;
int year1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
datetime=*temptime;
year1=temptime->tm_year;
}
else
{
datetime=rdPtr->datetime;
year1=datetime.tm_year;
}
int year2;
if(p2!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p2;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
year2=temptime->tm_year;
}
else
year2=rdPtr->datetime.tm_year;
datetime.tm_year=year2;
__time64_t timestamp1a=_mktime64(&datetime);
if(timestamp1a==-1) // shouldn't happen
return -1;
if((unsigned)p1>(unsigned)p2)
if(timestamp1a>=(__time64_t)(unsigned)p2)
return year1-year2;
else
return year1-year2-1;
else
if(timestamp1a<=(__time64_t)(unsigned)p2)
return year1-year2;
else
return year1-year2+1;
}
long WINAPI DLLExport GetMonthDiff(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1 || p2==-1)
return -1;
if(p1==p2)
return 0;
tm datetime;
int mon1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
datetime=*temptime;
mon1=temptime->tm_mon;
}
else
{
datetime=rdPtr->datetime;
mon1=datetime.tm_mon;
}
int year2, mon2;
if(p2!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p2;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
year2=temptime->tm_year;
mon2=temptime->tm_mon;
}
else
{
year2=rdPtr->datetime.tm_year;
mon2=rdPtr->datetime.tm_mon;
}
datetime.tm_year=year2;
datetime.tm_mon=mon2;
__time64_t timestamp1a=_mktime64(&datetime);
if(timestamp1a==-1) // shouldn't happen
return -1;
if((unsigned)p1>(unsigned)p2)
if(timestamp1a>=(__time64_t)(unsigned)p2)
return (mon1-mon2+12)%12;
else
return (mon1-mon2+11)%12;
else
if(timestamp1a<=(__time64_t)(unsigned)p2)
return (mon1-mon2-12)%12;
else
return (mon1-mon2-11)%12;
}
long WINAPI DLLExport GetDayDiff(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
if(p1==-1 || p2==-1)
return -1;
if(p1==p2)
return 0;
tm datetime1;
if(p1!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p1;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
datetime1=*temptime;
}
else
{
datetime1=rdPtr->datetime;
}
tm datetime2;
if(p2!=rdPtr->timestamp)
{
__time64_t timestamp=(unsigned)p2;
tm *temptime=_localtime64(×tamp);
if(temptime==0)
return -1;
datetime2=*temptime;
}
else
{
datetime2=rdPtr->datetime;
}
// move datetime1 into the same dst block as datetime2
// alter the hour instead of the isdst setting because a negative
// isdst makes it set the isdst instead of alter the hour.
datetime1.tm_hour += datetime2.tm_isdst - datetime1.tm_isdst;
_mktime64(&datetime1);
// prepare a datetime that is datetime1's time and datetime 2's date
tm datetime1a = datetime1;
datetime1a.tm_year=datetime2.tm_year;
datetime1a.tm_mon=datetime2.tm_mon;
datetime1a.tm_mday=datetime2.tm_mday;
__time64_t timestamp1a=_mktime64(&datetime1a);
if(timestamp1a==-1) // shouldn't happen
return -1;
if((unsigned)p1>(unsigned)p2)
{
if(timestamp1a>=(__time64_t)(unsigned)p2)
{
if(datetime1.tm_mday<datetime2.tm_mday)
datetime1a.tm_mon++;
datetime1a.tm_mday=datetime1.tm_mday;
if(_mktime64(&datetime1a)==-1)
return -1; // shouldn't happen
return datetime1a.tm_yday-datetime2.tm_yday;
}
else
{
if(datetime1.tm_mday<=datetime2.tm_mday)
datetime1a.tm_mon++;
datetime1a.tm_mday=datetime1.tm_mday;
if(_mktime64(&datetime1a)==-1)
return -1; // shouldn't happen
return datetime1a.tm_yday-datetime2.tm_yday-1;
}
}
else
{
if(timestamp1a<=(__time64_t)(unsigned)p2)
{
if(datetime1.tm_mday>datetime2.tm_mday)
datetime1a.tm_mon--;
datetime1a.tm_mday=datetime1.tm_mday;
if(_mktime64(&datetime1a)==-1)
return -1; // shouldn't happen
return datetime1a.tm_yday-datetime2.tm_yday;
}
else
{
if(datetime1.tm_mday>=datetime2.tm_mday)
datetime1a.tm_mon--;
datetime1a.tm_mday=datetime1.tm_mday;
if(_mktime64(&datetime1a)==-1)
return -1; // shouldn't happen
return datetime1a.tm_yday-datetime2.tm_yday+1;
}
}
}
long WINAPI DLLExport GetHoursDiff(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
__time64_t timestamp1 = (unsigned)p1;
__time64_t timestamp2 = (unsigned)p2;
return (long)(((timestamp1-timestamp2)/3600)%24);
}
long WINAPI DLLExport GetMinutesDiff(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
__time64_t timestamp1 = (unsigned)p1;
__time64_t timestamp2 = (unsigned)p2;
return (long)(((timestamp1-timestamp2)/60)%60);
}
long WINAPI DLLExport GetSecondsDiff(LPRDATA rdPtr, long param1)
{
long p1=CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT);
long p2=CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT);
__time64_t timestamp1 = (unsigned)p1;
__time64_t timestamp2 = (unsigned)p2;
return (long)((timestamp1-timestamp2)%60);
}
// ----------------------------------------------------------
// Condition / Action / Expression jump table
// ----------------------------------------------------------
// Contains the address inside the extension of the different
// routines that handle the action, conditions and expressions.
// Located at the end of the source for convinience
// Must finish with a 0
//
long (WINAPI * ConditionJumps[])(LPRDATA rdPtr, long param1, long param2) =
{
0
};
short (WINAPI * ActionJumps[])(LPRDATA rdPtr, long param1, long param2) =
{
0
};
long (WINAPI * ExpressionJumps[])(LPRDATA rdPtr, long param) =
{
GetTimeStamp,
GetYear,
GetMonth,
GetDay,
GetHours,
GetMinutes,
GetSeconds,
GetTodayStamp,
GetDayofWeek,
GetFullString,
AddYears,
AddMonths,
AddWeeks,
AddDays,
AddHours,
AddMinutes,
AddSeconds,
GetTimezone,
GetYYYYMMDD,
GetHHMMSS,
GetYearDiff,
GetMonthDiff,
GetDayDiff,
GetHoursDiff,
GetMinutesDiff,
GetSecondsDiff,
GetAsText,
GetVal,
0
};