Quizzer

 view release on metacpan or  search on metacpan

exercises/compile-tcsh/tcsh-6.10.00/sh.c  view on Meta::CPAN

#if ECHO_STYLE == BSD_ECHO
    set(STRecho_style, Strsave(STRbsd), VAR_READWRITE);
#endif /* ECHO_STYLE == BSD_ECHO */
#if ECHO_STYLE == SYSV_ECHO
    set(STRecho_style, Strsave(STRsysv), VAR_READWRITE);
#endif /* ECHO_STYLE == SYSV_ECHO */
#if ECHO_STYLE == BOTH_ECHO
    set(STRecho_style, Strsave(STRboth), VAR_READWRITE);
#endif /* ECHO_STYLE == BOTH_ECHO */

    /*
     * increment the shell level.
     */
    shlvl(1);

    if ((tcp = getenv("HOME")) != NULL)
	cp = quote(SAVE(tcp));
    else
	cp = NULL;
    if (cp == NULL)
	fast = 1;		/* No home -> can't read scripts */
    else
	set(STRhome, cp, VAR_READWRITE);
    dinit(cp);			/* dinit thinks that HOME == cwd in a login
				 * shell */
    /*
     * Grab other useful things from the environment. Should we grab
     * everything??
     */
    {
	char *cln, *cus, *cgr;
	Char    buff[BUFSIZE];
	struct passwd *pw;
	struct group *gr;


#ifdef apollo
	int     oid = getoid();

	(void) Itoa(oid, buff, 0, 0);
	set(STRoid, Strsave(buff), VAR_READWRITE);
#endif /* apollo */

	(void) Itoa(uid, buff, 0, 0);
	set(STRuid, Strsave(buff), VAR_READWRITE);

	(void) Itoa(gid, buff, 0, 0);
	set(STRgid, Strsave(buff), VAR_READWRITE);

	cln = getenv("LOGNAME");
	cus = getenv("USER");
	if (cus != NULL)
	    set(STRuser, quote(SAVE(cus)), VAR_READWRITE);
	else if (cln != NULL)
	    set(STRuser, quote(SAVE(cln)), VAR_READWRITE);
	else if ((pw = getpwuid(uid)) == NULL)
	    set(STRuser, SAVE("unknown"), VAR_READWRITE);
	else
	    set(STRuser, SAVE(pw->pw_name), VAR_READWRITE);
	if (cln == NULL)
	    tsetenv(STRLOGNAME, varval(STRuser));
	if (cus == NULL)
	    tsetenv(STRKUSER, varval(STRuser));
	
	cgr = getenv("GROUP");
	if (cgr != NULL)
	    set(STRgroup, quote(SAVE(cgr)), VAR_READWRITE);
	else if ((gr = getgrgid(gid)) == NULL)
	    set(STRgroup, SAVE("unknown"), VAR_READWRITE);
	else
	    set(STRgroup, SAVE(gr->gr_name), VAR_READWRITE);
	if (cgr == NULL)
	    tsetenv(STRKGROUP, varval(STRgroup));
    }

    /*
     * HOST may be wrong, since rexd transports the entire environment on sun
     * 3.x Just set it again
     */
    {
	char    cbuff[MAXHOSTNAMELEN];

	if (gethostname(cbuff, sizeof(cbuff)) >= 0) {
	    cbuff[sizeof(cbuff) - 1] = '\0';	/* just in case */
	    tsetenv(STRHOST, str2short(cbuff));
	}
	else
	    tsetenv(STRHOST, str2short("unknown"));
    }


#ifdef REMOTEHOST
    /*
     * Try to determine the remote host we were logged in from.
     */
    remotehost();
#endif /* REMOTEHOST */
 
#ifdef apollo
    if ((tcp = getenv("SYSTYPE")) == NULL)
	tcp = "bsd4.3";
    tsetenv(STRSYSTYPE, quote(str2short(tcp)));
