comparison os2/dw.c @ 1381:3ba4853d5b78

Initial attempt at dw_app_dir() for OS/2, Windows and Mac... This function will return the best attempt at determining the application data directory for the current platform. The executable directory on OS/2 or Windows. The application bundle directory on Mac. The "share" folder at the same level as the binary (or /usr/local/share if that can't be determined) plus the binary name on Unix.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 25 Nov 2011 17:36:59 +0000
parents b6249d66404c
children 3eedfd4f7c5d
comparison
equal deleted inserted replaced
1380:cc66b6d4b74e 1381:3ba4853d5b78
65 DWTID _dwtid = 0; 65 DWTID _dwtid = 0;
66 LONG _foreground = 0xAAAAAA, _background = DW_CLR_DEFAULT; 66 LONG _foreground = 0xAAAAAA, _background = DW_CLR_DEFAULT;
67 67
68 HWND hwndApp = NULLHANDLE, hwndBubble = NULLHANDLE, hwndBubbleLast = NULLHANDLE, hwndEmph = NULLHANDLE; 68 HWND hwndApp = NULLHANDLE, hwndBubble = NULLHANDLE, hwndBubbleLast = NULLHANDLE, hwndEmph = NULLHANDLE;
69 HWND hwndTrayServer = NULLHANDLE, hwndTaskBar = NULLHANDLE; 69 HWND hwndTrayServer = NULLHANDLE, hwndTaskBar = NULLHANDLE;
70 ; 70
71 PRECORDCORE pCoreEmph = NULL; 71 PRECORDCORE pCoreEmph = NULL;
72 ULONG aulBuffer[4]; 72 ULONG aulBuffer[4];
73 HWND lasthcnr = 0, lastitem = 0, popup = 0, desktop; 73 HWND lasthcnr = 0, lastitem = 0, popup = 0, desktop;
74 HMOD wpconfig = 0, pmprintf = 0; 74 HMOD wpconfig = 0, pmprintf = 0;
75 static char _dw_exec_dir[MAX_PATH+1] = {0};
75 76
76 unsigned long _colors[] = { 77 unsigned long _colors[] = {
77 CLR_BLACK, 78 CLR_BLACK,
78 CLR_DARKRED, 79 CLR_DARKRED,
79 CLR_DARKGREEN, 80 CLR_DARKGREEN,
3983 int API dw_init(int newthread, int argc, char *argv[]) 3984 int API dw_init(int newthread, int argc, char *argv[])
3984 { 3985 {
3985 APIRET rc; 3986 APIRET rc;
3986 char objnamebuf[300] = ""; 3987 char objnamebuf[300] = "";
3987 3988
3988 argc = argc; /* keep compiler happy */ 3989 /* Setup the private data directory */
3989 argv = argv; /* keep compiler happy */ 3990 if(argc > 0 && argv[0])
3991 {
3992 char *pos = strrchr(argv[0], '\\');
3993
3994 /* Just to be safe try the unix style */
3995 if(!pos)
3996 pos = strrchr(argv[0], '/');
3997
3998 if(pos)
3999 strncpy(_dw_exec_dir, argv[0], (size_t)(pos - argv[0]));
4000 }
4001 /* If that failed... just get the current directory */
4002 if(!_dw_exec_dir[0])
4003 _getcwd(_dw_exec_dir, MAX_PATH);
4004
3990 if(newthread) 4005 if(newthread)
3991 { 4006 {
3992 dwhab = WinInitialize(0); 4007 dwhab = WinInitialize(0);
3993 dwhmq = WinCreateMsgQueue(dwhab, 0); 4008 dwhmq = WinCreateMsgQueue(dwhab, 0);
3994 } 4009 }
11133 * current user directory. Or the root directory (C:\ on 11148 * current user directory. Or the root directory (C:\ on
11134 * OS/2 and Windows). 11149 * OS/2 and Windows).
11135 */ 11150 */
11136 char * API dw_user_dir(void) 11151 char * API dw_user_dir(void)
11137 { 11152 {
11138 static char _user_dir[1024] = ""; 11153 static char _user_dir[MAX_PATH+1] = {0};
11139 11154
11140 if(!_user_dir[0]) 11155 if(!_user_dir[0])
11141 { 11156 {
11142 char *home = getenv("HOME"); 11157 char *home = getenv("HOME");
11143 11158
11145 strcpy(_user_dir, home); 11160 strcpy(_user_dir, home);
11146 else 11161 else
11147 strcpy(_user_dir, "C:\\"); 11162 strcpy(_user_dir, "C:\\");
11148 } 11163 }
11149 return _user_dir; 11164 return _user_dir;
11165 }
11166
11167 /*
11168 * Returns a pointer to a static buffer which containes the
11169 * private application data directory.
11170 */
11171 char *dw_app_dir(void)
11172 {
11173 return _dw_exec_dir;
11150 } 11174 }
11151 11175
11152 /* 11176 /*
11153 * Call a function from the window (widget)'s context. 11177 * Call a function from the window (widget)'s context.
11154 * Parameters: 11178 * Parameters: