]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
some white-space changes, enum changes because of ridance of definitions.h, block...
[lyx.git] / src / support / lyxlib.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright (C) 1995 Matthias Ettrich
8  *           Copyright (C) 1995-1999 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef LYX_LIB_H
13 #define LYX_LIB_H
14
15 #include <ctime>
16 #include <unistd.h>
17
18 #include "LString.h"
19 #include "gettext.h"
20 #include "support/filetools.h"
21
22 /// generates an checksum
23 unsigned long lyxsum(char const * file);
24
25 /// returns a date string
26 inline char * date() 
27 {
28         time_t tid;
29         if ((tid= time(0)) == (time_t)-1)
30                 return (char*)0;
31         else
32                 return (ctime(&tid));
33 }
34
35
36 // Where can I put this?  I found the occurence of the same code
37 // three/four times. Don't you think it better to use a macro definition
38 // (an inlined member of some class)?
39 ///
40 inline string getUserName()
41 {
42         string userName(GetEnv("LOGNAME"));
43         if (userName.empty())
44                 userName = GetEnv("USER");
45         if (userName.empty())
46                 userName = _("unknown");
47         return userName;
48 }
49
50 // This should have been a namespace
51 struct lyx {
52         static char * getcwd(char * buffer, size_t size) {
53 #ifndef __EMX__
54                 return ::getcwd(buffer, size);
55 #else
56                 return ::_getcwd2(buffer, size);
57 #endif
58         };
59         static int chdir(char const * name) {
60 #ifndef __EMX__
61                 return ::chdir(name);
62 #else
63                 return ::_chdir2(name);
64 #endif
65         };
66 };
67 #endif