Fossil SCM

Add compression to the built-in javascript. Update comments on graph.js.

drh 2018-12-28 16:52 trunk
Commit 4da95b254396d1f3fc8875a9fdccec82499d669efa6bd3e96ce15a8210587c7a
+6 -8
--- src/graph.js
+++ src/graph.js
@@ -28,24 +28,22 @@
2828
** r: The "rail" that the node for this row sits on. The left-most
2929
** rail is 0 and the number increases to the right.
3030
** d: If exists and true then there is a "descender" - an arrow
3131
** coming from the bottom of the page straight up to this node.
3232
** mo: "merge-out". If it exists, this is the rail position
33
-** for the upward portion of a merge arrow. The merge arrow goes up
34
-** to the row identified by mu:. If this value is omitted then
35
-** node has no merge children and no merge-out line is drawn.
33
+** for the upward portion of a merge arrow. The merge arrow goes as
34
+** a solid normal merge line up to the row identified by "mu" and
35
+** then as a dashed cherrypick merge line up further to "cu".
36
+** If this value is omitted if there are no merge children.
3637
** mu: The id of the row which is the top of the merge-out arrow.
3738
** Only exists if "mo" exists.
38
-** cu: The id of the top row of the merge-out arrow for a cherrypick
39
-** merge arrow that extends beyond the main merge arrow. Only
40
-** exists if "mo" exists and if there is a cherrpick merge that is
41
-** higher than "mu".
39
+** cu: Extend the mu merge arrow up to this row as a cherrypick
40
+** merge line, if this value exists.
4241
** u: Draw a thick child-line out of the top of this node and up to
4342
** the node with an id equal to this value. 0 if it is straight to
4443
** the top of the page, -1 if there is no thick-line riser.
4544
** f: 0x01: a leaf node.
46
-** 0x02: all output merges are cherrypicks
4745
** au: An array of integers that define thick-line risers for branches.
4846
** The integers are in pairs. For each pair, the first integer is
4947
** is the rail on which the riser should run and the second integer
5048
** is the id of the node upto which the riser should run. If there
5149
** are no risers, this array does not exist.
5250
--- src/graph.js
+++ src/graph.js
@@ -28,24 +28,22 @@
28 ** r: The "rail" that the node for this row sits on. The left-most
29 ** rail is 0 and the number increases to the right.
30 ** d: If exists and true then there is a "descender" - an arrow
31 ** coming from the bottom of the page straight up to this node.
32 ** mo: "merge-out". If it exists, this is the rail position
33 ** for the upward portion of a merge arrow. The merge arrow goes up
34 ** to the row identified by mu:. If this value is omitted then
35 ** node has no merge children and no merge-out line is drawn.
 
36 ** mu: The id of the row which is the top of the merge-out arrow.
37 ** Only exists if "mo" exists.
38 ** cu: The id of the top row of the merge-out arrow for a cherrypick
39 ** merge arrow that extends beyond the main merge arrow. Only
40 ** exists if "mo" exists and if there is a cherrpick merge that is
41 ** higher than "mu".
42 ** u: Draw a thick child-line out of the top of this node and up to
43 ** the node with an id equal to this value. 0 if it is straight to
44 ** the top of the page, -1 if there is no thick-line riser.
45 ** f: 0x01: a leaf node.
46 ** 0x02: all output merges are cherrypicks
47 ** au: An array of integers that define thick-line risers for branches.
48 ** The integers are in pairs. For each pair, the first integer is
49 ** is the rail on which the riser should run and the second integer
50 ** is the id of the node upto which the riser should run. If there
51 ** are no risers, this array does not exist.
52
--- src/graph.js
+++ src/graph.js
@@ -28,24 +28,22 @@
28 ** r: The "rail" that the node for this row sits on. The left-most
29 ** rail is 0 and the number increases to the right.
30 ** d: If exists and true then there is a "descender" - an arrow
31 ** coming from the bottom of the page straight up to this node.
32 ** mo: "merge-out". If it exists, this is the rail position
33 ** for the upward portion of a merge arrow. The merge arrow goes as
34 ** a solid normal merge line up to the row identified by "mu" and
35 ** then as a dashed cherrypick merge line up further to "cu".
36 ** If this value is omitted if there are no merge children.
37 ** mu: The id of the row which is the top of the merge-out arrow.
38 ** Only exists if "mo" exists.
39 ** cu: Extend the mu merge arrow up to this row as a cherrypick
40 ** merge line, if this value exists.
 
 
41 ** u: Draw a thick child-line out of the top of this node and up to
42 ** the node with an id equal to this value. 0 if it is straight to
43 ** the top of the page, -1 if there is no thick-line riser.
44 ** f: 0x01: a leaf node.
 
