summaryrefslogtreecommitdiff
path: root/utility/demo-fw/pc-tools/CreateDemoBin/src/ScriptParse.cpp
blob: ad0c73b01a737a3215cc4e8c30f90547959cf22d (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
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
/*
 * ScriptParse.cpp
 *
 *  Created on: 2009-3-15
 *      Author: Tony.Liu
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "regex.h"
#include "ScriptParse.h"
#include "DemoBinHeader.h"

#define SUBSLEN 10
#define EBUFLEN 128 /* error buffer length */
#define BUFLEN 1024 /* matched buffer length */

using namespace std;

static size_t len;
static regex_t reSpace;
static regex_t reSlideCnt;
static regex_t reSlideSize;
static regex_t reSlideWidth;
static regex_t reSlideHeight;

static regex_t reSlideDispString;
static regex_t reSlideDispTop;
static regex_t reSlideDispLeft;
static regex_t reSlideDispWidth;
static regex_t reSlideDispHeight;

static regex_t reSlideLink;
static regex_t reSlideLinkAddr;
static regex_t reSlideLinkTop;
static regex_t reSlideLinkLeft;
static regex_t reSlideLinkWidth;
static regex_t reSlideLinkHeight;

static regex_t reSlideProps;
static regex_t reSlideOnInitCmds;
static regex_t reSlideOnRefreshCmds;
static regex_t reSlideOnCloseCmds;

static regmatch_t subs[SUBSLEN];
static char matched[BUFLEN];
static char errbuf[EBUFLEN];

static char *pSpacePtn = "^[[:space:]]+$";
static char *pSlideCntPtn = "^Slide[[:blank:]]+([[:digit:]]+):[[:space:]]+$";
static char *pSlideSizePtn = "^Slide Size:[[:space:]]+$";
static char *pSlideWidthPtn = "^Width:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";
static char *pSlideHeightPtn = "^Height:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";

static char *pSlideDispBoxStringPtn = "^Display Box:[[:space:]]+$";
static char *pSlideDispBoxTopPtn = "^Top:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";
static char *pSlideDispBoxLeftPtn = "^Left:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";
static char *pSlideDispBoxWidthPtn = "^Width:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";
static char *pSlideDispBoxHeightPtn = "^Height:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";

static char *pSlideLinkPtn = "^HyperLink[[:blank:]]+([[:digit:]]+)::[[:space:]]+$";
static char *pSlideLinkAddrPtn = "^\"Link Address\":[[:blank:]]+[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$";
static char *pSlideLinkTopPtn = "^Top:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";
static char *pSlideLinkLeftPtn = "^Left:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";
static char *pSlideLinkWidthPtn = "^Width:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";
static char *pSlideLinkHeightPtn = "^Height:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$";

static char *pSlidePropsPtn = "^Properties::[[:space:]]+$";
static char *pSlideOnInitCmdsPtn = "^OnInitCmds:[[:blank:]]*[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$";
static char *pSlideOnRefreshCmdsPtn = "^OnRefreshCmds:[[:blank:]]*[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$";
static char *pSlideOnCloseCmdsPtn = "^OnCloseCmds:[[:blank:]]*[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$";

//compile pattern
static bool CompileRegexPtn(regex_t *compiled, const char *pattern, int cflags)
{
	int err = regcomp (compiled, pattern, cflags);
	if (err)
	{
		len = regerror (err, compiled, errbuf, sizeof (errbuf));
		//printf("\n\r error compilation!");
		fprintf (stderr, "error: regcomp: %s\n", errbuf);
		return false;
	}

	return true;
}

//compile all pattern
bool CompileAllPtn()
{
	bool bRet=true;

	//compile slide section head pattern
	bRet &= CompileRegexPtn(&reSpace, pSpacePtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideCnt, pSlideCntPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideSize, pSlideSizePtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideWidth, pSlideWidthPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideHeight, pSlideHeightPtn, REG_EXTENDED | REG_NEWLINE);

	//compile display box section pattern
	bRet &= CompileRegexPtn(&reSlideDispString, pSlideDispBoxStringPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideDispTop, pSlideDispBoxTopPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideDispLeft, pSlideDispBoxLeftPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideDispWidth, pSlideDispBoxWidthPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideDispHeight, pSlideDispBoxHeightPtn, REG_EXTENDED | REG_NEWLINE);

	//compile hyperlink section pattern
	bRet &= CompileRegexPtn(&reSlideLink, pSlideLinkPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideLinkAddr, pSlideLinkAddrPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideLinkTop, pSlideLinkTopPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideLinkLeft, pSlideLinkLeftPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideLinkWidth, pSlideLinkWidthPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideLinkHeight, pSlideLinkHeightPtn, REG_EXTENDED | REG_NEWLINE);

	//compile slide config section pattern
	bRet &= CompileRegexPtn(&reSlideProps, pSlidePropsPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideOnInitCmds, pSlideOnInitCmdsPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideOnRefreshCmds, pSlideOnRefreshCmdsPtn, REG_EXTENDED | REG_NEWLINE);
	bRet &= CompileRegexPtn(&reSlideOnCloseCmds, pSlideOnCloseCmdsPtn, REG_EXTENDED | REG_NEWLINE);

	return bRet;
}

//free compiled regex pattern
void FreeAllRegex()
{
	//free slide section head patterns
	regfree(&reSlideCnt);
	regfree(&reSlideSize);
	regfree(&reSlideWidth);
	regfree(&reSlideHeight);

	//free slide display box section patterns
	regfree(&reSlideDispString);
	regfree(&reSlideDispTop);
	regfree(&reSlideDispLeft);
	regfree(&reSlideDispWidth);
	regfree(&reSlideDispHeight);

	//free slide hyperlink section patterns
	regfree(&reSlideLink);
	regfree(&reSlideLinkAddr);
	regfree(&reSlideLinkTop);
	regfree(&reSlideLinkLeft);
	regfree(&reSlideWidth);
	regfree(&reSlideHeight);

	//free slide config section pattern
	regfree(&reSlideProps);
	regfree(&reSlideOnInitCmds);
	regfree(&reSlideOnRefreshCmds);
	regfree(&reSlideOnCloseCmds);;
}

//match the pattern?
bool RegexMatch(const regex_t *compiled, const char *string, size_t nmatch, regmatch_t *matchptr, int eflags)
{
	bool bRet = true;

	int err = regexec (compiled, string, (size_t)nmatch, matchptr,eflags);

	if (err == REG_NOMATCH)
	{
		//fprintf (stderr, "Sorry, no match ...\n");
		bRet = false;
	}
	else if (err)
	{
		len = regerror (err, compiled, errbuf, sizeof (errbuf));
		fprintf (stderr, "error: regexec: %s\n", errbuf);
		bRet = false;
	}

	return bRet;
}

//is a space line?
bool IsSpaceLine(const char *string)
{
	bool bRet = RegexMatch(&reSpace, string, 0,0,0);

	return bRet;
}

//match slide count line and return the count
bool GetSlideCount( const char *string, unsigned int *slidenum)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_SLIDESECTION)
	printf("\n\r [Parsing slide count string is %s", string);
