fileloop.c

Go to the documentation of this file.
00001 
00002 /*  $Id: fileloop.c 1203 2006-04-05 22:58:09Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "memory.h"
00032 #include "strings.h"
00033 #include "error.h"
00034 #include "file.h"
00035 #include "oplist.h"
00036 #include "fileloop.h"
00037 
00038 
00039 
00040 
00041 #ifdef MACVERSION
00042 typedef struct tyfilelooprecord {
00043     
00044     short vnum; /*the volume we're looping through*/
00045     
00046     long dirid; /*the folder we're looking in*/
00047     
00048     short ixdirectory; /*index for the next file to look at*/
00049     
00050     hdllistrecord hfilelist; /*a list of filenames to be looped over*/
00051     } tyfilelooprecord, *ptrfilelooprecord, **hdlfilelooprecord;
00052     
00053     
00054 
00055 
00056 static boolean fileloopreleaseitem (Handle h) {
00057 #pragma unused(h)
00058 
00059     /*
00060     callback routine that disposes of one of our items.  since there are no
00061     handles linked into our handle, there's nothing to release.
00062     
00063     I just wanted to have one of these around so the next guy that uses the
00064     list facilty knows how to link a releaseitem callback routine.
00065     */
00066     
00067     return (true);
00068     } /*fileloopreleaseitem*/
00069     
00070 
00071 boolean diskinitloop (tyfileloopcallback diskfilter, Handle *hdiskloop) {
00072 #pragma unused(diskfilter)
00073 
00074     /*
00075     same as fileinitloop, but for volumes on line
00076     
00077     8/15/92 dmb: added, but commented out, diskfilter support
00078     */
00079     
00080     tyfilelooprecord info;
00081     ParamBlockRec pb;
00082     register hdlfilelooprecord h;
00083     short ix;
00084     hdllistrecord hlist;
00085     
00086     clearbytes (&pb, sizeof (pb)); /*init all fields to zero*/
00087     
00088     clearbytes (&info, sizeof (info));
00089     
00090     info.ixdirectory = 1; /*start with the first file*/
00091     
00092     if (!newfilledhandle (&info, sizeof (info), hdiskloop))
00093         return (false);
00094     
00095     h = (hdlfilelooprecord) *hdiskloop; /*copy into register*/
00096     
00097     hlist = nil;
00098     
00099     if (!opnewlist (&hlist, false)) 
00100         goto error;
00101     
00102     (**h).hfilelist = hlist;
00103     
00104     opsetreleaseitemcallback (hlist, &fileloopreleaseitem);
00105     
00106     ix = 1; /*start with file index 1*/
00107     
00108     while (true) {
00109         FSSpec fsvol;
00110         OSErr errcode;
00111         Handle hstring;
00112         #if TARGET_API_MAC_CARBON == 1
00113         HFSUniStr255    theName;
00114         //Code change by Timothy Paustian Thursday, June 29, 2000 10:29:59 AM
00115         //Updated to modern call for volume infomation
00116         //Ii am checking this now against the original.
00117         FSVolumeRefNum  vRefNum;//this is just a SInt16
00118         
00119         //Watch out that the fsvol.name parameter works as expected.
00120         //this is still not working the way it should
00121         errcode = FSGetVolumeInfo(0, ix, &vRefNum, kFSVolInfoNone, nil, &theName, nil);
00122         if (errcode == nsvErr) /*not an error, just ran out of volumes*/
00123             return (true);
00124         
00125         {
00126         UnicodeToTextInfo   theInfo;
00127         UnicodeMapping      theMapping;
00128         theMapping.unicodeEncoding = kTextEncodingUnicodeDefault;
00129         theMapping.otherEncoding = kTextEncodingMacRoman;
00130         theMapping.mappingVersion = kUnicodeUseLatestMapping;
00131         errcode = CreateUnicodeToTextInfo(&theMapping,&theInfo);
00132         if (oserror (errcode)) // 1/29/97 dmb: call oserror
00133             goto error;
00134         //fsvol.name[0] = theName.length;
00135         errcode = ConvertFromUnicodeToPString (theInfo, theName.length * 2, theName.unicode, fsvol.name);
00136         if (oserror (errcode)) // 1/29/97 dmb: call oserror
00137             goto error;
00138         }
00139         ix++;
00140         fsvol.vRefNum = vRefNum;
00141         
00142         #else //not carbon
00143         pb.volumeParam.ioVolIndex = ix++;
00144         
00145         pb.volumeParam.ioNamePtr = fsvol.name;
00146         
00147         errcode = PBGetVInfoSync (&pb);
00148         fsvol.vRefNum = pb.volumeParam.ioVRefNum;
00149         
00150         if (errcode == nsvErr) /*not an error, just ran out of volumes*/
00151             return (true);
00152         #endif//end carbon
00153         
00154         if (errcode == nsvErr) /*not an error, just ran out of volumes*/
00155             return (true);
00156         
00157         if (oserror (errcode)) // 1/29/97 dmb: call oserror
00158             goto error;
00159         
00160         fsvol.parID = fsRtParID;
00161         
00162         if (!newfilledhandle (&fsvol, sizeof (fsvol), &hstring))
00163             goto error;
00164         
00165         if (!oppushhandle (hlist, nil, (Handle) hstring))
00166             goto error;
00167 
00168         } /*while*/
00169     
00170     error:
00171     
00172     opdisposelist (hlist);
00173     
00174     disposehandle (*hdiskloop);
00175     
00176     *hdiskloop = nil;
00177     
00178     return (false);
00179     } /*diskinitloop*/
00180     
00181 
00182 boolean fileinitloop (const tyfilespec *fs, tyfileloopcallback filefilter, Handle *hfileloop) {
00183 #pragma unused(filefilter)
00184 
00185     /*
00186     a conglomeration of filemanager incantations which sets up a UserLand
00187     fileloop construct.  we create a new handle (allows fileloops to be
00188     nested inside other file loops, not statically allocated) and fill it
00189     with information that each iteration of a fileloop will need.  took
00190     a minimum of two days fiddling (3/16-17/90) to get this to work -- DW.
00191     
00192     12/6/91 dmb: generate dirNFErr when fileparsevolname fails
00193     
00194     8/15/92 dmb: added, but commented out, filefilter support
00195     
00196     2.1b2 dmb: updated to use filespecs
00197     
00198     3.0.2 dmb: make sure fs is a folder, not a file
00199     */
00200     
00201     tyfilelooprecord info;
00202     CInfoPBRec pb;
00203     long dirid;
00204     register hdlfilelooprecord h;
00205     short ix;
00206     hdllistrecord hlist;
00207     
00208     clearbytes (&pb, sizeof (CInfoPBRec)); /*init all fields to zero*/
00209     
00210     setoserrorparam ((ptrstring) (*fs).name);
00211     
00212     pb.hFileInfo.ioVRefNum = (*fs).vRefNum;
00213     
00214     pb.hFileInfo.ioDirID = (*fs).parID;
00215     
00216     pb.hFileInfo.ioNamePtr = (StringPtr) (*fs).name;
00217     
00218     if (oserror (PBGetCatInfoSync (&pb)))
00219         return (false);
00220     
00221     if (!foldertest (&pb)) { /*3.0.2*/
00222         
00223         oserror (dirNFErr);
00224         
00225         return (false);
00226         }
00227     
00228     dirid = pb.dirInfo.ioDrDirID; /*must remember this for loop body*/
00229     
00230     clearbytes (&info, sizeof (info));
00231     
00232     info.vnum = pb.hFileInfo.ioVRefNum;
00233     
00234     info.dirid = pb.hFileInfo.ioDirID;
00235     
00236     info.ixdirectory = 1; /*start with the first file*/
00237     
00238     if (!newfilledhandle (&info, sizeof (info), hfileloop))
00239         return (false);
00240     
00241     h = (hdlfilelooprecord) *hfileloop; /*copy into register*/
00242     
00243     hlist = nil;
00244     
00245     if (!opnewlist (&hlist, false)) 
00246         goto error;
00247         
00248     (**h).hfilelist = hlist;
00249     
00250     opsetreleaseitemcallback (hlist, &fileloopreleaseitem);
00251     
00252     ix = 1; /*start with file index 1*/
00253     
00254     while (true) {
00255         
00256         bigstring bsfile;
00257         Handle hstring;
00258         OSErr errcode;
00259         
00260         pb.dirInfo.ioDrDirID = dirid; /*may be smashed by ioFlNum on previous loop*/
00261         
00262         pb.dirInfo.ioFDirIndex = ix++;
00263         
00264         pb.dirInfo.ioNamePtr = bsfile;
00265         
00266         errcode = PBGetCatInfoSync (&pb);
00267         
00268         if (errcode == fnfErr) /*not an error, just ran out of files*/
00269             return (true);
00270             
00271         #if TARGET_API_MAC_CARBON == 1
00272         
00273         if (errcode == dirNFErr) /*On OS X, this is what's returned for a read permission error. Weird.*/
00274             return (true);
00275 
00276         if (errcode == afpAccessDenied) /* 2005-01-05 creedon - don't bail when user does not have the correct permissions < http://sourceforge.net/tracker/index.php?func=detail&aid=1096641&group_id=120666&atid=687798 > */
00277             return (true);
00278 
00279         #endif
00280         
00281         if (oserror (errcode)) /*errcode != noErr*/
00282             goto error;
00283         
00284         /*if it's a folder, insert a colon at the end of the file name*/
00285         
00286         if (foldertest (&pb))
00287             if (!pushchar (':', bsfile))
00288                 goto error;
00289         
00290         /*
00291         if (filefilter != nil) {
00292             
00293             if (!(*filefilter) (bspath, bsfile))
00294                 continue;
00295             }
00296         */
00297         
00298         if (!newtexthandle (bsfile, &hstring))
00299             goto error;
00300         
00301         if (!oppushhandle (hlist, nil, (Handle) hstring))
00302             goto error;
00303         } /*while*/
00304         
00305     error:
00306     
00307     opdisposelist (hlist);
00308     
00309     disposehandle (*hfileloop);
00310     
00311     *hfileloop = nil;
00312     
00313     return (false);
00314     } /*fileinitloop*/
00315 
00316 
00317 void fileendloop (Handle hfileloop) {
00318     
00319     register hdlfilelooprecord h = (hdlfilelooprecord) hfileloop;
00320     
00321     opdisposelist ((**h).hfilelist);
00322     
00323     disposehandle ((Handle) h);
00324     } /*fileendloop*/
00325 
00326 
00327 boolean filenextloop (Handle hfileloop, tyfilespec *fsfile, boolean *flfolder) {    
00328     
00329     /*
00330     8/17/92 dmb: we're using text handles now instead of string handles.
00331     
00332     2.1b2 dmb: now we're using filespecs!
00333     
00334     2.1b11 dmb: for volumes, whole fsspec is now stashed in handle
00335     
00336     3.0.2b1 dmb: must set flfolder to true for disks
00337     
00338     3.0.4b1 dmb: return true of fnfErr; script will have to handle error anyway
00339     
00340     5.0.2b21 dmb: don't call FSMakeFSSpec for each file; just the first.
00341     */
00342     
00343     register hdlfilelooprecord h = (hdlfilelooprecord) hfileloop;
00344     Handle hdata;
00345     bigstring bs;
00346     short vnum;
00347     long dirid;
00348     OSErr err;
00349     
00350     if (!opgetlisthandle ((**h).hfilelist, (**h).ixdirectory++, nil, &hdata))
00351         return (false);
00352     
00353     vnum = (**h).vnum;
00354     
00355     if (vnum == 0) { /*item is a volume, hdata contains refnum*/
00356         
00357         /*
00358         vnum = **(short **) hdata;
00359         
00360         setemptystring (bs);
00361         */
00362         
00363         *fsfile = **(FSSpec **) hdata;
00364         
00365         *flfolder = true; /*3.0.2b1*/
00366         
00367         return (true);
00368         }
00369     else {
00370         
00371         dirid = (**h).dirid;
00372         
00373         texthandletostring (hdata, bs);
00374         
00375         *flfolder = bs [*bs] == ':';
00376         
00377         if (*flfolder)
00378             --*bs;
00379         
00380         if ((**h).ixdirectory == 2) { //first time
00381             
00382             err = FSMakeFSSpec (vnum, dirid, bs, fsfile);
00383             
00384             (**h).vnum = (*fsfile).vRefNum;
00385             
00386             (**h).dirid = (*fsfile).parID;
00387             
00388             if ((err == noErr) || (err == fnfErr))  /* 3.0.4b1 dmb */
00389                 return (true);
00390             
00391             return (!oserror (err));    /* false */
00392             }
00393         else {
00394             
00395             (*fsfile).vRefNum = vnum;
00396             
00397             (*fsfile).parID = dirid;
00398             
00399             copystring (bs, (*fsfile).name);
00400             
00401             return (true);
00402             }
00403         }
00404     } /*filenextloop*/
00405 
00406 
00407 boolean diskloop (tyfileloopcallback diskcallback, long refcon) {
00408     
00409     /*
00410     dmb 9/21/93: filegetvolumeinfo takes a vRefNum, not a string.
00411     */
00412     
00413     HVolumeParam pb;
00414     short ix;
00415     
00416     clearbytes (&pb, sizeof (pb)); /*init all fields to zero*/
00417     
00418     ix = 1; /*start with file index 1*/
00419     
00420     while (true) {
00421         
00422         bigstring bsvolume;
00423         tyfileinfo info;
00424         OSErr errcode;
00425         
00426         pb.ioVolIndex = ix++;
00427         
00428         pb.ioNamePtr = bsvolume;
00429         
00430         errcode = PBHGetVInfoSync ((HParmBlkPtr) &pb);
00431         
00432         if (errcode == nsvErr) /*not an error, just ran out of volumes*/
00433             return (true);
00434         
00435         if (oserror (errcode)) 
00436             return (false);
00437         
00438         filegetvolumeinfo (pb.ioVRefNum, &info);
00439         
00440         if (!(*diskcallback) (bsvolume, &info, refcon))
00441             return (false);
00442         } /*while*/
00443     } /*diskloop*/
00444     
00445     
00446 boolean folderloop (const tyfilespec *pfs, boolean flreverse, tyfileloopcallback filecallback, long refcon) {
00447     
00448     /*
00449     loop through all of the files in the folder at fs, and call filecallback 
00450     for each one.
00451     
00452     if flreverse is true, loop through files backwards to allow for deletions
00453     
00454     DW 8/28/93: inexplicably, getmacfileinfo is determining that ctfiles is 1
00455     greater than the actual number of files in our folder (it's the History
00456     folder in clayhistorymenu.c). the way the loop was structured, we visit
00457     no files in the folder in this case. changed it so that on fnfErr we 
00458     continue the loop. the next time thru it will find a file. hope this
00459     doesn't break anything else (it shouldn't).
00460     */
00461     
00462     FSSpec fs = *pfs; /*work with a copy*/
00463     CInfoPBRec pb;
00464     long dirid;
00465     bigstring bsfile;
00466     short ix;
00467     long ctfiles;
00468     tyfileinfo info;
00469     OSErr ec;
00470     
00471     setoserrorparam ((ptrstring) fs.name);
00472     
00473     if (!getmacfileinfo (&fs, &pb))
00474         return (false);
00475         
00476     assert (BitTst (&pb.dirInfo.ioFlAttrib, 3)); /*be sure it's a folder*/
00477     
00478     dirid = pb.dirInfo.ioDrDirID; /*must remember this for loop body*/
00479     
00480     ctfiles = pb.dirInfo.ioDrNmFls;
00481     
00482     if (flreverse)
00483         ix = ctfiles;
00484     else
00485         ix = 1; /*start with file index 1*/
00486     
00487     while (--ctfiles >= 0) {
00488         
00489         pb.dirInfo.ioDrDirID = dirid; /*may be smashed by ioFlNum on previous loop*/
00490         
00491         pb.dirInfo.ioFDirIndex = ix;
00492         
00493         if (flreverse)
00494             --ix;
00495         else
00496             ++ix;
00497         
00498         pb.dirInfo.ioNamePtr = bsfile;
00499         
00500         ec = PBGetCatInfoSync (&pb);
00501         
00502         if (ec == fnfErr) /*DW 8/28/93: continue instead of returning true*/
00503             continue; 
00504             
00505         if (oserror (ec)) 
00506             return (false);
00507         
00508         filegetinfofrompb (&pb, &info);
00509         
00510         if (!(*filecallback) (bsfile, &info, refcon))
00511             return (false);
00512         } /*while*/
00513         
00514     return (true);
00515     } /*folderloop*/
00516 #endif
00517 
00518 
00519 
00520 
00521 #ifdef WIN95VERSION
00522 // start windows version......
00523 typedef struct tyfindloopinfo
00524     {
00525     tyfilespec fs;
00526     HANDLE findhandle;
00527     tyfileloopcallback ffilter;
00528     boolean doingDrives;
00529     short drivenum;
00530     } findloopinfo;
00531 
00532 static boolean initfileloopspec (tyfilespec *fs)
00533     {
00534     HANDLE findHandle;
00535     WIN32_FIND_DATA fileinfo;
00536     char fn[300];
00537     char * filename;
00538     short isFolder;
00539 
00540     copystring (fsname (fs), fn);
00541     filename = fsname (fs);
00542     
00543     if (fileisvolume (fs)) {
00544         cleanendoffilename (fsname (fs));
00545         appendcstring (filename, "\\*");
00546         return (true);
00547         }
00548 
00549     cleanendoffilename (fn);
00550     nullterminate (fn);
00551     
00552     findHandle = FindFirstFile (stringbaseaddress(fn), &fileinfo);
00553 
00554     if (findHandle == INVALID_HANDLE_VALUE)
00555         {
00556         oserror (GetLastError());
00557         return (false);                     //no match
00558         }
00559 
00560     isFolder = (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)?true:false;
00561 
00562     if (FindNextFile (findHandle, &fileinfo))
00563         {
00564         FindClose (findHandle);
00565         return (true);                      //wild card must be present to find second
00566         }
00567 
00568     FindClose (findHandle);
00569     if (isFolder) {
00570         cleanendoffilename (filename);
00571 
00572         appendcstring (filename, "\\*");
00573 
00574         nullterminate (filename);
00575         }
00576 
00577     return (true);
00578     }
00579 
00580 boolean fileinitloop (const tyfilespec *pfs, tyfileloopcallback filefilter, Handle *hfileloop) {
00581     
00582     findloopinfo ** fi;
00583     
00584     *hfileloop = NULL;
00585     fi = (findloopinfo **) NewHandle (sizeof(findloopinfo));
00586 
00587     if (fi == NULL)
00588         return (false);
00589 
00590     (**fi).fs = *pfs;
00591     (**fi).findhandle = NULL;
00592     (**fi).ffilter = filefilter;
00593     (**fi).doingDrives = false;
00594     (**fi).drivenum = 0;        /*start with A*/
00595 
00596     if (isemptystring ((**fi).fs.fullSpecifier)) {  /* do disks */
00597         (**fi).doingDrives = true;
00598         }
00599     else {
00600         initfileloopspec (&((**fi).fs));
00601         }
00602 
00603     *hfileloop = (Handle)fi;
00604     return (true);
00605     }
00606 
00607 void fileendloop (Handle hfileloop) {
00608     
00609     findloopinfo ** fi;
00610     fi = (findloopinfo **) hfileloop;
00611 
00612     if (fi != NULL)
00613         {
00614         if ((**fi).findhandle != NULL)
00615             FindClose ((**fi).findhandle);
00616     
00617         disposehandle ((Handle) fi);
00618         }
00619     } /*fileendloop*/
00620 
00621 
00622 boolean filenextloop (Handle hfileloop, tyfilespec *fsfile, boolean *flfolder) {    
00623     findloopinfo ** fi;
00624     HANDLE findHandle;
00625     WIN32_FIND_DATA fileinfo;
00626     char fn[300];
00627     char pathname[300];
00628     char * endofpath;
00629     int errCode;
00630     short drivenum;
00631     DWORD drivemap, drivemask;
00632 
00633     if (hfileloop == NULL)
00634         return (false);
00635 
00636     if (fsfile == NULL)
00637         return (false);
00638 
00639     fi = (findloopinfo **) hfileloop;
00640 
00641     if ((**fi).doingDrives) {               /*We are looping over each volume - not files*/
00642         while (true) {
00643             drivenum = (**fi).drivenum;
00644 
00645             ++((**fi).drivenum);
00646 
00647             if (drivenum >= 26)
00648                 return (false);
00649 
00650             drivemap = GetLogicalDrives();
00651         
00652             drivemask = 1 << drivenum;
00653 
00654             if ((drivemap & drivemask) == drivemask) { /* we found one */
00655                 /*convert drivenum to filespec */
00656                 wsprintf (stringbaseaddress(fsname(fsfile)), "%c:\\", drivenum + 'A');
00657                 setstringlength (fsname(fsfile), strlen(stringbaseaddress(fsname(fsfile))));
00658                 *flfolder = true;
00659                 return (true);
00660                 }
00661             }
00662         }
00663 
00664     if ((**fi).findhandle == NULL)          /*we are looking for the first one...*/
00665         {
00666         copystring (fsname (&(**fi).fs), fn);
00667 
00668         cleanendoffilename (fn);
00669 
00670         nullterminate (fn);
00671         
00672         findHandle = FindFirstFile (stringbaseaddress(fn), &fileinfo);
00673 
00674         if (findHandle == INVALID_HANDLE_VALUE)
00675             {
00676             oserror (GetLastError());
00677             return (false);
00678             }
00679 
00680         GetFullPathName (stringbaseaddress(fn), 300, stringbaseaddress(pathname), &endofpath);
00681 
00682         *endofpath = 0;  /*terminates path name*/
00683 
00684         setstringlength(pathname, strlen(stringbaseaddress(pathname)));
00685 
00686         copystring (pathname, fsname (&(**fi).fs));
00687         buildfilename (fsname (&(**fi).fs), 0, fileinfo.cFileName, 1, fsname (fsfile));
00688 
00689         if (flfolder != NULL)
00690             *flfolder = (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)?true:false;
00691 
00692         (**fi).findhandle = findHandle;
00693 
00694         if (strcmp (fileinfo.cFileName, ".") == 0)
00695             goto SkippingDotandDotDot;
00696 
00697         if (strcmp (fileinfo.cFileName, "..") == 0)
00698             goto SkippingDotandDotDot;
00699 
00700         if (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
00701             cleanendoffilename (fsname(fsfile));
00702             appendcstring (fsname(fsfile), "\\");
00703             }
00704 
00705         return (true);
00706         }
00707     else
00708         {
00709 SkippingDotandDotDot:
00710         if (FindNextFile ((**fi).findhandle, &fileinfo))
00711             {
00712             buildfilename (fsname (&(**fi).fs), 0, fileinfo.cFileName, 1, fsname (fsfile));
00713 
00714             if (flfolder != NULL)
00715                 *flfolder = (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)?true:false;
00716 
00717             if (strcmp (fileinfo.cFileName, ".") == 0)
00718                 goto SkippingDotandDotDot;
00719 
00720             if (strcmp (fileinfo.cFileName, "..") == 0)
00721                 goto SkippingDotandDotDot;
00722 
00723             if (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
00724                 cleanendoffilename (fsname(fsfile));
00725                 appendcstring (fsname(fsfile), "\\");
00726                 }
00727 
00728             return (true);
00729             }
00730 
00731         errCode = GetLastError();
00732 
00733 //      FindClose((**fi).findhandle);
00734 
00735         if (errCode != ERROR_NO_MORE_FILES)
00736             oserror(errCode);
00737         }
00738 
00739     return (false);
00740     }
00741 
00742 
00743 boolean folderloop (const tyfilespec *pfs, boolean flreverse, tyfileloopcallback filecallback, long refcon) {
00744     HANDLE findHandle;
00745     WIN32_FIND_DATA fileinfo;
00746     char fn[300];
00747     char pathname[300];
00748     char * endofpath;
00749     bigstring bsfile;
00750     tyfileinfo info;
00751     int errCode;
00752 
00753 
00754     copystring (fsname (pfs), fn);
00755 
00756     cleanendoffilename (fn);
00757 
00758     nullterminate (fn);
00759     
00760     findHandle = FindFirstFile (stringbaseaddress(fn), &fileinfo);
00761 
00762     if (findHandle == INVALID_HANDLE_VALUE)
00763         {
00764         oserror (GetLastError());
00765         return (false);
00766         }
00767 
00768     winsetfileinfo (&fileinfo, &info);
00769 
00770     GetFullPathName (stringbaseaddress(fn), 300, stringbaseaddress(pathname), &endofpath);
00771 
00772     *endofpath = 0;  /*terminates path name*/
00773 
00774     setstringlength(pathname, strlen(stringbaseaddress(pathname)));
00775 
00776     buildfilename (pathname, 0, fileinfo.cFileName, 1, bsfile);
00777 
00778     if (!(*filecallback) (bsfile, &info, refcon))
00779         {
00780         FindClose(findHandle);
00781         return (false);
00782         }
00783 
00784     while (FindNextFile (findHandle, &fileinfo))
00785         {
00786         winsetfileinfo (&fileinfo, &info);
00787 
00788         buildfilename (pathname, 0, fileinfo.cFileName, 1, bsfile);
00789 
00790         if (!(*filecallback) (bsfile, &info, refcon))
00791             {
00792             FindClose(findHandle);
00793             return (false);
00794             }
00795         }
00796 
00797     errCode = GetLastError();
00798 
00799     FindClose(findHandle);
00800 
00801     if (errCode == ERROR_NO_MORE_FILES)
00802         return (true);
00803 
00804     oserror(errCode);
00805     return (false);
00806     }
00807 
00808 #endif
00809 

Generated on Wed May 31 18:19:46 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6