int whatcursorposition(UNUSED(char **args)) { char msg[100]; char *s = msg, *mbstr; int bol = findbol(), len; ZLE_CHAR_T c = zleline[zlecs]; if (zlecs == zlell) strucpy(&s, "EOF"); else { strucpy(&s, "Char: "); switch (c) { case ZWC(' '): strucpy(&s, "SPC"); break; case ZWC('\t'): strucpy(&s, "TAB"); break; case ZWC('\n'): strucpy(&s, "LFD"); break; default: /* * convert a single character, remembering it may * turn into a multibyte string or be metafied. */ mbstr = zlelineasstring(zleline+zlecs, 1, 0, &len, NULL, 1); strcpy(s, mbstr); s += len; } sprintf(s, " (0%o, %u, 0x%x)", (unsigned int)c, (unsigned int)c, (unsigned int)c); s += strlen(s); } sprintf(s, " point %d of %d(%d%%) column %d", zlecs+1, zlell+1, zlell ? 100 * zlecs / zlell : 0, zlecs - bol); showmsg(msg); return 0; }
int get_str(void *vopt, WINDOW *win) { char *opt = (char *) vopt; char *sp; int oy, ox; int i; signed char c; static char buf[MAXSTR]; getyx(win, oy, ox); wrefresh(win); /* * loop reading in the string, and put it in a temporary buffer */ for (sp = buf; (c = readchar()) != '\n' && c != '\r' && c != ESCAPE; wclrtoeol(win), wrefresh(win)) { if (c == -1) continue; else if (c == erasechar() || c == 8 || c == 127) /* process erase character */ { if (sp > buf) { sp--; for (i = (int) strlen(unctrl(*sp)); i; i--) waddch(win, '\b'); } continue; } else if (c == killchar()) /* process kill character */ { sp = buf; wmove(win, oy, ox); continue; } else if (sp == buf) { if (c == '-' && win != stdscr) break; else if (c == '~') { strcpy(buf, home); waddstr(win, home); sp += strlen(home); continue; } } if (sp >= &buf[MAXINP] || !(isprint(c) || c == ' ')) putchar(CTRL('G')); else { *sp++ = c; waddstr(win, unctrl(c)); } } *sp = '\0'; if (sp > buf) /* only change option if something has been typed */ strucpy(opt, buf, (int) strlen(buf)); mvwprintw(win, oy, ox, "%s\n", opt); wrefresh(win); if (win == stdscr) mpos += (int)(sp - buf); if (c == '-') return MINUS; else if (c == ESCAPE) return QUIT; else return NORM; }
void parse_opts(char *str) { char *sp; OPTION *op; int len; char **i; char *start; while (*str) { /* * Get option name */ for (sp = str; isalpha(*sp); sp++) continue; len = (int)(sp - str); /* * Look it up and deal with it */ for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) if (EQSTR(str, op->o_name, len)) { if (op->o_putfunc == put_bool) /* if option is a boolean */ *(bool *)op->o_opt = TRUE; /* NOSTRICT */ else /* string option */ { /* * Skip to start of string value */ for (str = sp + 1; *str == '='; str++) continue; if (*str == '~') { strcpy((char *) op->o_opt, home); /* NOSTRICT */ start = (char *) op->o_opt + strlen(home);/* NOSTRICT */ while (*++str == '/') continue; } else start = (char *) op->o_opt; /* NOSTRICT */ /* * Skip to end of string value */ for (sp = str + 1; *sp && *sp != ','; sp++) continue; /* * check for type of inventory */ if (op->o_putfunc == put_inv_t) { if (islower(*str)) *str = (char) toupper(*str); for (i = inv_t_name; i <= &inv_t_name[INV_CLEAR]; i++) if (strncmp(str, *i, sp - str) == 0) { inv_type = (int)(i - inv_t_name); break; } } else strucpy(start, str, (int)(sp - str)); } break; } /* * check for "noname" for booleans */ else if (op->o_putfunc == put_bool && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) { *(bool *)op->o_opt = FALSE; /* NOSTRICT */ break; } /* * skip to start of next option name */ while (*sp && !isalpha(*sp)) sp++; str = sp; } }
/* * main: * The main program, of course */ int main(int argc, char **argv) { char *env; time_t lowtime; md_init(); #ifdef MASTER /* * Check to see if he is a wizard */ if (argc >= 2 && argv[1][0] == '\0') if (strcmp(PASSWD, md_crypt(md_getpass("wizard's password: "******"mT")) == 0) { wizard = TRUE; player.t_flags |= SEEMONST; argv++; argc--; } #endif /* * get home and options from environment */ strcpy(home, md_gethomedir()); if (strlen(home) > MAXSTR - strlen("rogue.save") - 1) *home = 0; strcpy(file_name, home); strcat(file_name, "rogue.save"); if ((env = getenv("ROGUEOPTS")) != NULL) parse_opts(env); if (env == NULL || whoami[0] == '\0') strucpy(whoami, md_getusername(), strlen(md_getusername())); lowtime = time(NULL); if (getenv("SEED") != NULL) { dnum = atoi(getenv("SEED")); noscore = 1; } else dnum = (unsigned int) lowtime + md_getpid(); seed = dnum; open_score(); /* * Drop setuid/setgid after opening the scoreboard file. */ md_normaluser(); /* * check for print-score option */ md_normaluser(); /* we drop any setgid/setuid priveldges here */ if (argc == 2) { if (strcmp(argv[1], "-s") == 0) { noscore = TRUE; score(0, -1, 0); exit(0); } else if (strcmp(argv[1], "-d") == 0) { dnum = rnd(100); /* throw away some rnd()s to break patterns */ while (--dnum) rnd(100); purse = rnd(100) + 1; level = rnd(100) + 1; initscr(); getltchars(); death(death_monst()); exit(0); } } init_check(); /* check for legal startup */ if (argc == 2) if (!restore(argv[1])) /* Note: restore will never return */ my_exit(1); #ifdef MASTER if (wizard) printf("Hello %s, welcome to dungeon #%d", whoami, dnum); else #endif printf("Hello %s, just a moment while I dig the dungeon...", whoami); fflush(stdout); initscr(); /* Start up cursor package */ init_probs(); /* Set up prob tables for objects */ init_player(); /* Set up initial player stats */ init_names(); /* Set up names of scrolls */ init_colors(); /* Set up colors of potions */ init_stones(); /* Set up stone settings of rings */ init_materials(); /* Set up materials of wands */ setup(); /* * The screen must be at least NUMLINES x NUMCOLS */ if (LINES < NUMLINES || COLS < NUMCOLS) { printf("\nSorry, the screen must be at least %dx%d\n", NUMLINES, NUMCOLS); endwin(); my_exit(1); } /* * Set up windows */ hw = newwin(LINES, COLS, 0, 0); idlok(stdscr, TRUE); idlok(hw, TRUE); #ifdef MASTER noscore = wizard; #endif new_level(); /* Draw current level */ /* * Start up daemons and fuses */ start_daemon(runners, 0, AFTER); start_daemon(doctor, 0, AFTER); fuse(swander, 0, WANDERTIME, AFTER); start_daemon(stomach, 0, AFTER); playit(); return(0); }
void parse_opts(char *str) { char *sp; OPTION *op; int len; while (*str) { /* * Get option name */ for (sp = str; isalpha(*sp); sp++) continue; len = (int)(sp - str); /* * Look it up and deal with it */ for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) if (EQSTR(str, op->o_name, len)) { if (op->o_putfunc == put_bool) /* if option is a boolean */ *(int *)op->o_opt = TRUE; else /* string option */ { char *start; /* * Skip to start of string value */ for (str = sp + 1; *str == '='; str++) continue; if (*str == '~') { strcpy((char *) op->o_opt, home); start = (char *) op->o_opt + strlen(home); while (*++str == '/') continue; } else start = (char *) op->o_opt; /* * Skip to end of string value */ for (sp = str + 1; *sp && *sp != ','; sp++) continue; strucpy(start, str, sp - str); } break; } /* * check for "noname" for booleans */ else if (op->o_putfunc == put_bool && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) { *(int *)op->o_opt = FALSE; break; } /* * skip to start of next option name */ while (*sp && !isalpha(*sp)) sp++; str = sp; } }
/* * set a string option */ int get_str(void *vopt, WINDOW *win) { char *opt = (char *) vopt; char *sp; int c, oy, ox; char buf[80]; PC_GFX_SET_CURSOR(1); draw(win); getyx(win, oy, ox); /* * loop reading in the string, and put it in a temporary buffer */ for (sp = buf; (c = readchar(win)) != '\n' && c != '\r' && c != '\033' && c != '\007'; wclrtoeol(win), draw(win)) { if (c == -1) continue; else if (c == md_erasechar()) /* process erase character */ { if (sp > buf) { int i; int myx, myy; sp--; for (i = (int) strlen(unctrl(*sp)); i; i--) { getyx(win,myy,myx); if ((myx == 0)&& (myy > 0)) { wmove(win,myy-1,getmaxx(win)-1); waddch(win,' '); wmove(win,myy-1,getmaxx(win)-1); } else waddch(win, '\b'); } } continue; } else if (c == md_killchar()) /* process kill character */ { sp = buf; wmove(win, oy, ox); continue; } else if (sp == buf) if (c == '-') break; else if (c == '~') { strcpy(buf, home); waddstr(win, home); sp += strlen(home); continue; } if ((sp - buf) < 78) /* Avoid overflow */ { *sp++ = c; waddstr(win, unctrl(c)); } } *sp = '\0'; if (sp > buf) /* only change option if something has been typed */ strucpy(opt, buf, strlen(buf)); wmove(win, oy, ox); waddstr(win, opt); waddch(win, '\n'); draw(win); if (win == cw) mpos += (int)(sp - buf); PC_GFX_SET_CURSOR(0); if (c == '-') return MINUS; else if (c == '\033' || c == '\007') return QUIT; else return NORM; }
/* * parse options from string, usually taken from the environment. * the string is a series of comma seperated values, with booleans * being stated as "name" (true) or "noname" (false), and strings * being "name=....", with the string being defined up to a comma * or the end of the entire option string. */ void parse_opts(char *str) { register char *sp; register OPTION *op; register int len; while (*str) { /* * Get option name */ for (sp = str; isalpha(*sp); sp++) continue; len = (int)(sp - str); /* * Look it up and deal with it */ for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) if (EQSTR(str, op->o_name, len)) { if (op->o_putfunc == put_bool) /* if option is a boolean */ *(int *)op->o_opt = TRUE; else /* string option */ { register char *start; char value[80]; /* * Skip to start of string value */ for (str = sp + 1; *str == '='; str++) continue; if (*str == '~') { strcpy((char *) value, home); start = (char *) value + strlen(home); while (*++str == '/') continue; } else start = (char *) value; /* * Skip to end of string value */ for (sp = str + 1; *sp && *sp != ','; sp++) continue; strucpy(start, str, (int)(sp - str)); /* Put the value into the option field */ if (op->o_putfunc != put_abil) strcpy(op->o_opt, value); else if (*(int *)op->o_opt == -1) { /* Only init ability once */ register size_t len = strlen(value); if (isupper(value[0])) value[0] = (char) tolower(value[0]); if (EQSTR(value, "fighter", len)) *(int *)op->o_opt = C_FIGHTER; else if (EQSTR(value, "magic", min(len, 5))) *(int *)op->o_opt = C_MAGICIAN; else if (EQSTR(value, "cleric", len)) *(int *)op->o_opt = C_CLERIC; else if (EQSTR(value, "thief", len)) *(int *)op->o_opt = C_THIEF; } } break; } /* * check for "noname" for booleans */ else if (op->o_putfunc == put_bool && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) { *(int *)op->o_opt = FALSE; break; } /* * skip to start of next option name */ while (*sp && !isalpha(*sp)) sp++; str = sp; } }
/* * set a string option */ int get_str(void *vp, WINDOW *win) { char *opt = (char *) vp; register char *sp; register int c, oy, ox; char buf[LINELEN]; *opt = 0; draw(win); getyx(win, oy, ox); /* * loop reading in the string, and put it in a temporary buffer */ for (sp = buf; (c = readchar(win)) != '\n' && c != '\r' && c != '\033' && c != '\007' && sp < &buf[LINELEN-1]; wclrtoeol(win), draw(win)) { if (c == -1) continue; else if (c == md_erasechar()) /* process erase character */ { if (sp > buf) { register size_t i; sp--; for (i = strlen(unctrl(*sp)); i; i--) waddch(win, '\b'); } continue; } else if (c == md_killchar()) /* process kill character */ { sp = buf; wmove(win, oy, ox); continue; } else if (sp == buf) { if (c == '-' && win == hw) /* To move back a line in hw */ break; else if (c == '~') { strcpy(buf, home); waddstr(win, home); sp += strlen(home); continue; } } *sp++ = (char) c; waddstr(win, unctrl(c)); } *sp = '\0'; if (sp > buf) /* only change option if something has been typed */ strucpy(opt, buf, strlen(buf)); wmove(win, oy, ox); waddstr(win, opt); waddch(win, '\n'); draw(win); if (win == cw) mpos += (int)(sp - buf); if (c == '-') return MINUS; else if (c == '\033' || c == '\007') return QUIT; else return NORM; }