Home | History | Annotate | Line # | Download | only in rogue
save.c revision 1.7.8.1
      1  1.7.8.1   itojun /*	$NetBSD: save.c,v 1.7.8.1 2002/10/02 01:21:01 itojun 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.7.8.1   itojun __RCSID("$NetBSD: save.c,v 1.7.8.1 2002/10/02 01:21:01 itojun 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.7.8.1   itojun 	if (((fp = fopen(sfile, "w")) == NULL) ||
    106  1.7.8.1   itojun 	    ((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.7.8.1   itojun 	if (((new_file_id = md_get_file_id(fname)) == -1) ||
    170  1.7.8.1   itojun 	    ((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.7.8.1   itojun 	read_string(hunger_str, fp, sizeof hunger_str);
    181      1.1      cgd 
    182  1.7.8.1   itojun 	(void) strlcpy(tbuf, login_name, sizeof tbuf);
    183  1.7.8.1   itojun 	read_string(login_name, fp, sizeof login_name);
    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.7.8.1   itojun 				do_wear(new_obj);
    273      1.1      cgd 			} else if (new_obj->in_use_flags & BEING_WIELDED) {
    274  1.7.8.1   itojun 				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.7.8.1   itojun 			read_string(id_table[i].title, fp, MAX_ID_TITLE_LEN);
    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.7.8.1   itojun read_string(s, fp, len)
    349      1.4    lukem 	char *s;
    350      1.4    lukem 	FILE *fp;
    351  1.7.8.1   itojun 	size_t len;
    352      1.1      cgd {
    353      1.1      cgd 	short n;
    354      1.1      cgd 
    355      1.1      cgd 	r_read(fp, (char *) &n, sizeof(short));
    356  1.7.8.1   itojun 	if (n > len)
    357  1.7.8.1   itojun 		clean_up("read_string: corrupt game file");
    358      1.1      cgd 	r_read(fp, s, n);
    359      1.1      cgd 	xxxx(s, n);
    360      1.1      cgd }
    361      1.1      cgd 
    362      1.4    lukem void
    363      1.1      cgd rw_rooms(fp, rw)
    364      1.4    lukem 	FILE *fp;
    365      1.4    lukem 	boolean rw;
    366      1.1      cgd {
    367      1.1      cgd 	short i;
    368      1.1      cgd 
    369      1.1      cgd 	for (i = 0; i < MAXROOMS; i++) {
    370      1.1      cgd 		rw ? r_write(fp, (char *) (rooms + i), sizeof(room)) :
    371      1.1      cgd 			r_read(fp, (char *) (rooms + i), sizeof(room));
    372      1.1      cgd 	}
    373      1.1      cgd }
    374      1.1      cgd 
    375      1.4    lukem void
    376      1.1      cgd r_read(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.7      jsm 	if (fread(buf, sizeof(char), n, fp) != (size_t)n) {
    382      1.1      cgd 		clean_up("read() failed, don't know why");
    383      1.1      cgd 	}
    384      1.1      cgd }
    385      1.1      cgd 
    386      1.4    lukem void
    387      1.1      cgd r_write(fp, buf, n)
    388      1.4    lukem 	FILE *fp;
    389      1.5  hubertf 	const char *buf;
    390      1.4    lukem 	int n;
    391      1.1      cgd {
    392      1.1      cgd 	if (!write_failed) {
    393      1.7      jsm 		if (fwrite(buf, sizeof(char), n, fp) != (size_t)n) {
    394      1.1      cgd 			message("write() failed, don't know why", 0);
    395      1.1      cgd 			sound_bell();
    396      1.1      cgd 			write_failed = 1;
    397      1.1      cgd 		}
    398      1.1      cgd 	}
    399      1.1      cgd }
    400      1.1      cgd 
    401      1.1      cgd boolean
    402      1.1      cgd has_been_touched(saved_time, mod_time)
    403      1.5  hubertf 	const struct rogue_time *saved_time, *mod_time;
    404      1.1      cgd {
    405      1.1      cgd 	if (saved_time->year < mod_time->year) {
    406      1.1      cgd 		return(1);
    407      1.1      cgd 	} else if (saved_time->year > mod_time->year) {
    408      1.1      cgd 		return(0);
    409      1.1      cgd 	}
    410      1.1      cgd 	if (saved_time->month < mod_time->month) {
    411      1.1      cgd 		return(1);
    412      1.1      cgd 	} else if (saved_time->month > mod_time->month) {
    413      1.1      cgd 		return(0);
    414      1.1      cgd 	}
    415      1.1      cgd 	if (saved_time->day < mod_time->day) {
    416      1.1      cgd 		return(1);
    417      1.1      cgd 	} else if (saved_time->day > mod_time->day) {
    418      1.1      cgd 		return(0);
    419      1.1      cgd 	}
    420      1.1      cgd 	if (saved_time->hour < mod_time->hour) {
    421      1.1      cgd 		return(1);
    422      1.1      cgd 	} else if (saved_time->hour > mod_time->hour) {
    423      1.1      cgd 		return(0);
    424      1.1      cgd 	}
    425      1.1      cgd 	if (saved_time->minute < mod_time->minute) {
    426      1.1      cgd 		return(1);
    427      1.1      cgd 	} else if (saved_time->minute > mod_time->minute) {
    428      1.1      cgd 		return(0);
    429      1.1      cgd 	}
    430      1.1      cgd 	if (saved_time->second < mod_time->second) {
    431      1.1      cgd 		return(1);
    432      1.1      cgd 	}
    433      1.1      cgd 	return(0);
    434      1.1      cgd }
    435