home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / net / nsh.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  66 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. # include "defs.h"
  3. /*
  4.     count is the # of arguments (= argc) allowed.
  5.     a count of 0 turns off the command */
  6. /* should get route # of Cory RCS lpr */
  7. struct {
  8.     char *app;
  9.     char count;
  10.     char *full;
  11.     char *full1;
  12.     } st[] = {
  13.     "finger",    20,    "/usr/new/finger",    "/usr/bin/finger",
  14.     "lpq",        20,    "/usr/bin/lpq",        "/bin/lpq",
  15.     "mmail",    20,    "/usr/net/bin/mmail",    "/usr/net/bin/mmail",
  16.     "mwrite",    20,    "/usr/net/bin/mwrite",    "/usr/net/bin/mwrite",
  17.     "netq",        20,    "/usr/bin/netq",    "/usr/new/netq",
  18.     "ps",        20,    "/bin/ps",        "/usr/bin/ps",
  19.     "pstat",    20,    "/usr/bin/pstat",    "/bin/pstat",
  20.     "rcs",        20,    "/usr/bin/rcs",        "/bin/rcs",
  21.     "rcslog",    1,    "/usr/bin/rcslog",    "/bin/rcslog",
  22.     "rcsq",        20,    "/usr/bin/rcsq",    "/bin/rcsq",
  23.     "trq",        20,    "/usr/bin/trq",        "/bin/trq",
  24.     "w",        20,    "/usr/bin/w",        "/bin/w",
  25.     "where",    20,    "/usr/bin/where",    "/bin/where",
  26.     "who",        20,    "/bin/who",        "/usr/bin/who",
  27.     "whom",        20,    "/usr/new/whom",    "/usr/bin/whom",
  28.     "write",    20,    "/usr/bin/write",    "/bin/write",
  29.     "yank",        20,    "/usr/new/yank",    "/usr/bin/yank",
  30.     0,         0,        0,        0
  31.     };
  32. /* nsh -c cmd */
  33. main(argc,argv)
  34.   char **argv; {
  35.     char *s, buf[500];
  36.     int i, flg = 0;
  37.     if(argc != 3)exit(8);
  38.     s = argv[2];
  39.     while(*s && *s != ' ')s++;
  40.     if(*s == ' ')flg++;
  41.     *s = 0;
  42.     if((i = mlookup(argv[2])) >= 0){
  43.         if(st[i].count == 0)exit(9);
  44.         if(stat(st[i].full,buf) >= 0)
  45.             strcpy(buf,st[i].full);
  46.         else strcpy(buf,st[i].full1);
  47.         if(flg && st[i].count > 1){  /* some cmds don't allow parms */
  48.             *s = ' ';
  49.             strcat(buf,s);
  50.             }
  51.         /*
  52.         fprintf(stderr,"%s\n",buf);
  53.         */
  54.         execl(Bsh,"sh","-c",buf,0);
  55.         }
  56.     exit(10);
  57.     }
  58. mlookup(s)
  59.   char *s; {
  60.     int i;
  61.     for(i = 0; st[i].app; i++)
  62.         if(strcmp(st[i].app,s) == 0 || strcmp(st[i].full,s) == 0
  63.          || strcmp(st[i].full1,s) == 0)return(i);
  64.     return(-1);
  65.     }
  66.