]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/io.c
1 /* $NetBSD: io.c,v 1.3 1997/10/13 02:18:25 lukem Exp $ */
4 * io.c - input/output routines for Phantasia
14 char *inptr
; /* pointer into string for next string */
15 int x
, y
; /* original x, y coordinates on screen */
18 getyx(stdscr
, y
, x
); /* get coordinates on screen */
20 *inptr
= '\0'; /* clear string to start */
21 --mx
; /* reserve room in string for nul terminator */
24 /* get characters and process */
27 mvaddstr(y
, x
, cp
); /* print string on screen */
28 clrtoeol(); /* clear any data after string */
29 refresh(); /* update screen */
31 ch
= getchar(); /* get character */
34 case CH_ERASE
: /* back up one character */
39 case CH_KILL
: /* back up to original location */
43 case CH_NEWLINE
: /* terminate string */
46 case CH_REDRAW
:/* redraw screen */
47 clearok(stdscr
, TRUE
);
50 default: /* put data in string */
51 if (ch
>= ' ' || Wizard
)
52 /* printing char; put in string */
56 *inptr
= '\0'; /* terminate string */
58 while (ch
!= CH_NEWLINE
&& inptr
< cp
+ mx
);
65 mvaddstr(where
, 0, "-- more --");
66 getanswer(" ", FALSE
);
72 double result
; /* return value */
74 getstring(Databuf
, SZ_DATABUF
);
75 if (sscanf(Databuf
, "%lf", &result
) < 1)
76 /* no valid number entered */
85 ++Player
.p_age
; /* increase age */
87 if (Player
.p_ring
.ring_type
!= R_SPOILED
)
89 return (getanswer("T ", TRUE
));
94 return ((int) ROLL(0.0, 5.0) + '0');
101 char line
[81]; /* a place to store data already on screen */
102 int loop
; /* counter */
103 int x
, y
; /* coordinates on screen */
105 unsigned savealarm
; /* to save alarm value */
108 signal(SIGINT
, SIG_IGN
);
111 signal(SIGINT
, SIG_IGN
);
114 savealarm
= alarm(0); /* turn off any alarms */
116 getyx(stdscr
, y
, x
); /* save cursor location */
118 for (loop
= 0; loop
< 80; ++loop
) { /* save line on screen */
122 line
[80] = '\0'; /* nul terminate */
124 if (Player
.p_status
== S_INBATTLE
|| Player
.p_status
== S_MONSTER
)
125 /* in midst of fighting */
127 mvaddstr(4, 0, "Quitting now will automatically kill your character. Still want to ? ");
128 ch
= getanswer("NY", FALSE
);
130 death("Bailing out");
133 mvaddstr(4, 0, "Do you really want to quit ? ");
134 ch
= getanswer("NY", FALSE
);
140 mvaddstr(4, 0, line
); /* restore data on screen */
141 move(y
, x
); /* restore cursor */
145 signal(SIGINT
, interrupt
);
148 signal(SIGINT
, interrupt
);
151 alarm(savealarm
); /* restore alarm */
155 getanswer(choices
, def
)
160 int loop
; /* counter */
161 int oldx
, oldy
; /* original coordinates on screen */
163 getyx(stdscr
, oldy
, oldx
);
164 alarm(0); /* make sure alarm is off */
167 (void)&loop
; /* XXX quiet gcc */
169 for (loop
= 3; loop
; --loop
)
170 /* try for 3 times */
172 if (setjmp(Timeoenv
) != 0)
173 /* timed out waiting for response */
175 if (def
|| loop
<= 1)
176 /* return default answer */
179 /* prompt, and try again */
182 /* wait for response */
187 sigset(SIGALRM
, catchalarm
);
189 signal(SIGALRM
, catchalarm
);
193 alarm(7); /* short */
195 alarm(600); /* long */
199 alarm(0); /* turn off timeout */
202 /* caught some signal */
210 clearok(stdscr
, TRUE
); /* force clear screen */
211 ++loop
; /* don't count this input */
215 addch(ch
); /* echo character */
219 /* convert to upper case */
222 if (def
|| strchr(choices
, ch
) != NULL
)
226 if (!def
&& loop
> 1)
227 /* bad choice; prompt, and try again */
229 YELL
: mvprintw(oldy
+ 1, 0, "Please choose one of : [%s]\n", choices
);
234 /* return default answer */
246 longjmp(Timeoenv
, 1);