]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/io.c
1 /* $NetBSD: io.c,v 1.9 2005/02/15 12:58:21 jsm Exp $ */
4 * io.c - input/output routines for Phantasia
16 char *inptr
; /* pointer into string for next string */
17 int x
, y
; /* original x, y coordinates on screen */
20 getyx(stdscr
, y
, x
); /* get coordinates on screen */
22 *inptr
= '\0'; /* clear string to start */
23 --mx
; /* reserve room in string for nul terminator */
26 /* get characters and process */
29 mvaddstr(y
, x
, cp
); /* print string on screen */
30 clrtoeol(); /* clear any data after string */
31 refresh(); /* update screen */
33 ch
= getchar(); /* get character */
36 case CH_ERASE
: /* back up one character */
41 case CH_KILL
: /* back up to original location */
45 case CH_NEWLINE
: /* terminate string */
48 case CH_REDRAW
:/* redraw screen */
49 clearok(stdscr
, TRUE
);
52 default: /* put data in string */
53 if (ch
>= ' ' || Wizard
)
54 /* printing char; put in string */
58 *inptr
= '\0'; /* terminate string */
60 while (ch
!= CH_NEWLINE
&& inptr
< cp
+ mx
);
67 mvaddstr(where
, 0, "-- more --");
68 getanswer(" ", FALSE
);
74 double result
; /* return value */
76 getstring(Databuf
, SZ_DATABUF
);
77 if (sscanf(Databuf
, "%lf", &result
) < 1)
78 /* no valid number entered */
87 ++Player
.p_age
; /* increase age */
89 if (Player
.p_ring
.ring_type
!= R_SPOILED
)
91 return (getanswer("T ", TRUE
));
96 return ((int) ROLL(0.0, 5.0) + '0');
103 char line
[81]; /* a place to store data already on screen */
104 int loop
; /* counter */
105 int x
, y
; /* coordinates on screen */
107 unsigned savealarm
; /* to save alarm value */
110 signal(SIGINT
, SIG_IGN
);
113 signal(SIGINT
, SIG_IGN
);
116 savealarm
= alarm(0); /* turn off any alarms */
118 getyx(stdscr
, y
, x
); /* save cursor location */
120 for (loop
= 0; loop
< 80; ++loop
) { /* save line on screen */
124 line
[80] = '\0'; /* nul terminate */
126 if (Player
.p_status
== S_INBATTLE
|| Player
.p_status
== S_MONSTER
)
127 /* in midst of fighting */
129 mvaddstr(4, 0, "Quitting now will automatically kill your character. Still want to ? ");
130 ch
= getanswer("NY", FALSE
);
132 death("Bailing out");
135 mvaddstr(4, 0, "Do you really want to quit ? ");
136 ch
= getanswer("NY", FALSE
);
142 mvaddstr(4, 0, line
); /* restore data on screen */
143 move(y
, x
); /* restore cursor */
147 signal(SIGINT
, interrupt
);
150 signal(SIGINT
, interrupt
);
153 alarm(savealarm
); /* restore alarm */
157 getanswer(choices
, def
)
162 volatile int loop
; /* counter */
163 volatile int oldx
, oldy
; /* original coordinates on screen */
165 getyx(stdscr
, oldy
, oldx
);
166 alarm(0); /* make sure alarm is off */
168 for (loop
= 3; loop
; --loop
)
169 /* try for 3 times */
171 if (setjmp(Timeoenv
) != 0)
172 /* timed out waiting for response */
174 if (def
|| loop
<= 1)
175 /* return default answer */
178 /* prompt, and try again */
181 /* wait for response */
186 sigset(SIGALRM
, catchalarm
);
188 signal(SIGALRM
, catchalarm
);
192 alarm(7); /* short */
194 alarm(600); /* long */
198 alarm(0); /* turn off timeout */
201 /* caught some signal */
209 clearok(stdscr
, TRUE
); /* force clear screen */
210 ++loop
; /* don't count this input */
214 addch(ch
); /* echo character */
218 /* convert to upper case */
221 if (def
|| strchr(choices
, ch
) != NULL
)
225 if (!def
&& loop
> 1)
226 /* bad choice; prompt, and try again */
228 YELL
: mvprintw(oldy
+ 1, 0, "Please choose one of : [%s]\n", choices
);
233 /* return default answer */
243 int dummy
__attribute__((__unused__
));
245 longjmp(Timeoenv
, 1);