]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - backgammon/common_source/save.c
bba3dddb90764c9ac9d0b09c165abeac5edff82f
1 /* $NetBSD: save.c,v 1.3 1995/03/21 15:05:52 cgd Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid
[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
40 static char rcsid
[] = "$NetBSD: save.c,v 1.3 1995/03/21 15:05:52 cgd Exp $";
48 static char confirm
[] = "Are you sure you want to leave now?";
49 static char prompt
[] = "Enter a file name: ";
50 static char exist1
[] = "The file '";
51 static char exist2
[] =
52 "' already exists.\nAre you sure you want to use this file?";
53 static char cantuse
[] = "\nCan't use ";
54 static char saved
[] = "This game has been saved on the file '";
55 static char type
[] = "'.\nType \"backgammon ";
56 static char rec
[] = "\" to recover your game.\n\n";
57 static char cantrec
[] = "Can't recover file: ";
81 while ((*fs
= readc()) != '\n') {
82 if (*fs
== tty
.sg_erase
) {
86 curmove (curr
,curc
-1);
96 if ((fdesc
= open(fname
,2)) == -1 && errno
== 2) {
97 if ((fdesc
= creat (fname
,0700)) != -1)
113 fdesc
= creat (fname
,0700);
126 write (fdesc
,board
,sizeof board
);
127 write (fdesc
,off
,sizeof off
);
128 write (fdesc
,in
,sizeof in
);
129 write (fdesc
,dice
,sizeof dice
);
130 write (fdesc
,&cturn
,sizeof cturn
);
131 write (fdesc
,&dlast
,sizeof dlast
);
132 write (fdesc
,&pnum
,sizeof pnum
);
133 write (fdesc
,&rscore
,sizeof rscore
);
134 write (fdesc
,&wscore
,sizeof wscore
);
135 write (fdesc
,&gvalue
,sizeof gvalue
);
136 write (fdesc
,&raflag
,sizeof raflag
);
157 if ((fdesc
= open (s
,0)) == -1)
159 read (fdesc
,board
,sizeof board
);
160 read (fdesc
,off
,sizeof off
);
161 read (fdesc
,in
,sizeof in
);
162 read (fdesc
,dice
,sizeof dice
);
163 read (fdesc
,&cturn
,sizeof cturn
);
164 read (fdesc
,&dlast
,sizeof dlast
);
165 read (fdesc
,&pnum
,sizeof pnum
);
166 read (fdesc
,&rscore
,sizeof rscore
);
167 read (fdesc
,&wscore
,sizeof wscore
);
168 read (fdesc
,&gvalue
,sizeof gvalue
);
169 read (fdesc
,&raflag
,sizeof raflag
);