#endif

	bRet = RegexMatch(&reSlideCnt,string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot slide count line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_SLIDESECTION)
	printf("\n\r Parsed slide count is %s]",matched);
#endif

	*slidenum = (unsigned int)floor(atof(matched));

	return bRet;
}

//check slide size line is correct
bool IsSlideSizeString(const char *string)
{
	bool bRet = false;

	bRet = RegexMatch(&reSlideSize,string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot slide size string line...!");
		return bRet;
	}

	return bRet;
}

//match slide width line and return the width
bool GetSlideWidth( const char *string, unsigned int *slidewidth)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_SLIDESECTION)
	printf("\n\r [Parsing slide width string is %s", string);
#endif

	bRet = RegexMatch(&reSlideWidth,string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot slide width line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_SLIDESECTION)
	printf("\n\r Parsed slide width is %s]",matched);
#endif

	*slidewidth = (unsigned int)floor(atof(matched));

	return bRet;
}

//match slide height line and return the height
bool GetSlideHeight( const char *string, unsigned int *slideheight)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_SLIDESECTION)
	printf("\n\r [Parsing slide height string is %s", string);
#endif

	bRet = RegexMatch(&reSlideHeight,string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot slide height line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_SLIDESECTION)
	printf("\n\r Parsed slide height is %s]",matched);
