]> git.zerfleddert.de Git - micropolis/blob - src/tclx/src/tclxclck.c
Import Micropolis from http://www.donhopkins.com/home/micropolis/
[micropolis] / src / tclx / src / tclxclck.c
1 /*
2 * tclXclock.c --
3 *
4 * Contains the TCL time and date related commands.
5 *-----------------------------------------------------------------------------
6 * Copyright 1992 Karl Lehenbauer and Mark Diekhans.
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation for any purpose and without fee is hereby granted, provided
10 * that the above copyright notice appear in all copies. Karl Lehenbauer and
11 * Mark Diekhans make no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *-----------------------------------------------------------------------------
15 * $Id: tclXclock.c,v 2.0 1992/10/16 04:50:28 markd Rel $
16 *-----------------------------------------------------------------------------
17 */
18
19 #include <time.h>
20 #include "tclxint.h"
21
22 \f
23 /*
24 *-----------------------------------------------------------------------------
25 *
26 * Tcl_GetclockCmd --
27 * Implements the TCL getclock command:
28 * getclock
29 *
30 * Results:
31 * Standard TCL results.
32 *
33 *-----------------------------------------------------------------------------
34 */
35 int
36 Tcl_GetclockCmd (clientData, interp, argc, argv)
37 ClientData clientData;
38 Tcl_Interp *interp;
39 int argc;
40 char **argv;
41 {
42 if (argc != 1) {
43 Tcl_AppendResult (interp, tclXWrongArgs, argv[0], (char *) NULL);
44 return TCL_ERROR;
45 }
46 sprintf (interp->result, "%ld", time ((long *) NULL));
47 return TCL_OK;
48 }
49 \f
50 /*
51 *-----------------------------------------------------------------------------
52 *
53 * Tcl_FmtclockCmd --
54 * Implements the TCL fmtclock command:
55 * fmtclock clockval [format] [GMT|{}]
56 *
57 * Results:
58 * Standard TCL results.
59 *
60 *-----------------------------------------------------------------------------
61 */
62 int
63 Tcl_FmtclockCmd (clientData, interp, argc, argv)
64 ClientData clientData;
65 Tcl_Interp *interp;
66 int argc;
67 char **argv;
68 {
69 int useGMT = FALSE;
70 long clockVal;
71 char *format;
72 struct tm *timeDataPtr;
73 int fmtError;
74
75 if ((argc < 2) || (argc > 4)) {
76 Tcl_AppendResult (interp, tclXWrongArgs, argv [0],
77 " clockval [format] [GMT|{}]", (char *) NULL);
78 return TCL_ERROR;
79 }
80
81 if (Tcl_GetLong (interp, argv[1], &clockVal) != TCL_OK)
82 return TCL_ERROR;
83 if ((argc == 4) && (argv [3][0] != '\0')) {
84 if (!STREQU (argv [3], "GMT")) {
85 Tcl_AppendResult (interp, "expected \"GMT\" or {} got \"",
86 argv [3], "\"", (char *) NULL);
87 return TCL_ERROR;
88 }
89 useGMT = TRUE;
90 }
91
92 if ((argc >= 3) && (argv [2][0] != '\0'))
93 format = argv[2];
94 else
95 format = "%a %b %d %X %Z %Y";
96
97 if (useGMT)
98 timeDataPtr = gmtime (&clockVal);
99 else
100 timeDataPtr = localtime (&clockVal);
101
102 fmtError = strftime (interp->result, TCL_RESULT_SIZE, format,
103 timeDataPtr) < 0;
104 if (fmtError) {
105 Tcl_AppendResult (interp, "error formating time", (char *) NULL);
106 return TCL_ERROR;
107 }
108 return TCL_OK;
109 }
Impressum, Datenschutz