annotate src/os_mac.c @ 9:4102fb4ea781 v7.0002

updated for version 7.0002
author vimboss
date Sun, 20 Jun 2004 12:51:53 +0000
parents 3fc0f57ecb91
children 631143ac4a01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * os_mac.c -- code for the MacOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * This file is mainly based on os_unix.c.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #if defined(__MRC__) || defined(__SC__) /* for Apple MPW Compilers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #include "StandardFile.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * Implements the corresponding unix function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 stat(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 char *p,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 struct stat *p_st)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 TODO: Use functions which fill the FileParam struct (Files.h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 and copy these contents to our self-defined stat struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 * change the current working directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 mch_chdir(char *p_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 #if defined(__MRC__) || defined(__SC__) /* for Apple MPW Compilers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 /* TODO */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 return chdir(p_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 * Recursively build up a list of files in "gap" matching the first wildcard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 * in `path'. Called by mch_expandpath().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 * "path" has backslashes before chars that are not to be expanded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 mac_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 int flags, /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 short start_at,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 short as_full)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 * TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 * +Get Volumes (when looking for files in current dir)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 * +Make it work when working dir not on select volume
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 * +Cleanup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 short index = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 OSErr gErr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 char_u dirname[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 char_u cfilename[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 long dirID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 char_u *new_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 CInfoPBRec gMyCPB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 HParamBlockRec gMyHPBlock;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 FSSpec usedDir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 char_u *p, *s, *e, dany;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 int start_len, c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 char_u *pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 start_len = gap->ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 buf = alloc(STRLEN(path) + BASENAMELEN + 5);/* make room for file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 * Find the first part in the path name that contains a wildcard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 * Copy it into buf, including the preceding characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 p = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 s = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 e = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 #if 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 STRNCPY(buf, path, start_at);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 p += start_at;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 path += start_at;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 while (*path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 if (*path == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 if (e)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 s = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 /* should use WILCARDLIST but what about ` */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 /* if (vim_strchr((char_u *)"*?[{~$", *path) != NULL)*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 else if (vim_strchr((char_u *)WILDCHAR_LIST, *path) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 int len = (*mb_ptr2len_check)(path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 STRNCPY(p, path, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 p += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 path += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 *p++ = *path++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 /* now we have one wildcard component between s and e */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 *e = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 #if 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 dany = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 *s = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 backslash_halve(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 *s = dany;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 /* convert the file pattern to a regexp pattern */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 if (pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 /* compile the regexp into a program */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 regmatch.rm_ic = FALSE; /* Don't ever ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 vim_free(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 if (regmatch.regprog == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 /* open the directory for scanning */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 c = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 *s = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 if (*buf == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 as_full = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 #if 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 (void) mch_dirname (&dirname[1], 254);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 dirname[0] = STRLEN(&dirname[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 if (*buf == ':') /* relative path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 (void)mch_dirname(&dirname[1], 254);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 new_name = concat_fnames(&dirname[1], buf+1, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 STRCPY(&dirname[1], new_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 dirname[0] = STRLEN(new_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 vim_free(new_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 STRCPY(&dirname[1], buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 backslash_halve(&dirname[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 dirname[0] = STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 *s = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 FSMakeFSSpec (0, 0, dirname, &usedDir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 gMyCPB.dirInfo.ioNamePtr = dirname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 gMyCPB.dirInfo.ioVRefNum = usedDir.vRefNum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 gMyCPB.dirInfo.ioFDirIndex = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 gMyCPB.dirInfo.ioDrDirID = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 gErr = PBGetCatInfo(&gMyCPB, false);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 gMyCPB.dirInfo.ioCompletion = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 dirID = gMyCPB.dirInfo.ioDrDirID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 gMyCPB.hFileInfo.ioFDirIndex = index;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 gMyCPB.hFileInfo.ioDirID = dirID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 gErr = PBGetCatInfo(&gMyCPB,false);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 if (gErr == noErr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 STRNCPY (cfilename, &dirname[1], dirname[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 cfilename[dirname[0]] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 if (vim_regexec(&regmatch, cfilename, (colnr_T)0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 if (s[-1] != ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 /* TODO: need to copy with cleaned name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 STRCPY(s+1, cfilename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 s[0] = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 { /* TODO: need to copy with cleeaned name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 STRCPY(s, cfilename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 start_at = STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 STRCAT(buf, path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 if (mch_has_exp_wildcard(path)) /* handle more wildcards */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 (void)mac_expandpath(gap, buf, flags, start_at, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 #ifdef DONT_ADD_PATHSEP_TO_DIR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 if ((gMyCPB.hFileInfo.ioFlAttrib & ioDirMask) !=0 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 STRCAT(buf, PATHSEPSTR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 addfile(gap, buf, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 if ((gMyCPB.hFileInfo.ioFlAttrib & ioDirMask) !=0 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 index++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 while (gErr == noErr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 if (as_full)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 index = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 gMyHPBlock.volumeParam.ioNamePtr = (char_u *) dirname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 gMyHPBlock.volumeParam.ioVRefNum =0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 gMyHPBlock.volumeParam.ioVolIndex = index;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 gErr = PBHGetVInfo (&gMyHPBlock,false);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 if (gErr == noErr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 STRNCPY (cfilename, &dirname[1], dirname[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 cfilename[dirname[0]] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 if (vim_regexec(&regmatch, cfilename, (colnr_T)0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 STRCPY(s, cfilename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 STRCAT(buf, path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 if (mch_has_exp_wildcard(path)) /* handle more wildcards */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 (void)mac_expandpath(gap, s, flags, 0, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 #ifdef DONT_ADD_PATHSEP_TO_DIR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 /* if ((gMyCPB.hFileInfo.ioFlAttrib & ioDirMask) !=0 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 */ STRCAT(buf, PATHSEPSTR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 addfile(gap, s, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 #if 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 STRCAT(cfilename, PATHSEPSTR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 addfile (gap, cfilename, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 index++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 while (gErr == noErr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 return gap->ga_len - start_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 #ifdef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 pstrcmp(a, b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 const void *a, *b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 return (pathcmp(*(char **)a, *(char **)b));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 unix_expandpath(gap, path, wildoff, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 garray_T *gap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 char_u *path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 int wildoff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 int flags; /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 char_u *path_end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 char_u *p, *s, *e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 int start_len, c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 char_u *pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 DIR *dirp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 struct dirent *dp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 int starts_with_dot;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 int matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 start_len = gap->ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 buf = alloc(STRLEN(path) + BASENAMELEN + 5);/* make room for file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 * Find the first part in the path name that contains a wildcard.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 * Copy it into buf, including the preceding characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 p = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 s = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 e = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 path_end = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 while (*path_end)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 /* May ignore a wildcard that has a backslash before it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 if (path_end >= path + wildoff && rem_backslash(path_end))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 else if (*path_end == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 if (e != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 s = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 else if (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 len = (*mb_ptr2len_check)(path_end);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 STRNCPY(p, path_end, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 p += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 path_end += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 *e = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 /* now we have one wildcard component between s and e */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 /* Remove backslashes between "wildoff" and the start of the wildcard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 * component. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 for (p = buf + wildoff; p < s; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 if (rem_backslash(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 STRCPY(p, p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 --e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 --s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 /* convert the file pattern to a regexp pattern */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 starts_with_dot = (*s == '.');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 if (pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 /* compile the regexp into a program */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 #ifdef MACOS_X
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 /* We want to behave like Terminal.app */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 regmatch.rm_ic = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 regmatch.rm_ic = FALSE; /* Don't ever ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 vim_free(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 if (regmatch.regprog == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 /* open the directory for scanning */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 c = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 *s = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 dirp = opendir(*buf == NUL ? "." : (char *)buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 *s = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 /* Find all matching entries */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 if (dirp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 dp = readdir(dirp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 if (dp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 if ((dp->d_name[0] != '.' || starts_with_dot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 && vim_regexec(&regmatch, (char_u *)dp->d_name, (colnr_T)0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 STRCPY(s, dp->d_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 len = STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 STRCPY(buf + len, path_end);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 if (mch_has_exp_wildcard(path_end)) /* handle more wildcards */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 /* need to expand another component of the path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 /* remove backslashes for the remaining components only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 (void)unix_expandpath(gap, buf, len + 1, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 /* no more wildcards, check if there is a match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 /* remove backslashes for the remaining components only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 if (*path_end)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 backslash_halve(buf + len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 if (mch_getperm(buf) >= 0) /* add existing file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 addfile(gap, buf, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 closedir(dirp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 matches = gap->ga_len - start_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 if (matches)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 qsort(((char_u **)gap->ga_data) + start_len, matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 sizeof(char_u *), pstrcmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 return matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 * Recursively build up a list of files in "gap" matching the first wildcard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 * in `path'. Called by expand_wildcards().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 * "pat" has backslashes before chars that are not to be expanded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 mch_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 int flags) /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 #ifdef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 return unix_expandpath(gap, path, 0, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 char_u first = *path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 short scan_volume;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 slash_n_colon_adjust(path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 scan_volume = (first != *path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 return mac_expandpath(gap, path, flags, 0, scan_volume);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 fname_case(name, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 int len; /* buffer size, ignored here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 * TODO: get the real casing for the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 * make it called
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 * with USE_FNAME_CASE & USE_LONG_FNAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 * CASE_INSENSITIVE_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 * within setfname, fix_fname, do_ecmd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 #ifdef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 OSStatus status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 FSRef refFile;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 UInt32 pathSize = STRLEN(name) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 char_u *path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 Boolean isDirectory;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 path = alloc(pathSize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 if (path == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 status = FSPathMakeRef((UInt8 *)name, &refFile, &isDirectory);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 if (status)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 status = FSRefMakePath(&refFile, (UInt8 *)path, pathSize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 if (status)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 /* Paranoid: Update the name if only the casing differ.*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 if (STRICMP(name, path) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 STRCPY(name, path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 static char_u *oldtitle = (char_u *) "gVim";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 * check for an "interrupt signal": CTRL-break or CTRL-C
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 mch_breakcheck()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 * TODO: Scan event for a CTRL-C or COMMAND-. and do: got_int=TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 * or only go proccess event?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 * or do nothing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 EventRecord theEvent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
530 if (EventAvail(keyDownMask, &theEvent))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 if ((theEvent.message & charCodeMask) == Ctrl_C && ctrl_c_interrupts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 got_int = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 #if 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 short i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 Boolean found = false;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 EventRecord theEvent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 while ((i < 10) && (!found))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 found = EventAvail (keyDownMask, &theEvent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 if (found)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 if ((theEvent.modifiers & controlKey) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 found = false;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 if ((theEvent.what == keyDown))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 found = false;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 if ((theEvent.message & charCodeMask) == Ctrl_C)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 found = false;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 got_int = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 i++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 * Return amount of memory currently available.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 long_u
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 mch_avail_mem(special)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 int special;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 * TODO: Use MaxBlock, FreeMeM, PurgeSpace, MaxBlockSys FAQ-266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 * figure out what the special is for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 * FreeMem -> returns all avail memory is application heap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 * MaxBlock -> returns the biggest contigeous block in application heap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 * PurgeSpace ->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 return MaxBlock();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 mch_delay(msec, ignoreinput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 long msec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 int ignoreinput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 #if (defined(__MWERKS__) && __MWERKS__ >= 0x2000) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 || defined(__MRC__) || defined(__SC__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 unsigned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 long finalTick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 if (ignoreinput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 Delay (60*msec/1000, &finalTick);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 /* even thougth we should call gui stuff from here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 it the simplest way to be safe */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 gui_mch_wait_for_chars(msec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 mch_init()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 * TODO: Verify if needed, or override later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 Columns = 80;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 Rows = 24;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 * Check_win checks whether we have an interactive stdout.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 mch_check_win(argc, argv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 int argc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 char **argv;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 * TODO: Maybe to be remove through NO_CONSOLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 * Return TRUE if the input comes from a terminal, FALSE otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 mch_input_isatty()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 * TODO: Maybe to be remove through NO_CONSOLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 #ifdef FEAT_TITLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 * Set the window title and icon.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 * (The icon is not taken care of).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 mch_settitle(title, icon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 char_u *title;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 char_u *icon;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 gui_mch_settitle(title, icon);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 * Restore the window/icon title.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 * which is one of:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 * 1 Just restore title
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 * 2 Just restore icon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 * 3 Restore title and icon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 * but don't care about the icon.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 mch_restore_title(which)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 int which;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 mch_settitle((which & 1) ? oldtitle : NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 * Insert user name in s[len].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 * Return OK if a name found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 mch_get_user_name(s, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 #if !(defined(__MRC__) || defined(__SC__)) /* No solution yet */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 * TODO: clean up and try getlogin ()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 struct passwd *pw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 uid_t uid;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 uid = getuid();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 if ((pw = getpwuid(uid)) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 && pw->pw_name != NULL && *(pw->pw_name) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 STRNCPY(s, pw->pw_name, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 return FAIL; /* a number is not a name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 * Copy host name into s[len].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 mch_get_host_name(s, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 #if defined(__MRC__) || defined(__SC__) || defined(__APPLE_CC__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 STRNCPY(s, "Mac", len); /* TODO: use Gestalt information */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 struct utsname vutsname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 if (uname(&vutsname) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 *s = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 STRNCPY(s, vutsname.nodename, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 s[len - 1] = NUL; /* make sure it's terminated */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 * return process ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 mch_get_pid()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 return (long)getpid();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 * Get name of current directory into buffer 'buf' of length 'len' bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 * Return OK for success, FAIL for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 mch_dirname(buf, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 #if defined(__MRC__) || defined(__SC__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 return FAIL; /* No solution yet */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 /* The last : is already put by getcwd */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 if (getcwd((char *)buf, len) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 STRCPY(buf, strerror(errno));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 # ifndef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 else if (*buf != NUL && buf[STRLEN(buf) - 1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 buf[STRLEN(buf) - 1] = NUL; /* remove trailing ':' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 slash_to_colon(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 for ( ; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 if (*p == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 *p = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 slash_to_colon_save (p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 char_u *res;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 res = vim_strsave(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 if (res == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 slash_to_colon(res);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 return res;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 slash_n_colon_adjust (buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 * TODO: Make it faster
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 #ifndef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 char_u temp[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 char_u *first_colon = vim_strchr(buf, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 char_u *first_slash = vim_strchr(buf, '/');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 int full = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 char_u *scanning;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 char_u *filling;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 char_u last_copied = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 if (*buf == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 return ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 if ((first_colon == NULL) && (first_slash == NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 full = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 if ((first_slash == NULL) && (first_colon != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 full = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 if ((first_colon == NULL) && (first_slash != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 full = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 if ((first_slash < first_colon) && (first_slash != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 full = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 if ((first_colon < first_slash) && (first_colon != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 full = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 if (first_slash == buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 full = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 if (first_colon == buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 full = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 scanning = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 filling = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 while (*scanning != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 if (*scanning == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 if ((scanning[1] != '/') && (scanning[-1] != ':'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 *filling++ = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 scanning++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 scanning++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 else if (*scanning == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 if ((scanning[1] == NUL) || scanning[1] == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 if (scanning[1] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 scanning += 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 scanning += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 else if (scanning[1] == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 if ((scanning[2] == NUL) || scanning[2] == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 *filling++ = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 if (scanning[2] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 scanning +=2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 scanning += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 *filling++ = *scanning++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 *filling++ = *scanning++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 *filling++ = *scanning++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 *filling = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 filling = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 if (!full)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 if (buf[0] != ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 buf[0] = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 buf[1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 buf[0] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 buf[0] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 if (filling[0] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 filling++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 STRCAT (buf, filling);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 * Get absolute filename into buffer 'buf' of length 'len' bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 * return FAIL for failure, OK for success
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 mch_FullName(fname, buf, len, force)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 char_u *fname, *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 int force; /* also expand when already absolute path name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 * TODO: Find what TODO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 char_u olddir[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 char_u newdir[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 char_u c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 int retval = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 if (force || !mch_isFullName(fname))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 * Forced or not an absolute path.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 * If the file name has a path, change to that directory for a moment,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 * and then do the getwd() (and get back to where we were).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 * This will get the correct path name with "../" things.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 if ((p = vim_strrchr(fname, ':')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 if (mch_dirname(olddir, MAXPATHL) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 p = NULL; /* can't get current dir: don't chdir */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 c = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 if (mch_chdir((char *)fname))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 fname = p; /* + 1;*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 *p = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 if (mch_dirname(buf, len) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 *newdir = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 l = STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 if (STRCMP(fname, ".") != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 #ifdef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 if (l > 0 && buf[l - 1] != '/' && *fname != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 STRCAT(buf, "/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 if (l > 0 && buf[l - 1] != ':' && *fname != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 STRCAT(buf, ":");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 mch_chdir((char *)olddir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 if (STRCMP(fname, ".") != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 STRCAT(buf, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 STRNCPY(buf, fname, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 buf[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 slash_n_colon_adjust(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 * Return TRUE if "fname" does not depend on the current directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 mch_isFullName(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 #ifdef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 return ((fname[0] == '/') || (fname[0] == '~'));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 * TODO: Make sure fname is always of mac still
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 * i.e: passed throught slash_n_colon_adjust
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 char_u *first_colon = vim_strchr(fname, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 char_u *first_slash = vim_strchr(fname, '/');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 if (first_colon == fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 if (first_slash == fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 if ((first_colon < first_slash) && (first_colon != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 if ((first_slash < first_colon) && (first_slash != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 if ((first_colon == NULL) && (first_slash != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 if ((first_slash == NULL) && (first_colon != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 if ((first_colon == NULL) && (first_slash == NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 * Replace all slashes by colons.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 slash_adjust(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 #ifndef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 * TODO: keep escaped '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 while (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 if (*p == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 *p = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 p += (*mb_ptr2len_check)(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 * Get file permissions for 'name'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 * Returns -1 when it doesn't exist.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 mch_getperm(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 * TODO: Maybe use AppleShare info??
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 * Use locked for non writable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 struct stat statb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 if (stat((char *)name, &statb))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 return statb.st_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 * set file permission for 'name' to 'perm'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 mch_setperm(name, perm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 long perm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 * TODO: Maybe use AppleShare info??
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 * Use locked for non writable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 return (OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 * Set hidden flag for "name".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 mch_hide(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 * TODO: Hide the file throught FileManager FAQ 8-34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 * *name is mac style start with : for relative
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 * return TRUE if "name" is a directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 * return FALSE if "name" is not a directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 * return FALSE for error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 mch_isdir(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 * TODO: Find out by FileManager calls ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 struct stat statb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 #if defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 /* For some reason the name is sometimes empty,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 * (such as for a not yet named file). An empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 * filename is interpreted by the MacOS version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 * of stat (at least under Codewarrior) as the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 * current directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 /* AK 20020413
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 * This is required for Carbon but breaks the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 * explorer plugin in Classic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 if (name[0] == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 if (stat((char *)name, &statb))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 #if defined(__MRC__) || defined(__SC__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 return FALSE; /* definitely TODO */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 return ((statb.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 #if defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 * Return 1 if "name" can be executed, 0 if not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 * Return -1 if unknown.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 mch_can_exe(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 /* TODO */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 * Check what "name" is:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 * NODE_NORMAL: file or directory (or doesn't exist)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 * NODE_WRITABLE: writable device, socket, fifo, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 * NODE_OTHER: non-writable things
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 mch_nodetype(name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 /* TODO */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 return NODE_NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 mch_early_init()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 mch_exit(r)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 int r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 display_errors();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 ml_close_all(TRUE); /* remove all memfiles */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 exit(r);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 mch_settmode(tmode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 int tmode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 * TODO: remove the needs of it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 * set mouse clicks on or off (only works for xterms)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 mch_setmouse(on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 int on;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 * TODO: remove the needs of it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 * set screen mode, always fails.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 mch_screenmode(arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 char_u *arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 EMSG(_(e_screenmode));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 mch_call_shell(cmd, options)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 char_u *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 int options; /* SHELL_*, see vim.h */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 * TODO: find a shell or pseudo-shell to call
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 * for some simple useful command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 return (-1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 * Return TRUE if "p" contains a wildcard that can be expanded by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 * mch_expandpath().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 mch_has_exp_wildcard(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 for ( ; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 if (*p == '\\' && p[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 else if (vim_strchr((char_u *)WILDCHAR_LIST, *p) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 p += (*mb_ptr2len_check)(p) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 mch_has_wildcard(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 #ifdef USE_UNIXFILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 if (*p == '~' && p[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 return mch_has_exp_wildcard(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 * This procedure duplicate a file, it is used in order to keep
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 * the footprint of the previous file, when some info can be easily
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 * restored with set_perm().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 * Return -1 for failure, 0 for success.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 mch_copy_file(from, to)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 char_u *from;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 char_u *to;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 char_u from_str[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 char_u to_str[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 char_u to_name[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 HParamBlockRec paramBlock;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 char_u *char_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 * Convert C string to Pascal string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 char_ptr = from;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 for (; (*char_ptr != 0) && (len < 255); len++, char_ptr++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 from_str[len] = *char_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 from_str[0] = len-1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 char_ptr = to;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 for (; (*char_ptr != 0) && (len < 255); len++, char_ptr++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 to_str[len] = *char_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 to_str[0] = len-1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 paramBlock.copyParam.ioCompletion = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 paramBlock.copyParam.ioNamePtr = from_str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 /* paramBlock.copyParam.ioVRefnum = overided by ioFilename; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 /* paramBlock.copyParam.ioDirI = overided by ioFilename; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 paramBlock.copyParam.ioNewName = to_str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 paramBlock.copyParam.ioCopyName = to_name; /* NIL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 /* paramBlock.copyParam.ioDstVRefNum = overided by ioNewName; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 /* paramBlock.copyParam.ioNewDirID = overided by ioNewName; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 * First delete the "to" file, this is required on some systems to make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 * the rename() work, on other systems it makes sure that we don't have
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 * two files when the rename() fails.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 mch_remove(to);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 * First try a normal rename, return if it works.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 (void) PBHCopyFile(&paramBlock, false);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 mch_copy_file_attribute(from, to)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 char_u *from;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 char_u *to;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 FSSpec frFSSpec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 FSSpec toFSSpec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 FInfo fndrInfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 Str255 name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 ResType type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 ResType sink;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 Handle resource;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 short idxTypes;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 short nbTypes;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 short idxResources;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 short nbResources;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 short ID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 short frRFid;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 short toRFid;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 short attrs_orig;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 short attrs_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 short temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 /* TODO: Handle error */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 (void) GetFSSpecFromPath (from, &frFSSpec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 (void) GetFSSpecFromPath (to , &toFSSpec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 /* Copy resource fork */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 #if 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 frRFid = FSpOpenResFile (&frFSSpec, fsCurPerm);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 if (frRFid != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 FSpCreateResFile(&toFSSpec, 'TEXT', UNKNOWN_CREATOR, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 toRFid = FSpOpenResFile (&toFSSpec, fsRdWrPerm);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 UseResFile (frRFid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 nbTypes = Count1Types();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 for (idxTypes = 1; idxTypes <= nbTypes; idxTypes++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 Get1IndType (&type, idxTypes);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 nbResources = Count1Resources(type);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 for (idxResources = 1; idxResources <= nbResources; idxResources++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 attrs_orig = 0; /* in case GetRes fails */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 attrs_copy = 0; /* in case GetRes fails */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 resource = Get1IndResource(type, idxResources);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 GetResInfo (resource, &ID, &sink, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 HLock (resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 attrs_orig = GetResAttrs (resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 DetachResource (resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 UseResFile (toRFid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 AddResource (resource, type, ID, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 attrs_copy = GetResAttrs (resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 attrs_copy = (attrs_copy & 0x2) | (attrs_orig & 0xFD);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 SetResAttrs (resource, attrs_copy);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 WriteResource (resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 UpdateResFile (toRFid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 temp = GetResAttrs (resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 /*SetResAttrs (resource, 0);*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 HUnlock(resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 ReleaseResource (resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 UseResFile (frRFid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 CloseResFile (toRFid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 CloseResFile (frRFid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 /* Copy Finder Info */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 (void) FSpGetFInfo (&frFSSpec, &fndrInfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 (void) FSpSetFInfo (&toFSSpec, &fndrInfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 return (temp == attrs_copy);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 mch_has_resource_fork (file)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 char_u *file;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 FSSpec fileFSSpec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 short fileRFid;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 /* TODO: Handle error */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 (void) GetFSSpecFromPath (file, &fileFSSpec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 fileRFid = FSpOpenResFile (&fileFSSpec, fsCurPerm);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 if (fileRFid != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 CloseResFile (fileRFid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 return (fileRFid != -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 mch_get_shellsize(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 /* never used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 mch_set_shellsize(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 /* never used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 * Rows and/or Columns has changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 mch_new_shellsize(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 /* never used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 * Those function were set as #define before, but in order
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 * to allow an easier us of os_unix.c for the MacOS X port,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 * they are change to procedure. Thec ompile whould optimize
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 * them out.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 mch_can_restore_title()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 mch_can_restore_icon()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 * If the machine has job control, use it to suspend the program,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 * otherwise fake it by starting a new shell.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 mch_suspend()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 /* TODO: get calle in #ifndef NO_CONSOLE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 gui_mch_iconify();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451