home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2290 / login.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.1 KB  |  68 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <ctype.h>
  11. #ifndef    BSD
  12. #include <string.h>
  13. #include <memory.h>
  14. #else
  15. #include <strings.h>
  16. #define    strchr    index
  17. #define    strrchr    rindex
  18. #endif
  19.  
  20. #ifndef    lint
  21. static    char    sccsid[] = "@(#)login.c    2.3    19:23:55    7/29/90";
  22. #endif
  23.  
  24. void    setenv ();
  25.  
  26. void    login (name)
  27. char    *name;
  28. {
  29.     char    buf[BUFSIZ];
  30.     char    *envp[32];
  31.     int    envc;
  32.     char    *cp;
  33.     int    i;
  34.  
  35. #ifndef    BSD
  36.     (void) memset (buf, '\0', sizeof buf);
  37. #else
  38.     bzero (buf, sizeof buf);
  39. #endif
  40.     fputs ("login: ", stdout);
  41.  
  42.     if (fgets (buf, BUFSIZ, stdin) != buf)
  43.         exit (1);
  44.  
  45.     buf[strlen (buf) - 1] = '\0';    /* remove \n [ must be there ] */
  46.  
  47.     for (cp = buf;*cp == ' ' || *cp == '\t';cp++)
  48.         ;
  49.  
  50.     for (i = 0;i < BUFSIZ - 1 && isgraph (*cp);name[i++] = *cp++)
  51.         ;
  52.  
  53.     if (*cp)
  54.         cp++;
  55.  
  56.     name[i] = '\0';
  57.  
  58.     if (*cp != '\0') {        /* process new variables */
  59.         for (envc = 0;envc < 32;envc++) {
  60.             envp[envc] = strtok (envc == 0 ? cp:(char *) 0, " \t,");
  61.  
  62.             if (envp[envc] == (char *) 0)
  63.                 break;
  64.         }
  65.         setenv (envc, envp);
  66.     }
  67. }
  68.