1 | /*
|
---|
2 | * COMMDLG - File Dialogs
|
---|
3 | *
|
---|
4 | * Copyright 1994 Martin Ayotte
|
---|
5 | * Copyright 1996 Albrecht Kleine
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include <string.h>
|
---|
9 |
|
---|
10 | #include "wine/winestring.h"
|
---|
11 | #include "winbase.h"
|
---|
12 | #include "commdlg.h"
|
---|
13 | #include "debugtools.h"
|
---|
14 |
|
---|
15 | #include "heap.h" /* Has to go */
|
---|
16 |
|
---|
17 | DEFAULT_DEBUG_CHANNEL(commdlg)
|
---|
18 |
|
---|
19 | #include "cdlg.h"
|
---|
20 |
|
---|
21 | /***********************************************************************
|
---|
22 | * GetFileTitleA (COMDLG32.8)
|
---|
23 | *
|
---|
24 | */
|
---|
25 | short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
|
---|
26 | {
|
---|
27 | int i, len;
|
---|
28 |
|
---|
29 | TRACE("(%p %p %d); \n", lpFile, lpTitle, cbBuf);
|
---|
30 |
|
---|
31 | if(lpFile == NULL || lpTitle == NULL)
|
---|
32 | return -1;
|
---|
33 |
|
---|
34 | len = strlen(lpFile);
|
---|
35 |
|
---|
36 | if (len == 0)
|
---|
37 | return -1;
|
---|
38 |
|
---|
39 | if(strpbrk(lpFile, "*[]"))
|
---|
40 | return -1;
|
---|
41 |
|
---|
42 | len--;
|
---|
43 |
|
---|
44 | if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
|
---|
45 | return -1;
|
---|
46 |
|
---|
47 | for(i = len; i >= 0; i--)
|
---|
48 | {
|
---|
49 | if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
|
---|
50 | {
|
---|
51 | i++;
|
---|
52 | break;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | if(i == -1)
|
---|
57 | i++;
|
---|
58 |
|
---|
59 | TRACE("---> '%s' \n", &lpFile[i]);
|
---|
60 |
|
---|
61 | len = strlen(lpFile+i)+1;
|
---|
62 | if(cbBuf < len)
|
---|
63 | return len;
|
---|
64 |
|
---|
65 | strncpy(lpTitle, &lpFile[i], len);
|
---|
66 | return 0;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /***********************************************************************
|
---|
71 | * GetFileTitleW (COMDLG32.9)
|
---|
72 | *
|
---|
73 | */
|
---|
74 | short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, UINT cbBuf)
|
---|
75 | {
|
---|
76 | LPSTR file = HEAP_strdupWtoA(GetProcessHeap(), 0, lpFile); /* Has to go */
|
---|
77 | LPSTR title = HeapAlloc(GetProcessHeap(), 0, cbBuf);
|
---|
78 | short ret;
|
---|
79 |
|
---|
80 | ret = GetFileTitleA(file, title, cbBuf);
|
---|
81 |
|
---|
82 | lstrcpynAtoW(lpTitle, title, cbBuf);
|
---|
83 | HeapFree(GetProcessHeap(), 0, file);
|
---|
84 | HeapFree(GetProcessHeap(), 0, title);
|
---|
85 | return ret;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | #ifndef __WIN32OS2__
|
---|
90 | /***********************************************************************
|
---|
91 | * GetFileTitle16 (COMMDLG.27)
|
---|
92 | */
|
---|
93 | short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
|
---|
94 | {
|
---|
95 | return GetFileTitleA(lpFile, lpTitle, cbBuf);
|
---|
96 | }
|
---|
97 | #endif
|
---|
98 |
|
---|