aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-12-08 08:20:50 +0000
committerRichard M. Stallman1996-12-08 08:20:50 +0000
commit3415b0e9d2a78e212ba7eb77e720a1862d4f943b (patch)
tree1a8941b2fc596a3cb956359777c78823855cae2b /src
parente98bcc1abdfdeacb3171d1488000f8e22d3edb33 (diff)
downloademacs-3415b0e9d2a78e212ba7eb77e720a1862d4f943b.tar.gz
emacs-3415b0e9d2a78e212ba7eb77e720a1862d4f943b.zip
(Fuser_full_name): Accept a string (the login name) as
a parameter. Do ampersand expansion, if required. (init_editfns): Use it.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c73
1 files changed, 44 insertions, 29 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 699cadc6046..72c32afa34e 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -63,7 +63,6 @@ init_editfns ()
63 char *user_name; 63 char *user_name;
64 register unsigned char *p, *q, *r; 64 register unsigned char *p, *q, *r;
65 struct passwd *pw; /* password entry for the current user */ 65 struct passwd *pw; /* password entry for the current user */
66 extern char *index ();
67 Lisp_Object tem; 66 Lisp_Object tem;
68 67
69 /* Set up system_name even when dumping. */ 68 /* Set up system_name even when dumping. */
@@ -104,30 +103,9 @@ init_editfns ()
104 /* If the user name claimed in the environment vars differs from 103 /* If the user name claimed in the environment vars differs from
105 the real uid, use the claimed name to find the full name. */ 104 the real uid, use the claimed name to find the full name. */
106 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name); 105 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
107 if (NILP (tem)) 106 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid())
108 pw = (struct passwd *) getpwnam (XSTRING (Vuser_login_name)->data); 107 : Vuser_login_name);
109 108
110 p = (unsigned char *) (pw ? USER_FULL_NAME : "unknown");
111 q = (unsigned char *) index (p, ',');
112 Vuser_full_name = make_string (p, q ? q - p : strlen (p));
113
114#ifdef AMPERSAND_FULL_NAME
115 p = XSTRING (Vuser_full_name)->data;
116 q = (unsigned char *) index (p, '&');
117 /* Substitute the login name for the &, upcasing the first character. */
118 if (q)
119 {
120 r = (unsigned char *) alloca (strlen (p)
121 + XSTRING (Vuser_login_name)->size + 1);
122 bcopy (p, r, q - p);
123 r[q - p] = 0;
124 strcat (r, XSTRING (Vuser_login_name)->data);
125 r[q - p] = UPCASE (r[q - p]);
126 strcat (r, q + 1);
127 Vuser_full_name = build_string (r);
128 }
129#endif /* AMPERSAND_FULL_NAME */
130
131 p = (unsigned char *) getenv ("NAME"); 109 p = (unsigned char *) getenv ("NAME");
132 if (p) 110 if (p)
133 Vuser_full_name = build_string (p); 111 Vuser_full_name = build_string (p);
@@ -586,18 +564,55 @@ DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0,
586DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 1, 0, 564DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 1, 0,
587 "Return the full name of the user logged in, as a string.\n\ 565 "Return the full name of the user logged in, as a string.\n\
588If optional argument UID is an integer, return the full name of the user\n\ 566If optional argument UID is an integer, return the full name of the user\n\
589with that uid, or nil if there is no such user.") 567with that uid, or \"unknown\" if there is no such user.
568If UID is a string, return the full name of the user with that login\n\
569name, or \"unknown\" if no such user could be found.")
590 (uid) 570 (uid)
591 Lisp_Object uid; 571 Lisp_Object uid;
592{ 572{
593 struct passwd *pw; 573 struct passwd *pw;
574 register char *p, *q;
575 extern char *index ();
576 Lisp_Object full;
594 577
595 if (NILP (uid)) 578 if (NILP (uid))
596 return Vuser_full_name; 579 return Vuser_full_name;
580 else if (NUMBERP (uid))
581 pw = (struct passwd *) getpwuid (XINT (uid));
582 else if (STRINGP (uid))
583 pw = (struct passwd *) getpwnam (XSTRING (uid)->data);
584 else
585 error ("Invalid UID specification");
597 586
598 CHECK_NUMBER (uid, 0); 587 if (!pw)
599 pw = (struct passwd *) getpwuid (XINT (uid)); 588 return make_string ("unknown");
600 return (pw ? build_string (pw->pw_gecos) : Qnil); 589
590 p = (unsigned char *) USER_FULL_NAME;
591 /* Chop off everything after the first comma. */
592 q = (unsigned char *) index (p, ',');
593 full = make_string (p, q ? q - p : strlen (p));
594
595#ifdef AMPERSAND_FULL_NAME
596 p = XSTRING (full)->data;
597 q = (unsigned char *) index (p, '&');
598 /* Substitute the login name for the &, upcasing the first character. */
599 if (q)
600 {
601 register char *r;
602 Lisp_Object login;
603
604 login = Fuser_login_name (make_number (pw->pw_uid));
605 r = (unsigned char *) alloca (strlen (p) + XSTRING (login)->size + 1);
606 bcopy (p, r, q - p);
607 r[q - p] = 0;
608 strcat (r, XSTRING (login)->data);
609 r[q - p] = UPCASE (r[q - p]);
610 strcat (r, q + 1);
611 full = build_string (r);
612 }
613#endif /* AMPERSAND_FULL_NAME */
614
615 return full;
601} 616}
602 617
603DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0, 618DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,