Wikia

Wikihack

Source:NetHack 2.3e/pctty.c

2,032pages on
this wiki
Talk0

Below is the full text to pctty.c from the source code of NetHack 2.3e. To link to a particular line, write [[NetHack 2.3e/pctty.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

Screenshots and source code from Hack are used under the CWI license.
1.    /*	SCCS Id: @(#)pctty.c	2.3	87/12/12
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* tty.c - (PC) version */
4.    
5.    /* With thanks to the people who sent code for SYSV - hpscdi!jon,
6.     * arnold@ucsf-cgl, wcs@bo95b, cbcephus!pds and others.
7.     */
8.    
9.    #include <stdio.h>
10.   #include "hack.h"
11.   #include "func_tab.h"
12.   
13.   extern void savech();
14.   
15.   static char erase_char, kill_char;
16.   
17.   /*
18.    * Get initial state of terminal, set ospeed (for termcap routines)
19.    * and switch off tab expansion if necessary.
20.    * Called by startup() in termcap.c and after returning from ! or ^Z
21.    */
22.   gettty(){
23.   	erase_char = '\b';
24.   	kill_char = 21;		/* cntl-U */
25.   	flags.cbreak = TRUE;
26.   #ifdef DGK
27.   	disable_ctrlP();	/* turn off ^P processing */
28.   #endif
29.   }
30.   
31.   /* reset terminal to original state */
32.   settty(s) char *s; {
33.   	end_screen();
34.   	if(s) printf(s);
35.   	(void) fflush(stdout);
36.   #ifdef DGK
37.   	enable_ctrlP();		/* turn on ^P processing */
38.   #endif
39.   }
40.   
41.   
42.   /* fatal error */
43.   /*VARARGS1*/
44.   error(s,x,y) char *s; {
45.   	end_screen();
46.   	putchar('\n');
47.   	printf(s,x,y);
48.   	putchar('\n');
49.   	exit(1);
50.   }
51.   
52.   /*
53.    * Read a line closed with '\n' into the array char bufp[BUFSZ].
54.    * (The '\n' is not stored. The string is closed with a '\0'.)
55.    * Reading can be interrupted by an escape ('\033') - now the
56.    * resulting string is "\033".
57.    */
58.   getlin(bufp)
59.   register char *bufp;
60.   {
61.   	register char *obufp = bufp;
62.   	register int c;
63.   
64.   	flags.toplin = 2;		/* nonempty, no --More-- required */
65.   	for(;;) {
66.   		(void) fflush(stdout);
67.   		if((c = getchar()) == EOF) {
68.   			*bufp = 0;
69.   			return;
70.   		}
71.   		if(c == '\033') {
72.   			*obufp = c;
73.   			obufp[1] = 0;
74.   			return;
75.   		}
76.   		if(c == erase_char || c == '\b') {
77.   			if(bufp != obufp) {
78.   				bufp--;
79.   				putstr("\b \b"); /* putsym converts \b */
80.   			} else	bell();
81.   		} else if(c == '\n') {
82.   			*bufp = 0;
83.   			return;
84.   		} else if(' ' <= c && c < '\177') {
85.   				/* avoid isprint() - some people don't have it
86.   				   ' ' is not always a printing char */
87.   			*bufp = c;
88.   			bufp[1] = 0;
89.   			putstr(bufp);
90.   			if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)
91.   				bufp++;
92.   		} else if(c == kill_char || c == '\177') { /* Robert Viduya */
93.   				/* this test last - @ might be the kill_char */
94.   			while(bufp != obufp) {
95.   				bufp--;
96.   				putstr("\b \b");
97.   			}
98.   		} else
99.   			bell();
100.  	}
101.  }
102.  
103.  getret() {
104.  	cgetret("");
105.  }
106.  
107.  cgetret(s)
108.  register char *s;
109.  {
110.  	putsym('\n');
111.  	if(flags.standout)
112.  		standoutbeg();
113.  	putstr("Hit ");
114.  	putstr(flags.cbreak ? "space" : "return");
115.  	putstr(" to continue: ");
116.  	if(flags.standout)
117.  		standoutend();
118.  	xwaitforspace(s);
119.  }
120.  
121.  char morc;	/* tell the outside world what char he used */
122.  
123.  xwaitforspace(s)
124.  register char *s;	/* chars allowed besides space or return */
125.  {
126.  register int c;
127.  
128.  	morc = 0;
129.  	while((c = readchar()) != '\n') {
130.  	    if(flags.cbreak) {
131.  		if(c == ' ') break;
132.  		if(s && index(s,c)) {
133.  			morc = c;
134.  			break;
135.  		}
136.  		bell();
137.  	    }
138.  	}
139.  }
140.  
141.  static int last_multi;
142.  
143.  char *
144.  parse()
145.  {
146.  	static char inline[COLNO];
147.  	register foo;
148.  
149.  	flags.move = 1;
150.  	if(!Invisible) curs_on_u(); else home();
151.  	multi = 0;
152.  #ifdef DGK
153.  	while((foo = readchar()) >= '0' && foo <= '9') {
154.  		multi = 10*multi+foo-'0';
155.  		if (multi < 0 || multi > LARGEST_INT)
156.  			multi = LARGEST_INT;
157.  		if (multi > 9) {
158.  			remember_topl();
159.  			home();
160.  			cl_end();
161.  			printf("Count: %d", multi);
162.  		}
163.  		last_multi = multi;
164.  	}
165.  # ifdef REDO
166.  	if (foo == DOAGAIN || in_doagain)
167.  		multi = last_multi;
168.  	else {
169.  		savech(0);	/* reset input queue */
170.  		savech(foo);
171.  	}
172.  # endif
173.  
174.  #else /* DGK */
175.  
176.  	while((foo = readchar()) >= '0' && foo <= '9')
177.  		multi = 10*multi+foo-'0';
178.  
179.  #endif /* DGK */
180.  
181.  	if(multi) {
182.  		multi--;
183.  		save_cm = inline;
184.  	}
185.  	inline[0] = foo;
186.  	inline[1] = 0;
187.  	if(foo == 'g' || foo == 'G'){
188.  		inline[1] = getchar();
189.  #ifdef REDO
190.  		savech(inline[1]);
191.  #endif
192.  		inline[2] = 0;
193.  	}
194.  	if(foo == 'm' || foo == 'M'){
195.  		inline[1] = getchar();
196.  #ifdef REDO
197.  		savech(inline[1]);
198.  #endif
199.  		inline[2] = 0;
200.  	}
201.  	clrlin();
202.  	return(inline);
203.  }
204.  
205.  char
206.  readchar() {
207.  	register int sym;
208.  
209.  	(void) fflush(stdout);
210.  	sym = getchar();
211.  	if(flags.toplin == 1)
212.  		flags.toplin = 2;
213.  	return((char) sym);
214.  }
215.  #ifdef COM_COMPL
216.  /* Read in an extended command - doing command line completion for
217.   * when enough character have been entered to make a unique command.
218.   * This is just a modified getlin().   -jsb
219.   */
220.  get_ext_cmd(bufp)
221.  register char *bufp;
222.  {
223.  	register char *obufp = bufp;
224.  	register int c;
225.  	int com_index, index;
226.  
227.  	flags.toplin = 2;		/* nonempty, no --More-- required */
228.  
229.  	for(;;) {
230.  		(void) fflush(stdout);
231.  		if((c = readchar()) == EOF) {
232.  			*bufp = 0;
233.  			return;
234.  		}
235.  		if(c == '\033') {
236.  			*obufp = c;
237.  			obufp[1] = 0;
238.  			return;
239.  		}
240.  		if(c == erase_char || c == '\b') {
241.  			if(bufp != obufp) {
242.  				bufp--;
243.  				putstr("\b \b"); /* putsym converts \b */
244.  			} else	bell();
245.  		} else if(c == '\n') {
246.  			*bufp = 0;
247.  			return;
248.  		} else if(' ' <= c && c < '\177') {
249.  				/* avoid isprint() - some people don't have it
250.  				   ' ' is not always a printing char */
251.  			*bufp = c;
252.  			bufp[1] = 0;
253.  			index = 0;
254.  			com_index = -1;
255.  
256.  			while(extcmdlist[index].ef_txt != (char *) 0){
257.  				if(!strncmp(obufp, extcmdlist[index].ef_txt,
258.  				strlen(obufp)))
259.  					if(com_index == -1) /* No matches yet*/
260.  					    com_index = index;
261.  					else /* More than 1 match */
262.  					    com_index = -2;
263.  				index++;
264.  			}
265.  			if(com_index >= 0){
266.  				strcpy(obufp,
267.  				extcmdlist[com_index].ef_txt);
268.  				/* finish print our string */
269.  				putstr(bufp);
270.  				bufp = obufp; /* reset it */
271.  				if(strlen(obufp) < BUFSIZ-1 &&
272.  				 strlen(obufp) < COLNO)
273.  					/* set bufp at the end of our
274.  					 * string
275.  					 */
276.  					bufp += strlen(obufp);
277.  			} else {
278.  				putstr(bufp);
279.  				if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)
280.  					bufp++;
281.  			}
282.  		} else if(c == kill_char || c == '\177') { /* Robert Viduya */
283.  				/* this test last - @ might be the kill_char */
284.  			while(bufp != obufp) {
285.  				bufp--;
286.  				putstr("\b \b");
287.  			}
288.  		} else
289.  			bell();
290.  	}
291.  
292.  }
293.  #endif /* COM_COMPL /* */

Around Wikia's network

Random Wiki