~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Frontier Kernel
Frontier/Common/source/filepath.c

Version: ~ [ 10.0 ] ~

** Warning: Cannot open xref database.

1 2 /* $Id: filepath.c,v 1.8 2005/08/22 02:08:48 terry_teague Exp $ */ 3 4 /****************************************************************************** 5 6 UserLand Frontier(tm) -- High performance Web content management, 7 object database, system-level and Internet scripting environment, 8 including source code editing and debugging. 9 10 Copyright (C) 1992-2004 UserLand Software, Inc. 11 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 26 ******************************************************************************/ 27 28 #include "frontier.h" 29 #include "standard.h" 30 31 #include "error.h" 32 #include "memory.h" 33 #include "strings.h" 34 #include "ops.h" 35 #include "file.h" 36 #include "launch.h" /* 2005-07-18 creedon */ 37 38 39 #define flaux false /*if true, we're running under the A/UX operating system*/ 40 41 42 #ifdef MACVERSION 43 44 static FSSpec fsdefault = {0}; /*we maintain our own default directory*/ 45 46 boolean directorytopath (long DirID, short vnum, bigstring path) { 47 48 CInfoPBRec block; 49 bigstring bsdirectory; 50 OSErr errcode; 51 52 setemptystring (path); 53 54 clearbytes (&block, longsizeof (block)); 55 56 block.dirInfo.ioNamePtr = bsdirectory; 57 58 block.dirInfo.ioDrParID = DirID; 59 60 do { 61 block.dirInfo.ioVRefNum = vnum; 62 63 block.dirInfo.ioFDirIndex = -1; 64 65 block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID; 66 67 errcode = PBGetCatInfoSync (&block); 68 69 if (errcode != noErr) 70 return (false); 71 72 if (flaux) { 73 if (bsdirectory[1] != '/') 74 if (!pushchar ('/', bsdirectory)) 75 return (false); 76 } 77 else 78 if (!pushchar (':', bsdirectory)) 79 return (false); 80 81 if (!pushstring (path, bsdirectory)) 82 return (false); 83 84 copystring (bsdirectory, path); 85 } while (block.dirInfo.ioDrDirID != fsRtDirID); 86 87 return (true); 88 } /*directorytopath*/ 89 90 #endif 91 92 boolean filegetdefaultpath (tyfilespec *fs) { 93 94 #ifdef MACVERSION 95 return (!oserror (FSMakeFSSpec (fsdefault.vRefNum, fsdefault.parID, nil, fs))); 96 #endif 97 98 #ifdef WIN95VERSION 99 DWORD sz; 100 101 sz = GetCurrentDirectory (257, stringbaseaddress (fsname (fs))); 102 103 if (sz == 0) { 104 105 oserror (GetLastError ()); 106 107 return (false); 108 } 109 110 strcat (stringbaseaddress (fsname (fs)), "\\"); 111 112 setstringlength(fsname (fs), sz + 1); 113 114 return (true); 115 #endif 116 } /*filegetdefaultpath*/ 117 118 119 boolean filesetdefaultpath (const tyfilespec *fs) { 120 121 #ifdef MACVERSION 122 CInfoPBRec pb; 123 124 clearbytes (&fsdefault, longsizeof (fsdefault)); 125 126 if (isemptystring ((*fs).name)) 127 return (true); 128 129 setoserrorparam ((ptrstring) (*fs).name); 130 131 clearbytes (&pb, longsizeof (pb)); 132 133 pb.dirInfo.ioNamePtr = (StringPtr) (*fs).name; 134 135 pb.dirInfo.ioVRefNum = (*fs).vRefNum; 136 137 pb.dirInfo.ioDrDirID = (*fs).parID; 138 139 if (oserror (PBGetCatInfoSync (&pb))) 140 return (false); 141 142 fsdefault.vRefNum = pb.dirInfo.ioVRefNum; 143 144 fsdefault.parID = pb.dirInfo.ioDrDirID; 145 146 return (true); 147 #endif 148 149 #ifdef WIN95VERSION 150 if (isemptystring (fsname (fs))) 151 return (true); 152 153 if (!SetCurrentDirectory (stringbaseaddress(fsname (fs)))) { 154 155 oserror (GetLastError ()); 156 157 return (false); 158 } 159 160 return (true); 161 #endif 162 } /*filesetdefaultpath*/ 163 164 165 boolean filespectopath (const tyfilespec *fs, bigstring bspath) { 166 167 /* 168 6/28/91 dmb: when you resolve an alias of a volume, the fsspec has a 169 parent dirid of 1. we catch this as a special case here, and return 170 the empty string as the path 171 172 10/14/91 dmb: make sure folder paths end in : 173 174 12/17/91 dmb: don't check for folderness if file doesn't exist-- we 175 dont want to generate any errors here 176 177 2.1a7 dmb: if it's a null filespec, return the empty string 178 */ 179 180 #ifdef MACVERSION 181 boolean flfolder; 182 183 if ((*fs).parID == fsRtParID) { /*it's a volume*/ 184 185 copystring ((ptrstring) (*fs).name, bspath); 186 187 pushchar (':', bspath); 188 189 return (true); 190 } 191 192 setemptystring (bspath); 193 194 if (((*fs).parID == 0) && ((*fs).vRefNum == 0) && (isemptystring ((*fs).name))) 195 return (true); 196 197 if (!directorytopath ((*fs).parID, (*fs).vRefNum, bspath)) 198 return (false); 199 200 pushstring ((ptrstring) (*fs).name, bspath); 201 202 if (fileexists (fs, &flfolder)) 203 if (flfolder) 204 assurelastchariscolon (bspath); 205 206 return (true); 207 #endif 208 209 #ifdef WIN95VERSION 210 // 5.0d12 dmb: use GetFullPath to clean up 8.3 names 211 char * fileptr; 212 213 copyptocstring (fsname (fs), bspath); 214 215 GetFullPathName (bspath, lenbigstring, bspath, &fileptr); 216 217 convertcstring (bspath); 218 219 nullterminate (bspath); 220 221 return (true); 222 #endif 223 } /*filespectopath*/ 224 225 226 boolean pathtofilespec (bigstring bspath, tyfilespec *fs) { 227 228 /* 229 7/5/91 dmb: use FSMakeFSSpec if it's available. since it only returns 230 noErr if the file exists, and we want to handle non-existant files, we 231 don't give up right away. 232 233 12/17/91 dmb: dont append path to default directory if it's a full path 234 235 6/11/93 dmb: if FSMakeFSSpec returns fnfErr, the spec is cool (but file 236 doesn't exist) 237 238 2.1b2 dmb: added special case for empty string. also, added drive number 239 interpretation here. 240 241 2.1b2 dmb: use new fsdefault for building filespec. note that if bspath 242 isn't a partial path, the vref and dirid will be ignored. 243 */ 244 245 bigstring bsfolder; 246 #ifdef MACVERSION 247 OSErr errcode; 248 short ix = 1; 249 #endif 250 251 clearbytes (fs, sizeof (tyfilespec)); // 5,0d8 dmb 252 253 if (isemptystring (bspath)) 254 return (true); 255 256 #ifdef MACVERSION 257 errcode = FSMakeFSSpec (fsdefault.vRefNum, fsdefault.parID, bspath, fs); 258 259 //for some reason if there is a trailing : you get a dirNFErr and it doesn't work 260 //This little hack saves us. It still is a fnfErr, but it works. 261 #if TARGET_API_MAC_CARBON 262 if(errcode == dirNFErr) 263 { 264 poptrailingchars(bspath, ':'); 265 errcode = FSMakeFSSpec (fsdefault.vRefNum, fsdefault.parID, bspath, fs); 266 } 267 #endif 268 if ((errcode == noErr) || (errcode == fnfErr)) 269 return (true); 270 271 if (scanstring (':', bspath, &ix) && (ix > 1)) { /*includes a colon, not the first thing*/ 272 273 short drivenum; 274 275 midstring (bspath, 1, ix - 1, bsfolder); /*pull out volume name*/ 276 277 if (isallnumeric (bsfolder) && stringtoshort (bsfolder, &drivenum)) { /*it's a number*/ 278 279 midstring (bspath, ix, stringlength (bspath) - ix + 1, bsfolder); 280 281 errcode = FSMakeFSSpec (drivenum, 0, bsfolder, fs); 282 283 if ((errcode == noErr) || (errcode == fnfErr)) 284 return (true); 285 } 286 } 287 288 return (false); 289 #endif 290 291 #ifdef WIN95VERSION 292 copystring (bspath, fsname (fs)); 293 294 folderfrompath (bspath, bsfolder); 295 296 if ((isemptystring (bsfolder)) && (! fileisvolume(fs))) { 297 298 filegetdefaultpath (fs); 299 300 pushstring (bspath, fsname (fs)); 301 } 302 303 nullterminate (fsname (fs)); 304 305 return (true); 306 #endif 307 308 } /*pathtofilespec*/ 309 310 311 boolean setfsfile (tyfilespec *fs, bigstring bsfile) { 312 313 /* 314 2004-10-26 aradke: Since the getmacfileinfo/foldertest gymnastics do not 315 seem to fit any particular purpose and since none of our callers 316 seem to rely it since they usually pass in a file rather than a directory, 317 I commented it out. 318 319 The only time we get called with a directory is apparently by 320 shellopendefaultfile on startup in the Carbon/Mach-O build. 321 getapplicationfilespec returns a directory in that case and 322 the code below somehow screwed up when called to set the 323 filename to Frontier.root so that it wouldn't be found. 324 */ 325 326 #ifdef MACVERSION 327 /* 328 CInfoPBRec pb; 329 330 if (getmacfileinfo (fs, &pb) && foldertest (&pb)) { 331 332 FSMakeFSSpec ((*fs).vRefNum, pb.dirInfo.ioDrDirID, bsfile, fs); 333 334 return (false); 335 } 336 */ 337 338 copystring (bsfile, (*fs).name); 339 340 return (true); 341 #endif 342 343 #ifdef WIN95VERSION 344 bigstring bsfolder; 345 346 folderfrompath (fsname (fs), bsfolder); 347 348 pushstring (bsfile, bsfolder); 349 350 copystring (bsfolder, fsname (fs)); 351 352 nullterminate (fsname (fs)); 353 354 return (true); 355 #endif 356 } /*setfsfile*/ 357 358 359 boolean getfsfile (const tyfilespec *fs, bigstring bsfile) { 360 361 /* 362 5.0b9 dmb: we're needing this in a few places. better late 363 than never 364 */ 365 366 #ifdef WIN95VERSION 367 bigstring bspath; 368 369 filespectopath (fs, bspath); 370 371 filefrompath (bspath, bsfile); 372 373 return (true); 374 #endif 375 376 #ifdef MACVERSION 377 copystring (fsname (fs), bsfile); 378 379 return (true); 380 #endif 381 } /*getfsfile*/ 382 383 384 boolean getfsvolume (const tyfilespec *fs, long *vnum) { 385 386 /* 387 5.1.5b11 dmb: get the volume that is actually specified in the fspec. 388 389 don't expand partial paths using the default directory. 390 */ 391 392 #ifdef WIN95VERSION 393 return (fileparsevolname ((ptrstring) fsname (fs), vnum, nil)); 394 #endif 395 396 #ifdef MACVERSION 397 HVolumeParam pb; 398 399 *vnum = (*fs).vRefNum; 400 401 if (*vnum == 0) 402 return (false); 403 404 clearbytes (&pb, sizeof (pb)); /*init all fields to zero*/ 405 406 pb.ioVRefNum = *vnum; 407 408 return (PBHGetVInfoSync ((HParmBlkPtr) &pb) == noErr); 409 #endif 410 } /*getfsfile*/ 411 412 void initfsdefault (void) { 413 #ifdef MACVERSION 414 /* 2005-07-18 creedon, karstenw */ 415 getapplicationfilespec (nil, &fsdefault); 416 #endif 417 } /* initfsdefault */ 418

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.