]> git.lyx.org Git - lyx.git/blob - src/support/userinfo.cpp
Account for old versions of Pygments
[lyx.git] / src / support / userinfo.cpp
1 /**
2  * \file userinfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/userinfo.h"
14 #include "support/environment.h"
15 #include "support/docstring.h"
16
17 #include "support/lassert.h"
18
19 #if defined (_WIN32)
20 # include "support/gettext.h"
21 # include <windows.h>
22 # include <lmcons.h>
23 #else
24 # include <pwd.h>
25 # ifdef HAVE_UNISTD_H
26 #  include <unistd.h>
27 # endif
28 #endif
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32
33 using namespace std;
34
35 namespace lyx {
36 namespace support {
37
38 docstring const user_name()
39 {
40 #if defined (_WIN32)
41
42         char name[UNLEN + 1];
43         DWORD size = UNLEN + 1;
44         if (!GetUserName(name, &size))
45                 return _("Unknown user");
46         return from_local8bit(name);
47 #else
48         struct passwd * pw = getpwuid(geteuid());
49         LASSERT(pw, return docstring());
50
51         const string gecos = pw->pw_gecos;
52         const size_t pos = gecos.find(",");
53         string name = gecos.substr(0, pos);
54         if (name.empty())
55                 name = pw->pw_name;
56         return from_local8bit(name);
57 #endif
58 }
59
60
61 docstring const user_email()
62 {
63         //FIXME: quick fix wrt bug #3764; only Anonymous is detected now.
64         //The code after should be used only after user approval.
65         return docstring();
66
67 #if 0
68         string email = getEnv("EMAIL_ADDRESS");
69         if (email.empty())
70                 email = getEnv("EMAIL");
71         return from_local8bit(email);
72 #endif
73 }
74
75 } // namespace support
76 } // namespace lyx