#endif /* apollo */

    /*
     * set editing on by default, unless running under Emacs as an inferior
     * shell.
     * We try to do this intelligently. If $TERM is available, then it
     * should determine if we should edit or not. $TERM is preserved
     * across rlogin sessions, so we will not get confused if we rlogin
     * under an emacs shell. Another advantage is that if we run an
     * xterm under an emacs shell, then the $TERM will be set to 
     * xterm, so we are going to want to edit. Unfortunately emacs
     * does not restore all the tty modes, so xterm is not very well
     * set up. But this is not the shell's fault.
     * Also don't edit if $TERM == wm, for when we're running under an ATK app.
     * Finally, emacs compiled under terminfo, sets the terminal to dumb,
     * so disable editing for that too.
     * 
     * Unfortunately, in some cases the initial $TERM setting is "unknown",
     * "dumb", or "network" which is then changed in the user's startup files.
     * We fix this by setting noediting here if $TERM is unknown/dumb and
     * if noediting is set, we switch on editing if $TERM is changed.
     */
    if ((tcp = getenv("TERM")) != NULL) {
	set(STRterm, quote(SAVE(tcp)), VAR_READWRITE);
	noediting = strcmp(tcp, "unknown") == 0 || strcmp(tcp, "dumb") == 0 ||
		    strcmp(tcp, "network") == 0;
	editing = strcmp(tcp, "emacs") != 0 && strcmp(tcp, "wm") != 0 &&
		  !noediting;
    }
    else {
	noediting = 0;
	editing = ((tcp = getenv("EMACS")) == NULL || strcmp(tcp, "t") != 0);
    }

    /* 
     * The 'edit' variable is either set or unset.  It doesn't 
     * need a value.  Making it 'emacs' might be confusing. 
     */
    if (editing)
	set(STRedit, Strsave(STRNULL), VAR_READWRITE);


    /*
     * still more mutability: make the complete routine automatically add the
     * suffix of file names...
     */
    set(STRaddsuffix, Strsave(STRNULL), VAR_READWRITE);

    /*
     * Re-initialize path if set in environment
     */
    if ((tcp = getenv("PATH")) == NULL)
#ifdef _PATH_DEFPATH
	importpath(str2short(_PATH_DEFPATH));
#else /* !_PATH_DEFPATH */
	setq(STRpath, defaultpath(), &shvhed, VAR_READWRITE);
#endif /* _PATH_DEFPATH */
    else
	/* Importpath() allocates memory for the path, and the
	 * returned pointer from SAVE() was discarded, so

exercises/compile-tcsh/tcsh-6.10.00/sh.c  view on Meta::CPAN


	    case 'b':		/* -b	Next arg is input file */
		batch = 1;
		break;

	    case 'c':		/* -c	Command input from arg */
		if (argc == 1)
		    xexit(0);
		argc--, tempv++;
#ifdef M_XENIX
		/* Xenix Vi bug:
		   it relies on a 7 bit environment (/bin/sh), so it
		   pass ascii arguments with the 8th bit set */
		if (!strcmp(argv[0], "sh"))
		  {
		    char *p;

		    for (p = tempv[0]; *p; ++p)
		      *p &= ASCII;
		  }
#endif
		arginp = SAVE(tempv[0]);

		/*
		 * we put the command into a variable
		 */
		if (arginp != NULL)
		  set(STRcommand, quote(Strsave(arginp)), VAR_READWRITE);

		/*
		 * * Give an error on -c arguments that end in * backslash to
		 * ensure that you don't make * nonportable csh scripts.
		 */
		{
		    register int count;

		    cp = arginp + Strlen(arginp);
		    count = 0;
		    while (cp > arginp && *--cp == '\\')
			++count;
		    if ((count & 1) != 0) {
			exiterr = 1;
			stderror(ERR_ARGC);
		    }
		}
		prompt = 0;
		nofile = 1;
		break;
	    case 'd':		/* -d	Load directory stack from file */
		rdirs = 1;
		break;

#ifdef apollo
	    case 'D':		/* -D	Define environment variable */
		{
		    register Char *dp;

		    cp = str2short(tcp);
		    if (dp = Strchr(cp, '=')) {
			*dp++ = '\0';
			tsetenv(cp, dp);
		    }
		    else
			tsetenv(cp, STRNULL);
		}
		*tcp = '\0'; 	/* done with this argument */
		break;
#endif /* apollo */

	    case 'e':		/* -e	Exit on any error */
		exiterr = 1;
		break;

	    case 'f':		/* -f	Fast start */
		fast = 1;
		break;

	    case 'i':		/* -i	Interactive, even if !intty */
		intact = 1;
		nofile = 1;
		break;

	    case 'm':		/* -m	read .cshrc (from su) */
		mflag = 1;
		break;

	    case 'n':		/* -n	Don't execute */
		noexec = 1;
		break;

	    case 'q':		/* -q	(Undoc'd) ... die on quit */
		quitit = 1;
		break;

	    case 's':		/* -s	Read from std input */
		nofile = 1;
		break;

	    case 't':		/* -t	Read one line from input */
		onelflg = 2;
		prompt = 0;
		nofile = 1;
		break;

	    case 'v':		/* -v	Echo hist expanded input */
		nverbose = 1;	/* ... later */
		break;

	    case 'x':		/* -x	Echo just before execution */
		nexececho = 1;	/* ... later */
		break;

	    case 'V':		/* -V	Echo hist expanded input */
		setNS(STRverbose);	/* NOW! */
		break;

	    case 'X':		/* -X	Echo just before execution */
		setNS(STRecho);	/* NOW! */
		break;

	    case 'F':		/* Undocumented flag */
		/*
		 * This will cause children to be created using fork instead of
		 * vfork.



( run in 3.281 seconds using v1.01-cache-2.11-cpan-d01c6094234 )