1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: $
|
---|
5 |
|
---|
6 | Path handling utility functions
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2001, 2008 Steven H. Levine
|
---|
10 |
|
---|
11 | 05 Jan 08 SHL Move from arccnrs.c and comp.c to here
|
---|
12 |
|
---|
13 | ***********************************************************************/
|
---|
14 |
|
---|
15 | #include <string.h>
|
---|
16 |
|
---|
17 | #define INCL_WIN
|
---|
18 | #define INCL_LONGLONG
|
---|
19 |
|
---|
20 | #include "pathutil.h"
|
---|
21 | #include "fm3dll.h" // needs_quoting
|
---|
22 |
|
---|
23 | // #pragma data_seg(DATA1)
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Build full path name in callers buffer given directory
|
---|
27 | * name and filename
|
---|
28 | * @param pszPathName points to drive/directory if not NULL
|
---|
29 | * @returns pointer to full path name in caller's buffer
|
---|
30 | * @note OK for pszFullPathName and pszPathName to point to same buffer
|
---|
31 | *
|
---|
32 | */
|
---|
33 |
|
---|
34 | PSZ BldFullPathName(PSZ pszFullPathName, PSZ pszPathName, PSZ pszFileName)
|
---|
35 | {
|
---|
36 | UINT c = pszPathName ? strlen(pszPathName) : 0;
|
---|
37 | if (c > 0) {
|
---|
38 | memcpy(pszFullPathName, pszPathName, c);
|
---|
39 | if (pszFullPathName[c - 1] != '\\')
|
---|
40 | pszFullPathName[c++] = '\\';
|
---|
41 | }
|
---|
42 | strcpy(pszFullPathName + c, pszFileName);
|
---|
43 | return pszFullPathName;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Build quoted full path name in callers buffer given
|
---|
48 | * directory name and filename
|
---|
49 | * @param pszPathName points to drive/directory if not NULL
|
---|
50 | * @returns pointer to quoted path name in caller's buffer
|
---|
51 | */
|
---|
52 |
|
---|
53 | PSZ BldQuotedFullPathName(PSZ pszFullPathName, PSZ pszPathName, PSZ pszFileName)
|
---|
54 | {
|
---|
55 | UINT c = pszPathName ? strlen(pszPathName) : 0;
|
---|
56 | BOOL q = needs_quoting(pszPathName) ||
|
---|
57 | needs_quoting(pszFileName);
|
---|
58 | PSZ psz = pszFullPathName;
|
---|
59 |
|
---|
60 | if (q)
|
---|
61 | *psz++ = '"';
|
---|
62 | if (c > 0) {
|
---|
63 | memcpy(psz, pszPathName, c);
|
---|
64 | psz += c;
|
---|
65 | if (*(psz - 1) != '\\')
|
---|
66 | *psz++ = '\\';
|
---|
67 | }
|
---|
68 | strcpy(psz, pszFileName);
|
---|
69 | if (q) {
|
---|
70 | psz += strlen(psz);
|
---|
71 | *psz++ = '"';
|
---|
72 | *psz = 0;
|
---|
73 | }
|
---|
74 | return pszFullPathName;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Build quoted full path name in callers buffer given a filename
|
---|
79 | * @returns pointer to quoted file name in caller's buffer
|
---|
80 | */
|
---|
81 |
|
---|
82 | PSZ BldQuotedFileName(PSZ pszQuotedFileName, PSZ pszFileName)
|
---|
83 | {
|
---|
84 | BOOL q = needs_quoting(pszFileName);
|
---|
85 | PSZ psz = pszQuotedFileName;
|
---|
86 |
|
---|
87 | if (q)
|
---|
88 | *psz++ = '"';
|
---|
89 | strcpy(psz, pszFileName);
|
---|
90 | if (q) {
|
---|
91 | psz += strlen(psz);
|
---|
92 | *psz++ = '"';
|
---|
93 | *psz = 0;
|
---|
94 | }
|
---|
95 | return pszQuotedFileName;
|
---|
96 | }
|
---|
97 |
|
---|
98 | #pragma alloc_text(PATHUTIL,BldFullPathName)
|
---|
99 | #pragma alloc_text(PATHUTIL,BldQuotedFileName)
|
---|
100 | #pragma alloc_text(PATHUTIL,BldQuotedFullPathName)
|
---|