45 ** au: An array of integers that define thick-line risers for branches.
46 ** The integers are in pairs. For each pair, the first integer is
47 ** is the rail on which the riser should run and the second integer
48 ** is the id of the node upto which the riser should run. If there
49 ** are no risers, this array does not exist.
50
--- src/mkbuiltin.c
+++ src/mkbuiltin.c
@@ -54,10 +54,49 @@
5454
got = fread(z, 1, nByte, in);
5555
fclose(in);
5656
z[got] = 0;
5757
return z;
5858
}
59
+
60
+/*
61
+** Try to compress a javascript file by removing unnecessary whitespace.
62
+**
63
+** Warning: This compression routine does not necessarily work for any
64
+** arbitrary Javascript source file. But it should work ok for the
65
+** well-behaved source files in this project.
66
+*/
67
+static void compressJavascript(unsigned char *z, int *pn){
68
+ int n = *pn;
69
+ int i, j, k;
70
+ for(i=j=0; i<n; i++){
71
+ unsigned char c = z[i];
72
+ if( c=='/' ){
73
+ if( z[i+1]=='*' ){
74
+ for(k=i+3; k<n && (z[k]!='/' || z[k-1]!='*'); k++){}
75
+ if( k<n ){
76
+ i = k;
77
+ while( i+1<n && isspace(z[i+1]) ) i++;
78
+ continue;
79
+ }
80
+ }else if( z[i+1]=='/' ){
81
+ for(k=i+2; k<n && z[k]!='\n'; k++){}
82
+ i = k;
83
+ while( i+1<n && isspace(z[i+1]) ) i++;
84
+ continue;
85
+ }
86
+ }
87
+ if( c=='\n' ){
88
+ while( j>0 && isspace(z[j-1]) ) j--;
89
+ z[j++] = '\n';
90
+ while( i+1<n && isspace(z[i+1]) ) i++;
91
+ continue;
92
+ }
93
+ z[j++] = c;
94
+ }
95
+ z[j] = 0;
96
+ *pn = j;
97
+}
5998
6099
/*
61100
** There is an instance of the following for each file translated.
62101
*/
63102
typedef struct Resource Resource;
@@ -85,10 +124,11 @@
85124
int nRes;
86125
unsigned char *pData;
87126
int nErr = 0;
88127
int nSkip;
89128
int nPrefix = 0;
129
+ int nName;
90130
91131
if( argc>3 && strcmp(argv[1],"--prefix")==0 ){
92132
nPrefix = (int)strlen(argv[2]);
93133
argc -= 2;
94134
argv += 2;
@@ -119,10 +159,18 @@
119159
nSkip = 0;
120160
while( pData[nSkip]=='#' ){
121161
while( pData[nSkip]!=0 && pData[nSkip]!='\n' ){ nSkip++; }
122162
if( pData[nSkip]=='\n' ) nSkip++;
123163
}
164
+
165
+ /* Compress javascript source files */
166
+ nName = (int)strlen(aRes[i].zName);
167
+ if( nName>3 && strcmp(&aRes[i].zName[nName-3],".js")==0 ){
168
+ int x = sz-nSkip;
169
+ compressJavascript(pData+nSkip, &x);
170
+ sz = x + nSkip;
171
+ }
124172
125173
aRes[i].nByte = sz - nSkip;
126174
aRes[i].idx = i;
127175
printf("/* Content of file %s */\n", aRes[i].zName);
128176
printf("static const unsigned char bidata%d[%d] = {\n ",
129177
--- src/mkbuiltin.c
+++ src/mkbuiltin.c
@@ -54,10 +54,49 @@
54 got = fread(z, 1, nByte, in);
55 fclose(in);
56 z[got] = 0;
57 return z;
58 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
60 /*
61 ** There is an instance of the following for each file translated.
62 */
63 typedef struct Resource Resource;
@@ -85,10 +124,11 @@
85 int nRes;
86 unsigned char *pData;
87 int nErr = 0;
88 int nSkip;
89 int nPrefix = 0;
 
90
91 if( argc>3 && strcmp(argv[1],"--prefix")==0 ){
92 nPrefix = (int)strlen(argv[2]);
93 argc -= 2;
94 argv += 2;
@@ -119,10 +159,18 @@
119 nSkip = 0;
120 while( pData[nSkip]=='#' ){
121 while( pData[nSkip]!=0 && pData[nSkip]!='\n' ){ nSkip++; }
122 if( pData[nSkip]=='\n' ) nSkip++;
123 }
 
 
 
 
 
 
 
 
124
125 aRes[i].nByte = sz - nSkip;
126 aRes[i].idx = i;
127 printf("/* Content of file %s */\n", aRes[i].zName);
128 printf("static const unsigned char bidata%d[%d] = {\n ",
129
--- src/mkbuiltin.c
+++ src/mkbuiltin.c
@@ -54,10 +54,49 @@
54 got = fread(z, 1, nByte, in);
55 fclose(in);
56 z[got] = 0;
57 return z;
58 }
59
60 /*
61 ** Try to compress a javascript file by removing unnecessary whitespace.
62 **
63 ** Warning: This compression routine does not necessarily work for any
64 ** arbitrary Javascript source file. But it should work ok for the
65 ** well-behaved source files in this project.
66 */
67 static void compressJavascript(unsigned char *z, int *pn){
68 int n = *pn;
69 int i, j, k;
70 for(i=j=0; i<n; i++){
71 unsigned char c = z[i];
72 if( c=='/' ){
73 if( z[i+1]=='*' ){
74 for(k=i+3; k<n && (z[k]!='/' || z[k-1]!='*'); k++){}
75 if( k<n ){
76 i = k;
77 while( i+1<n && isspace(z[i+1]) ) i++;
78 continue;
79 }
80 }else if( z[i+1]=='/' ){
81 for(k=i+2; k<n && z[k]!='\n'; k++){}
82 i = k;
83 while( i+1<n && isspace(z[i+1]) ) i++;
84 continue;
85 }
86 }
87 if( c=='\n' ){
88 while( j>0 && isspace(z[j-1]) ) j--;
89 z[j++] = '\n';
90 while( i+1<n && isspace(z[i+1]) ) i++;
91 continue;
92 }
93 z[j++] = c;
94 }
95 z[j] = 0;
96 *pn = j;
97 }
98
99 /*
100 ** There is an instance of the following for each file translated.
101 */
102 typedef struct Resource Resource;
@@ -85,10 +124,11 @@
124 int nRes;
125 unsigned char *pData;
126 int nErr = 0;
127 int nSkip;
128 int nPrefix = 0;
129 int nName;
130
131 if( argc>3 && strcmp(argv[1],"--prefix")==0 ){
132 nPrefix = (int)strlen(argv[2]);
133 argc -= 2;
134 argv += 2;
@@ -119,10 +159,18 @@
159 nSkip = 0;
160 while( pData[nSkip]=='#' ){
161 while( pData[nSkip]!=0 && pData[nSkip]!='\n' ){ nSkip++; }
162 if( pData[nSkip]=='\n' ) nSkip++;
163 }
164
165 /* Compress javascript source files */
166 nName = (int)strlen(aRes[i].zName);
167 if( nName>3 && strcmp(&aRes[i].zName[nName-3],".js")==0 ){
168 int x = sz-nSkip;
169 compressJavascript(pData+nSkip, &x);
170 sz = x + nSkip;
171 }
172
173 aRes[i].nByte = sz - nSkip;
174 aRes[i].idx = i;
175 printf("/* Content of file %s */\n", aRes[i].zName);
176 printf("static const unsigned char bidata%d[%d] = {\n ",
177
+1 -1
--- src/timeline.c
+++ src/timeline.c
@@ -872,11 +872,11 @@
872872
** a solid normal merge line up to the row identified by "mu" and
873873
** then as a dashed cherrypick merge line up further to "cu".
874874
** If this value is omitted if there are no merge children.
875875
** mu: The id of the row which is the top of the merge-out arrow.
876876
** Only exists if "mo" exists.
877
- ** cu: Extend the mu merge error on up to this row as a cherrypick
877
+ ** cu: Extend the mu merge arrow up to this row as a cherrypick
878878
** merge line, if this value exists.
879879
** u: Draw a thick child-line out of the top of this node and up to
880880
** the node with an id equal to this value. 0 if it is straight to
881881
** the top of the page, -1 if there is no thick-line riser.
882882
** f: 0x01: a leaf node.
883883
--- src/timeline.c
+++ src/timeline.c
@@ -872,11 +872,11 @@
872 ** a solid normal merge line up to the row identified by "mu" and
873 ** then as a dashed cherrypick merge line up further to "cu".
874 ** If this value is omitted if there are no merge children.
875 ** mu: The id of the row which is the top of the merge-out arrow.
876 ** Only exists if "mo" exists.
877 ** cu: Extend the mu merge error on up to this row as a cherrypick
878 ** merge line, if this value exists.
879 ** u: Draw a thick child-line out of the top of this node and up to
880 ** the node with an id equal to this value. 0 if it is straight to
881 ** the top of the page, -1 if there is no thick-line riser.
882 ** f: 0x01: a leaf node.
883
--- src/timeline.c
+++ src/timeline.c
@@ -872,11 +872,11 @@
872 ** a solid normal merge line up to the row identified by "mu" and
873 ** then as a dashed cherrypick merge line up further to "cu".
874 ** If this value is omitted if there are no merge children.
875 ** mu: The id of the row which is the top of the merge-out arrow.
876 ** Only exists if "mo" exists.
877 ** cu: Extend the mu merge arrow up to this row as a cherrypick
878 ** merge line, if this value exists.
879 ** u: Draw a thick child-line out of the top of this node and up to
880 ** the node with an id equal to this value. 0 if it is straight to
881 ** the top of the page, -1 if there is no thick-line riser.
882 ** f: 0x01: a leaf node.
883

Keyboard Shortcuts

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