home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / elm-2.4-pl20.tar.Z / elm-2.4-pl20.tar / lib / gcos_name.c < prev    next >
C/C++ Source or Header  |  1992-10-03  |  2KB  |  96 lines

  1. static char rcsid[] = "@(#)$Id: gcos_name.c,v 5.1 1992/10/03 22:41:36 syd Exp $";
  2.  
  3. /*******************************************************************************
  4.  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
  5.  *
  6.  *            Copyright (c) 1988-1992 USENET Community Trust
  7.  *            Copyright (c) 1986,1987 Dave Taylor
  8.  *******************************************************************************
  9.  * Bug reports, patches, comments, suggestions should be sent to:
  10.  *
  11.  *    Syd Weinstein, Elm Coordinator
  12.  *    elm@DSI.COM            dsinc!elm
  13.  *
  14.  *******************************************************************************
  15.  * $Log: gcos_name.c,v $
  16.  * Revision 5.1  1992/10/03  22:41:36  syd
  17.  * Initial checkin as of 2.4 Release at PL0
  18.  *
  19.  *
  20.  ******************************************************************************/
  21.  
  22. /** 
  23.  
  24. **/
  25.  
  26. #include "headers.h"
  27. #include <ctype.h>
  28.  
  29. #ifdef BSD 
  30. #undef tolower
  31. #undef toupper
  32. #endif
  33.  
  34. char *strtok(), *strcpy(), *strcat(), *strncpy(), *index(), *rindex();
  35.  
  36. char *
  37. gcos_name(gcos_field, logname)
  38. char *logname, *gcos_field;
  39. {
  40.     /** Return the full name found in a passwd file gcos field **/
  41.  
  42. #ifdef BERKNAMES
  43.  
  44.     static char fullname[SLEN];
  45.     register char *fncp, *gcoscp, *lncp, *end;
  46.  
  47.  
  48.     /* full name is all chars up to first ',' (or whole gcos, if no ',') */
  49.     /* replace any & with logname in upper case */
  50.  
  51.     for(fncp = fullname, gcoscp= gcos_field, end = fullname + SLEN - 1;
  52.         (*gcoscp != ',' && *gcoscp != '\0' && fncp != end);
  53.     gcoscp++) {
  54.  
  55.     if(*gcoscp == '&') {
  56.         for(lncp = logname; *lncp; fncp++, lncp++)
  57.         *fncp = toupper(*lncp);
  58.     } else {
  59.         *fncp++ = *gcoscp;
  60.     }
  61.     }
  62.     
  63.     *fncp = '\0';
  64.     return(fullname);
  65. #else
  66. #ifdef USGNAMES
  67.  
  68.     char *firstcp, *lastcp;
  69.  
  70.     /* The last character of the full name is the one preceding the first
  71.      * '('. If there is no '(', then the full name ends at the end of the
  72.      * gcos field.
  73.      */
  74.     if(lastcp = index(gcos_field, '('))
  75.     *lastcp = '\0';
  76.  
  77.     /* The first character of the full name is the one following the 
  78.      * last '-' before that ending character. NOTE: that's why we
  79.      * establish the ending character first!
  80.      * If there is no '-' before the ending character, then the fullname
  81.      * begins at the beginning of the gcos field.
  82.      */
  83.     if(firstcp = rindex(gcos_field, '-'))
  84.     firstcp++;
  85.     else
  86.     firstcp = gcos_field;
  87.  
  88.     return(firstcp);
  89.  
  90. #else
  91.     /* use full gcos field */
  92.     return(gcos_field);
  93. #endif
  94. #endif
  95. }
  96.