🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.folklore.computers
Article #1414

emacs as login shell

#1414
From: gu... David Vinayak Wallace
Date: Mon, 19 Feb 1990 10:05
147 lines
6283 bytes
   Date: 16 Feb 90 22:33:37 GMT
   From: r...@think.com (Robert Krawitz)

   One former prep[.ai.mit.edu]pie told me that he set up emacs as his
   login shell a while back.  Dunno if he still uses it...

Actually, I used the program below.  It let you win even if the tty
was too feeble to run emacs.  The only change between then and now is
that I added everything between the -*- line and the 30 dashes.  

Compile this, change your entry in the passwd file, and do
ln -s `which emacs` ~/.emacs-binary.  Use it in good health.

/*                         -*- Mode: c -*-

  boot-emacs.c -- program to use as your `shell' which trampolines emacs

  Copyright 1984 David Vinayak Wallace.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 1, or (at your option)
  any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  Contact the author if you need a copy of the license, at
  gu...@cygnus.com.

		    ------------------------------

  Help us use emacs standalone.  If TERM is defined in the
  environment, make sure it's powerful enough to run EMACS.  If not,
  ask the user for a new terminal type.  Then exec the program
  ~/.emacs-binary.  Why that?
  1> so I can run this program at J Random Site, and
  2> If anything goes wrong I can delete that file.

  If anything goes wrong (or the user supplies a blank line when asked
  for a tty type), then the program loads /bin/csh.

  Don't worry about initialising the tty -- emacs should do it.
  I don't know if this will run under anything but 4.2BSD.

*/

#include <stdio.h>

/* There's no way to know in a general way what sort of terminal EMACS
   will accept, but we can catch cases we know about */

#define TTY_GOOD 0              /* TTY fine for EMACS */
#define NONE_SET 1              /* no TTY set at all */
#define NO_ENTRY 2              /* TTY unknown to termcap */
#define TOO_WEAK 3              /* TTY not powerful enough */
#define TTY_IS_X 4              /* TTY claimed to be under X */

tty_ok_p (terminal_type)
     char *terminal_type;
{
  char tbuf[2044];              /* Termcap entry buffer */
 
  /* has c no cond? */
  if (!terminal_type) return(NONE_SET);
  if (!strncmp(terminal_type, "xterm", 5)) return(TTY_IS_X);
  if (!strncmp(terminal_type, "supdup", 6)) return(TTY_GOOD);
  if (!strncmp(terminal_type, "network", 7)) return(TOO_WEAK);
  if (tgetent (tbuf, terminal_type) <= 0) return(NO_ENTRY);
  return(TTY_GOOD);
}

/* Like execle, but if dash_p is true the program will be given a dash before its name.
   This is how unix indicates that you are the head of a tree (!) */

p_replace (file_name, program_name, dash_p, envp)
     char **file_name;
     char **program_name;
     int dash_p;
     char **envp;
{
  char name[40];

  sprintf(name,(dash_p ? "-%s" : "%s"), program_name);
  execle(file_name, name, 0, envp);
}

/* This program is a mass of magic numbers.  So be it.  It's not
   general anyway; if you want to do it right you'll have to re-write
   it completely. */

main (argc, argv, envp)
     int argc;
     char **argv;
     char **envp;
{
  char name_buf[257];           /* max unix filename is 256, right? */
  char initial, c;
  char ttyname[100];
  char ttyenv[106];             /* for the new TERM=type string */
  int  ttystat;                 /* temp for while loop */
  char **ep;                    /* ptr into envp for hacking TERM */

  for ( ep=envp ; *ep; ep++)
    if (strncmp (*ep, "TERM=", 5) == 0)
      break;
  if (!*ep)
    /* The first time this hits me I'm gonna scream and curse the
       twit who failed to write this in a more general manner.  Then
       I'll fix it.  Until then I'll assume it won't happen. */
    fprintf(stderr, "TERM not defined in environment.  ");
  else
    {
      strcpy(ttyname,(*ep)+5);
      while (*ttyname &&
             ((ttystat=tty_ok_p(ttyname)) != TTY_GOOD) &&
             (ttystat != TTY_IS_X))
        {
          if (ttystat == NO_ENTRY) fprintf(stderr, "Terminal %s unknown.\n",
                                           ttyname);
          if (ttystat == TOO_WEAK) fprintf(stderr, "Terminal %s is too weak for EMACS.\n",
                                           ttyname);
          /* Were I paranoid I'd use fgets to avoid buffer overflow */
          fputs("What is your terminal type: ", stderr);
          gets(ttyname);
        }
      if (!*ttyname)
        fprintf(stderr, "Null terminal specified.  ");
      else        
        {
          sprintf(ttyenv, "TERM=%s", ttyname);
          *ep=ttyenv;

          sprintf(name_buf,"%s%s",getenv("HOME"),"/.emacs-binary");
          p_replace(name_buf, "emacs", (*argv[0] == '-'), envp);
          fprintf(stderr, "Can't map %s.  ", name_buf);
        }
    }

  /* Something wrong?  Fall back on /bin/csh */

  fprintf(stderr, "Loading /bin/csh...\n");
  p_replace("/bin/csh", "csh", (*argv[0] == '-'), envp);
}
Technical Details
Message-ID: <GUMBY.90Feb19020542@Gang-of-Four.Stanford.EDU>
Path: mbox-mo1.pugleaf.net!gmdzi!unido!mcsun!uunet!ns-mx!iowasp!ceres!zaphod.mps.ohio-state.edu!wuarchive!decwrl!shelby!neon!neon!gumby
References: <1990Feb14.230018.14983@chinet.chi.il.us> <21743@unix.cis.pitt.edu> <4504@rtech.rtech.com> <51073@bbn.COM> <6194@sdcc6.ucsd.edu> <4534@amelia.nas.nasa.gov> <2878@paperbo <1990Feb13.031811.3909@world.std.com> <15954@haddock.ima.isc.com> <34060@news.Thi

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!gmdzi!unido!mcsun!uunet!ns-mx!iowasp!ceres!zaphod.mps.ohio-state.edu!wuarchive!decwrl!shelby!neon!neon!gumby
From: gu...@Gang-of-Four.Stanford.EDU (David Vinayak Wallace)
Newsgroups: alt.folklore.computers
Subject: emacs as login shell
Message-ID: <GUMBY.90Feb19020542@Gang-of-Four.Stanford.EDU>
Date: 19 Feb 90 10:05:42 GMT
References: <1990Feb14.230018.14983@chinet.chi.il.us> <21743@unix.cis.pitt.edu> <4504@rtech.rtech.com> <51073@bbn.COM> <6194@sdcc6.ucsd.edu> <4534@amelia.nas.nasa.gov> <2878@paperbo <1990Feb13.031811.3909@world.std.com> <15954@haddock.ima.isc.com> <34060@news.Thi
Sender: ro...@Neon.Stanford.EDU (System PRIVILEGED Account)
Organization: Computer Science Department, Stanford University
Lines: 147
Posted: Mon Feb 19 11:05:42 1990
In-Reply-To: rlk@think.com's message of 16 Feb 90 22:33:37 GMT
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit