Home | History | Annotate | Line # | Download | only in rogue
save.c revision 1.6
      1  1.6      jsm /*	$NetBSD: save.c,v 1.6 1999/09/13 17:19:55 jsm 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.6      jsm __RCSID("$NetBSD: save.c,v 1.6 1999/09/13 17:19:55 jsm 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.5  hubertf 	const char *sfile;
     83  1.1      cgd {
     84  1.1      cgd 	FILE *fp;
     85  1.1      cgd 	int file_id;
     86  1.6      jsm 	char *name_buffer;
     87  1.6      jsm 	size_t len;
     88  1.1      cgd 	char *hptr;
     89  1.1      cgd 	struct rogue_time rt_buf;
     90  1.1      cgd 
     91  1.1      cgd 	if (sfile[0] == '~') {
     92  1.4    lukem 		if ((hptr = md_getenv("HOME")) != NULL) {
     93  1.6      jsm 			len = strlen(hptr) + strlen(sfile);
     94  1.6      jsm 			name_buffer = md_malloc(len);
     95  1.6      jsm 			if (name_buffer == NULL) {
     96  1.6      jsm 				message("out of memory for save file name", 0);
     97  1.6      jsm 				sfile = error_file;
     98  1.6      jsm 			} else {
     99  1.6      jsm 				(void) strcpy(name_buffer, hptr);
    100  1.6      jsm 				(void) strcat(name_buffer, sfile+1);
    101  1.6      jsm 				sfile = name_buffer;
    102  1.6      jsm 			}
    103  1.1      cgd 		}
    104  1.1      cgd 	}
    105  1.1      cgd 	if (	((fp = fopen(sfile, "w")) == NULL) ||
    106  1.1      cgd 			((file_id = md_get_file_id(sfile)) == -1)) {
    107  1.1      cgd 		message("problem accessing the save file", 0);
    108  1.1      cgd 		return;
    109  1.1      cgd 	}
    110  1.1      cgd 	md_ignore_signals();
    111  1.1      cgd 	write_failed = 0;
    112  1.1      cgd 	(void) xxx(1);
    113  1.1      cgd 	r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    114  1.1      cgd 	r_write(fp, (char *) &cur_level, sizeof(cur_level));
    115  1.1      cgd 	r_write(fp, (char *) &max_level, sizeof(max_level));
    116  1.1      cgd 	write_string(hunger_str, fp);
    117  1.1      cgd 	write_string(login_name, fp);
    118  1.1      cgd 	r_write(fp, (char *) &party_room, sizeof(party_room));
    119  1.1      cgd 	write_pack(&level_monsters, fp);
    120  1.1      cgd 	write_pack(&level_objects, fp);
    121  1.1      cgd 	r_write(fp, (char *) &file_id, sizeof(file_id));
    122  1.1      cgd 	rw_dungeon(fp, 1);
    123  1.1      cgd 	r_write(fp, (char *) &foods, sizeof(foods));
    124  1.1      cgd 	r_write(fp, (char *) &rogue, sizeof(fighter));
    125  1.1      cgd 	write_pack(&rogue.pack, fp);
    126  1.1      cgd 	rw_id(id_potions, fp, POTIONS, 1);
    127  1.1      cgd 	rw_id(id_scrolls, fp, SCROLS, 1);
    128  1.1      cgd 	rw_id(id_wands, fp, WANDS, 1);
    129  1.1      cgd 	rw_id(id_rings, fp, RINGS, 1);
    130  1.1      cgd 	r_write(fp, (char *) traps, (MAX_TRAPS * sizeof(trap)));
    131  1.1      cgd 	r_write(fp, (char *) is_wood, (WANDS * sizeof(boolean)));
    132  1.1      cgd 	r_write(fp, (char *) &cur_room, sizeof(cur_room));
    133  1.1      cgd 	rw_rooms(fp, 1);
    134  1.1      cgd 	r_write(fp, (char *) &being_held, sizeof(being_held));
    135  1.1      cgd 	r_write(fp, (char *) &bear_trap, sizeof(bear_trap));
    136  1.1      cgd 	r_write(fp, (char *) &halluc, sizeof(halluc));
    137  1.1      cgd 	r_write(fp, (char *) &blind, sizeof(blind));
    138  1.1      cgd 	r_write(fp, (char *) &confused, sizeof(confused));
    139  1.1      cgd 	r_write(fp, (char *) &levitate, sizeof(levitate));
    140  1.1      cgd 	r_write(fp, (char *) &haste_self, sizeof(haste_self));
    141  1.1      cgd 	r_write(fp, (char *) &see_invisible, sizeof(see_invisible));
    142  1.1      cgd 	r_write(fp, (char *) &detect_monster, sizeof(detect_monster));
    143  1.1      cgd 	r_write(fp, (char *) &wizard, sizeof(wizard));
    144  1.1      cgd 	r_write(fp, (char *) &score_only, sizeof(score_only));
    145  1.1      cgd 	r_write(fp, (char *) &m_moves, sizeof(m_moves));
    146  1.1      cgd 	md_gct(&rt_buf);
    147  1.1      cgd 	rt_buf.second += 10;		/* allow for some processing time */
    148  1.1      cgd 	r_write(fp, (char *) &rt_buf, sizeof(rt_buf));
    149  1.1      cgd 	fclose(fp);
    150  1.1      cgd 
    151  1.1      cgd 	if (write_failed) {
    152  1.1      cgd 		(void) md_df(sfile);	/* delete file */
    153  1.1      cgd 	} else {
    154  1.1      cgd 		clean_up("");
    155  1.1      cgd 	}
    156  1.1      cgd }
    157  1.1      cgd 
    158  1.4    lukem void
    159  1.1      cgd restore(fname)
    160  1.5  hubertf 	const char *fname;
    161  1.1      cgd {
    162  1.1      cgd 	FILE *fp;
    163  1.1      cgd 	struct rogue_time saved_time, mod_time;
    164  1.1      cgd 	char buf[4];
    165  1.1      cgd 	char tbuf[40];
    166  1.1      cgd 	int new_file_id, saved_file_id;
    167  1.1      cgd 
    168  1.4    lukem 	fp = NULL;
    169  1.1      cgd 	if (	((new_file_id = md_get_file_id(fname)) == -1) ||
    170  1.1      cgd 			((fp = fopen(fname, "r")) == NULL)) {
    171  1.1      cgd 		clean_up("cannot open file");
    172  1.1      cgd 	}
    173  1.1      cgd 	if (md_link_count(fname) > 1) {
    174  1.1      cgd 		clean_up("file has link");
    175  1.1      cgd 	}
    176  1.1      cgd 	(void) xxx(1);
    177  1.1      cgd 	r_read(fp, (char *) &detect_monster, sizeof(detect_monster));
    178  1.1      cgd 	r_read(fp, (char *) &cur_level, sizeof(cur_level));
    179  1.1      cgd 	r_read(fp, (char *) &max_level, sizeof(max_level));
    180  1.1      cgd 	read_string(hunger_str, fp);
    181  1.1      cgd 
    182  1.1      cgd 	(void) strcpy(tbuf, login_name);
    183  1.1      cgd 	read_string(login_name, fp);
    184  1.1      cgd 	if (strcmp(tbuf, login_name)) {
    185  1.1      cgd 		clean_up("you're not the original player");
    186  1.1      cgd 	}
    187  1.1      cgd 
    188  1.1      cgd 	r_read(fp, (char *) &party_room, sizeof(party_room));
    189  1.1      cgd 	read_pack(&level_monsters, fp, 0);
    190  1.1      cgd 	read_pack(&level_objects, fp, 0);
    191  1.1      cgd 	r_read(fp, (char *) &saved_file_id, sizeof(saved_file_id));
    192  1.1      cgd 	if (new_file_id != saved_file_id) {
    193  1.1      cgd 		clean_up("sorry, saved game is not in the same file");
    194  1.1      cgd 	}
    195  1.1      cgd 	rw_dungeon(fp, 0);
    196  1.1      cgd 	r_read(fp, (char *) &foods, sizeof(foods));
    197  1.1      cgd 	r_read(fp, (char *) &rogue, sizeof(fighter));
    198  1.1      cgd 	read_pack(&rogue.pack, fp, 1);
    199  1.1      cgd 	rw_id(id_potions, fp, POTIONS, 0);
    200  1.1      cgd 	rw_id(id_scrolls, fp, SCROLS, 0);
    201  1.1      cgd 	rw_id(id_wands, fp, WANDS, 0);
    202  1.1      cgd 	rw_id(id_rings, fp, RINGS, 0);
    203  1.1      cgd 	r_read(fp, (char *) traps, (MAX_TRAPS * sizeof(trap)));
    204  1.1      cgd 	r_read(fp, (char *) is_wood, (WANDS * sizeof(boolean)));
    205  1.1      cgd 	r_read(fp, (char *) &cur_room, sizeof(cur_room));
    206  1.1      cgd 	rw_rooms(fp, 0);
    207  1.1      cgd 	r_read(fp, (char *) &being_held, sizeof(being_held));
    208  1.1      cgd 	r_read(fp, (char *) &bear_trap, sizeof(bear_trap));
    209  1.1      cgd 	r_read(fp, (char *) &halluc, sizeof(halluc));
    210  1.1      cgd 	r_read(fp, (char *) &blind, sizeof(blind));
    211  1.1      cgd 	r_read(fp, (char *) &confused, sizeof(confused));
    212  1.1      cgd 	r_read(fp, (char *) &levitate, sizeof(levitate));
    213  1.1      cgd 	r_read(fp, (char *) &haste_self, sizeof(haste_self));
    214  1.1      cgd 	r_read(fp, (char *) &see_invisible, sizeof(see_invisible));
    215  1.1      cgd 	r_read(fp, (char *) &detect_monster, sizeof(detect_monster));
    216  1.1      cgd 	r_read(fp, (char *) &wizard, sizeof(wizard));
    217  1.1      cgd 	r_read(fp, (char *) &score_only, sizeof(score_only));
    218  1.1      cgd 	r_read(fp, (char *) &m_moves, sizeof(m_moves));
    219  1.1      cgd 	r_read(fp, (char *) &saved_time, sizeof(saved_time));
    220  1.1      cgd 
    221  1.1      cgd 	if (fread(buf, sizeof(char), 1, fp) > 0) {
    222  1.1      cgd 		clear();
    223  1.1      cgd 		clean_up("extra characters in file");
    224  1.1      cgd 	}
    225  1.1      cgd 
    226  1.1      cgd 	md_gfmt(fname, &mod_time);	/* get file modification time */
    227  1.1      cgd 
    228  1.1      cgd 	if (has_been_touched(&saved_time, &mod_time)) {
    229  1.1      cgd 		clear();
    230  1.1      cgd 		clean_up("sorry, file has been touched");
    231  1.1      cgd 	}
    232  1.1      cgd 	if ((!wizard) && !md_df(fname)) {
    233  1.1      cgd 		clean_up("cannot delete file");
    234  1.1      cgd 	}
    235  1.1      cgd 	msg_cleared = 0;
    236  1.1      cgd 	ring_stats(0);
    237  1.1      cgd 	fclose(fp);
    238  1.1      cgd }
    239  1.1      cgd 
    240  1.4    lukem void
    241  1.1      cgd write_pack(pack, fp)
    242  1.5  hubertf 	const object *pack;
    243  1.4    lukem 	FILE *fp;
    244  1.1      cgd {
    245  1.1      cgd 	object t;
    246  1.1      cgd 
    247  1.4    lukem 	while ((pack = pack->next_object) != NULL) {
    248  1.5  hubertf 		r_write(fp, (const char *) pack, sizeof(object));
    249  1.1      cgd 	}
    250  1.1      cgd 	t.ichar = t.what_is = 0;
    251  1.5  hubertf 	r_write(fp, (const char *) &t, sizeof(object));
    252  1.1      cgd }
    253  1.1      cgd 
    254  1.4    lukem void
    255  1.1      cgd read_pack(pack, fp, is_rogue)
    256  1.4    lukem 	object *pack;
    257  1.4    lukem 	FILE *fp;
    258  1.4    lukem 	boolean is_rogue;
    259  1.1      cgd {
    260  1.1      cgd 	object read_obj, *new_obj;
    261  1.1      cgd 
    262  1.1      cgd 	for (;;) {
    263  1.1      cgd 		r_read(fp, (char *) &read_obj, sizeof(object));
    264  1.1      cgd 		if (read_obj.ichar == 0) {
    265  1.1      cgd 			pack->next_object = (object *) 0;
    266  1.1      cgd 			break;
    267  1.1      cgd 		}
    268  1.1      cgd 		new_obj = alloc_object();
    269  1.1      cgd 		*new_obj = read_obj;
    270  1.1      cgd 		if (is_rogue) {
    271  1.1      cgd 			if (new_obj->in_use_flags & BEING_WORN) {
    272  1.1      cgd 					do_wear(new_obj);
    273  1.1      cgd 			} else if (new_obj->in_use_flags & BEING_WIELDED) {
    274  1.1      cgd 					do_wield(new_obj);
    275  1.1      cgd 			} else if (new_obj->in_use_flags & (ON_EITHER_HAND)) {
    276  1.1      cgd 				do_put_on(new_obj,
    277  1.1      cgd 					((new_obj->in_use_flags & ON_LEFT_HAND) ? 1 : 0));
    278  1.1      cgd 			}
    279  1.1      cgd 		}
    280  1.1      cgd 		pack->next_object = new_obj;
    281  1.1      cgd 		pack = new_obj;
    282  1.1      cgd 	}
    283  1.1      cgd }
    284  1.1      cgd 
    285  1.4    lukem void
    286  1.1      cgd rw_dungeon(fp, rw)
    287  1.4    lukem 	FILE *fp;
    288  1.4    lukem 	boolean rw;
    289  1.1      cgd {
    290  1.1      cgd 	short i, j;
    291  1.1      cgd 	char buf[DCOLS];
    292  1.1      cgd 
    293  1.1      cgd 	for (i = 0; i < DROWS; i++) {
    294  1.1      cgd 		if (rw) {
    295  1.1      cgd 			r_write(fp, (char *) dungeon[i], (DCOLS * sizeof(dungeon[0][0])));
    296  1.1      cgd 			for (j = 0; j < DCOLS; j++) {
    297  1.1      cgd 				buf[j] = mvinch(i, j);
    298  1.1      cgd 			}
    299  1.1      cgd 			r_write(fp, buf, DCOLS);
    300  1.1      cgd 		} else {
    301  1.1      cgd 			r_read(fp, (char *) dungeon[i], (DCOLS * sizeof(dungeon[0][0])));
    302  1.1      cgd 			r_read(fp, buf, DCOLS);
    303  1.1      cgd 			for (j = 0; j < DCOLS; j++) {
    304  1.1      cgd 				mvaddch(i, j, buf[j]);
    305  1.1      cgd 			}
    306  1.1      cgd 		}
    307  1.1      cgd 	}
    308  1.1      cgd }
    309  1.1      cgd 
    310  1.4    lukem void
    311  1.1      cgd rw_id(id_table, fp, n, wr)
    312  1.4    lukem 	struct id id_table[];
    313  1.4    lukem 	FILE *fp;
    314  1.4    lukem 	int n;
    315  1.4    lukem 	boolean wr;
    316  1.1      cgd {
    317  1.1      cgd 	short i;
    318  1.1      cgd 
    319  1.1      cgd 	for (i = 0; i < n; i++) {
    320  1.1      cgd 		if (wr) {
    321  1.5  hubertf 			r_write(fp, (const char *) &(id_table[i].value), sizeof(short));
    322  1.5  hubertf 			r_write(fp, (const char *) &(id_table[i].id_status),
    323  1.1      cgd 				sizeof(unsigned short));
    324  1.1      cgd 			write_string(id_table[i].title, fp);
    325  1.1      cgd 		} else {
    326  1.1      cgd 			r_read(fp, (char *) &(id_table[i].value), sizeof(short));
    327  1.1      cgd 			r_read(fp, (char *) &(id_table[i].id_status),
    328  1.1      cgd 				sizeof(unsigned short));
    329  1.1      cgd 			read_string(id_table[i].title, fp);
    330  1.1      cgd 		}
    331  1.1      cgd 	}
    332  1.1      cgd }
    333  1.1      cgd 
    334  1.4    lukem void
    335  1.1      cgd write_string(s, fp)
    336  1.4    lukem 	char *s;
    337  1.4    lukem 	FILE *fp;
    338  1.1      cgd {
    339  1.1      cgd 	short n;
    340  1.1      cgd 
    341  1.1      cgd 	n = strlen(s) + 1;
    342  1.1      cgd 	xxxx(s, n);
    343  1.1      cgd 	r_write(fp, (char *) &n, sizeof(short));
    344  1.1      cgd 	r_write(fp, s, n);
    345  1.1      cgd }
    346  1.1      cgd 
    347  1.4    lukem void
    348  1.1      cgd read_string(s, fp)
    349  1.4    lukem 	char *s;
    350  1.4    lukem 	FILE *fp;
    351  1.1      cgd {
    352  1.1      cgd 	short n;
    353  1.1      cgd 
    354  1.1      cgd 	r_read(fp, (char *) &n, sizeof(short));
    355  1.1      cgd 	r_read(fp, s, n);
    356  1.1      cgd 	xxxx(s, n);
    357  1.1      cgd }
    358  1.1      cgd 
    359  1.4    lukem void
    360  1.1      cgd rw_rooms(fp, rw)
    361  1.4    lukem 	FILE *fp;
    362  1.4    lukem 	boolean rw;
    363  1.1      cgd {
    364  1.1      cgd 	short i;
    365  1.1      cgd 
    366  1.1      cgd 	for (i = 0; i < MAXROOMS; i++) {
    367  1.1      cgd 		rw ? r_write(fp, (char *) (rooms + i), sizeof(room)) :
    368  1.1      cgd 			r_read(fp, (char *) (rooms + i), sizeof(room));
    369  1.1      cgd 	}
    370  1.1      cgd }
    371  1.1      cgd 
    372  1.4    lukem void
    373  1.1      cgd r_read(fp, buf, n)
    374  1.4    lukem 	FILE *fp;
    375  1.4    lukem 	char *buf;
    376  1.4    lukem 	int n;
    377  1.1      cgd {
    378  1.1      cgd 	if (fread(buf, sizeof(char), n, fp) != n) {
    379  1.1      cgd 		clean_up("read() failed, don't know why");
    380  1.1      cgd 	}
    381  1.1      cgd }
    382  1.1      cgd 
    383  1.4    lukem void
    384  1.1      cgd r_write(fp, buf, n)
    385  1.4    lukem 	FILE *fp;
    386  1.5  hubertf 	const char *buf;
    387  1.4    lukem 	int n;
    388  1.1      cgd {
    389  1.1      cgd 	if (!write_failed) {
    390  1.1      cgd 		if (fwrite(buf, sizeof(char), n, fp) != n) {
    391  1.1      cgd 			message("write() failed, don't know why", 0);
    392  1.1      cgd 			sound_bell();
    393  1.1      cgd 			write_failed = 1;
    394  1.1      cgd 		}
    395  1.1      cgd 	}
    396  1.1      cgd }
    397  1.1      cgd 
    398  1.1      cgd boolean
    399  1.1      cgd has_been_touched(saved_time, mod_time)
    400  1.5  hubertf 	const struct rogue_time *saved_time, *mod_time;
    401  1.1      cgd {
    402  1.1      cgd 	if (saved_time->year < mod_time->year) {
    403  1.1      cgd 		return(1);
    404  1.1      cgd 	} else if (saved_time->year > mod_time->year) {
    405  1.1      cgd 		return(0);
    406  1.1      cgd 	}
    407  1.1      cgd 	if (saved_time->month < mod_time->month) {
    408  1.1      cgd 		return(1);
    409  1.1      cgd 	} else if (saved_time->month > mod_time->month) {
    410  1.1      cgd 		return(0);
    411  1.1      cgd 	}
    412  1.1      cgd 	if (saved_time->day < mod_time->day) {
    413  1.1      cgd 		return(1);
    414  1.1      cgd 	} else if (saved_time->day > mod_time->day) {
    415  1.1      cgd 		return(0);
    416  1.1      cgd 	}
    417  1.1      cgd 	if (saved_time->hour < mod_time->hour) {
    418  1.1      cgd 		return(1);
    419  1.1      cgd 	} else if (saved_time->hour > mod_time->hour) {
    420  1.1      cgd 		return(0);
    421  1.1      cgd 	}
    422  1.1      cgd 	if (saved_time->minute < mod_time->minute) {
    423  1.1      cgd 		return(1);
    424  1.1      cgd 	} else if (saved_time->minute > mod_time->minute) {
    425  1.1      cgd 		return(0);
    426  1.1      cgd 	}
    427  1.1      cgd 	if (saved_time->second < mod_time->second) {
    428  1.1      cgd 		return(1);
    429  1.1      cgd 	}
    430  1.1      cgd 	return(0);
    431  1.1      cgd }
    432