Fossil SCM

simplify setup code and fix comment

jan.nijtmans 2013-12-30 19:07 UTC pending-review merge
Commit 9e5a9d1c715724f61a18f854bffe9744c7f4d00f
+2 -3
--- src/setup.c
+++ src/setup.c
@@ -1184,15 +1184,14 @@
11841184
@ <hr />
11851185
onoff_attribute("Use Universal Coordinated Time (UTC)",
11861186
"timeline-utc", "utc", 1, 0);
11871187
@ <p>Show times as UTC (also sometimes called Greenwich Mean Time (GMT) or
11881188
@ Zulu) instead of in local time. On this server, local time is currently
1189
- g.fTimeFormat = 2;
11901189
tmDiff = db_double(0.0, "SELECT julianday('now')");
11911190
tmDiff = db_double(0.0,
1192
- "SELECT (julianday(%.17g%s)-julianday(%.17g))*24.0",
1193
- tmDiff, timeline_utc(), tmDiff);
1191
+ "SELECT (julianday(%.17g,'localtime')-julianday(%.17g))*24.0",
1192
+ tmDiff, tmDiff);
11941193
sqlite3_snprintf(sizeof(zTmDiff), zTmDiff, "%.1f", tmDiff);
11951194
if( strcmp(zTmDiff, "0.0")==0 ){
11961195
@ the same as UTC and so this setting will make no difference in
11971196
@ the display.</p>
11981197
}else if( tmDiff<0.0 ){
11991198
--- src/setup.c
+++ src/setup.c
@@ -1184,15 +1184,14 @@
1184 @ <hr />
1185 onoff_attribute("Use Universal Coordinated Time (UTC)",
1186 "timeline-utc", "utc", 1, 0);
1187 @ <p>Show times as UTC (also sometimes called Greenwich Mean Time (GMT) or
1188 @ Zulu) instead of in local time. On this server, local time is currently
1189 g.fTimeFormat = 2;
1190 tmDiff = db_double(0.0, "SELECT julianday('now')");
1191 tmDiff = db_double(0.0,
1192 "SELECT (julianday(%.17g%s)-julianday(%.17g))*24.0",
1193 tmDiff, timeline_utc(), tmDiff);
1194 sqlite3_snprintf(sizeof(zTmDiff), zTmDiff, "%.1f", tmDiff);
1195 if( strcmp(zTmDiff, "0.0")==0 ){
1196 @ the same as UTC and so this setting will make no difference in
1197 @ the display.</p>
1198 }else if( tmDiff<0.0 ){
1199
--- src/setup.c
+++ src/setup.c
@@ -1184,15 +1184,14 @@
1184 @ <hr />
1185 onoff_attribute("Use Universal Coordinated Time (UTC)",
1186 "timeline-utc", "utc", 1, 0);
1187 @ <p>Show times as UTC (also sometimes called Greenwich Mean Time (GMT) or
1188 @ Zulu) instead of in local time. On this server, local time is currently
 
1189 tmDiff = db_double(0.0, "SELECT julianday('now')");
1190 tmDiff = db_double(0.0,
1191 "SELECT (julianday(%.17g,'localtime')-julianday(%.17g))*24.0",
1192 tmDiff, tmDiff);
1193 sqlite3_snprintf(sizeof(zTmDiff), zTmDiff, "%.1f", tmDiff);
1194 if( strcmp(zTmDiff, "0.0")==0 ){
1195 @ the same as UTC and so this setting will make no difference in
1196 @ the display.</p>
1197 }else if( tmDiff<0.0 ){
1198
+2 -3
--- src/setup.c
+++ src/setup.c
@@ -1184,15 +1184,14 @@
11841184
@ <hr />
11851185
onoff_attribute("Use Universal Coordinated Time (UTC)",
11861186
"timeline-utc", "utc", 1, 0);
11871187
@ <p>Show times as UTC (also sometimes called Greenwich Mean Time (GMT) or
11881188
@ Zulu) instead of in local time. On this server, local time is currently
1189
- g.fTimeFormat = 2;
11901189
tmDiff = db_double(0.0, "SELECT julianday('now')");
11911190
tmDiff = db_double(0.0,
1192
- "SELECT (julianday(%.17g%s)-julianday(%.17g))*24.0",
1193
- tmDiff, timeline_utc(), tmDiff);
1191
+ "SELECT (julianday(%.17g,'localtime')-julianday(%.17g))*24.0",
1192
+ tmDiff, tmDiff);
11941193
sqlite3_snprintf(sizeof(zTmDiff), zTmDiff, "%.1f", tmDiff);
11951194
if( strcmp(zTmDiff, "0.0")==0 ){
11961195
@ the same as UTC and so this setting will make no difference in
11971196
@ the display.</p>
11981197
}else if( tmDiff<0.0 ){
11991198
--- src/setup.c
+++ src/setup.c
@@ -1184,15 +1184,14 @@
1184 @ <hr />
1185 onoff_attribute("Use Universal Coordinated Time (UTC)",
1186 "timeline-utc", "utc", 1, 0);
1187 @ <p>Show times as UTC (also sometimes called Greenwich Mean Time (GMT) or
1188 @ Zulu) instead of in local time. On this server, local time is currently
1189 g.fTimeFormat = 2;
1190 tmDiff = db_double(0.0, "SELECT julianday('now')");
1191 tmDiff = db_double(0.0,
1192 "SELECT (julianday(%.17g%s)-julianday(%.17g))*24.0",
1193 tmDiff, timeline_utc(), tmDiff);
1194 sqlite3_snprintf(sizeof(zTmDiff), zTmDiff, "%.1f", tmDiff);
1195 if( strcmp(zTmDiff, "0.0")==0 ){
1196 @ the same as UTC and so this setting will make no difference in
1197 @ the display.</p>
1198 }else if( tmDiff<0.0 ){
1199
--- src/setup.c
+++ src/setup.c
@@ -1184,15 +1184,14 @@
1184 @ <hr />
1185 onoff_attribute("Use Universal Coordinated Time (UTC)",
1186 "timeline-utc", "utc", 1, 0);
1187 @ <p>Show times as UTC (also sometimes called Greenwich Mean Time (GMT) or
1188 @ Zulu) instead of in local time. On this server, local time is currently
 
1189 tmDiff = db_double(0.0, "SELECT julianday('now')");
1190 tmDiff = db_double(0.0,
1191 "SELECT (julianday(%.17g,'localtime')-julianday(%.17g))*24.0",
1192 tmDiff, tmDiff);
1193 sqlite3_snprintf(sizeof(zTmDiff), zTmDiff, "%.1f", tmDiff);
1194 if( strcmp(zTmDiff, "0.0")==0 ){
1195 @ the same as UTC and so this setting will make no difference in
1196 @ the display.</p>
1197 }else if( tmDiff<0.0 ){
1198
+9 -3
--- src/th.c
+++ src/th.c
@@ -1876,18 +1876,18 @@
18761876
if( rc==TH_OK && eArgType==ARG_INTEGER ){
18771877
int iRes = 0;
18781878
switch( pExpr->pOp->eOp ) {
18791879
case OP_MULTIPLY: iRes = iLeft*iRight; break;
18801880
case OP_DIVIDE:
1881
- if(!iRight){
1881
+ if( !iRight ){
18821882
Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
18831883
return TH_ERROR;
18841884
}
18851885
iRes = iLeft/iRight;
18861886
break;
18871887
case OP_MODULUS:
1888
- if(!iRight){
1888
+ if( !iRight ){
18891889
Th_ErrorMessage(interp, "Modulo by 0:", zLeft, nLeft);
18901890
return TH_ERROR;
18911891
}
18921892
iRes = iLeft%iRight;
18931893
break;
@@ -1913,11 +1913,17 @@
19131913
}
19141914
Th_SetResultInt(interp, iRes);
19151915
}else if( rc==TH_OK && eArgType==ARG_NUMBER ){
19161916
switch( pExpr->pOp->eOp ) {
19171917
case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break;
1918
- case OP_DIVIDE: Th_SetResultDouble(interp, fLeft/fRight); break;
1918
+ case OP_DIVIDE:
1919
+ if( fRight==0.0 ){
1920
+ Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
1921
+ return TH_ERROR;
1922
+ }
1923
+ Th_SetResultDouble(interp, fLeft/fRight);
1924
+ break;
19191925
case OP_ADD: Th_SetResultDouble(interp, fLeft+fRight); break;
19201926
case OP_SUBTRACT: Th_SetResultDouble(interp, fLeft-fRight); break;
19211927
case OP_LT: Th_SetResultInt(interp, fLeft<fRight); break;
19221928
case OP_GT: Th_SetResultInt(interp, fLeft>fRight); break;
19231929
case OP_LE: Th_SetResultInt(interp, fLeft<=fRight); break;
19241930
--- src/th.c
+++ src/th.c
@@ -1876,18 +1876,18 @@
1876 if( rc==TH_OK && eArgType==ARG_INTEGER ){
1877 int iRes = 0;
1878 switch( pExpr->pOp->eOp ) {
1879 case OP_MULTIPLY: iRes = iLeft*iRight; break;
1880 case OP_DIVIDE:
1881 if(!iRight){
1882 Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
1883 return TH_ERROR;
1884 }
1885 iRes = iLeft/iRight;
1886 break;
1887 case OP_MODULUS:
1888 if(!iRight){
1889 Th_ErrorMessage(interp, "Modulo by 0:", zLeft, nLeft);
1890 return TH_ERROR;
1891 }
1892 iRes = iLeft%iRight;
1893 break;
@@ -1913,11 +1913,17 @@
1913 }
1914 Th_SetResultInt(interp, iRes);
1915 }else if( rc==TH_OK && eArgType==ARG_NUMBER ){
1916 switch( pExpr->pOp->eOp ) {
1917 case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break;
1918 case OP_DIVIDE: Th_SetResultDouble(interp, fLeft/fRight); break;
 
 
 
 
 
 
1919 case OP_ADD: Th_SetResultDouble(interp, fLeft+fRight); break;
1920 case OP_SUBTRACT: Th_SetResultDouble(interp, fLeft-fRight); break;
1921 case OP_LT: Th_SetResultInt(interp, fLeft<fRight); break;
1922 case OP_GT: Th_SetResultInt(interp, fLeft>fRight); break;
1923 case OP_LE: Th_SetResultInt(interp, fLeft<=fRight); break;
1924
--- src/th.c
+++ src/th.c
@@ -1876,18 +1876,18 @@
1876 if( rc==TH_OK && eArgType==ARG_INTEGER ){
1877 int iRes = 0;
1878 switch( pExpr->pOp->eOp ) {
1879 case OP_MULTIPLY: iRes = iLeft*iRight; break;
1880 case OP_DIVIDE:
1881 if( !iRight ){
1882 Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
1883 return TH_ERROR;
1884 }
1885 iRes = iLeft/iRight;
1886 break;
1887 case OP_MODULUS:
1888 if( !iRight ){
1889 Th_ErrorMessage(interp, "Modulo by 0:", zLeft, nLeft);
1890 return TH_ERROR;
1891 }
1892 iRes = iLeft%iRight;
1893 break;
@@ -1913,11 +1913,17 @@
1913 }
1914 Th_SetResultInt(interp, iRes);
1915 }else if( rc==TH_OK && eArgType==ARG_NUMBER ){
1916 switch( pExpr->pOp->eOp ) {
1917 case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break;
1918 case OP_DIVIDE:
1919 if( fRight==0.0 ){
1920 Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
1921 return TH_ERROR;
1922 }
1923 Th_SetResultDouble(interp, fLeft/fRight);
1924 break;
1925 case OP_ADD: Th_SetResultDouble(interp, fLeft+fRight); break;
1926 case OP_SUBTRACT: Th_SetResultDouble(interp, fLeft-fRight); break;
1927 case OP_LT: Th_SetResultInt(interp, fLeft<fRight); break;
1928 case OP_GT: Th_SetResultInt(interp, fLeft>fRight); break;
1929 case OP_LE: Th_SetResultInt(interp, fLeft<=fRight); break;
1930
+2 -2
--- src/timeline.c
+++ src/timeline.c
@@ -1886,13 +1886,13 @@
18861886
}
18871887
18881888
/*
18891889
** Return one of two things:
18901890
**
1891
-** ",'localtime'" if the timeline-utc property is set.
1891
+** ",'localtime'" if the timeline-utc property is set to 0.
18921892
**
1893
-** "" (empty string) otherwise.
1893
+** "" (empty string) otherwise.
18941894
*/
18951895
const char *timeline_utc(){
18961896
if( g.fTimeFormat==0 ){
18971897
if( db_get_int("timeline-utc", 1) ){
18981898
g.fTimeFormat = 1;
18991899
--- src/timeline.c
+++ src/timeline.c
@@ -1886,13 +1886,13 @@
1886 }
1887
1888 /*
1889 ** Return one of two things:
1890 **
1891 ** ",'localtime'" if the timeline-utc property is set.
1892 **
1893 ** "" (empty string) otherwise.
1894 */
1895 const char *timeline_utc(){
1896 if( g.fTimeFormat==0 ){
1897 if( db_get_int("timeline-utc", 1) ){
1898 g.fTimeFormat = 1;
1899
--- src/timeline.c
+++ src/timeline.c
@@ -1886,13 +1886,13 @@
1886 }
1887
1888 /*
1889 ** Return one of two things:
1890 **
1891 ** ",'localtime'" if the timeline-utc property is set to 0.
1892 **
1893 ** "" (empty string) otherwise.
1894 */
1895 const char *timeline_utc(){
1896 if( g.fTimeFormat==0 ){
1897 if( db_get_int("timeline-utc", 1) ){
1898 g.fTimeFormat = 1;
1899
+2 -2
--- src/timeline.c
+++ src/timeline.c
@@ -1886,13 +1886,13 @@
18861886
}
18871887
18881888
/*
18891889
** Return one of two things:
18901890
**
1891
-** ",'localtime'" if the timeline-utc property is set.
1891
+** ",'localtime'" if the timeline-utc property is set to 0.
18921892
**
1893
-** "" (empty string) otherwise.
1893
+** "" (empty string) otherwise.
18941894
*/
18951895
const char *timeline_utc(){
18961896
if( g.fTimeFormat==0 ){
18971897
if( db_get_int("timeline-utc", 1) ){
18981898
g.fTimeFormat = 1;
18991899
--- src/timeline.c
+++ src/timeline.c
@@ -1886,13 +1886,13 @@
1886 }
1887
1888 /*
1889 ** Return one of two things:
1890 **
1891 ** ",'localtime'" if the timeline-utc property is set.
1892 **
1893 ** "" (empty string) otherwise.
1894 */
1895 const char *timeline_utc(){
1896 if( g.fTimeFormat==0 ){
1897 if( db_get_int("timeline-utc", 1) ){
1898 g.fTimeFormat = 1;
1899
--- src/timeline.c
+++ src/timeline.c
@@ -1886,13 +1886,13 @@
1886 }
1887
1888 /*
1889 ** Return one of two things:
1890 **
1891 ** ",'localtime'" if the timeline-utc property is set to 0.
1892 **
1893 ** "" (empty string) otherwise.
1894 */
1895 const char *timeline_utc(){
1896 if( g.fTimeFormat==0 ){
1897 if( db_get_int("timeline-utc", 1) ){
1898 g.fTimeFormat = 1;
1899
--- test/th1.test
+++ test/th1.test
@@ -65,5 +65,25 @@
6565
6666
###############################################################################
6767
6868
fossil test-th-eval --th-open-config "setting -strict -- --"
6969
test th1-setting-10 {$RESULT eq {TH_ERROR: no value for setting "--"}}
70
+
71
+###############################################################################
72
+
73
+fossil test-th-eval "expr 42/0"
74
+test th1-divide-by-zero-1 {$RESULT eq {TH_ERROR: Divide by 0: 42}}
75
+
76
+###############################################################################
77
+
78
+fossil test-th-eval "expr 42/0.0"
79
+test th1-divide-by-zero-2 {$RESULT eq {TH_ERROR: Divide by 0: 42}}
80
+
81
+###############################################################################
82
+
83
+fossil test-th-eval "expr 42.0/0"
84
+test th1-divide-by-zero-3 {$RESULT eq {TH_ERROR: Divide by 0: 42.0}}
85
+
86
+###############################################################################
87
+
88
+fossil test-th-eval "expr 42.0/0.0"
89
+test th1-divide-by-zero-4 {$RESULT eq {TH_ERROR: Divide by 0: 42.0}}
7090
--- test/th1.test
+++ test/th1.test
@@ -65,5 +65,25 @@
65
66 ###############################################################################
67
68 fossil test-th-eval --th-open-config "setting -strict -- --"
69 test th1-setting-10 {$RESULT eq {TH_ERROR: no value for setting "--"}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
--- test/th1.test
+++ test/th1.test
@@ -65,5 +65,25 @@
65
66 ###############################################################################
67
68 fossil test-th-eval --th-open-config "setting -strict -- --"
69 test th1-setting-10 {$RESULT eq {TH_ERROR: no value for setting "--"}}
70
71 ###############################################################################
72
73 fossil test-th-eval "expr 42/0"
74 test th1-divide-by-zero-1 {$RESULT eq {TH_ERROR: Divide by 0: 42}}
75
76 ###############################################################################
77
78 fossil test-th-eval "expr 42/0.0"
79 test th1-divide-by-zero-2 {$RESULT eq {TH_ERROR: Divide by 0: 42}}
80
81 ###############################################################################
82
83 fossil test-th-eval "expr 42.0/0"
84 test th1-divide-by-zero-3 {$RESULT eq {TH_ERROR: Divide by 0: 42.0}}
85
86 ###############################################################################
87
88 fossil test-th-eval "expr 42.0/0.0"
89 test th1-divide-by-zero-4 {$RESULT eq {TH_ERROR: Divide by 0: 42.0}}
90

Keyboard Shortcuts

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