#endif

	*slideheight = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link top line and return link top position
bool GetDispBoxTop(const char *string, unsigned int *top)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r [Parsing display box top string is %s", string);
#endif

	bRet = RegexMatch(&reSlideDispTop, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link top line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r Parsed display box top is %s]",matched);
#endif

	*top = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link left line and return link left position
bool GetDispBoxLeft(const char *string, unsigned int *left)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r [Parsing display box left string is %s", string);
#endif

	bRet = RegexMatch(&reSlideDispLeft, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link left line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r Parsed display box left is %s]",matched);
#endif

	*left = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link width line and return width value
bool GetDispBoxWidth(const char *string, unsigned int *width)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r [Parsing display box width string is %s", string);
#endif

	bRet = RegexMatch(&reSlideDispWidth, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link width line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r Parsed display box width is %s]",matched);
#endif

	*width = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link width line and return width value
bool GetDispBoxHeight(const char *string, unsigned int *height)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r [Parsing display box height string is %s", string);
#endif

	bRet = RegexMatch(&reSlideDispHeight, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link height line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION)
	printf("\n\r Parsed display box height is %s]",matched);
#endif

	*height = (unsigned int)floor(atof(matched));

	return bRet;
}

//match hyperlink line and return link count
bool GetLinkCount(const char *string, unsigned int *linkcnt)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r [Parsing link count string is %s", string);
#endif

	bRet = RegexMatch(&reSlideLink, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot hyperlink line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r Parsed link count is %s]",matched);
#endif

	*linkcnt = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link address line and return the address
bool GetLinkAddr(const char *string, char *link)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r [Parsing link address string is %s", string);
#endif

	bRet = RegexMatch(&reSlideLinkAddr, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link address line...!");
		return bRet;
	}

	//printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;

	if(len > MAXLINKLEN - 1) {
		fprintf(stderr, "\n\r link address is too long!");
		return false;
	}

	memcpy (link, string + subs[1].rm_so, len);
	link[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r");
	for(int j=0;j<len;++j) {
		printf(" %d",link[j]);
	}
	printf("\n\r Parsed link address %s]",link);
#endif

	return bRet;
}

//match link top line and return link top position
bool GetLinkTop(const char *string, unsigned int *top)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r [Parsing link top string is %s", string);
#endif

	bRet = RegexMatch(&reSlideLinkTop, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link top line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r Parsed link top is %s]",matched);
#endif

	*top = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link left line and return link left position
bool GetLinkLeft(const char *string, unsigned int *left)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r [Parsing link left string is %s", string);
#endif

	bRet = RegexMatch(&reSlideLinkLeft, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link left line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r Parsed link left is %s]",matched);
#endif

	*left = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link width line and return width value
bool GetLinkWidth(const char *string, unsigned int *width)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r [Parsing link width string is %s", string);
#endif

	bRet = RegexMatch(&reSlideLinkWidth, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link width line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r Parsed link width is %s]",matched);
#endif

	*width = (unsigned int)floor(atof(matched));

	return bRet;
}

//match link width line and return width value
bool GetLinkHeight(const char *string, unsigned int *height)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r [Parsing link height string is %s", string);
#endif

	bRet = RegexMatch(&reSlideLinkHeight, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot link height line...!");
		return bRet;
	}

//	printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;
	memcpy (matched, string + subs[1].rm_so, len);
	matched[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION)
	printf("\n\r Parsed link height is %s]",matched);
#endif

	*height = (unsigned int)floor(atof(matched));

	return bRet;
}

//get OnInit cmds of slide
bool GetSlideOnInitCmds(const char *string, char * pOnInitCmds)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_PROPSECTION)
	printf("\n\r [Parsing OnInitCmds string is %s", string);
#endif

	bRet = RegexMatch(&reSlideOnInitCmds, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\r Not OnInit commands line...!");
		return bRet;
	}

	//printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;

	if(len > MAXLINKLEN - 1) {
		fprintf(stderr, "\n\r OnInitCmds line is too long!");
		return false;
	}

	memcpy (pOnInitCmds, string + subs[1].rm_so, len);
	pOnInitCmds[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_PROPSECTION)
	printf("\n\r Hex code of parsed: ");
	for(int j=0;j<len;++j) {
		printf(" %d",pOnInitCmds[j]);
	}
	printf("\n\r Parsed OnInitCmds: %s]",pOnInitCmds);
#endif

	return bRet;
}

//Get OnRefreshCmds of slide
bool GetSlideOnRefreshCmds(const char *string, char *pOnRefreshCmds)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_PROPSECTION)
	printf("\n\r [Parsing OnRefresh string is %s", string);
#endif

	bRet = RegexMatch(&reSlideOnRefreshCmds, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot OnRefresh commands line...!");
		return bRet;
	}

	//printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;

	if(len > MAXLINKLEN - 1) {
		fprintf(stderr, "\n\r OnRefreshCmds is too long!");
		return false;
	}

	memcpy (pOnRefreshCmds, string + subs[1].rm_so, len);
	pOnRefreshCmds[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_PROPSECTION)
	printf("\n\r Hex code of parsed: ");
	for(int j=0;j<len;++j) {
		printf(" %d",pOnRefreshCmds[j]);
	}
	printf("\n\r Parsed OnRefreshCmds: %s]",pOnRefreshCmds);
#endif

	return bRet;
}

//Get OnCloseCmds of slide
bool GetSlideOnCloseCmds(const char *string, char *pOnCloseCmds)
{
	bool bRet = false;

#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_PROPSECTION)
	printf("\n\r [Parsing OnCloseCmds string is %s", string);
#endif

	bRet = RegexMatch(&reSlideOnCloseCmds, string, (size_t)SUBSLEN, subs, 0);
	//not match pattern
	if(!bRet) {
		fprintf(stderr, "\n\rNot OnCloseCmds line...!");
		return bRet;
	}

	//printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so);
	int len = subs[1].rm_eo - subs[1].rm_so;

	if(len > MAXLINKLEN - 1) {
		fprintf(stderr, "\n\r OnCloseCmds is too long!");
		return false;
	}

	memcpy (pOnCloseCmds, string + subs[1].rm_so, len);
	pOnCloseCmds[len] = '\0';

#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_PROPSECTION)
	printf("\n\r  Hex code of parsed: ");
	for(int j=0;j<len;++j) {
		printf(" %d",pOnCloseCmds[j]);
	}
	printf("\n\r Parsed OncloseCmds %s]",pOnCloseCmds);
#endif

	return bRet;
}

//Parse slide section of script
bool ParseSlideSection(const char *string, \
		unsigned int *slideindex, \
		unsigned int *slidewidth, \
		unsigned int *slideheight)
{
	bool bRet = true;

	//parse slide section
	bRet &= GetSlideCount(string, slideindex);
	bRet &= IsSlideSizeString(string+MAXSCRIPTSTRINGLINE);
	bRet &= GetSlideWidth(string+MAXSCRIPTSTRINGLINE*2, slidewidth);
	bRet &= GetSlideHeight(string+MAXSCRIPTSTRINGLINE*3, slideheight);

	//one of parsing fails
	if(!bRet) {
		fprintf(stderr, "\n\rScript section format is not right!");
		return false;
	}

	return bRet;
}

//Parse hyperlink section of script
bool ParseLinkSection(const char *string, \
		unsigned int *linkindex, \
		char *linkstr, \
		unsigned int *linktop, \
		unsigned int *linkleft, \
		unsigned int *linkwidth, \
		unsigned int *linkheight)
{
	bool bRet = true;

	//parse link section
	bRet &= GetLinkCount(string, linkindex);
	bRet &= GetLinkAddr(string+MAXSCRIPTSTRINGLINE, linkstr);
	bRet &= GetLinkTop(string+MAXSCRIPTSTRINGLINE*2, linktop);
	bRet &= GetLinkLeft(string+MAXSCRIPTSTRINGLINE*3, linkleft);
	bRet &= GetLinkWidth(string+MAXSCRIPTSTRINGLINE*4, linkwidth);
	bRet &= GetLinkHeight(string+MAXSCRIPTSTRINGLINE*5, linkheight);

	//one of parsing fails
	if(!bRet) {
		fprintf(stderr, "\n\r Script link section format is not right!");
		return false;
	}

	return bRet;
}

//Parse display box section of script
bool ParseDispBoxSection(const char *string, \
		unsigned int *disptop, \
		unsigned int *displeft, \
		unsigned int *dispwidth, \
		unsigned int *dispheight)
{
	bool bRet = true;

	//parse link section
	bRet &= IsDispBoxSectionStart(string);
	bRet &= GetDispBoxTop(string+MAXSCRIPTSTRINGLINE, disptop);
	bRet &= GetDispBoxLeft(string+MAXSCRIPTSTRINGLINE*2, displeft);
	bRet &= GetDispBoxWidth(string+MAXSCRIPTSTRINGLINE*3, dispwidth);
	bRet &= GetDispBoxHeight(string+MAXSCRIPTSTRINGLINE*4, dispheight);

	//one of parsing fails
	if(!bRet) {
		fprintf(stderr, "\n\r Script link section format is not right!");
		return false;
	}

	return bRet;
}

//Parse slide properties section of script
bool ParsePropertiesSection(const char *string, \
		char *pOnInitCmds, \
		char *pOnRefreshCmds, \
		char *pOnCloseCmds)
{
	bool bRet = true;

	//parse slide properties section
	bRet &= IsPropertiesSectionStart(string);
	bRet &= GetSlideOnInitCmds(string+MAXSCRIPTSTRINGLINE, pOnInitCmds);
	bRet &= GetSlideOnRefreshCmds(string+MAXSCRIPTSTRINGLINE*2, pOnRefreshCmds);
	bRet &= GetSlideOnCloseCmds(string+MAXSCRIPTSTRINGLINE*3, pOnCloseCmds);

	//if any one of parsing fails
	if(!bRet) {
		fprintf(stderr, "\n\r Script slide properties section format is not right!");
		return false;
	}

	return bRet;
}

//Is slide section starting?
bool IsSlideSectionStart(const char *string)
{
	bool bRet;
	bRet = RegexMatch(&reSlideCnt,string, (size_t)SUBSLEN, subs, 0);

	return bRet;
}

//Is hyperlink section starting?
bool IsLinkSectionStart(const char *string)
{
	bool bRet;
	bRet = RegexMatch(&reSlideLink, string, (size_t)SUBSLEN, subs, 0);

	return bRet;
}

//Is Display Box section starting?
bool IsDispBoxSectionStart(const char *string)
{
	bool bRet;
	bRet = RegexMatch(&reSlideDispString, string, (size_t)SUBSLEN, subs, 0);

	return bRet;
}

//Is slide properties section starting?
bool IsPropertiesSectionStart(const char *string)
{
	bool bRet;

	bRet = RegexMatch(&reSlideProps, string, (size_t)SUBSLEN, subs, 0);

	return bRet;
}




personal git repositories of Harald Welte. Your mileage may vary