comparison srogue/main.c @ 119:458df24e973d

srogue: use functions from mdport.c. Shell escape, passwd entries, terminal settings, and most signal handling is now done with the more portable md_* functions.
author John "Elwin" Edwards
date Wed, 30 Apr 2014 14:46:30 -0700
parents ee250e3646fd
children d6b7c3fb37ea
comparison
equal deleted inserted replaced
118:8d1dfc5a912c 119:458df24e973d
16 */ 16 */
17 17
18 #include <stdlib.h> 18 #include <stdlib.h>
19 #include <string.h> 19 #include <string.h>
20 #include <time.h> 20 #include <time.h>
21 #include <termios.h>
22 #include <fcntl.h> 21 #include <fcntl.h>
23 #include <stdio.h> 22 #include <stdio.h>
24 #include <signal.h>
25 #include <pwd.h>
26 #include <limits.h> 23 #include <limits.h>
27 #include <sys/stat.h> 24 #include <sys/stat.h>
28 #include "rogue.h" 25 #include "rogue.h"
29 26
30 #ifdef ATT 27 #ifdef ATT
37 #include <sys/time.h> 34 #include <sys/time.h>
38 #endif 35 #endif
39 36
40 #include "rogue.ext" 37 #include "rogue.ext"
41 38
42 struct termios terminal;
43
44 main(argc, argv, envp) 39 main(argc, argv, envp)
45 char **argv; 40 char **argv;
46 char **envp; 41 char **envp;
47 { 42 {
48 register char *env; 43 register char *env;
49 register struct linked_list *item; 44 register struct linked_list *item;
50 register struct object *obj; 45 register struct object *obj;
51 struct passwd *pw;
52 struct passwd *getpwuid();
53 char alldone, wpt; 46 char alldone, wpt;
54 char *getpass(), *xcrypt(), *strrchr(); 47 char *getpass(), *xcrypt(), *strrchr();
55 int lowtime; 48 int lowtime;
56 time_t now; 49 time_t now;
57 char *roguehome(); 50 char *roguehome();
130 123
131 /* get home and options from environment */ 124 /* get home and options from environment */
132 125
133 if ((env = getenv("HOME")) != NULL) 126 if ((env = getenv("HOME")) != NULL)
134 strcpy(home, env); 127 strcpy(home, env);
135 else if ((pw = getpwuid(playuid)) != NULL) 128 else {
136 strcpy(home, pw->pw_dir); 129 strncpy(home, md_gethomedir(), LINLEN);
137 else 130 if (home[LINLEN-1] != '\0')
138 home[0] = '\0'; 131 home[0] = '\0';
132 }
139 133
140 if (strcmp(home,"/") == 0) 134 if (strcmp(home,"/") == 0)
141 home[0] = '\0'; 135 home[0] = '\0';
142 136
143 if ((strlen(home) > 0) && (home[strlen(home)-1] != '/')) 137 if ((strlen(home) > 0) && (home[strlen(home)-1] != '/'))
151 if ((env = getenv("ROGUEOPTS")) != NULL) 145 if ((env = getenv("ROGUEOPTS")) != NULL)
152 parse_opts(env); 146 parse_opts(env);
153 147
154 if (!use_savedir && (env == NULL || whoami[0] == '\0')) 148 if (!use_savedir && (env == NULL || whoami[0] == '\0'))
155 { 149 {
156 if((pw = getpwuid(playuid)) == NULL) 150 strucpy(whoami, md_getusername(), strlen(md_getusername()));
157 {
158 printf("Say, who are you?\n");
159 exit(1);
160 }
161 else
162 strucpy(whoami, pw->pw_name, strlen(pw->pw_name));
163 } 151 }
164 152
165 if (env == NULL || fruit[0] == '\0') 153 if (env == NULL || fruit[0] == '\0')
166 strcpy(fruit, "juicy-fruit"); 154 strcpy(fruit, "juicy-fruit");
167 155
189 177
190 fflush(stdout); 178 fflush(stdout);
191 seed = dnum; 179 seed = dnum;
192 srand48(seed); /* init rnd number gen */ 180 srand48(seed); /* init rnd number gen */
193 181
194 signal(SIGINT, byebye); /* just in case */ 182 md_onsignal_exit(); /* just in case */
195 signal(SIGQUIT ,byebye);
196 183
197 init_everything(); 184 init_everything();
198 185
199 #ifdef __INTERIX 186 #ifdef __INTERIX
200 setenv("TERM","interix"); 187 setenv("TERM","interix");
395 /* 382 /*
396 ** setup: Setup signal catching functions 383 ** setup: Setup signal catching functions
397 */ 384 */
398 setup() 385 setup()
399 { 386 {
400 signal(SIGHUP, auto_save); 387 md_onsignal_autosave();
401 signal(SIGINT, auto_save);
402 signal(SIGQUIT, byebye);
403 signal(SIGILL, game_err);
404 signal(SIGTRAP, game_err);
405 #ifdef SIGIOT
406 signal(SIGIOT, game_err);
407 #endif
408 #ifdef SIGEMT
409 signal(SIGEMT, game_err);
410 #endif
411 signal(SIGFPE, game_err);
412 #ifdef SIGBUS
413 signal(SIGBUS, game_err);
414 #endif
415 signal(SIGSEGV, game_err);
416 #ifdef SIGSYS
417 signal(SIGSYS, game_err);
418 #endif
419 signal(SIGPIPE, game_err);
420 signal(SIGTERM, game_err);
421 388
422 nonl(); 389 nonl();
423 cbreak(); 390 cbreak();
424 noecho(); 391 noecho();
425 } 392 }
430 */ 397 */
431 398
432 playit() 399 playit()
433 { 400 {
434 reg char *opts; 401 reg char *opts;
435
436 tcgetattr(0,&terminal);
437
438 402
439 /* parse environment declaration of options */ 403 /* parse environment declaration of options */
440 404
441 if ((opts = getenv("ROGUEOPTS")) != NULL) 405 if ((opts = getenv("ROGUEOPTS")) != NULL)
442 parse_opts(opts); 406 parse_opts(opts);