Mercurial > hg > early-roguelike
comparison srogue/main.c @ 36:2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Thu, 25 Nov 2010 12:21:41 +0000 |
| parents | |
| children | 34d7a614855e |
comparison
equal
deleted
inserted
replaced
| 35:05018c63a721 | 36:2128c7dc8a40 |
|---|---|
| 1 /* | |
| 2 * Rogue | |
| 3 * Exploring the dungeons of doom | |
| 4 * | |
| 5 * @(#)main.c 9.0 (rdk) 7/17/84 | |
| 6 * | |
| 7 * Super-Rogue | |
| 8 * Copyright (C) 1984 Robert D. Kindelberger | |
| 9 * All rights reserved. | |
| 10 * | |
| 11 * Based on "Rogue: Exploring the Dungeons of Doom" | |
| 12 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 13 * All rights reserved. | |
| 14 * | |
| 15 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 16 */ | |
| 17 | |
| 18 #include <time.h> | |
| 19 #include <termios.h> | |
| 20 #include <fcntl.h> | |
| 21 #include <stdio.h> | |
| 22 #include <signal.h> | |
| 23 #include <pwd.h> | |
| 24 #include <limits.h> | |
| 25 #include <sys/stat.h> | |
| 26 #include "rogue.h" | |
| 27 | |
| 28 #ifdef ATT | |
| 29 #include <time.h> | |
| 30 #endif | |
| 31 | |
| 32 #ifdef BSD | |
| 33 #define srand48(seed) srandom(seed) | |
| 34 #define lrand48() random() | |
| 35 #include <sys/time.h> | |
| 36 #endif | |
| 37 | |
| 38 #include "rogue.ext" | |
| 39 | |
| 40 struct termios terminal; | |
| 41 | |
| 42 main(argc, argv, envp) | |
| 43 char **argv; | |
| 44 char **envp; | |
| 45 { | |
| 46 register char *env; | |
| 47 register struct linked_list *item; | |
| 48 register struct object *obj; | |
| 49 struct passwd *pw; | |
| 50 struct passwd *getpwuid(); | |
| 51 char alldone, wpt; | |
| 52 char *getpass(), *xcrypt(), *strrchr(); | |
| 53 int lowtime; | |
| 54 time_t now; | |
| 55 char *roguehome(); | |
| 56 char *homedir = roguehome(); | |
| 57 | |
| 58 #ifdef __DJGPP__ | |
| 59 _fmode = O_BINARY; | |
| 60 #endif | |
| 61 | |
| 62 if (homedir == NULL) | |
| 63 homedir = ""; | |
| 64 | |
| 65 playuid = getuid(); | |
| 66 | |
| 67 if (setuid(playuid) < 0) { | |
| 68 printf("Cannot change to effective uid: %d\n", playuid); | |
| 69 exit(1); | |
| 70 } | |
| 71 playgid = getgid(); | |
| 72 | |
| 73 /* check for print-score option */ | |
| 74 | |
| 75 strcpy(scorefile, homedir); | |
| 76 | |
| 77 if (*scorefile) | |
| 78 strcat(scorefile,"/"); | |
| 79 strcat(scorefile, "srogue.scr"); | |
| 80 | |
| 81 if(argc >= 2 && strcmp(argv[1], "-s") == 0) | |
| 82 { | |
| 83 showtop(0); | |
| 84 exit(0); | |
| 85 } | |
| 86 | |
| 87 if (argc >= 2 && author() && strcmp(argv[1],"-a") == 0) | |
| 88 { | |
| 89 wizard = TRUE; | |
| 90 argv++; | |
| 91 argc--; | |
| 92 } | |
| 93 | |
| 94 /* Check to see if he is a wizard */ | |
| 95 | |
| 96 if (argc >= 2 && strcmp(argv[1],"-w") == 0) | |
| 97 { | |
| 98 if (strcmp(PASSWD, xcrypt(getpass(wizstr),"mT")) == 0) | |
| 99 { | |
| 100 wizard = TRUE; | |
| 101 argv++; | |
| 102 argc--; | |
| 103 } | |
| 104 } | |
| 105 time(&now); | |
| 106 lowtime = (int) now; | |
| 107 | |
| 108 /* get home and options from environment */ | |
| 109 | |
| 110 if ((env = getenv("HOME")) != NULL) | |
| 111 strcpy(home, env); | |
| 112 else if ((pw = getpwuid(playuid)) != NULL) | |
| 113 strcpy(home, pw->pw_dir); | |
| 114 else | |
| 115 home[0] = '\0'; | |
| 116 | |
| 117 if (strcmp(home,"/") == 0) | |
| 118 home[0] = '\0'; | |
| 119 | |
| 120 if ((strlen(home) > 0) && (home[strlen(home)-1] != '/')) | |
| 121 strcat(home, "/"); | |
| 122 | |
| 123 strcpy(file_name, home); | |
| 124 strcat(file_name, "srogue.sav"); | |
| 125 | |
| 126 if ((env = getenv("ROGUEOPTS")) != NULL) | |
| 127 parse_opts(env); | |
| 128 | |
| 129 if (env == NULL || whoami[0] == '\0') | |
| 130 { | |
| 131 if((pw = getpwuid(playuid)) == NULL) | |
| 132 { | |
| 133 printf("Say, who are you?\n"); | |
| 134 exit(1); | |
| 135 } | |
| 136 else | |
| 137 strucpy(whoami, pw->pw_name, strlen(pw->pw_name)); | |
| 138 } | |
| 139 | |
| 140 if (env == NULL || fruit[0] == '\0') | |
| 141 strcpy(fruit, "juicy-fruit"); | |
| 142 | |
| 143 if (argc == 2) | |
| 144 if(!restore(argv[1], envp)) /* NOTE: NEVER RETURNS */ | |
| 145 exit(1); | |
| 146 | |
| 147 dnum = (wizard && getenv("SEED") != NULL ? | |
| 148 atoi(getenv("SEED")) : lowtime + getpid()); | |
| 149 | |
| 150 if(wizard) | |
| 151 printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum); | |
| 152 else | |
| 153 printf("Hello %s, One moment while I open the door to the dungeon...\n", whoami); | |
| 154 | |
| 155 fflush(stdout); | |
| 156 seed = dnum; | |
| 157 srand48(seed); /* init rnd number gen */ | |
| 158 | |
| 159 signal(SIGINT, byebye); /* just in case */ | |
| 160 signal(SIGQUIT ,byebye); | |
| 161 | |
| 162 init_everything(); | |
| 163 | |
| 164 #ifdef __INTERIX | |
| 165 setenv("TERM","interix"); | |
| 166 #endif | |
| 167 | |
| 168 initscr(); /* Start up cursor package */ | |
| 169 | |
| 170 if (strcmp(termname(),"dumb") == 0) | |
| 171 { | |
| 172 endwin(); | |
| 173 printf("ERROR in terminal parameters.\n"); | |
| 174 printf("Check TERM in environment.\n"); | |
| 175 byebye(1); | |
| 176 } | |
| 177 | |
| 178 if (LINES < 24 || COLS < 80) { | |
| 179 endwin(); | |
| 180 printf("ERROR: screen size too small\n"); | |
| 181 byebye(1); | |
