Debian Codegraph @

terps/advsys/advjunk.c

raw symbols SCIP
1
2
3 #include "header.h"
4 #define UNIX
5 #include <stdio.h>
6
7 long _seed = 1L;
8
9 #ifndef UNIX
10 int rand()
11 {
12 _seed *= 397204094L;
13 return (_seed & 0x7FFF);
14 }
15
16 srand(n)
17 long n;
18 {
19 _seed = n;
20 }
21 #endif
22
23 int getch()
24 {
25 #ifdef UNIX
26 return getchar();
27 #else
28 int ch;
29 if ((ch = bdos(1) & 0xFF) == '\r') { bdos(6,'\n'); ch = '\n'; }
30 return (ch);
31 #endif
32 }
33
34 void waitch()
35 {
36 #ifndef UNIX
37 bdos(7);
38 #endif
39 }
40
41 void putch(int ch, FILE *fp)
42 {
43 #ifdef UNIX
44 putc(ch,fp);
45 #else
46 aputc(ch,fp);
47 #endif
48 }
49
50 int advsave(char *hdr,int hlen,char *save,int slen)
51 {
52 frefid_t fdref;
53 strid_t fd;
54
55 fdref = glk_fileref_create_by_prompt(fileusage_SavedGame, filemode_Write, 0);
56 fd = glk_stream_open_file(fdref, filemode_Write, 0);
57
58 glk_put_buffer_stream(fd,hdr,hlen);
59
60 /* write the data */
61 glk_put_buffer_stream(fd,save,slen);
62
63 /* close the file and return successfully */
64 glk_stream_close(fd, NULL);
65 glk_fileref_destroy(fdref);
66 return (1);
67 }
68
69 int advrestore(char *hdr,int hlen,char *save,int slen)
70 {
71 char hbuf[50],*p;
72 frefid_t fdref;
73 strid_t fd;
74
75
76 if (hlen > 50)
77 error("save file header buffer too small");
78
79 fdref = glk_fileref_create_by_prompt(fileusage_SavedGame, filemode_Read, 0);
80 fd = glk_stream_open_file(fdref, filemode_Read, 0);
81
82
83 /* read the header */
84 if (glk_get_buffer_stream(fd,hbuf,hlen) != hlen) {
85 glk_stream_close(fd, NULL);
86 glk_fileref_destroy(fdref);
87 return (0);
88 }
89
90 /* compare the headers */
91 for (p = hbuf; hlen--; )
92 if (*hdr++ != *p++) {
93 trm_str("This save file does not match the adventure!\n");
94 return (0);
95 }
96
97 /* read the data */
98 if (glk_get_buffer_stream(fd,save,slen) != slen) {
99 glk_stream_close(fd, NULL);
100 glk_fileref_destroy(fdref);
101 return (0);
102 }
103
104 /* close the file and return successfully */
105 glk_stream_close(fd, NULL);
106 glk_fileref_destroy(fdref);
107 return (1);
108 }
109
110