summaryrefslogtreecommitdiffstats
path: root/generic/tclGetDate.y
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2019-07-15 12:12:22 (GMT)
committersebres <sebres@users.sourceforge.net>2019-07-15 12:12:22 (GMT)
commit9f872f5338b49bea2e8022380a50c2257e42f26d (patch)
tree7b7a3714d0aecdcb95d3a06a611cce1baf128928 /generic/tclGetDate.y
parentc587280d004ba2c60c5b1ce29dfecd3b6dc12e6d (diff)
downloadtcl-9f872f5338b49bea2e8022380a50c2257e42f26d.zip
tcl-9f872f5338b49bea2e8022380a50c2257e42f26d.tar.gz
tcl-9f872f5338b49bea2e8022380a50c2257e42f26d.tar.bz2
simplifying info-structure, usage of flags etc (normalizing in order to use same flags as by formatted scan instead of members like yyHave...);
(additionally allocates info->messages object on demand, if free scan fails)
Diffstat (limited to 'generic/tclGetDate.y')
-rw-r--r--generic/tclGetDate.y78
1 files changed, 33 insertions, 45 deletions
diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y
index cf1f674..8594a3e 100644
--- a/generic/tclGetDate.y
+++ b/generic/tclGetDate.y
@@ -185,13 +185,14 @@ item : time {
yyIncrFlags(CLF_DAYOFWEEK);
}
| relspec {
- yyIncrFlags(CLF_RELCONV);
+ info->flags |= CLF_RELCONV;
}
| iso {
yyIncrFlags(CLF_TIME|CLF_HAVEDATE);
}
| trek {
- yyIncrFlags(CLF_TIME|CLF_HAVEDATE|CLF_RELCONV);
+ yyIncrFlags(CLF_TIME|CLF_HAVEDATE);
+ info->flags |= CLF_RELCONV;
}
| number
;
@@ -698,6 +699,9 @@ TclDateerror(
const char *s)
{
Tcl_Obj* t;
+ if (!infoPtr->messages) {
+ infoPtr->messages = Tcl_NewObj();
+ }
Tcl_AppendToObj(infoPtr->messages, infoPtr->separatrix, -1);
Tcl_AppendToObj(infoPtr->messages, s, -1);
Tcl_AppendToObj(infoPtr->messages, " (characters ", -1);
@@ -995,9 +999,7 @@ TclClockFreeScan(
yyDSTmode = DSTmaybe;
- info->messages = Tcl_NewObj();
info->separatrix = "";
- Tcl_IncrRefCount(info->messages);
info->dateStart = yyInput;
@@ -1007,58 +1009,44 @@ TclClockFreeScan(
/* parse */
status = yyparse(info);
if (status == 1) {
- Tcl_SetObjResult(interp, info->messages);
- Tcl_DecrRefCount(info->messages);
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "PARSE", NULL);
- return TCL_ERROR;
+ const char *msg = NULL;
+ if (info->errFlags & CLF_HAVEDATE) {
+ msg = "more than one date in string";
+ } else if (info->errFlags & CLF_TIME) {
+ msg = "more than one time of day in string";
+ } else if (info->errFlags & CLF_ZONE) {
+ msg = "more than one time zone in string";
+ } else if (info->errFlags & CLF_DAYOFWEEK) {
+ msg = "more than one weekday in string";
+ } else if (info->errFlags & CLF_ORDINALMONTH) {
+ msg = "more than one ordinal month in string";
+ }
+ if (msg) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", NULL);
+ } else {
+ Tcl_SetObjResult(interp,
+ info->messages ? info->messages : Tcl_NewObj());
+ info->messages = NULL;
+ Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "PARSE", NULL);
+ }
+ status = TCL_ERROR;
} else if (status == 2) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("memory exhausted", -1));
- Tcl_DecrRefCount(info->messages);
Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
- return TCL_ERROR;
+ status = TCL_ERROR;
} else if (status != 0) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("Unknown status returned "
"from date parser. Please "
"report this error as a "
"bug in Tcl.", -1));
- Tcl_DecrRefCount(info->messages);
Tcl_SetErrorCode(interp, "TCL", "BUG", NULL);
- return TCL_ERROR;
+ status = TCL_ERROR;
}
- Tcl_DecrRefCount(info->messages);
-
- if (info->errFlags & CLF_HAVEDATE) {
- Tcl_SetObjResult(interp,
- Tcl_NewStringObj("more than one date in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", NULL);
- return TCL_ERROR;
- }
- if (info->errFlags & CLF_TIME) {
- Tcl_SetObjResult(interp,
- Tcl_NewStringObj("more than one time of day in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", NULL);
- return TCL_ERROR;
- }
- if (info->errFlags & CLF_ZONE) {
- Tcl_SetObjResult(interp,
- Tcl_NewStringObj("more than one time zone in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", NULL);
- return TCL_ERROR;
- }
- if (info->errFlags & CLF_DAYOFWEEK) {
- Tcl_SetObjResult(interp,
- Tcl_NewStringObj("more than one weekday in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", NULL);
- return TCL_ERROR;
- }
- if (info->errFlags & CLF_ORDINALMONTH) {
- Tcl_SetObjResult(interp,
- Tcl_NewStringObj("more than one ordinal month in string", -1));
- Tcl_SetErrorCode(interp, "TCL", "VALUE", "DATE", "MULTIPLE", NULL);
- return TCL_ERROR;
+ if (info->messages) {
+ Tcl_DecrRefCount(info->messages);
}
-
- return TCL_OK;
+ return status;
}
/*