Skip to content

Commit

Permalink
[unix] build for *nix fixed, code clean-ups; missing declarations; un…
Browse files Browse the repository at this point in the history
…used vars, functions etc; types normalization;
  • Loading branch information
sebres committed Dec 30, 2016
1 parent b5b5b73 commit 5674e9c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 74 deletions.
6 changes: 1 addition & 5 deletions generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ static unsigned long TzsetGetEpoch(void);
static void TzsetIfNecessary(void);
static void ClockDeleteCmdProc(ClientData);

static int ClockTestObjCmd(
ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);

/*
* Structure containing description of "native" clock commands to create.
*/
Expand Down Expand Up @@ -3365,7 +3361,7 @@ ClockFreeScan(
/* relative time (seconds), if exceeds current date, do the day conversion and
* leave rest of the increment in yyRelSeconds to add it hereafter in UTC seconds */
if (yyRelSeconds) {
time_t newSecs = yySeconds + yyRelSeconds;
int newSecs = yySeconds + yyRelSeconds;

/* if seconds increment outside of current date, increment day */
if (newSecs / SECONDS_PER_DAY != yySeconds / SECONDS_PER_DAY) {
Expand Down
31 changes: 17 additions & 14 deletions generic/tclClockFmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ CLOCK_LOCALE_LITERAL_ARRAY(MsgCtLitIdxs, "_IDX_");

inline int
_str2int(
time_t *out,
int *out,
register
const char *p,
const char *e,
int sign)
{
register time_t val = 0, prev = 0;
register int val = 0, prev = 0;
if (sign >= 0) {
while (p < e) {
val = val * 10 + (*p++ - '0');
Expand Down Expand Up @@ -880,6 +880,7 @@ ObjListSearch(ClockFmtScnCmdArgs *opts,
}
return TCL_RETURN;
}
#if 0

static int
LocaleListSearch(ClockFmtScnCmdArgs *opts,
Expand All @@ -905,6 +906,7 @@ LocaleListSearch(ClockFmtScnCmdArgs *opts,
return ObjListSearch(opts, info, val, lstv, lstc,
minLen, maxLen);
}
#endif

static TclStrIdxTree *
ClockMCGetListIdxTree(
Expand Down Expand Up @@ -1039,6 +1041,7 @@ ClockStrIdxTreeSearch(ClockFmtScnCmdArgs *opts,

return TCL_OK;
}
#if 0

static int
StaticListSearch(ClockFmtScnCmdArgs *opts,
Expand All @@ -1062,14 +1065,15 @@ StaticListSearch(ClockFmtScnCmdArgs *opts,
}
return TCL_RETURN;
}
#endif

inline const char *
FindWordEnd(
ClockScanToken *tok,
register const char * p, const char * end)
{
register const char *x = tok->tokWord.start;
const char *pfnd;
const char *pfnd = p;
if (x == tok->tokWord.end - 1) { /* fast phase-out for single char word */
if (*p == *x) {
return ++p;
Expand All @@ -1088,14 +1092,14 @@ static int
ClockScnToken_Month_Proc(ClockFmtScnCmdArgs *opts,
DateInfo *info, ClockScanToken *tok)
{
/*
#if 0
static const char * months[] = {
/* full * /
/* full */
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December",
/* abbr * /
/* abbr */
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
NULL
Expand All @@ -1106,7 +1110,7 @@ ClockScnToken_Month_Proc(ClockFmtScnCmdArgs *opts,
}
yyMonth = (val % 12) + 1;
return TCL_OK;
*/
#endif

static int monthsKeys[] = {MCLIT_MONTHS_FULL, MCLIT_MONTHS_ABBREV, 0};

Expand Down Expand Up @@ -1300,7 +1304,7 @@ ClockScnToken_LocaleListMatcher_Proc(ClockFmtScnCmdArgs *opts,
}

if (tok->map->offs > 0) {
*(time_t *)(((char *)info) + tok->map->offs) = val;
*(int *)(((char *)info) + tok->map->offs) = val;
}

return TCL_OK;
Expand Down Expand Up @@ -1334,7 +1338,7 @@ ClockScnToken_TimeZone_Proc(ClockFmtScnCmdArgs *opts,
*bp++ = *p++; len++;
if (len + 2 < maxLen) {
if (*p == ':') {
*p++; len++;
p++; len++;
}
}
}
Expand Down Expand Up @@ -1392,7 +1396,7 @@ ClockScnToken_StarDate_Proc(ClockFmtScnCmdArgs *opts,
{
int minLen, maxLen;
register const char *p = yyInput, *end; const char *s;
time_t year, fractYear, fractDayDiv, fractDay;
int year, fractYear, fractDayDiv, fractDay;
static const char *stardatePref = "stardate ";

DetermineGreedySearchLen(opts, info, tok, &minLen, &maxLen);
Expand Down Expand Up @@ -1626,7 +1630,7 @@ EstimateTokenCount(

#define AllocTokenInChain(tok, chain, tokCnt) \
if (++(tok) >= (chain) + (tokCnt)) { \
(char *)(chain) = ckrealloc((char *)(chain), \
*((char **)&chain) = ckrealloc((char *)(chain), \
(tokCnt + CLOCK_MIN_TOK_CHAIN_BLOCK_SIZE) * sizeof(*(tok))); \
if ((chain) == NULL) { goto done; }; \
(tok) = (chain) + (tokCnt); \
Expand Down Expand Up @@ -1929,7 +1933,7 @@ ClockScan(
if (map->offs) {
p = yyInput; x = p + size;
if (!(map->flags & (CLF_LOCALSEC|CLF_POSIXSEC))) {
if (_str2int((time_t *)(((char *)info) + map->offs),
if (_str2int((int *)(((char *)info) + map->offs),
p, x, sign) != TCL_OK) {
goto overflow;
}
Expand Down Expand Up @@ -2678,7 +2682,6 @@ ClockFormat(
register DateFormat *dateFmt, /* Date fields used for parsing & converting */
ClockFmtScnCmdArgs *opts) /* Command options */
{
ClockClientData *dataPtr = opts->clientData;
ClockFmtScnStorage *fss;
ClockFormatToken *tok;
ClockFormatTokenMap *map;
Expand Down Expand Up @@ -2716,7 +2719,7 @@ ClockFormat(
{
case CFMTT_INT:
if (1) {
int val = (int)*(time_t *)(((char *)dateFmt) + map->offs);
int val = (int)*(int *)(((char *)dateFmt) + map->offs);
if (map->fmtproc == NULL) {
if (map->flags & CLFMT_DECR) {
val--;
Expand Down
8 changes: 4 additions & 4 deletions generic/tclDate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2448,11 +2448,11 @@ TclDateerror(
infoPtr->separatrix = "\n";
}

time_t
MODULE_SCOPE int
ToSeconds(
time_t Hours,
time_t Minutes,
time_t Seconds,
int Hours,
int Minutes,
int Seconds,
MERIDIAN Meridian)
{
if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) {
Expand Down
80 changes: 41 additions & 39 deletions generic/tclDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ typedef struct TclDateFields {
* epoch */
Tcl_WideInt localSeconds; /* Local time expressed in nominal seconds
* from the Posix epoch */
time_t tzOffset; /* Time zone offset in seconds east of
int tzOffset; /* Time zone offset in seconds east of
* Greenwich */
time_t julianDay; /* Julian Day Number in local time zone */
int julianDay; /* Julian Day Number in local time zone */
enum {BCE=1, CE=0} era; /* Era */
time_t gregorian; /* Flag == 1 if the date is Gregorian */
time_t year; /* Year of the era */
time_t dayOfYear; /* Day of the year (1 January == 1) */
time_t month; /* Month number */
time_t dayOfMonth; /* Day of the month */
time_t iso8601Year; /* ISO8601 week-based year */
time_t iso8601Week; /* ISO8601 week number */
time_t dayOfWeek; /* Day of the week */
time_t hour; /* Hours of day (in-between time only calculation) */
time_t minutes; /* Minutes of day (in-between time only calculation) */
time_t secondOfDay; /* Seconds of day (in-between time only calculation) */
int gregorian; /* Flag == 1 if the date is Gregorian */
int year; /* Year of the era */
int dayOfYear; /* Day of the year (1 January == 1) */
int month; /* Month number */
int dayOfMonth; /* Day of the month */
int iso8601Year; /* ISO8601 week-based year */
int iso8601Week; /* ISO8601 week number */
int dayOfWeek; /* Day of the week */
int hour; /* Hours of day (in-between time only calculation) */
int minutes; /* Minutes of day (in-between time only calculation) */
int secondOfDay; /* Seconds of day (in-between time only calculation) */

/* Non cacheable fields: */

Expand All @@ -180,34 +180,34 @@ typedef struct DateInfo {

int flags;

time_t dateHaveDate;
int dateHaveDate;

time_t dateMeridian;
time_t dateHaveTime;
int dateMeridian;
int dateHaveTime;

time_t dateTimezone;
time_t dateDSTmode;
time_t dateHaveZone;
int dateTimezone;
int dateDSTmode;
int dateHaveZone;

time_t dateRelMonth;
time_t dateRelDay;
time_t dateRelSeconds;
time_t dateHaveRel;
int dateRelMonth;
int dateRelDay;
int dateRelSeconds;
int dateHaveRel;

time_t dateMonthOrdinalIncr;
time_t dateMonthOrdinal;
time_t dateHaveOrdinalMonth;
int dateMonthOrdinalIncr;
int dateMonthOrdinal;
int dateHaveOrdinalMonth;

time_t dateDayOrdinal;
time_t dateDayNumber;
time_t dateHaveDay;
int dateDayOrdinal;
int dateDayNumber;
int dateHaveDay;

time_t *dateRelPointer;
int *dateRelPointer;

time_t dateSpaceCount;
time_t dateDigitCount;
int dateSpaceCount;
int dateDigitCount;

time_t dateCentury;
int dateCentury;

Tcl_Obj* messages; /* Error messages */
const char* separatrix; /* String separating messages */
Expand Down Expand Up @@ -244,7 +244,7 @@ typedef struct DateInfo {
#define yyDigitCount (info->dateDigitCount)
#define yySpaceCount (info->dateSpaceCount)

inline void
static inline void
ClockInitDateInfo(DateInfo *info) {
memset(info, 0, sizeof(DateInfo));
}
Expand Down Expand Up @@ -314,7 +314,7 @@ typedef struct ClockClientData {
Tcl_WideInt seconds;
Tcl_WideInt rangesVal[2]; /* Bounds for cached time zone offset */
/* values */
time_t tzOffset;
int tzOffset;
Tcl_Obj *tzName;
} UTC2Local;
/* Las-period cache for fast Local2UTC conversion */
Expand All @@ -325,7 +325,7 @@ typedef struct ClockClientData {
Tcl_WideInt localSeconds;
Tcl_WideInt rangesVal[2]; /* Bounds for cached time zone offset */
/* values */
time_t tzOffset;
int tzOffset;
} Local2UTC;
} ClockClientData;

Expand Down Expand Up @@ -444,16 +444,18 @@ typedef struct ClockFmtScnStorage {
ClockFmtScnStorage *nextPtr;
ClockFmtScnStorage *prevPtr;
#endif
/* +Tcl_HashEntry hashEntry /* ClockFmtScnStorage is a derivate of Tcl_HashEntry,
#if 0
+Tcl_HashEntry hashEntry /* ClockFmtScnStorage is a derivate of Tcl_HashEntry,
* stored by offset +sizeof(self) */
#endif
} ClockFmtScnStorage;

/*
* Prototypes of module functions.
*/

MODULE_SCOPE time_t ToSeconds(time_t Hours, time_t Minutes,
time_t Seconds, MERIDIAN Meridian);
MODULE_SCOPE int ToSeconds(int Hours, int Minutes,
int Seconds, MERIDIAN Meridian);
MODULE_SCOPE int IsGregorianLeapYear(TclDateFields *);
MODULE_SCOPE void
GetJulianDayFromEraYearWeekDay(
Expand Down
8 changes: 4 additions & 4 deletions generic/tclGetDate.y
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,11 @@ TclDateerror(
infoPtr->separatrix = "\n";
}

time_t
MODULE_SCOPE int
ToSeconds(
time_t Hours,
time_t Minutes,
time_t Seconds,
int Hours,
int Minutes,
int Seconds,
MERIDIAN Meridian)
{
if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) {
Expand Down
8 changes: 4 additions & 4 deletions generic/tclStrIdxTree.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ TclStrIdxTreeInsertBranch(
parent->firstPtr = item;
if (parent->lastPtr == child)
parent->lastPtr = item;
if (item->nextPtr = child->nextPtr) {
if ( (item->nextPtr = child->nextPtr) ) {
item->nextPtr->prevPtr = item;
child->nextPtr = NULL;
}
if (item->prevPtr = child->prevPtr) {
if ( (item->prevPtr = child->prevPtr) ) {
item->prevPtr->nextPtr = item;
child->prevPtr = NULL;
}
Expand Down Expand Up @@ -365,7 +365,7 @@ StrIdxTreeObj_DupIntRepProc(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr)
srcPtr = (Tcl_Obj*)srcPtr->internalRep.twoPtrValue.ptr1;
}
/* create smart pointer to it (ptr1 != NULL, ptr2 = NULL) */
Tcl_InitObjRef(((Tcl_Obj *)copyPtr->internalRep.twoPtrValue.ptr1),
Tcl_InitObjRef(*((Tcl_Obj **)&copyPtr->internalRep.twoPtrValue.ptr1),
srcPtr);
copyPtr->internalRep.twoPtrValue.ptr2 = NULL;
copyPtr->typePtr = &StrIdxTreeObjType;
Expand All @@ -379,7 +379,7 @@ StrIdxTreeObj_FreeIntRepProc(Tcl_Obj *objPtr)
&& objPtr->internalRep.twoPtrValue.ptr2 == NULL
) {
/* is a link */
Tcl_UnsetObjRef(((Tcl_Obj *)objPtr->internalRep.twoPtrValue.ptr1));
Tcl_UnsetObjRef(*((Tcl_Obj **)&objPtr->internalRep.twoPtrValue.ptr1));
} else {
/* is a tree */
TclStrIdxTree *tree = (TclStrIdxTree*)&objPtr->internalRep.twoPtrValue.ptr1;
Expand Down
Loading

0 comments on commit 5674e9c

Please sign in to comment.