]> cvs.zerfleddert.de Git - micropolis/blob - src/tclx/src/tclxcclk.c
Fixes for compilation with gcc 15
[micropolis] / src / tclx / src / tclxcclk.c
1 /*
2 * tclXcnvclock.c --
3 *
4 * Contains the TCL convertclock command. This is in a module seperate
5 * from clock so that it can be excluded, along with the yacc generated code,
6 * since its rather large.
7 *-----------------------------------------------------------------------------
8 * Copyright 1992 Karl Lehenbauer and Mark Diekhans.
9 *
10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted, provided
12 * that the above copyright notice appear in all copies. Karl Lehenbauer and
13 * Mark Diekhans make no representations about the suitability of this
14 * software for any purpose. It is provided "as is" without express or
15 * implied warranty.
16 *-----------------------------------------------------------------------------
17 * $Id: tclXcnvclock.c,v 2.1 1992/11/07 22:23:03 markd Exp $
18 *-----------------------------------------------------------------------------
19 */
20
21 #include "tclxint.h"
22 #include <time.h>
23
24 \f
25 /*
26 *-----------------------------------------------------------------------------
27 *
28 * Tcl_ConvertclockCmd --
29 * Implements the TCL convertclock command:
30 * convertclock dateString [GMT|{}]
31 *
32 * Results:
33 * Standard TCL results.
34 *
35 *-----------------------------------------------------------------------------
36 */
37 int
38 Tcl_ConvertclockCmd (
39 ClientData clientData,
40 Tcl_Interp *interp,
41 int argc,
42 char **argv
43 )
44 {
45 long clockVal;
46 time_t baseClock;
47 struct tm *timeDataPtr;
48 long zone;
49
50 if ((argc < 2) || (argc > 4)) {
51 Tcl_AppendResult (interp, tclXWrongArgs, argv [0],
52 " dateString [GMT|{}] [baseclock]", (char *) NULL);
53 return TCL_ERROR;
54 }
55 if (argc == 4) {
56 if (Tcl_GetLong (interp, argv [3], &baseClock) != TCL_OK)
57 return TCL_ERROR;
58 } else
59 time (&baseClock);
60
61 if ((argc > 2) && (argv [2][0] != '\0')) {
62 if (!STREQU (argv [2], "GMT")) {
63 Tcl_AppendResult (interp, "invalid argument: expected `GMT', ",
64 "got : `", argv [2], "'", (char *) NULL);
65 return TCL_ERROR;
66 }
67 zone = 0; /* Zero minutes from GMT */
68 } else {
69 timeDataPtr = localtime (&baseClock);
70 /*
71 * Get the minutes east of GMT.
72 */
73 #ifdef TCL_TM_GMTOFF
74 zone = -(timeDataPtr->tm_gmtoff / 60);
75 #endif
76 #ifdef TCL_TIMEZONE_VAR
77 zone = timezone / 60;
78 #endif
79 #if !defined(TCL_TM_GMTOFF) && !defined(TCL_TIMEZONE_VAR)
80 zone = timeDataPtr->tm_tzadj / 60;
81 #endif
82 }
83
84 clockVal = Tcl_GetDate (argv [1], baseClock, zone);
85 if (clockVal == -1) {
86 Tcl_AppendResult (interp, "Unable to convert date-time string \"",
87 argv [1], "\"", (char *) NULL);
88 return TCL_ERROR;
89 }
90 sprintf (interp->result, "%ld", clockVal);
91 return TCL_OK;
92 }
93
Impressum, Datenschutz