Home | History | Annotate | Line # | Download | only in rogue
save.c revision 1.4
      1  1.4  lukem /*	$NetBSD: save.c,v 1.4 1997/10/12 11:45:58 lukem Exp $	*/
      2  1.3    cgd 
      3  1.1    cgd /*
      4  1.3    cgd  * Copyright (c) 1988, 1993
      5  1.3    cgd  *	The Regents of the University of California.  All rights reserved.
      6  1.1    cgd  *
      7  1.1    cgd  * This code is derived from software contributed to Berkeley by
      8  1.1    cgd  * Timothy C. Stoehr.
      9  1.1    cgd  *
     10  1.1    cgd  * Redistribution and use in source and binary forms, with or without
     11  1.1    cgd  * modification, are permitted provided that the following conditions
     12  1.1    cgd  * are met:
     13  1.1    cgd  * 1. Redistributions of source code must retain the above copyright
     14  1.1    cgd  *    notice, this list of conditions and the following disclaimer.
     15  1.1    cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1    cgd  *    notice, this list of conditions and the following disclaimer in the
     17  1.1    cgd  *    documentation and/or other materials provided with the distribution.
     18  1.1    cgd  * 3. All advertising materials mentioning features or use of this software
     19  1.1    cgd  *    must display the following acknowledgement:
     20  1.1    cgd  *	This product includes software developed by the University of
     21  1.1    cgd  *	California, Berkeley and its contributors.
     22  1.1    cgd  * 4. Neither the name of the University nor the names of its contributors
     23  1.1    cgd  *    may be used to endorse or promote products derived from this software
     24  1.1    cgd  *    without specific prior written permission.
     25  1.1    cgd  *
     26  1.1    cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1    cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1    cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1    cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1    cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1    cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1    cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1    cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1    cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1    cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1    cgd  * SUCH DAMAGE.
     37  1.1    cgd  */
     38  1.1    cgd 
     39  1.4  lukem #include <sys/cdefs.h>
     40  1.1    cgd #ifndef lint
     41  1.3    cgd #if 0
     42  1.3    cgd static char sccsid[] = "@(#)save.c	8.1 (Berkeley) 5/31/93";
     43  1.3    cgd #else
     44  1.4  lukem __RCSID("$NetBSD: save.c,v 1.4 1997/10/12 11:45:58 lukem Exp $");
     45  1.3    cgd #endif
     46  1.1    cgd #endif /* not lint */
     47  1.1    cgd 
     48  1.1    cgd /*
     49  1.1    cgd  * save.c
     50  1.1    cgd  *
     51  1.1    cgd  * This source herein may be modified and/or distributed by anybody who
     52  1.1    cgd  * so desires, with the following restrictions:
     53  1.1    cgd  *    1.)  No portion of this notice shall be removed.
     54  1.1    cgd  *    2.)  Credit shall not be taken for the creation of this source.
     55  1.1    cgd  *    3.)  This code is not to be traded, sold, or used for personal
     56  1.1    cgd  *         gain or profit.
     57  1.1    cgd  *
     58  1.1    cgd  */
     59  1.1    cgd 
     60  1.1    cgd #include <stdio.h>
     61  1.1    cgd #include "rogue.h"
     62  1.1    cgd 
     63  1.1    cgd short write_failed = 0;
     64  1.1    cgd char *save_file = (char *) 0;
     65  1.1    cgd 
     66  1.4  lukem void
     67  1.1    cgd save_game()
     68  1.1    cgd {
     69  1.1    cgd 	char fname[64];
     70  1.1    cgd 
     71  1.1    cgd 	if (!get_input_line("file name?", save_file, fname, "game not saved",
     72  1.1    cgd 			0, 1)) {
     73  1.1    cgd 		return;
     74  1.1    cgd 	}
     75  1.1    cgd 	check_message();
     76  1.1    cgd 	message(fname, 0);
     77  1.1    cgd 	save_into_file(fname);
     78  1.1    cgd }
     79  1.1    cgd 
     80  1.4  lukem void
     81  1.1    cgd save_into_file(sfile)
     82  1.4  lukem 	char *sfile;
     83  1.1    cgd {
     84  1.1    cgd 	FILE *fp;
     85  1.1    cgd 	int file_id;
     86  1.1    cgd 	char name_buffer[80];
     87  1.1    cgd 	char *hptr;
     88  1.1    cgd 	struct rogue_time rt_buf;
     89  1.1    cgd 
     90  1.1    cgd 	if (sfile[0] == '~') {
     91  1.4  lukem 		if ((hptr = md_getenv("HOME")) != NULL) {
     92  1.1    cgd 			(void) strcpy(name_buffer, hptr);
     93  1.1    cgd 			(void) strcat(name_buffer, sfile+1);
     94  1.1    cgd 			sfile = name_buffer;
     95  1.1    cgd 		}
     96  1.1    cgd 	}
     97  1.1    cgd 	if (	((fp = fopen(sfile, "w")) == NULL) ||
     98  1.1    cgd 			((file_id = md_get_file_id(sfile)) == -1)) {
     99  1.1    cgd 		message("problem accessing the save file", 0);
    100  1.1    cgd 		return;
    101  1.1    cgd 	}
    102  1.1    cgd 	md_ignore_signals();
    103  1.1    cgd 	write_failed = 0;
    104  1.1    cgd 	(void) xxx(1);
    105  1.1    cgd 	r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    106  1.1    cgd 	r_write(fp, (char *) &cur_level, sizeof(cur_level));
    107  1.1    cgd 	r_write(fp, (char *) &max_level, sizeof(max_level));
    108  1.1    cgd 	write_string(hunger_str, fp);
    109  1.1    cgd 	write_string(login_name, fp);
    110  1.1    cgd 	r_write(fp, (char *) &party_room, sizeof(party_room));
    111  1.1    cgd 	write_pack(&level_monsters, fp);
    112  1.1    cgd 	write_pack(&level_objects, fp);
    113  1.1    cgd 	r_write(fp, (char *) &file_id, sizeof(file_id));
    114  1.1    cgd 	rw_dungeon(fp, 1);
    115  1.1    cgd 	r_write(fp, (char *) &foods, sizeof(foods));
    116  1.1    cgd 	r_write(fp, (char *) &rogue, sizeof(fighter));
    117  1.1    cgd 	write_pack(&rogue.pack, fp);
    118  1.1    cgd 	rw_id(id_potions, fp, POTIONS, 1);
    119  1.1    cgd 	rw_id(id_scrolls, fp, SCROLS, 1);
    120  1.1    cgd 	rw_id(id_wands, fp, WANDS, 1);
    121  1.1    cgd 	rw_id(id_rings, fp, RINGS, 1);
    122  1.1    cgd 	r_write(fp, (char *) traps, (MAX_TRAPS * sizeof(trap)));
    123  1.1    cgd 	r_write(fp, (char *) is_wood, (WANDS * sizeof(boolean)));
    124  1.1    cgd 	r_write(fp, (char *) &cur_room, sizeof(cur_room));
    125  1.1    cgd 	rw_rooms(fp, 1);
    126  1.1    cgd 	r_write(fp, (char *) &being_held, sizeof(being_held));
    127  1.1    cgd 	r_write(fp, (char *) &bear_trap, sizeof(bear_trap));
    128  1.1    cgd 	r_write(fp, (char *) &halluc, sizeof(halluc));
    129  1.1    cgd 	r_write(fp, (char *) &blind, sizeof(blind));
    130  1.1    cgd 	r_write(fp, (char *) &confused, sizeof(confused));
    131  1.1    cgd 	r_write(fp, (char *) &levitate, sizeof(levitate));
    132  1.1    cgd 	r_write(fp, (char *) &haste_self, sizeof(haste_self));
    133  1.1    cgd 	r_write(fp, (char *) &see_invisible, sizeof(see_invisible));
    134  1.1    cgd 	r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    135  1.1    cgd 	r_write(fp, (char *) &wizard, sizeof(wizard));
    136  1.1    cgd 	r_write(fp, (char *) &score_only, sizeof(score_only));
    137  1.1    cgd 	r_write(fp, (char *) &m_moves, sizeof(m_moves));
    138  1.1    cgd 	md_gct(&rt_buf);
    139  1.1    cgd 	rt_buf.second += 10;		/* allow for some processing time */
    140  1.1    cgd 	r_write(fp, (char *) &rt_buf, sizeof(rt_buf));
    141  1.1    cgd 	fclose(fp);
    142  1.1    cgd 
    143  1.1    cgd 	if (write_failed) {
    144  1.1    cgd 		(void) md_df(sfile);	/* delete file */
    145  1.1    cgd 	} else {
    146  1.1    cgd 		clean_up("");
    147  1.1    cgd 	}
    148  1.1    cgd }
    149  1.1    cgd 
    150  1.4  lukem void
    151  1.1    cgd restore(fname)
    152  1.4  lukem 	char *fname;
    153  1.1    cgd {
    154  1.1    cgd 	FILE *fp;
    155  1.1    cgd 	struct rogue_time saved_time, mod_time;
    156  1.1    cgd 	char buf[4];
    157  1.1    cgd 	char tbuf[40];
    158  1.1    cgd 	int new_file_id, saved_file_id;
    159  1.1    cgd 
    160  1.4  lukem 	fp = NULL;
    161  1.1    cgd 	if (	((new_file_id = md_get_file_id(fname)) == -1) ||
    162  1.1    cgd 			((fp = fopen(fname, "r")) == NULL)) {
    163  1.1    cgd 		clean_up("cannot open file");
    164  1.1    cgd 	}
    165  1.1    cgd 	if (md_link_count(fname) > 1) {
    166  1.1    cgd 		clean_up("file has link");
    167  1.1    cgd 	}
    168  1.1    cgd 	(void) xxx(1);
    169  1.1    cgd 	r_read(fp, (char *) &detect_monster, sizeof(detect_monster));
    170  1.1    cgd 	r_read(fp, (char *) &cur_level, sizeof(cur_level));
    171  1.1    cgd 	r_read(fp, (char *) &max_level, sizeof(max_level));
    172  1.1    cgd 	read_string(hunger_str, fp);
    173  1.1    cgd 
    174  1.1    cgd 	(void) strcpy(tbuf, login_name);
    175  1.1    cgd 	read_string(login_name, fp);
    176  1.1    cgd 	if (strcmp(tbuf, login_name)) {
    177  1.1    cgd 		clean_up("you're not the original player");
    178  1.1    cgd 	}
    179  1.1    cgd 
    180  1.1    cgd 	r_read(fp, (char *) &party_room, sizeof(party_room));
    181  1.1    cgd 	read_pack(&level_monsters, fp, 0);
    182  1.1    cgd 	read_pack(&level_objects, fp, 0);
    183  1.1    cgd 	r_read(fp, (char *) &saved_file_id, sizeof(saved_file_id));
    184  1.1    cgd 	if (new_file_id != saved_file_id) {
    185  1.1    cgd 		clean_up("sorry, saved game is not in the same file");
    186  1.1    cgd 	}
    187  1.1    cgd 	rw_dungeon(fp, 0);
    188  1.1    cgd 	r_read(fp, (char *) &foods, sizeof(foods));
    189  1.1    cgd 	r_read(fp, (char *) &rogue, sizeof(fighter));
    190  1.1    cgd 	read_pack(&rogue.pack, fp, 1);
    191  1.1    cgd 	rw_id(id_potions, fp, POTIONS, 0);
    192  1.1    cgd 	rw_id(id_scrolls, fp, SCROLS, 0);
    193  1.1    cgd 	rw_id(id_wands, fp, WANDS, 0);
    194  1.1    cgd 	rw_id(id_rings, fp, RINGS, 0);
    195  1.1    cgd 	r_read(fp, (char *) traps, (MAX_TRAPS * sizeof(trap)));
    196  1.1    cgd 	r_read(fp, (char *) is_wood, (WANDS * sizeof(boolean)));
    197  1.1    cgd 	r_read(fp, (char *) &cur_room, sizeof(cur_room));
    198  1.1    cgd 	rw_rooms(fp, 0);
    199  1.1    cgd 	r_read(fp, (char *) &being_held, sizeof(being_held));
    200  1.1    cgd 	r_read(fp, (char *) &bear_trap, sizeof(bear_trap));
    201  1.1    cgd 	r_read(fp, (char *) &halluc, sizeof(halluc));
    202  1.1    cgd 	r_read(fp, (char *) &blind, sizeof(blind));
    203  1.1    cgd 	r_read(fp, (char *) &confused, sizeof(confused));
    204  1.1    cgd 	r_read(fp, (char *) &levitate, sizeof(levitate));
    205  1.1    cgd 	r_read(fp, (char *) &haste_self, sizeof(haste_self));
    206  1.1    cgd 	r_read(fp, (char *) &see_invisible, sizeof(see_invisible));
    207  1.1    cgd 	r_read(fp, (char *) &detect_monster, sizeof(detect_monster));
    208  1.1    cgd 	r_read(fp, (char *) &wizard, sizeof(wizard));
    209  1.1    cgd 	r_read(fp, (char *) &score_only, sizeof(score_only));
    210  1.1    cgd 	r_read(fp, (char *) &m_moves, sizeof(m_moves));
    211  1.1    cgd 	r_read(fp, (char *) &saved_time, sizeof(saved_time));
    212  1.1    cgd 
    213  1.1    cgd 	if (fread(buf, sizeof(char), 1, fp) > 0) {
    214  1.1    cgd 		clear();
    215  1.1    cgd 		clean_up("extra characters in file");
    216  1.1    cgd 	}
    217  1.1    cgd 
    218  1.1    cgd 	md_gfmt(fname, &mod_time);	/* get file modification time */
    219  1.1    cgd 
    220  1.1    cgd 	if (has_been_touched(&saved_time, &mod_time)) {
    221  1.1    cgd 		clear();
    222  1.1    cgd 		clean_up("sorry, file has been touched");
    223  1.1    cgd 	}
    224  1.1    cgd 	if ((!wizard) && !md_df(fname)) {
    225  1.1    cgd 		clean_up("cannot delete file");
    226  1.1    cgd 	}
    227  1.1    cgd 	msg_cleared = 0;
    228  1.1    cgd 	ring_stats(0);
    229  1.1    cgd 	fclose(fp);
    230  1.1    cgd }
    231  1.1    cgd 
    232  1.4  lukem void
    233  1.1    cgd write_pack(pack, fp)
    234  1.4  lukem 	object *pack;
    235  1.4  lukem 	FILE *fp;
    236  1.1    cgd {
    237  1.1    cgd 	object t;
    238  1.1    cgd 
    239  1.4  lukem 	while ((pack = pack->next_object) != NULL) {
    240  1.1    cgd 		r_write(fp, (char *) pack, sizeof(object));
    241  1.1    cgd 	}
    242  1.1    cgd 	t.ichar = t.what_is = 0;
    243  1.1    cgd 	r_write(fp, (char *) &t, sizeof(object));
    244  1.1    cgd }
    245  1.1    cgd 
    246  1.4  lukem void
    247  1.1    cgd read_pack(pack, fp, is_rogue)
    248  1.4  lukem 	object *pack;
    249  1.4  lukem 	FILE *fp;
    250  1.4  lukem 	boolean is_rogue;
    251  1.1    cgd {
    252  1.1    cgd 	object read_obj, *new_obj;
    253  1.1    cgd 
    254  1.1    cgd 	for (;;) {
    255  1.1    cgd 		r_read(fp, (char *) &read_obj, sizeof(object));
    256  1.1    cgd 		if (read_obj.ichar == 0) {
    257  1.1    cgd 			pack->next_object = (object *) 0;
    258  1.1    cgd 			break;
    259  1.1    cgd 		}
    260  1.1    cgd 		new_obj = alloc_object();
    261  1.1    cgd 		*new_obj = read_obj;
    262  1.1    cgd 		if (is_rogue) {
    263  1.1    cgd 			if (new_obj->in_use_flags & BEING_WORN) {
    264  1.1    cgd 					do_wear(new_obj);
    265  1.1    cgd 			} else if (new_obj->in_use_flags & BEING_WIELDED) {
    266  1.1    cgd 					do_wield(new_obj);
    267  1.1    cgd 			} else if (new_obj->in_use_flags & (ON_EITHER_HAND)) {
    268  1.1    cgd 				do_put_on(new_obj,
    269  1.1    cgd 					((new_obj->in_use_flags & ON_LEFT_HAND) ? 1 : 0));
    270  1.1    cgd 			}
    271  1.1    cgd 		}
    272  1.1    cgd 		pack->next_object = new_obj;
    273  1.1    cgd 		pack = new_obj;
    274  1.1    cgd 	}
    275  1.1    cgd }
    276  1.1    cgd 
    277  1.4  lukem void
    278  1.1    cgd rw_dungeon(fp, rw)
    279  1.4  lukem 	FILE *fp;
    280  1.4  lukem 	boolean rw;
    281  1.1    cgd {
    282  1.1    cgd 	short i, j;
    283  1.1    cgd 	char buf[DCOLS];
    284  1.1    cgd 
    285  1.1    cgd 	for (i = 0; i < DROWS; i++) {
    286  1.1    cgd 		if (rw) {
    287  1.1    cgd 			r_write(fp, (char *) dungeon[i], (DCOLS * sizeof(dungeon[0][0])));
    288  1.1    cgd 			for (j = 0; j < DCOLS; j++) {
    289  1.1    cgd 				buf[j] = mvinch(i, j);
    290  1.1    cgd 			}
    291  1.1    cgd 			r_write(fp, buf, DCOLS);
    292  1.1    cgd 		} else {
    293  1.1    cgd 			r_read(fp, (char *) dungeon[i], (DCOLS * sizeof(dungeon[0][0])));
    294  1.1    cgd 			r_read(fp, buf, DCOLS);
    295  1.1    cgd 			for (j = 0; j < DCOLS; j++) {
    296  1.1    cgd 				mvaddch(i, j, buf[j]);
    297  1.1    cgd 			}
    298  1.1    cgd 		}
    299  1.1    cgd 	}
    300  1.1    cgd }
    301  1.1    cgd 
    302  1.4  lukem void
    303  1.1    cgd rw_id(id_table, fp, n, wr)
    304  1.4  lukem 	struct id id_table[];
    305  1.4  lukem 	FILE *fp;
    306  1.4  lukem 	int n;
    307  1.4  lukem 	boolean wr;
    308  1.1    cgd {
    309  1.1    cgd 	short i;
    310  1.1    cgd 
    311  1.1    cgd 	for (i = 0; i < n; i++) {
    312  1.1    cgd 		if (wr) {
    313  1.1    cgd 			r_write(fp, (char *) &(id_table[i].value), sizeof(short));
    314  1.1    cgd 			r_write(fp, (char *) &(id_table[i].id_status),
    315  1.1    cgd 				sizeof(unsigned short));
    316  1.1    cgd 			write_string(id_table[i].title, fp);
    317  1.1    cgd 		} else {
    318  1.1    cgd 			r_read(fp, (char *) &(id_table[i].value), sizeof(short));
    319  1.1    cgd 			r_read(fp, (char *) &(id_table[i].id_status),
    320  1.1    cgd 				sizeof(unsigned short));
    321  1.1    cgd 			read_string(id_table[i].title, fp);
    322  1.1    cgd 		}
    323  1.1    cgd 	}
    324  1.1    cgd }
    325  1.1    cgd 
    326  1.4  lukem void
    327  1.1    cgd write_string(s, fp)
    328  1.4  lukem 	char *s;
    329  1.4  lukem 	FILE *fp;
    330  1.1    cgd {
    331  1.1    cgd 	short n;
    332  1.1    cgd 
    333  1.1    cgd 	n = strlen(s) + 1;
    334  1.1    cgd 	xxxx(s, n);
    335  1.1    cgd 	r_write(fp, (char *) &n, sizeof(short));
    336  1.1    cgd 	r_write(fp, s, n);
    337  1.1    cgd }
    338  1.1    cgd 
    339  1.4  lukem void
    340  1.1    cgd read_string(s, fp)
    341  1.4  lukem 	char *s;
    342  1.4  lukem 	FILE *fp;
    343  1.1    cgd {
    344  1.1    cgd 	short n;
    345  1.1    cgd 
    346  1.1    cgd 	r_read(fp, (char *) &n, sizeof(short));
    347  1.1    cgd 	r_read(fp, s, n);
    348  1.1    cgd 	xxxx(s, n);
    349  1.1    cgd }
    350  1.1    cgd 
    351  1.4  lukem void
    352  1.1    cgd rw_rooms(fp, rw)
    353  1.4  lukem 	FILE *fp;
    354  1.4  lukem 	boolean rw;
    355  1.1    cgd {
    356  1.1    cgd 	short i;
    357  1.1    cgd 
    358  1.1    cgd 	for (i = 0; i < MAXROOMS; i++) {
    359  1.1    cgd 		rw ? r_write(fp, (char *) (rooms + i), sizeof(room)) :
    360  1.1    cgd 			r_read(fp, (char *) (rooms + i), sizeof(room));
    361  1.1    cgd 	}
    362  1.1    cgd }
    363  1.1    cgd 
    364  1.4  lukem void
    365  1.1    cgd r_read(fp, buf, n)
    366  1.4  lukem 	FILE *fp;
    367  1.4  lukem 	char *buf;
    368  1.4  lukem 	int n;
    369  1.1    cgd {
    370  1.1    cgd 	if (fread(buf, sizeof(char), n, fp) != n) {
    371  1.1    cgd 		clean_up("read() failed, don't know why");
    372  1.1    cgd 	}
    373  1.1    cgd }
    374  1.1    cgd 
    375  1.4  lukem void
    376  1.1    cgd r_write(fp, buf, n)
    377  1.4  lukem 	FILE *fp;
    378  1.4  lukem 	char *buf;
    379  1.4  lukem 	int n;
    380  1.1    cgd {
    381  1.1    cgd 	if (!write_failed) {
    382  1.1    cgd 		if (fwrite(buf, sizeof(char), n, fp) != n) {
    383  1.1    cgd 			message("write() failed, don't know why", 0);
    384  1.1    cgd 			sound_bell();
    385  1.1    cgd 			write_failed = 1;
    386  1.1    cgd 		}
    387  1.1    cgd 	}
    388  1.1    cgd }
    389  1.1    cgd 
    390  1.1    cgd boolean
    391  1.1    cgd has_been_touched(saved_time, mod_time)
    392  1.4  lukem 	struct rogue_time *saved_time, *mod_time;
    393  1.1    cgd {
    394  1.1    cgd 	if (saved_time->year < mod_time->year) {
    395  1.1    cgd 		return(1);
    396  1.1    cgd 	} else if (saved_time->year > mod_time->year) {
    397  1.1    cgd 		return(0);
    398  1.1    cgd 	}
    399  1.1    cgd 	if (saved_time->month < mod_time->month) {
    400  1.1    cgd 		return(1);
    401  1.1    cgd 	} else if (saved_time->month > mod_time->month) {
    402  1.1    cgd 		return(0);
    403  1.1    cgd 	}
    404  1.1    cgd 	if (saved_time->day < mod_time->day) {
    405  1.1    cgd 		return(1);
    406  1.1    cgd 	} else if (saved_time->day > mod_time->day) {
    407  1.1    cgd 		return(0);
    408  1.1    cgd 	}
    409  1.1    cgd 	if (saved_time->hour < mod_time->hour) {
    410  1.1    cgd 		return(1);
    411  1.1    cgd 	} else if (saved_time->hour > mod_time->hour) {
    412  1.1    cgd 		return(0);
    413  1.1    cgd 	}
    414  1.1    cgd 	if (saved_time->minute < mod_time->minute) {
    415  1.1    cgd 		return(1);
    416  1.1    cgd 	} else if (saved_time->minute > mod_time->minute) {
    417  1.1    cgd 		return(0);
    418  1.1    cgd 	}
    419  1.1    cgd 	if (saved_time->second < mod_time->second) {
    420  1.1    cgd 		return(1);
    421  1.1    cgd 	}
    422  1.1    cgd 	return(0);
    423  1.1    cgd }
    424