Source:NetHack 1.3d/pctty.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to pctty.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/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	1.3	87/07/14
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* tty.c - (PC) version 1.0.3 */
4.    /* With thanks to the people who sent code for SYSV - hpscdi!jon,
5.       arnold@ucsf-cgl, wcs@bo95b, cbcephus!pds and others. */
6.    
7.    #include <stdio.h>
8.    #include "hack.h"
9.    
10.   static char erase_char, kill_char;
11.   
12.   /*
13.    * Get initial state of terminal, set ospeed (for termcap routines)
14.    * and switch off tab expansion if necessary.
15.    * Called by startup() in termcap.c and after returning from ! or ^Z
16.    */
17.   gettty(){
18.   	erase_char = '\b';
19.   	kill_char = 21;		/* cntl-U */
20.   	flags.cbreak = TRUE;
21.   #ifdef DGK
22.   	disable_ctrlP();	/* turn off ^P processing */
23.   #endif
24.   }
25.   
26.   /* reset terminal to original state */
27.   settty(s) char *s; {
28.   	end_screen();
29.   	if(s) printf(s);
30.   	(void) fflush(stdout);
31.   #ifdef DGK
32.   	enable_ctrlP();		/* turn on ^P processing */
33.   #endif
34.   }
35.   
36.   
37.   /* fatal error */
38.   /*VARARGS1*/
39.   error(s,x,y) char *s; {
40.   	end_screen();
41.   	putchar('\n');
42.   	printf(s,x,y);
43.   	putchar('\n');
44.   	exit(1);
45.   }
46.   
47.   /*
48.    * Read a line closed with '\n' into the array char bufp[BUFSZ].
49.    * (The '\n' is not stored. The string is closed with a '\0'.)
50.    * Reading can be interrupted by an escape ('\033') - now the
51.    * resulting string is "\033".
52.    */
53.   getlin(bufp)
54.   register char *bufp;
55.   {
56.   	register char *obufp = bufp;
57.   	register int c;
58.   
59.   	flags.toplin = 2;		/* nonempty, no --More-- required */
60.   	for(;;) {
61.   		(void) fflush(stdout);
62.   		if((c = getchar()) == EOF) {
63.   			*bufp = 0;
64.   			return;
65.   		}
66.   		if(c == '\033') {
67.   			*obufp = c;
68.   			obufp[1] = 0;
69.   			return;
70.   		}
71.   		if(c == erase_char || c == '\b') {
72.   			if(bufp != obufp) {
73.   				bufp--;
74.   				putstr("\b \b"); /* putsym converts \b */
75.   			} else	bell();
76.   		} else if(c == '\n') {
77.   			*bufp = 0;
78.   			return;
79.   		} else if(' ' <= c && c < '\177') {
80.   				/* avoid isprint() - some people don't have it
81.   				   ' ' is not always a printing char */
82.   			*bufp = c;
83.   			bufp[1] = 0;
84.   			putstr(bufp);
85.   			if(bufp-obufp < BUFSZ-1 && bufp-obufp < COLNO)
86.   				bufp++;
87.   		} else if(c == kill_char || c == '\177') { /* Robert Viduya */
88.   				/* this test last - @ might be the kill_char */
89.   			while(bufp != obufp) {
90.   				bufp--;
91.   				putstr("\b \b");
92.   			}
93.   		} else
94.   			bell();
95.   	}
96.   }
97.   
98.   getret() {
99.   	cgetret("");
100.  }
101.  
102.  cgetret(s)
103.  register char *s;
104.  {
105.  	putsym('\n');
106.  	if(flags.standout)
107.  		standoutbeg();
108.  	putstr("Hit ");
109.  	putstr(flags.cbreak ? "space" : "return");
110.  	putstr(" to continue: ");
111.  	if(flags.standout)
112.  		standoutend();
113.  	xwaitforspace(s);
114.  }
115.  
116.  char morc;	/* tell the outside world what char he used */
117.  
118.  xwaitforspace(s)
119.  register char *s;	/* chars allowed besides space or return */
120.  {
121.  register int c;
122.  
123.  	morc = 0;
124.  	while((c = readchar()) != '\n') {
125.  	    if(flags.cbreak) {
126.  		if(c == ' ') break;
127.  		if(s && index(s,c)) {
128.  			morc = c;
129.  			break;
130.  		}
131.  		bell();
132.  	    }
133.  	}
134.  }
135.  
136.  static int last_multi;
137.  
138.  char *
139.  parse()
140.  {
141.  	static char inline[COLNO];
142.  	register foo;
143.  
144.  	flags.move = 1;
145.  	if(!Invisible) curs_on_u(); else home();
146.  	multi = 0;
147.  #ifdef DGK
148.  	while((foo = readchar()) >= '0' && foo <= '9') {
149.  		multi = 10*multi+foo-'0';
150.  		if (multi < 0 || multi > LARGEST_INT)
151.  			multi = LARGEST_INT;
152.  		if (multi > 9) {
153.  			remember_topl();
154.  			home();
155.  			cl_end();
156.  			printf("Count: %d", multi);
157.  		}
158.  		last_multi = multi;
159.  	}
160.  # ifdef REDO
161.  	if (foo == DOAGAIN || in_doagain)
162.  		multi = last_multi;
163.  	else {
164.  		savech(0);	/* reset input queue */
165.  		savech(foo);
166.  	}
167.  # endif
168.  
169.  #else /* DGK */
170.  
171.  	while((foo = readchar()) >= '0' && foo <= '9')
172.  		multi = 10*multi+foo-'0';
173.  
174.  #endif /* DGK */
175.  
176.  	if(multi) {
177.  		multi--;
178.  		save_cm = inline;
179.  	}
180.  	inline[0] = foo;
181.  	inline[1] = 0;
182.  	if(foo == 'g' || foo == 'G'){
183.  		inline[1] = getchar();
184.  		savech(inline[1]);
185.  		inline[2] = 0;
186.  	}
187.  	if(foo == 'm' || foo == 'M'){
188.  		inline[1] = getchar();
189.  		savech(inline[1]);
190.  		inline[2] = 0;
191.  	}
192.  	clrlin();
193.  	return(inline);
194.  }
195.  
196.  char
197.  readchar() {
198.  	register int sym;
199.  
200.  	(void) fflush(stdout);
201.  	sym = getchar();
202.  	if(flags.toplin == 1)
203.  		flags.toplin = 2;
204.  	return((char) sym);
205.  }