Exemple #1
0
int
doset(void)
{
	char buf[BUFSZ];
	size_t pos;

	pline("What options do you want to set? ");
	getlin(buf);
	if (!buf[0] || buf[0] == '\033') {
		(void) strcpy(buf, "HACKOPTIONS=");
		(void) strcat(buf, flags.female ? "female," : "male,");
		if (flags.standout)
			(void) strlcat(buf, "standout,", sizeof(buf));
		if (flags.nonull)
			(void) strlcat(buf, "nonull,", sizeof(buf));
		if (flags.nonews)
			(void) strlcat(buf, "nonews,", sizeof(buf));
		if (flags.time)
			(void) strlcat(buf, "time,", sizeof(buf));
		if (flags.notombstone)
			(void) strlcat(buf, "notombstone,", sizeof(buf));
		if (flags.no_rest_on_space)
			(void) strlcat(buf, "!rest_on_space,", sizeof(buf));
		if (flags.end_top != 5 || flags.end_around != 4 || flags.end_own) {
			pos = strlen(buf);
			(void) snprintf(buf+pos, sizeof(buf)-pos,
				       "endgame: %u topscores/%u around me",
				       flags.end_top, flags.end_around);
			if (flags.end_own)
				(void) strlcat(buf, "/own scores", sizeof(buf));
		} else {
			char           *eop = eos(buf);
			if (*--eop == ',')
				*eop = 0;
		}
		pline("%s", buf);
	} else
		parseoptions(buf, FALSE);

	return (0);
}
Exemple #2
0
int main(int argc, char* argv[])
{
    short rotornumbers = 0123;
    int rpositions[3] = {0};
    char* input_filename;
    FILE* fd;

    /* Checks the cli arguments */
    if (parseoptions(argc, argv, &input_filename, &rotornumbers, rpositions)
            == EXIT_FAILURE) {
        printusage(argv[0]);
        return EXIT_FAILURE;
    }

    if ((fd = fopen(input_filename, "r")) == NULL) {
        perror("fopen:");
        return EXIT_FAILURE;
    }
    cryptstream(fd, rotornumbers, rpositions);

    return EXIT_SUCCESS;
}
Exemple #3
0
int main(int argc,char *argv[])
{
char *ptr;

progname=argv[0]?argv[0]:"aylet";
if((ptr=strrchr(progname,'/'))!=NULL)
  progname=ptr+1;

parseoptions(argc,argv);

if(list_only)
  {
  do_list();
  exit(0);
  }

/* even when not using curses/GTK+ we go via the UI code
 * (apart from the above :-)).
 */
ui_init(argc,argv);

if(!sound_init())
  {
  ui_end();
  fprintf(stderr,"%s: couldn't open sound device.\n",progname);
  exit(1);
  }

mainloop();

if(sound_enabled)
  sound_end();

ui_end();

exit(0);
}
Exemple #4
0
int main(int argc, const char **argv)
{
  unitrv_parseoptionst parseoptions(argc, argv);
  return parseoptions.main();
}
Exemple #5
0
static void
parseoptions(char *opts, bool from_env)
{
	char *op, *op2;
	unsigned num;
	boolean negated;

	if ((op = strchr(opts, ',')) != NULL) {
		*op++ = 0;
		parseoptions(op, from_env);
	}
	if ((op = strchr(opts, ' ')) != NULL) {
		op2 = op;
		while (*op++)
			if (*op != ' ')
				*op2++ = *op;
	}
	if (!*opts)
		return;
	negated = FALSE;
	while ((*opts == '!') || !strncmp(opts, "no", 2)) {
		if (*opts == '!')
			opts++;
		else
			opts += 2;
		negated = !negated;
	}

	if (!strncmp(opts, "standout", 8)) {
		flags.standout = !negated;
		return;
	}

	if (!strncmp(opts, "null", 3)) {
		flags.nonull = negated;
		return;
	}

	if (!strncmp(opts, "tombstone", 4)) {
		flags.notombstone = negated;
		return;
	}

	if (!strncmp(opts, "news", 4)) {
		flags.nonews = negated;
		return;
	}

	if (!strncmp(opts, "time", 4)) {
		flags.time = !negated;
		flags.botl = 1;
		return;
	}

	if (!strncmp(opts, "restonspace", 4)) {
		flags.no_rest_on_space = negated;
		return;
	}

	if (!strncmp(opts, "fixinv", 4)) {
		if (from_env)
			flags.invlet_constant = !negated;
		else
			pline("The fixinvlet option must be in HACKOPTIONS.");
		return;
	}

	if (!strncmp(opts, "male", 4)) {
		flags.female = negated;
		return;
	}
	if (!strncmp(opts, "female", 6)) {
		flags.female = !negated;
		return;
	}

	/* name:string */
	if (!strncmp(opts, "name", 4)) {
		if (!from_env) {
			pline("The playername can be set only from HACKOPTIONS.");
			return;
		}
		op = strchr(opts, ':');
		if (!op)
			goto bad;
		strncpy(plname, op + 1, sizeof(plname) - 1);
		return;
	}

	/* endgame:5t[op] 5a[round] o[wn] */
	if (!strncmp(opts, "endgame", 3)) {
		op = strchr(opts, ':');
		if (!op)
			goto bad;
		op++;
		while (*op) {
			num = 1;
			if (digit(*op)) {
				num = atoi(op);
				while (digit(*op))
					op++;
			} else if (*op == '!') {
				negated = !negated;
				op++;
			}
			switch (*op) {
			case 't':
				flags.end_top = num;
				break;
			case 'a':
				flags.end_around = num;
				break;
			case 'o':
				flags.end_own = !negated;
				break;
			default:
				goto bad;
			}
			while (letter(*++op))
				; /* nothing */
			if (*op == '/')
				op++;
		}
		return;
	}
bad:
	if (!from_env) {
		if (!strncmp(opts, "help", 4)) {
			pline("%s%s%s",
			    "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
			    "give the command 'o' followed by the line `<options>' while playing. ",
			    "Here <options> is a list of <option>s separated by commas.");
			pline("%s%s%s",
			    "Simple (boolean) options are rest_on_space, news, time, ",
			    "null, tombstone, (fe)male. ",
			    "These can be negated by prefixing them with '!' or \"no\".");
			pline("%s",
			    "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\".");
			pline("%s%s%s",
			    "A compound option is endgame; it is followed by a description of what ",
			    "parts of the scorelist you want to see. You might for example say: ",
			    "`endgame:own scores/5 top scores/4 around my score'.");
			return;
		}
		pline("Bad option: %s.", opts);
		pline("Type `o help<cr>' for help.");
		return;
	}
	puts("Bad syntax in HACKOPTIONS.");
	puts("Use for example:");
	puts("HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\"");
	getret();
}
Exemple #6
0
void
initoptions()
{
	register char *opts;
#ifdef MACOS
	char keepname[PL_NSIZ];  /* for save file starts */
#endif

	flags.time = flags.nonews = flags.notombstone = flags.end_own =
	flags.standout = flags.nonull = flags.ignintr = FALSE;
	flags.no_rest_on_space = flags.invlet_constant = TRUE;
	flags.end_top = 3;
	flags.end_around = 2;
	flags.female = FALSE;			/* players are usually male */
	flags.sortpack = TRUE;
	flags.soundok = TRUE;
	flags.verbose = TRUE;
	flags.confirm = TRUE;
	flags.safe_dog = TRUE;
	flags.silent = 	flags.pickup = TRUE;
#ifdef TUTTI_FRUTTI
	nmcpy(pl_fruit, objects[SLIME_MOLD].oc_name, PL_FSIZ);
#endif
	flags.num_pad = FALSE;
	flags.help = TRUE;
	flags.IBMgraphics = FALSE;
	flags.DECgraphics = FALSE;
#ifdef TEXTCOLOR
	flags.use_color = TRUE;
#endif
#ifdef AMIFLUSH
	flags.amiflush = FALSE;	/* default to original behaviour */
#endif
#ifdef MSDOS
#ifdef DGK
	flags.IBMBIOS =
#ifdef TOS
	TRUE;			/* BIOS might as well always be on for TOS */
#endif
	flags.rawio = FALSE;
#endif
	read_config_file();
#endif /* MSDOS */
#ifdef MACOS
	if (plname[0] == '\0') keepname[0] = '\0';
	else Strcpy(keepname, plname);  /* keep name from save file */
	read_config_file();
	if (keepname[0] != '\0') Strcpy(plname, keepname);
	flags.standout = TRUE;	
#endif
	if(opts = getenv("NETHACKOPTIONS"))
		parseoptions(opts,TRUE);
#ifdef TUTTI_FRUTTI
	(void)fruitadd(pl_fruit);
	/* Remove "slime mold" from list of object names; this will	*/
	/* prevent it from being wished unless it's actually present	*/
	/* as a named (or default) fruit.  Wishing for "fruit" will	*/
	/* result in the player's preferred fruit [better than "\033"].	*/
	objects[SLIME_MOLD].oc_name = "fruit";
#endif
}
Exemple #7
0
int wmain(int argc, const wchar_t **argv_wide)
{
  const char **argv=narrow_argv(argc, argv_wide);
  symex_parseoptionst parseoptions(argc, argv);
  return parseoptions.main();
}
int main(int argc, char *argv[])
{
    int upload_pipe_fd;
    char *who;
    char *file;

#ifdef HAVE_SETLOCALE
# ifdef LC_MESSAGES
    (void) setlocale(LC_MESSAGES, "");
# endif
# ifdef LC_CTYPE
    (void) setlocale(LC_CTYPE, "");
# endif
# ifdef LC_COLLATE
    (void) setlocale(LC_COLLATE, "");
# endif
#endif

    if (init() < 0) {
        return -1;
    }
    if (parseoptions(argc, argv) < 0) {
        return -1;
    }
    if (script == NULL) {
        fprintf(stderr, "Sorry, but I need -r <program to run>\n\n");
        usage();
    }
    if (daemonize != 0) {
        dodaemonize();
    }
    if ((upload_pipe_fd = upload_pipe_ropen()) == -1) {
        return -1;
    }
    updatepidfile();
    if (changeuidgid() < 0) {
        perror("Identity change");
        (void) unlink(uploadscript_pid_file);
        return -1;
    }
#ifdef SIGPIPE
    signal(SIGPIPE, SIG_IGN);
#endif
#ifdef SIGCHLD
    signal(SIGCHLD, SIG_DFL);
#endif
    for (;;) {
        if (readpipe(upload_pipe_fd, &who, &file) != 0) {
            (void) sleep(1);
            continue;
        }
        file = checkvirtual(file);
        if (file != NULL && who != NULL) {
            run(who, file, upload_pipe_fd);
        }
    }
    /* NOTREACHED */
#if 0
    close(upload_pipe_fd);
    (void) unlink(uploadscript_pid_file);
#endif

    return 0;
}
Exemple #9
0
int main (int argc, char *argv[])
{
	int status = 0;
	static char eoferrmsg[] =
		"Unexpected end of file in %s section of file \"%s\" (line %d)\n";

	parseoptions(argc, argv);
	InitTables();
	InitConvert();

	errno = 0;
	infp = fopen(Inputfile, "r");
	if(!infp) {
		fprintf(stderr, "Can't open file '%s' for input (E%d: %s)\n",
			Inputfile, errno, strerror(errno));
		exit(-1);
	}
	/* Initialise group  */
	Group.line = 0;

	/* Read DXF file and write Radiance data.  */
	next_group(infp, &Group);
	while (!feof(infp) && strcmp(Group.value,FILEEND) != 0) {
		if(Group.code == 0) {
			if(strcmp(Group.value, SECTION) == 0) {
				next_group(infp, &Group); /* code 2 group */
				if(strcmp(Group.value,HEADER) == 0) {
					if(Options.verbose > 0) {
						fprintf(stderr, "  Reading headers\n");
					}
					HeaderSection();
					if(feof(infp)) {
						fprintf(stderr, eoferrmsg,
								"HEADER", Inputfile, Group.line);
						status = -1;
					}
				}
				else if(strcmp(Group.value,CLASSES) == 0) {
					if(Options.verbose > 0) {
						fprintf(stderr, "  Ignoring classes\n");
					}
					IgnoreSection();
					if(feof(infp)) {
						fprintf(stderr, eoferrmsg,
								"CLASSES", Inputfile, Group.line);
						status = -1;
					}
				}
				else if(strcmp(Group.value,TABLES) == 0) {
					if(Options.verbose > 0) {
						fprintf(stderr, "  Reading tables\n");
					}
					TablesSection();
					if(feof(infp)) {
						fprintf(stderr, eoferrmsg,
								"TABLES", Inputfile, Group.line);
						status = -1;
					}
				}
				else if(strcmp(Group.value,BLOCKS) == 0) {
					if(Options.verbose > 0) {
						fprintf(stderr, "  Reading blocks\n");
					}
					BlocksSection();
					if(feof(infp)) {
						fprintf(stderr, eoferrmsg,
								"BLOCKS", Inputfile, Group.line);
						status = -1;
					}
				}
				else if(strcmp(Group.value,ENTITIES) == 0) {
					if(Options.geom) {
						int i;
						time_t ltime;
						if(*Outputfile == '\0') {
							outf = stdout;
						} else {
							errno = 0;
							outf = fopen((const char*)&Outputfile, "w");
							if(outf == NULL) {
								fprintf(stderr,
										"Can't open file '%s' for output (E%d: %s)\n",
										Outputfile, errno, strerror(errno));
								exit(1);
							}
						}
						(void)time(&ltime);
						fprintf(outf, "## Radiance geometry file \"%s\"\n",
								Outputfile[0] ? Outputfile : "<stdout>");
						fprintf(outf, "## Converted by dxf2rad %s: %s##",
								DXF2RAD_VER, ctime(&ltime));
						for(i = 0; i < argc; i ++) {
							fprintf(outf, " %s", argv[i]);
						}
						fprintf(outf, "\n\n");
						if(Options.verbose > 0) {
							fprintf(stderr, "  Reading entities\n");
						}
						EntitiesSection();
						if(feof(infp)) {
							fprintf(stderr, eoferrmsg,
									"ENTITIES", Inputfile, Group.line);
							status = -1;
						}
					} else {
						if(Options.verbose > 0) {
							fprintf(stderr, "  Ignoring entities\n");
						}
						IgnoreSection();
						if(feof(infp)) {
							fprintf(stderr, eoferrmsg,
									"ENTITIES", Inputfile, Group.line);
							status = -1;
						}
					}
				}
				else if(strcmp(Group.value,OBJECTS) == 0) {
					if(Options.verbose > 0) {
						fprintf(stderr, "  Ignoring objects\n");
					}
					IgnoreSection();
					if(feof(infp)) {
						fprintf(stderr, eoferrmsg,
								"OBJECTS", Inputfile, Group.line);
						status = -1;
					}
				}
			}
		}
		next_group(infp, &Group);
	}

	if(outf) {
		if (status == 0) {
			fprintf(outf, "\n## End of Radiance geometry file \"%s\"\n\n",
					Outputfile[0] ? Outputfile : "<stdout>");
		}
		fclose(outf);
	}
	fclose(infp);
	return status;
}