home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume38 / menushell / part03 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-30  |  1.8 KB  |  107 lines

  1. /*
  2.  * Mshell
  3.  *
  4.  * A menu shell.
  5.  *
  6.  * Copyright 1991 by Andrew Burt and the University of Denver.
  7.  */
  8. #include "mshell.h"
  9.  
  10. char     G_homevar      [] = { "$HOME" };
  11. char     G_uservar      [] = { "$USER" };
  12. char      G_termvar      [] = { "$TERM" };
  13. char     G_mailfile     [WORDLEN];
  14. char     G_mail_message [WORDLEN];
  15. int      G_mailsize; 
  16. struct   stat G_st;
  17. int     G_shell_ok;
  18. int     G_limited = FALSE;
  19.  
  20. main (argc, argv)
  21. int     argc;
  22. char ** argv;
  23.  
  24. {
  25.     char menu[WORDLEN];
  26.     char menuname[WORDLEN];
  27.     char *progname = argv[0];
  28.  
  29.     G_shell_ok = TRUE;
  30.     if ( argc > 1 && strcmp(argv[1], "-s") == 0 ) {
  31.         G_shell_ok = FALSE;
  32.         argc--;
  33.         argv++;
  34.     }
  35.     else if ( argc > 1 && strcmp(argv[1], "-r") == 0 ) {
  36.         G_limited = TRUE;
  37.         G_shell_ok = FALSE;
  38.         argc--;
  39.         argv++;
  40.     }
  41.  
  42.     if ( argc < 2 ) {
  43.         printf ("Usage: %s <primary menu name>\n", progname);
  44.         exit (1);
  45.     }
  46.  
  47.     strcpy ( G_mailfile, MAILDIR );
  48.     strcat ( G_mailfile, getenv(&G_uservar[1]) );
  49.     G_mail_message[0] = EOS;
  50.  
  51.     stat ( G_mailfile, &G_st );
  52.     G_mailsize = G_st.st_size;
  53.     if (G_mailsize > 0)
  54.         strcpy(G_mail_message, "    [You have mail.]");
  55.     else
  56.         G_mail_message[0] = EOS;
  57.  
  58. #ifdef check_parent
  59.     if ( getppid() == 1 )            /* Mshell is login shell */
  60. #endif
  61.         set_terminal_attributes();
  62.     set_resource_limits();
  63.  
  64.     rc();
  65.     openlog();
  66.     load_macrofile(GLOBAL_MACRO_FILE);
  67.     load_macrofile(".mshellmac");
  68.  
  69.     M_Shell (argv[1]);
  70.     bye(0);
  71. }
  72.  
  73. rc()
  74. {
  75.     if (!G_shell_ok)
  76.         return;
  77.  
  78.     if (access(".mshellrc", 0) == -1)    /* assumedly now in home dir */
  79.         return;
  80.  
  81.     system("sh .mshellrc");
  82. }
  83.  
  84. #ifndef LOGDIR
  85. #define LOGDIR "/u1/logs"
  86. #endif
  87.  
  88. FILE *logfp;
  89. openlog()
  90. {
  91.     struct passwd *pw;
  92.     char fn[32];
  93.  
  94.     if ((pw = getpwuid(getuid())) == NULL)
  95.         return;
  96.     sprintf(fn, "%s/%s", LOGDIR, pw->pw_name);
  97.     logfp = fopen(fn, "a");
  98.     chmod(fn, 0600);
  99. }
  100.  
  101. log(s1, s2)
  102. char *s1, *s2;
  103. {
  104.     if (logfp)
  105.         fprintf(logfp, "%s %s\n", s1, s2);
  106. }
  107.