/src/ghostpdl/psi/zdevcal.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2023 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* %Calendar% IODevice */ |
18 | | #include "time_.h" |
19 | | #include "ghost.h" |
20 | | #include "gxiodev.h" |
21 | | #include "istack.h" |
22 | | #include "iparam.h" |
23 | | |
24 | | /* ------ %Calendar% ------ */ |
25 | | |
26 | | static iodev_proc_get_params(calendar_get_params); |
27 | | const gx_io_device gs_iodev_calendar = { |
28 | | "%Calendar%", "Special", |
29 | | { iodev_no_init, iodev_no_finit, iodev_no_open_device, iodev_no_open_file, |
30 | | iodev_no_fopen, iodev_no_fclose, |
31 | | iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status, |
32 | | iodev_no_enumerate_files, NULL, NULL, |
33 | | calendar_get_params, iodev_no_put_params |
34 | | }, |
35 | | NULL, |
36 | | NULL |
37 | | }; |
38 | | |
39 | | /* Get the date and time. */ |
40 | | static int |
41 | | calendar_get_params(gx_io_device * iodev, gs_param_list * plist) |
42 | 0 | { |
43 | 0 | int code; |
44 | 0 | time_t t; |
45 | 0 | struct tm *pltime; |
46 | 0 | struct tm ltime; |
47 | 0 | static const gs_param_item_t items[] = { |
48 | 0 | {"Year", gs_param_type_int, offset_of(struct tm, tm_year)}, |
49 | 0 | {"Month", gs_param_type_int, offset_of(struct tm, tm_mon)}, |
50 | 0 | {"Day", gs_param_type_int, offset_of(struct tm, tm_mday)}, |
51 | 0 | {"Weekday", gs_param_type_int, offset_of(struct tm, tm_wday)}, |
52 | 0 | {"Hour", gs_param_type_int, offset_of(struct tm, tm_hour)}, |
53 | 0 | {"Minute", gs_param_type_int, offset_of(struct tm, tm_min)}, |
54 | 0 | {"Second", gs_param_type_int, offset_of(struct tm, tm_sec)}, |
55 | 0 | gs_param_item_end |
56 | 0 | }; |
57 | 0 | bool running; |
58 | |
|
59 | 0 | if (time(&t) == (time_t)-1 || (pltime = localtime(&t)) == 0) { |
60 | 0 | ltime.tm_sec = ltime.tm_min = ltime.tm_hour = |
61 | 0 | ltime.tm_mday = ltime.tm_mon = ltime.tm_year = 0; |
62 | 0 | running = false; |
63 | 0 | } else { |
64 | 0 | ltime = *pltime; |
65 | 0 | ltime.tm_year += 1900; |
66 | 0 | ltime.tm_mon++; /* 1-origin */ |
67 | 0 | running = true; |
68 | 0 | } |
69 | 0 | if ((code = gs_param_write_items(plist, <ime, NULL, items)) < 0) |
70 | 0 | return code; |
71 | 0 | return param_write_bool(plist, "Running", &running); |
72 | 0 | } |