Quizzer

 view release on metacpan or  search on metacpan

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

     * Publish the selected echo style
     */
#if ECHO_STYLE == NONE_ECHO
    set(STRecho_style, Strsave(STRnone), VAR_READWRITE);
#endif /* ECHO_STYLE == NONE_ECHO */
#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.



( run in 1.351 second using v1.01-cache-2.11-cpan-b16cb0d3907 )