1 /* Copyright (C) 1995, 1998, 2000 Aladdin Enterprises. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 /* $Id: zdevcal.c,v 1.5 2002/02/21 22:24:54 giles Exp $ */ 18 /* %Calendar% IODevice */ 19 #include "time_.h" 20 #include "ghost.h" 21 #include "gxiodev.h" 22 #include "istack.h" 23 #include "iparam.h" 24 25 /* ------ %Calendar% ------ */ 26 27 private iodev_proc_get_params(calendar_get_params); 28 const gx_io_device gs_iodev_calendar = { 29 "%Calendar%", "Special", 30 { iodev_no_init, iodev_no_open_device, iodev_no_open_file, 31 iodev_no_fopen, iodev_no_fclose, 32 iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status, 33 iodev_no_enumerate_files, NULL, NULL, 34 calendar_get_params, iodev_no_put_params 35 } 36 }; 37 38 /* Get the date and time. */ 39 private int 40 calendar_get_params(gx_io_device * iodev, gs_param_list * plist) 41 { 42 int code; 43 time_t t; 44 struct tm *pltime; 45 struct tm ltime; 46 static const gs_param_item_t items[] = { 47 {"Year", gs_param_type_int, offset_of(struct tm, tm_year)}, 48 {"Month", gs_param_type_int, offset_of(struct tm, tm_mon)}, 49 {"Day", gs_param_type_int, offset_of(struct tm, tm_mday)}, 50 {"Weekday", gs_param_type_int, offset_of(struct tm, tm_wday)}, 51 {"Hour", gs_param_type_int, offset_of(struct tm, tm_hour)}, 52 {"Minute", gs_param_type_int, offset_of(struct tm, tm_min)}, 53 {"Second", gs_param_type_int, offset_of(struct tm, tm_sec)}, 54 gs_param_item_end 55 }; 56 bool running; 57 58 if (time(&t) == (time_t)-1 || (pltime = localtime(&t)) == 0) { 59 ltime.tm_sec = ltime.tm_min = ltime.tm_hour = 60 ltime.tm_mday = ltime.tm_mon = ltime.tm_year = 0; 61 running = false; 62 } else { 63 ltime = *pltime; 64 ltime.tm_year += 1900; 65 ltime.tm_mon++; /* 1-origin */ 66 running = true; 67 } 68 if ((code = gs_param_write_items(plist, <ime, NULL, items)) < 0) 69 return code; 70 return param_write_bool(plist, "Running", &running); 71 } 72