Use GECOS field a bit better to produce default human readable name.
This updates the default human readable name we generate from GECOS field. We assume the "full-name, followed by additional information separated by commas" format, with an & expanding to the capitalized login name. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 19, 2005 at 16:06 UTC
e9bacb4f6a6f0aae7270acb257977f9ee0bbd6db
1 file changed
+35
-4
ident.c
+35
-4
@@ -15,6 +15,40 @@ static char real_email[1000];
15
static char real_name[1000];
16
static char real_date[50];
17
18
+static void copy_gecos(struct passwd *w, char *name, int sz)
19
+{
20
+ char *src, *dst;
21
+ int len, nlen;
22
+
23
+ nlen = strlen(w->pw_name);
24
+
25
+ /* Traditionally GECOS field had office phone numbers etc, separated
26
+ * with commas. Also & stands for capitalized form of the login name.
27
+ */
28
+
29
+ for (len = 0, dst = name, src = w->pw_gecos; len < sz; src++) {
30
+ int ch = *src;
31
+ if (ch != '&') {
32
+ *dst++ = ch;
33
+ if (ch == 0 || ch == ',')
34
+ break;
35
+ len++;
36
+ continue;
37
+ }
38
+ if (len + nlen < sz) {
39
+ /* Sorry, Mr. McDonald... */
40
+ *dst++ = toupper(*w->pw_name);
41
+ memcpy(dst, w->pw_name + 1, nlen - 1);
42
+ dst += nlen - 1;
43
+ }
44
+ }
45
+ if (len < sz)
46
+ name[len] = 0;
47
+ else
48
+ die("Your parents must have hated you!");
49
+
50
+}
51
+
52
int setup_ident(void)
53
{
54
int len;
@@ -24,10 +58,7 @@ int setup_ident(void)
58
die("You don't exist. Go away!");
59
60
/* Get the name ("gecos") */
27
- len = strlen(pw->pw_gecos);
28
- if (len >= sizeof(real_name))
29
- die("Your parents must have hated you!");
30
- memcpy(real_name, pw->pw_gecos, len+1);
61
+ copy_gecos(pw, real_name, sizeof(real_name));
62
63
/* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */
64
len = strlen(pw->pw_name);