コード例 #1
0
ファイル: var.c プロジェクト: sairamsrkdgl/Sivaramakrishnan
/*
 * create a new block for function calls and simple commands
 * assume caller has allocated and set up e.loc
 */
void
newblock()
{
	register struct block *l = e.loc;
	static char *empty[] = {""};

	ainit(&l->area);
	l->argc = 0;
	l->argv = empty;
	l->exit = l->error = NULL;
	tinit(&l->vars, &l->area);
	tinit(&l->funs, &l->area);
}
コード例 #2
0
ファイル: keyout.c プロジェクト: smaclennan/zedit
int main(int argc, char *argv[])
{
	unsigned char buff[24];
	int i, n;

	tinit();

	while (1) {
		n = read(0, buff, sizeof(buff));
		if (n == 0)
			break;

		if (*buff == 'q')
			break;

		for (i = 0; i < n; ++i)
			if (buff[i] >= ' ' && buff[i] <= '~')
				putchar(buff[i]);
			else
				printf("\\%03o", buff[i]);
		puts("\r");
	}

	return 0;
}
コード例 #3
0
ファイル: var.c プロジェクト: jkoshy/netbsd-elftoolchain
/*
 * create a new block for function calls and simple commands
 * assume caller has allocated and set up e->loc
 */
void
newblock()
{
	register struct block *l;
	static char *const empty[] = {null};

	l = (struct block *) alloc(sizeof(struct block), ATEMP);
	l->flags = 0;
	ainit(&l->area); /* todo: could use e->area (l->area => l->areap) */
	if (!e->loc) {
		l->argc = 0;
		l->argv = (char **) __UNCONST(empty);
	} else {
		l->argc = e->loc->argc;
		l->argv = e->loc->argv;
	}
	l->exit = l->error = NULL;
	tinit(&l->vars, &l->area, 0);
	tinit(&l->funs, &l->area, 0);
	l->next = e->loc;
	e->loc = l;
}
コード例 #4
0
ファイル: init.c プロジェクト: Strade288/42
void		init(int argc, char **argv, t_data *data)
{
	data->size = argc - 1;
	data->words = (t_word *)malloc(sizeof(t_word));
	winit(argc, argv, data->words);
	data->current = 0;
	data->tsel = 0;
	data->cpage = 1;
	data->tpage = 0;
	data->maxl = 0;
	data->maxc = 0;
	data->maxwpp = 0;
	data->colwid = 30;
	tinit(data);
}
コード例 #5
0
ファイル: var.c プロジェクト: tomgrean/kash
/* called by main() to initialize variable data structures */
void
initvar(void)
{
	static const struct {
		const char *name;
		int v;
	} names[] = {
			{ "COLUMNS",		V_COLUMNS },
			{ "IFS",		V_IFS },
			{ "OPTIND",		V_OPTIND },
			{ "PATH",		V_PATH },
			{ "POSIXLY_CORRECT",	V_POSIXLY_CORRECT },
			{ "TMPDIR",		V_TMPDIR },
#ifdef HISTORY
			{ "HISTFILE",		V_HISTFILE },
			{ "HISTSIZE",		V_HISTSIZE },
#endif /* HISTORY */
#ifdef EDIT
			{ "EDITOR",		V_EDITOR },
			{ "EDITMODE",		V_EDITMODE },
			{ "VISUAL",		V_VISUAL },
#endif /* EDIT */
#ifdef KSH
			{ "MAIL",		V_MAIL },
			{ "MAILCHECK",		V_MAILCHECK },
			{ "MAILPATH",		V_MAILPATH },
			{ "RANDOM",		V_RANDOM },
			{ "SECONDS",		V_SECONDS },
			{ "TMOUT",		V_TMOUT },
#endif /* KSH */
			{ "LINENO",		V_LINENO },
			{ (char *) 0,	0 }
		};
	int i;
	struct tbl *tp;

	tinit(&specials, APERM, 32); /* must be 2^n (currently 18 specials) */
	for (i = 0; names[i].name; i++) {
		tp = tenter(&specials, names[i].name, hash(names[i].name));
		tp->flag = DEFINED|ISSET;
		tp->type = names[i].v;
	}
}
コード例 #6
0
ファイル: common.c プロジェクト: norayr/kronos
tcheck(){ /* ensure that all nodes have been freed */

register NODE *p;
static NODE *first = node;  /* SS. 25.feb.87 added */

 if( !nerrors )
 /* for( p=node; p<= &node[TREESZ-1]; ++p )  */
  for( p=first; p != lastfree; p= TNEXT(p) ){
   if( p->in.op != FREE ){
#ifndef BUG4
    extern int e2print();
    printf( "\ntree causing cerror <wasted space>:\n" );
    fwalk( p, e2print, 0 );
#endif
    cerror( 209, p );  /* wasted space: %o */
   }
   first = lastfree; /* SS. remember the location */
  }
 else
  tinit(); /* SS. call the tinit() only if there were errors */
 freetstr();

} /* tcheck */
コード例 #7
0
ファイル: main.c プロジェクト: ryo/netbsd-src
PUBLIC int
main(int argc, char *argv[])
{
	jmp_buf jmpbuf;
	struct sigaction sa;
	struct name *to, *cc, *bcc, *smopts;
#ifdef MIME_SUPPORT
	struct name *attach_optargs;
	struct name *attach_end;
#endif
	char *subject;
	const char *ef;
	char nosrc = 0;
	const char *rc;
	int Hflag;
	int i;

	/*
	 * For portability, call setprogname() early, before
	 * getprogname() is called.
	 */
	(void)setprogname(argv[0]);

	/*
	 * Set up a reasonable environment.
	 * Figure out whether we are being run interactively,
	 * start the SIGCHLD catcher, and so forth.
	 * (Other signals are setup later by sig_setup().)
	 */
	(void)sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	sa.sa_handler = sigchild;
	(void)sigaction(SIGCHLD, &sa, NULL);

	if (isatty(0))
		assign(ENAME_INTERACTIVE, "");
	image = -1;

	/*
	 * Now, determine how we are being used.
	 * We successively pick off - flags.
	 * If there is anything left, it is the base of the list
	 * of users to mail to.  Argp will be set to point to the
	 * first of these users.
	 */
	rc = NULL;
	ef = NULL;
	to = NULL;
	cc = NULL;
	bcc = NULL;
	smopts = NULL;
	subject = NULL;
	Hflag = 0;
#ifdef MIME_SUPPORT
	attach_optargs = NULL;
	attach_end = NULL;
	while ((i = getopt(argc, argv, ":~EH:INT:a:b:c:dfinr:s:u:v")) != -1)
#else
	while ((i = getopt(argc, argv, ":~EH:INT:b:c:dfinr:s:u:v")) != -1)
#endif
	{
		switch (i) {
		case 'T':
			/*
			 * Next argument is temp file to write which
			 * articles have been read/deleted for netnews.
			 */
			Tflag = optarg;
			if ((i = creat(Tflag, 0600)) < 0) {
				warn("%s", Tflag);
				exit(1);
			}
			(void)close(i);
			break;
#ifdef MIME_SUPPORT
		case 'a': {
			struct name *np;
			np = nalloc(optarg, 0);
			if (attach_end == NULL)
				attach_optargs = np;
			else {
				np->n_blink = attach_end;
				attach_end->n_flink = np;
			}
			attach_end = np;
			break;
		}
#endif
		case 'u':
			/*
			 * Next argument is person to pretend to be.
			 */
			myname = optarg;
			(void)unsetenv("MAIL");
			break;
		case 'i':
			/*
			 * User wants to ignore interrupts.
			 * Set the variable "ignore"
			 */
			assign(ENAME_IGNORE, "");
			break;
		case 'd':
			debug++;
			break;
		case 'r':
			rc = optarg;
			break;
		case 's':
			/*
			 * Give a subject field for sending from
			 * non terminal
			 */
			subject = optarg;
			break;
		case 'f':
			/*
			 * User is specifying file to "edit" with Mail,
			 * as opposed to reading system mailbox.
			 * If no argument is given after -f, we read his
			 * mbox file.
			 *
			 * getopt() can't handle optional arguments, so here
			 * is an ugly hack to get around it.
			 */
			if ((argv[optind]) && (argv[optind][0] != '-'))
				ef = argv[optind++];
			else
				ef = "&";
			break;
		case 'H':
			/*
			 * Print out the headers and quit.
			 */
			Hflag = get_Hflag(argv);
			break;
		case 'n':
			/*
			 * User doesn't want to source /usr/lib/Mail.rc
			 */
			nosrc++;
			break;
		case 'N':
			/*
			 * Avoid initial header printing.
			 */
			assign(ENAME_NOHEADER, "");
			break;
		case 'v':
			/*
			 * Send mailer verbose flag
			 */
			assign(ENAME_VERBOSE, "");
			break;
		case 'I':
		case '~':
			/*
			 * We're interactive
			 */
			assign(ENAME_INTERACTIVE, "");
			break;
		case 'c':
			/*
			 * Get Carbon Copy Recipient list
			 */
			cc = cat(cc, lexpand(optarg, GCC));
			break;
		case 'b':
			/*
			 * Get Blind Carbon Copy Recipient list
			 */
			bcc = cat(bcc, lexpand(optarg, GBCC));

			break;
		case 'E':
			/*
			 * Don't send empty files.
			 */
			assign(ENAME_DONTSENDEMPTY, "");
			break;
		case ':':
			/*
			 * An optarg was expected but not found.
			 */
			if (optopt == 'H') {
				Hflag = get_Hflag(NULL);
				break;
			}
			(void)fprintf(stderr,
			    "%s: option requires an argument -- %c\n",
			    getprogname(), optopt);

			/* FALLTHROUGH */
		case '?':
			/*
			 * An unknown option flag.  We need to do the
			 * error message.
			 */
			if (optopt != '?')
				(void)fprintf(stderr,
				    "%s: unknown option -- %c\n", getprogname(),
				    optopt);
			usage();	/* print usage message and die */
			/*NOTREACHED*/
		}
	}
	for (i = optind; (argv[i]) && (*argv[i] != '-'); i++)
		to = cat(to, nalloc(argv[i], GTO));
	for (/*EMPTY*/; argv[i]; i++)
		smopts = cat(smopts, nalloc(argv[i], GSMOPTS));
	/*
	 * Check for inconsistent arguments.
	 */
	if (to == NULL && (subject != NULL || cc != NULL || bcc != NULL))
		errx(EXIT_FAILURE, "You must specify direct recipients with -s, -c, or -b.");
	if (ef != NULL && to != NULL) {
		errx(EXIT_FAILURE, "Cannot give -f and people to send to.");
	}
	if (Hflag != 0 && to != NULL)
		errx(EXIT_FAILURE, "Cannot give -H and people to send to.");
#ifdef MIME_SUPPORT
	if (attach_optargs != NULL && to == NULL)
		errx(EXIT_FAILURE, "Cannot give -a without people to send to.");
#endif
	tinit();	/* must be done before loading the rcfile */
	input = stdin;
	mailmode = Hflag ? mm_hdrsonly :
	    to ? mm_sending : mm_receiving;

	spreserve();
	if (!nosrc)
		load(_PATH_MASTER_RC);
	/*
	 * Expand returns a savestr, but load only uses the file name
	 * for fopen, so it's safe to do this.
	 */
	if (rc == NULL && (rc = getenv("MAILRC")) == NULL)
		rc = "~/.mailrc";
	load(expand(rc));
	setscreensize();	/* do this after loading the rcfile */

#ifdef USE_EDITLINE
	/*
	 * This is after loading the MAILRC so we can use value().
	 * Avoid editline in mm_hdrsonly mode or pipelines will screw
	 * up.  XXX - there must be a better way!
	 */
	if (mailmode != mm_hdrsonly)
		init_editline();
#endif

	sig_setup();

	switch (mailmode) {
	case mm_sending:
		(void)mail(to, cc, bcc, smopts, subject,
		    mime_attach_optargs(attach_optargs));
		/*
		 * why wait?
		 */
		exit(senderr);
		break;	/* XXX - keep lint happy */

	case mm_receiving:
	case mm_hdrsonly:
		/*
		 * Ok, we are reading mail.
		 * Decide whether we are editing a mailbox or reading
		 * the system mailbox, and open up the right stuff.
		 */
		if (ef == NULL)
			ef = "%";
		if (setfile(ef) < 0)
			exit(1);		/* error already reported */
		if (value(ENAME_QUIET) == NULL)
			(void)printf("Mail version %s.  Type ? for help.\n",
			    version);
		if (mailmode == mm_hdrsonly)
			show_headers_and_exit(Hflag);	/* NORETURN */
		announce();
		(void)fflush(stdout);

		if (setjmp(jmpbuf) != 0) {
			/* Return here if quit() fails below. */
			(void)printf("Use 'exit' to quit without saving changes.\n");
		}
		commands();

		/* Ignore these signals from now on! */
		(void)signal(SIGHUP, SIG_IGN);
		(void)signal(SIGINT, SIG_IGN);
		(void)signal(SIGQUIT, SIG_IGN);
		quit(jmpbuf);
		break;

	default:
		assert(/*CONSTCOND*/0);
		break;
	}

	return 0;
}
コード例 #8
0
ファイル: transition.c プロジェクト: LeTchang/STRP
static void	trans_3(t_env *e, int nb)
{
	tinit(e, "./img/red/red_up_1.xpm", 16, 32, NULL, 50000);
	tinit(e, "./img/red/red_right_1.xpm", 16, 32, NULL, 50000);
	tinit(e, "./img/red/red_down_1.xpm", 16, 32, NULL, 50000);
	tinit(e, "./img/red/red_left_1.xpm", 16, 32, NULL, 50000);
	tinit(e, "./img/red/red_up_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_right_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_down_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_left_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_up_1.xpm", 16, 32, NULL, 10000);
	tinit(e, "./img/red/red_right_1.xpm", 16, 32, NULL, 10000);
	tinit(e, "./img/red/red_down_1.xpm", 16, 32, NULL, 10000);
	tinit(e, "./img/red/red_left_1.xpm", 16, 32, NULL, 10000);
	e->x = e->img_tab[nb].teleport_x;
	e->y = e->img_tab[nb].teleport_y;
	free(e->map.map);
	free(e->map.back);
	gm_init_map(e, e->img_tab[nb].teleport);
	tinit(e, "./img/red/red_up_1.xpm", 16, 32, NULL, 10000);
	tinit(e, "./img/red/red_right_1.xpm", 16, 32, NULL, 10000);
	tinit(e, "./img/red/red_down_1.xpm", 16, 32, NULL, 10000);
	tinit(e, "./img/red/red_left_1.xpm", 16, 32, NULL, 10000);
	tinit(e, "./img/red/red_up_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_right_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_down_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_left_1.xpm", 16, 32, NULL, 30000);
	tinit(e, "./img/red/red_up_1.xpm", 16, 32, NULL, 50000);
	tinit(e, "./img/red/red_right_1.xpm", 16, 32, NULL, 50000);
	tinit(e, "./img/red/red_down_1.xpm", 16, 32, NULL, 50000);
	tinit(e, "./img/red/red_left_1.xpm", 16, 32, NULL, 50000);
	if (e->img_tab[nb].teleport_sens == 1)
		dinit(e, &(e->red), "./img/red/red_up_1.xpm", 16, 32);
	else if (e->img_tab[nb].teleport_sens == 2)
		dinit(e, &(e->red), "./img/red/red_left_1.xpm", 16, 32);
	else if (e->img_tab[nb].teleport_sens == 3)
		dinit(e, &(e->red), "./img/red/red_down_1.xpm", 16, 32);
	else
		dinit(e, &(e->red), "./img/red/red_right_1.xpm", 16, 32);
	gm_putallarrow(e, 0);
}
コード例 #9
0
ファイル: main.c プロジェクト: Scarletts/LiteBSD
int
main(int argc, char *argv[])
{
	int i;
	int argi;
	Source *s;
	struct block *l;
	int restricted, errexit;
	char **wp;
	struct env env;
	pid_t ppid;

	/* make sure argv[] is sane */
	if (!*argv) {
		static const char	*empty_argv[] = {
					    "pdksh", (char *) 0
					};

		argv = (char **) empty_argv;
		argc = 1;
	}
	kshname = *argv;

	ainit(&aperm);		/* initialize permanent Area */

	/* set up base environment */
	memset(&env, 0, sizeof(env));
	env.type = E_NONE;
	ainit(&env.area);
	e = &env;
	newblock();		/* set up global l->vars and l->funs */

	/* Do this first so output routines (eg, errorf, shellf) can work */
	initio();

	initvar();

	initctypes();

	inittraps();

	coproc_init();

	/* set up variable and command dictionaries */
	tinit(&taliases, APERM, 0);
	tinit(&aliases, APERM, 0);
	tinit(&homedirs, APERM, 0);

	/* define shell keywords */
	initkeywords();

	/* define built-in commands */
	tinit(&builtins, APERM, 64); /* must be 2^n (currently 40 builtins) */
	for (i = 0; shbuiltins[i].name != NULL; i++)
		builtin(shbuiltins[i].name, shbuiltins[i].func);
	for (i = 0; kshbuiltins[i].name != NULL; i++)
		builtin(kshbuiltins[i].name, kshbuiltins[i].func);

	init_histvec();

	def_path = _PATH_DEFPATH;
	{
		size_t len = confstr(_CS_PATH, (char *) 0, 0);
		char *new;

		if (len > 0) {
			confstr(_CS_PATH, new = alloc(len + 1, APERM), len + 1);
			def_path = new;
		}
	}
コード例 #10
0
ファイル: irc_.c プロジェクト: HackerVBI/ZiFi
int
main(int argc, char *argv[])
{
	const char *user = getenv("USER");
	const char *ircnick = getenv("IRCNICK");
	const char *server = SRV;
	unsigned short port = PORT;
	int o;

	while ((o=getopt(argc, argv, "hn:u:s:p:"))>=0)
		switch (o) {
		case 'h':
		case '?':
		usage:
			fputs("Usage: irc [-n NICK] [-u USER] [-s SERVER] [-p PORT] [-h]\n", stderr);
			exit(0);
		case 'n':
			if (strlen(optarg)>=sizeof nick) goto usage;
			strcpy(nick, optarg);
			break;
		case 'u':
			user = optarg;
			break;
		case 's':
			server = optarg;
			break;
		case 'p':
			if (!(port=strtol(optarg, 0, 0))) goto usage;
			break;
		}
	if (!nick[0] && ircnick && strlen(ircnick)<sizeof nick)
		strcpy(nick, ircnick);
	if (!nick[0]) goto usage;
	if (!user) user = "******";
	tinit();
	sfd = dial(server, port);
	chadd("*server*");
	sndf("NICK %s", nick);
	sndf("USER %s 8 * :%s", user, user);
	sndf("MODE %s +i", nick);
	while (!quit) {
		fd_set rfs, wfs;
		int ret;

		if (winchg)
			tresize();
		FD_ZERO(&wfs);
		FD_ZERO(&rfs);
		FD_SET(0, &rfs);
		FD_SET(sfd, &rfs);
		if (outp!=outb)
			FD_SET(sfd, &wfs);
		ret=select(sfd+1, &rfs, &wfs, 0, 0);
		if (ret<0) {
			if (errno==EINTR) continue;
			panic("Select failed.");
		}
		if (FD_ISSET(sfd, &rfs)) {
			if (!srd())
				quit=1;
		}
		if (FD_ISSET(sfd, &wfs)) {
			int wr;

			wr=write(sfd, outb, outp-outb);
			if (wr<0) {
				if (errno==EINTR) continue;
				panic("Write error.");
			}
			if (wr==0) continue;
			outp-=wr;
			memmove(outb, outb+wr, outp-outb);
		}
		if (FD_ISSET(0, &rfs)) {
			tgetch();
			wrefresh(scr.iw);
		}
	}
	close(sfd);
	while (nch--)
		free(chl[nch].buf);
	treset();
	exit(0);
}
コード例 #11
0
ファイル: main.c プロジェクト: djbclark/bb10qnx
int
main(int argc, char *argv[])
{
	register int i;
	int argi;
	Source *s;
	struct block *l;
	int restricted, errexit;
	char **wp;
	struct env env;
	pid_t ppid;

#ifdef MEM_DEBUG
	chmem_set_defaults("ct", 1);
	/* chmem_push("+c", 1); */
#endif /* MEM_DEBUG */

#ifdef OS2
	setmode (0, O_BINARY);
	setmode (1, O_TEXT);
#endif

	/* make sure argv[] is sane */
	if (!*argv) {
		static const char	*empty_argv[] = {
					    "pdksh", (char *) 0
					};

		argv = (char **)__UNCONST(empty_argv);
		argc = 1;
	}
	kshname = *argv;

	ainit(&aperm);		/* initialize permanent Area */

	/* set up base environment */
	memset(&env, 0, sizeof(env));
	env.type = E_NONE;
	ainit(&env.area);
	e = &env;
	newblock();		/* set up global l->vars and l->funs */

	/* Do this first so output routines (eg, errorf, shellf) can work */
	initio();

	initvar();

	initctypes();

	inittraps();

#ifdef KSH
	coproc_init();
#endif /* KSH */

	/* set up variable and command dictionaries */
	tinit(&taliases, APERM, 0);
	tinit(&aliases, APERM, 0);
	tinit(&homedirs, APERM, 0);

	/* define shell keywords */
	initkeywords();

	/* define built-in commands */
	tinit(&builtins, APERM, 64); /* must be 2^n (currently 40 builtins) */
	for (i = 0; shbuiltins[i].name != NULL; i++)
		builtin(shbuiltins[i].name, shbuiltins[i].func);
	for (i = 0; kshbuiltins[i].name != NULL; i++)
		builtin(kshbuiltins[i].name, kshbuiltins[i].func);

	init_histvec();

	def_path = DEFAULT__PATH;
#if defined(HAVE_CONFSTR) && defined(_CS_PATH)
	{
		size_t len = confstr(_CS_PATH, (char *) 0, 0);
		char *new;

		if (len > 0) {
			confstr(_CS_PATH, new = alloc(len + 1, APERM), len + 1);
			def_path = new;
		}
	}