Fossil SCM

Bug fixes in the pikchr.c tokenizer.

drh 2020-09-16 15:30 trunk
Commit 367654037435909b701f695afd2fd0753e8b66cf763bdfe36b96bfe73bb075b0
1 file changed +16 -12
+16 -12
--- src/pikchr.c
+++ src/pikchr.c
@@ -376,11 +376,11 @@
376376
char isLine; /* True if a line class */
377377
char eJust; /* Use box-style text justification */
378378
void (*xInit)(Pik*,PElem*); /* Initializer */
379379
void (*xNumProp)(Pik*,PElem*,PToken*); /* Value change notification */
380380
void (*xCheck)(Pik*,PElem*); /* Checks to after parsing */
381
- PPoint (*xChop)(PElem*,PPoint*); /* Chopper */
381
+ PPoint (*xChop)(Pik*,PElem*,PPoint*); /* Chopper */
382382
PPoint (*xOffset)(Pik*,PElem*,int); /* Offset from .c to edge point */
383383
void (*xFit)(Pik*,PElem*,PNum w,PNum h); /* Size to fit text */
384384
void (*xRender)(Pik*,PElem*); /* Render */
385385
};
386386
@@ -3586,11 +3586,11 @@
35863586
case CP_W: pt.x = -w2; pt.y = 0.0; break;
35873587
case CP_NW: pt.x = rx-w2; pt.y = h2-rx; break;
35883588
}
35893589
return pt;
35903590
}
3591
-static PPoint boxChop(PElem *pElem, PPoint *pPt){
3591
+static PPoint boxChop(Pik *p, PElem *pElem, PPoint *pPt){
35923592
PNum dx, dy;
35933593
int cp = CP_C;
35943594
PPoint chop = pElem->ptAt;
35953595
if( pElem->w<=0.0 ) return chop;
35963596
if( pElem->h<=0.0 ) return chop;
@@ -3619,11 +3619,11 @@
36193619
cp = CP_SW;
36203620
}else{
36213621
cp = CP_S;
36223622
}
36233623
}
3624
- chop = pElem->type->xOffset(0,pElem,cp);
3624
+ chop = pElem->type->xOffset(p,pElem,cp);
36253625
chop.x += pElem->ptAt.x;
36263626
chop.y += pElem->ptAt.y;
36273627
return chop;
36283628
}
36293629
static void boxFit(Pik *p, PElem *pElem, PNum w, PNum h){
@@ -3705,11 +3705,11 @@
37053705
pElem->w = pElem->h;
37063706
pElem->rad = 0.5*pElem->w;
37073707
break;
37083708
}
37093709
}
3710
-static PPoint circleChop(PElem *pElem, PPoint *pPt){
3710
+static PPoint circleChop(Pik *p, PElem *pElem, PPoint *pPt){
37113711
PPoint chop;
37123712
PNum dx = pPt->x - pElem->ptAt.x;
37133713
PNum dy = pPt->y - pElem->ptAt.y;
37143714
PNum dist = hypot(dx,dy);
37153715
if( dist<pElem->rad ) return pElem->ptAt;
@@ -3830,11 +3830,11 @@
38303830
/* Methods for the "ellipse" class */
38313831
static void ellipseInit(Pik *p, PElem *pElem){
38323832
pElem->w = pik_value(p, "ellipsewid",10,0);
38333833
pElem->h = pik_value(p, "ellipseht",9,0);
38343834
}
3835
-static PPoint ellipseChop(PElem *pElem, PPoint *pPt){
3835
+static PPoint ellipseChop(Pik *p, PElem *pElem, PPoint *pPt){
38363836
PPoint chop;
38373837
PNum s, dq, dist;
38383838
PNum dx = pPt->x - pElem->ptAt.x;
38393839
PNum dy = pPt->y - pElem->ptAt.y;
38403840
if( pElem->w<=0.0 ) return pElem->ptAt;
@@ -5573,11 +5573,11 @@
55735573
cnt++;
55745574
if( z[j]=='\\' && z[j+1]!='&' ){
55755575
j++;
55765576
}else if( z[j]=='&' ){
55775577
int k;
5578
- for(k=j+1; k<j+7 && z[k]!=';'; k++){}
5578
+ for(k=j+1; k<j+7 && z[k]!=0 && z[k]!=';'; k++){}
55795579
if( z[k]==';' ) j = k;
55805580
}
55815581
}
55825582
return cnt;
55835583
}
@@ -6111,11 +6111,11 @@
61116111
** of pFrom.
61126112
*/
61136113
static void pik_autochop(Pik *p, PPoint *pFrom, PPoint *pTo){
61146114
PElem *pElem = pik_find_chopper(p->list, pTo);
61156115
if( pElem ){
6116
- *pTo = pElem->type->xChop(pElem, pFrom);
6116
+ *pTo = pElem->type->xChop(p, pElem, pFrom);
61176117
}
61186118
}
61196119
61206120
/* This routine runs after all attributes have been received
61216121
** on an element.
@@ -6591,11 +6591,15 @@
65916591
pToken->eType = T_EOL;
65926592
return 1;
65936593
}
65946594
case '"': {
65956595
for(i=1; (c = z[i])!=0; i++){
6596
- if( c=='\\' ){ i++; continue; }
6596
+ if( c=='\\' ){
6597
+ if( z[i+1]==0 ) break;
6598
+ i++;
6599
+ continue;
6600
+ }
65976601
if( c=='"' ){
65986602
pToken->eType = T_STRING;
65996603
return i+1;
66006604
}
66016605
}
@@ -6718,11 +6722,11 @@
67186722
pFound->eType==T_START ||
67196723
pFound->eType==T_END )
67206724
){
67216725
/* Dot followed by something that is a 2-D place value */
67226726
pToken->eType = T_DOT_E;
6723
- }else if( pFound->eType==T_X || pFound->eType==T_Y ){
6727
+ }else if( pFound && (pFound->eType==T_X || pFound->eType==T_Y) ){
67246728
/* Dot followed by "x" or "y" */
67256729
pToken->eType = T_DOT_XY;
67266730
}else{
67276731
/* Any other "dot" */
67286732
pToken->eType = T_DOT_L;
@@ -6745,11 +6749,11 @@
67456749
int isInt = 1;
67466750
if( c!='.' ){
67476751
nDigit = 1;
67486752
for(i=1; (c = z[i])>='0' && c<='9'; i++){ nDigit++; }
67496753
if( i==1 && (c=='x' || c=='X') ){
6750
- for(i=3; (c = z[i])!=0 && isxdigit(c); i++){}
6754
+ for(i=2; (c = z[i])!=0 && isxdigit(c); i++){}
67516755
pToken->eType = T_NUMBER;
67526756
return i;
67536757
}
67546758
}else{
67556759
isInt = 0;
@@ -6777,11 +6781,11 @@
67776781
i++;
67786782
isInt = 0;
67796783
while( (c = z[i])>=0 && c<='9' ){ i++; }
67806784
}
67816785
}
6782
- c2 = z[i+1];
6786
+ c2 = c ? z[i+1] : 0;
67836787
if( isInt ){
67846788
if( (c=='t' && c2=='h')
67856789
|| (c=='r' && c2=='d')
67866790
|| (c=='n' && c2=='d')
67876791
|| (c=='s' && c2=='t')
@@ -7051,6 +7055,6 @@
70517055
printf("</body></html>\n");
70527056
return 0;
70537057
}
70547058
#endif /* PIKCHR_SHELL */
70557059
7056
-#line 7081 "pikchr.c"
7060
+#line 7085 "pikchr.c"
70577061
--- src/pikchr.c
+++ src/pikchr.c
@@ -376,11 +376,11 @@
376 char isLine; /* True if a line class */
377 char eJust; /* Use box-style text justification */
378 void (*xInit)(Pik*,PElem*); /* Initializer */
379 void (*xNumProp)(Pik*,PElem*,PToken*); /* Value change notification */
380 void (*xCheck)(Pik*,PElem*); /* Checks to after parsing */
381 PPoint (*xChop)(PElem*,PPoint*); /* Chopper */
382 PPoint (*xOffset)(Pik*,PElem*,int); /* Offset from .c to edge point */
383 void (*xFit)(Pik*,PElem*,PNum w,PNum h); /* Size to fit text */
384 void (*xRender)(Pik*,PElem*); /* Render */
385 };
386
@@ -3586,11 +3586,11 @@
3586 case CP_W: pt.x = -w2; pt.y = 0.0; break;
3587 case CP_NW: pt.x = rx-w2; pt.y = h2-rx; break;
3588 }
3589 return pt;
3590 }
3591 static PPoint boxChop(PElem *pElem, PPoint *pPt){
3592 PNum dx, dy;
3593 int cp = CP_C;
3594 PPoint chop = pElem->ptAt;
3595 if( pElem->w<=0.0 ) return chop;
3596 if( pElem->h<=0.0 ) return chop;
@@ -3619,11 +3619,11 @@
3619 cp = CP_SW;
3620 }else{
3621 cp = CP_S;
3622 }
3623 }
3624 chop = pElem->type->xOffset(0,pElem,cp);
3625 chop.x += pElem->ptAt.x;
3626 chop.y += pElem->ptAt.y;
3627 return chop;
3628 }
3629 static void boxFit(Pik *p, PElem *pElem, PNum w, PNum h){
@@ -3705,11 +3705,11 @@
3705 pElem->w = pElem->h;
3706 pElem->rad = 0.5*pElem->w;
3707 break;
3708 }
3709 }
3710 static PPoint circleChop(PElem *pElem, PPoint *pPt){
3711 PPoint chop;
3712 PNum dx = pPt->x - pElem->ptAt.x;
3713 PNum dy = pPt->y - pElem->ptAt.y;
3714 PNum dist = hypot(dx,dy);
3715 if( dist<pElem->rad ) return pElem->ptAt;
@@ -3830,11 +3830,11 @@
3830 /* Methods for the "ellipse" class */
3831 static void ellipseInit(Pik *p, PElem *pElem){
3832 pElem->w = pik_value(p, "ellipsewid",10,0);
3833 pElem->h = pik_value(p, "ellipseht",9,0);
3834 }
3835 static PPoint ellipseChop(PElem *pElem, PPoint *pPt){
3836 PPoint chop;
3837 PNum s, dq, dist;
3838 PNum dx = pPt->x - pElem->ptAt.x;
3839 PNum dy = pPt->y - pElem->ptAt.y;
3840 if( pElem->w<=0.0 ) return pElem->ptAt;
@@ -5573,11 +5573,11 @@
5573 cnt++;
5574 if( z[j]=='\\' && z[j+1]!='&' ){
5575 j++;
5576 }else if( z[j]=='&' ){
5577 int k;
5578 for(k=j+1; k<j+7 && z[k]!=';'; k++){}
5579 if( z[k]==';' ) j = k;
5580 }
5581 }
5582 return cnt;
5583 }
@@ -6111,11 +6111,11 @@
6111 ** of pFrom.
6112 */
6113 static void pik_autochop(Pik *p, PPoint *pFrom, PPoint *pTo){
6114 PElem *pElem = pik_find_chopper(p->list, pTo);
6115 if( pElem ){
6116 *pTo = pElem->type->xChop(pElem, pFrom);
6117 }
6118 }
6119
6120 /* This routine runs after all attributes have been received
6121 ** on an element.
@@ -6591,11 +6591,15 @@
6591 pToken->eType = T_EOL;
6592 return 1;
6593 }
6594 case '"': {
6595 for(i=1; (c = z[i])!=0; i++){
6596 if( c=='\\' ){ i++; continue; }
 
 
 
 
6597 if( c=='"' ){
6598 pToken->eType = T_STRING;
6599 return i+1;
6600 }
6601 }
@@ -6718,11 +6722,11 @@
6718 pFound->eType==T_START ||
6719 pFound->eType==T_END )
6720 ){
6721 /* Dot followed by something that is a 2-D place value */
6722 pToken->eType = T_DOT_E;
6723 }else if( pFound->eType==T_X || pFound->eType==T_Y ){
6724 /* Dot followed by "x" or "y" */
6725 pToken->eType = T_DOT_XY;
6726 }else{
6727 /* Any other "dot" */
6728 pToken->eType = T_DOT_L;
@@ -6745,11 +6749,11 @@
6745 int isInt = 1;
6746 if( c!='.' ){
6747 nDigit = 1;
6748 for(i=1; (c = z[i])>='0' && c<='9'; i++){ nDigit++; }
6749 if( i==1 && (c=='x' || c=='X') ){
6750 for(i=3; (c = z[i])!=0 && isxdigit(c); i++){}
6751 pToken->eType = T_NUMBER;
6752 return i;
6753 }
6754 }else{
6755 isInt = 0;
@@ -6777,11 +6781,11 @@
6777 i++;
6778 isInt = 0;
6779 while( (c = z[i])>=0 && c<='9' ){ i++; }
6780 }
6781 }
6782 c2 = z[i+1];
6783 if( isInt ){
6784 if( (c=='t' && c2=='h')
6785 || (c=='r' && c2=='d')
6786 || (c=='n' && c2=='d')
6787 || (c=='s' && c2=='t')
@@ -7051,6 +7055,6 @@
7051 printf("</body></html>\n");
7052 return 0;
7053 }
7054 #endif /* PIKCHR_SHELL */
7055
7056 #line 7081 "pikchr.c"
7057
--- src/pikchr.c
+++ src/pikchr.c
@@ -376,11 +376,11 @@
376 char isLine; /* True if a line class */
377 char eJust; /* Use box-style text justification */
378 void (*xInit)(Pik*,PElem*); /* Initializer */
379 void (*xNumProp)(Pik*,PElem*,PToken*); /* Value change notification */
380 void (*xCheck)(Pik*,PElem*); /* Checks to after parsing */
381 PPoint (*xChop)(Pik*,PElem*,PPoint*); /* Chopper */
382 PPoint (*xOffset)(Pik*,PElem*,int); /* Offset from .c to edge point */
383 void (*xFit)(Pik*,PElem*,PNum w,PNum h); /* Size to fit text */
384 void (*xRender)(Pik*,PElem*); /* Render */
385 };
386
@@ -3586,11 +3586,11 @@
3586 case CP_W: pt.x = -w2; pt.y = 0.0; break;
3587 case CP_NW: pt.x = rx-w2; pt.y = h2-rx; break;
3588 }
3589 return pt;
3590 }
3591 static PPoint boxChop(Pik *p, PElem *pElem, PPoint *pPt){
3592 PNum dx, dy;
3593 int cp = CP_C;
3594 PPoint chop = pElem->ptAt;
3595 if( pElem->w<=0.0 ) return chop;
3596 if( pElem->h<=0.0 ) return chop;
@@ -3619,11 +3619,11 @@
3619 cp = CP_SW;
3620 }else{
3621 cp = CP_S;
3622 }
3623 }
3624 chop = pElem->type->xOffset(p,pElem,cp);
3625 chop.x += pElem->ptAt.x;
3626 chop.y += pElem->ptAt.y;
3627 return chop;
3628 }
3629 static void boxFit(Pik *p, PElem *pElem, PNum w, PNum h){
@@ -3705,11 +3705,11 @@
3705 pElem->w = pElem->h;
3706 pElem->rad = 0.5*pElem->w;
3707 break;
3708 }
3709 }
3710 static PPoint circleChop(Pik *p, PElem *pElem, PPoint *pPt){
3711 PPoint chop;
3712 PNum dx = pPt->x - pElem->ptAt.x;
3713 PNum dy = pPt->y - pElem->ptAt.y;
3714 PNum dist = hypot(dx,dy);
3715 if( dist<pElem->rad ) return pElem->ptAt;
@@ -3830,11 +3830,11 @@
3830 /* Methods for the "ellipse" class */
3831 static void ellipseInit(Pik *p, PElem *pElem){
3832 pElem->w = pik_value(p, "ellipsewid",10,0);
3833 pElem->h = pik_value(p, "ellipseht",9,0);
3834 }
3835 static PPoint ellipseChop(Pik *p, PElem *pElem, PPoint *pPt){
3836 PPoint chop;
3837 PNum s, dq, dist;
3838 PNum dx = pPt->x - pElem->ptAt.x;
3839 PNum dy = pPt->y - pElem->ptAt.y;
3840 if( pElem->w<=0.0 ) return pElem->ptAt;
@@ -5573,11 +5573,11 @@
5573 cnt++;
5574 if( z[j]=='\\' && z[j+1]!='&' ){
5575 j++;
5576 }else if( z[j]=='&' ){
5577 int k;
5578 for(k=j+1; k<j+7 && z[k]!=0 && z[k]!=';'; k++){}
5579 if( z[k]==';' ) j = k;
5580 }
5581 }
5582 return cnt;
5583 }
@@ -6111,11 +6111,11 @@
6111 ** of pFrom.
6112 */
6113 static void pik_autochop(Pik *p, PPoint *pFrom, PPoint *pTo){
6114 PElem *pElem = pik_find_chopper(p->list, pTo);
6115 if( pElem ){
6116 *pTo = pElem->type->xChop(p, pElem, pFrom);
6117 }
6118 }
6119
6120 /* This routine runs after all attributes have been received
6121 ** on an element.
@@ -6591,11 +6591,15 @@
6591 pToken->eType = T_EOL;
6592 return 1;
6593 }
6594 case '"': {
6595 for(i=1; (c = z[i])!=0; i++){
6596 if( c=='\\' ){
6597 if( z[i+1]==0 ) break;
6598 i++;
6599 continue;
6600 }
6601 if( c=='"' ){
6602 pToken->eType = T_STRING;
6603 return i+1;
6604 }
6605 }
@@ -6718,11 +6722,11 @@
6722 pFound->eType==T_START ||
6723 pFound->eType==T_END )
6724 ){
6725 /* Dot followed by something that is a 2-D place value */
6726 pToken->eType = T_DOT_E;
6727 }else if( pFound && (pFound->eType==T_X || pFound->eType==T_Y) ){
6728 /* Dot followed by "x" or "y" */
6729 pToken->eType = T_DOT_XY;
6730 }else{
6731 /* Any other "dot" */
6732 pToken->eType = T_DOT_L;
@@ -6745,11 +6749,11 @@
6749 int isInt = 1;
6750 if( c!='.' ){
6751 nDigit = 1;
6752 for(i=1; (c = z[i])>='0' && c<='9'; i++){ nDigit++; }
6753 if( i==1 && (c=='x' || c=='X') ){
6754 for(i=2; (c = z[i])!=0 && isxdigit(c); i++){}
6755 pToken->eType = T_NUMBER;
6756 return i;
6757 }
6758 }else{
6759 isInt = 0;
@@ -6777,11 +6781,11 @@
6781 i++;
6782 isInt = 0;
6783 while( (c = z[i])>=0 && c<='9' ){ i++; }
6784 }
6785 }
6786 c2 = c ? z[i+1] : 0;
6787 if( isInt ){
6788 if( (c=='t' && c2=='h')
6789 || (c=='r' && c2=='d')
6790 || (c=='n' && c2=='d')
6791 || (c=='s' && c2=='t')
@@ -7051,6 +7055,6 @@
7055 printf("</body></html>\n");
7056 return 0;
7057 }
7058 #endif /* PIKCHR_SHELL */
7059
7060 #line 7085 "pikchr.c"
7061

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button