// Compare two entries for sort by date int ASM buffer_sort_entries_date( REG(a0, DirEntry *entry1), REG(a1, DirEntry *entry2)) { register int ret; // Compare dates if ((ret=CompareDates(&entry2->de_Date,&entry1->de_Date))==0) { // If values are equal, do name sort return namesort(entry1->de_Node.dn_Name,entry2->de_Node.dn_Name); } return ret; }
// Delete any temporary files void delete_temp_files(struct DateStamp *last) { struct AnchorPath *anchor; BPTR old,lock; // Lock T: and cd if ((lock=Lock("t:",ACCESS_READ))) { // CD to t: old=CurrentDir(lock); // Allocate an anchor if ((anchor=AllocVec(sizeof(struct AnchorPath),MEMF_CLEAR))) { short error; struct FileInfoBlock fibcopy; // See if any script files already exist error=MatchFirst("T:dopus#?tmp#?",anchor); while (!error) { // Copy fib fibcopy=anchor->ap_Info; // Get next error=MatchNext(anchor); // Check datestamp if (!last || CompareDates(&fibcopy.fib_Date,last)>=0) { // Try to delete file DeleteFile(fibcopy.fib_FileName); } } // Cleanup anchor MatchEnd(anchor); FreeVec(anchor); } UnLock(CurrentDir(old)); } }
JOrderedSetT::CompareResult GMessageHeader::CompareSubject ( GMessageHeader* const & h1, GMessageHeader* const & h2 ) { const int r = JStringCompare(h1->GetBaseSubject(), h2->GetBaseSubject(), kJFalse); if (r > 0) { return JOrderedSetT::kFirstGreaterSecond; } else if (r < 0) { return JOrderedSetT::kFirstLessSecond; } else { return CompareDates(h1, h2); } }
// Check if a volume/path is available BOOL VolumePresent(DirBuffer *buffer) { D_S(struct InfoData, info) struct DosList *dos; char volume[32]; // Valid path? if (!buffer->buf_Path[0]) return 0; // Get current disk info if (!(GetDiskInfo(buffer->buf_Path,info)) || !(dos=(struct DosList *)BADDR(info->id_VolumeNode))) return 0; // Valid dos list? if (!dos || !dos->dol_Name) return 0; // Is volume mounted? if (info->id_DiskType==ID_NO_DISK_PRESENT || info->id_DiskType==ID_UNREADABLE_DISK) return 0; // Get current disk name if (dos->dol_Name) BtoCStr(dos->dol_Name,volume,32); else { char *ptr; stccpy(volume,buffer->buf_ExpandedPath,32); if ((ptr=strchr(volume,':'))) *ptr=0; } // Compare disk name if (strcmp(volume,buffer->buf_VolumeLabel)!=0) return 0; // Compare date stamp if (CompareDates(&dos->dol_misc.dol_volume.dol_VolumeDate,&buffer->buf_VolumeDate)!=0) return 0; // Volume is available return 1; }
// Searches for a named buffer and moves to it if found // Called from the LISTER PROCESS (unless LISTER_BFPF_DONT_MOVE is set) DirBuffer *lister_find_buffer( Lister *lister, DirBuffer *start, char *path, struct DateStamp *stamp, char *volume, ULONG flags) { short ret=0; DirBuffer *buffer; char *path_buffer; struct FileInfoBlock *fib; // Got a lister? if (lister) { path_buffer=lister->work_buffer; fib=lister->fib; } // Need to allocate data else { if (!(path_buffer=AllocVec(512,0)) || !(fib=AllocDosObject(DOS_FIB,0))) { FreeVec(path_buffer); return 0; } } // Copy path, terminate correctly strcpy(path_buffer,path); AddPart(path_buffer,"",512); // Lock buffer list if (!(flags&LISTER_BFPF_DONT_LOCK)) lock_listlock(&GUI->buffer_list,FALSE); // Get starting position if (start) buffer=start; else buffer=(DirBuffer *)GUI->buffer_list.list.lh_Head; // Go through all buffers for (;buffer->node.ln_Succ; buffer=(DirBuffer *)buffer->node.ln_Succ) { // Valid path in this directory? if (buffer->flags&DWF_VALID && (flags&LISTER_BFPF_DONT_LOCK || !buffer->buf_CurrentLister || buffer->buf_CurrentLister==lister)) { // Does pathname match? if (stricmp(path_buffer,buffer->buf_Path)==0) { BOOL match=1; // If datestamp is supplied, try that if (stamp) { if (CompareDates(stamp,&buffer->buf_VolumeDate)!=0) match=0; } // Or if a volume name is provided, test that if (volume) { if (stricmp(volume,buffer->buf_VolumeLabel)!=0) match=0; } // Matched? if (match) { BPTR lock; // Do we need to test dates? if (!(flags&LISTER_BFPF_DONT_TEST)) { // Try to lock and examine this directory if (lock=Lock(path_buffer,ACCESS_READ)) { // Examine and unlock Examine(lock,fib); UnLock(lock); // If datestamp on directory has changed, don't go to it if (CompareDates(&fib->fib_Date,&buffer->buf_DirectoryDate)!=0) continue; } else continue; } ret=1; break; } } } } // Did we find one? if (ret) { // Go to buffer if requested if (!(flags&LISTER_BFPF_DONT_MOVE) && lister) { // Show buffer in lister lister_show_buffer(lister,buffer,1,1); // See if buffer needs re-reading lister_check_old_buffer(lister,0); } } else buffer=0; // Was the list locked? if (!(flags&LISTER_BFPF_DONT_LOCK)) { // Allowed to unlock? if (!(flags&LISTER_BFPF_DONT_UNLOCK) || !buffer) // Unlock buffer list unlock_listlock(&GUI->buffer_list); } // Cleanup if (!lister) { FreeVec(path_buffer); FreeDosObject(DOS_FIB,fib); } return buffer; }
// Checks buffers to see if they need re-reading // Called from the LISTER PROCESS void lister_check_old_buffer( Lister *lister, BOOL force) { int reread=0; #ifdef DEBUG if (lister) check_call("lister_check_old_buffer",lister); #endif // If re-read flag is set, and buffer is valid if ((force || environment->env->settings.dir_flags&DIRFLAGS_REREAD_CHANGED) && lister->cur_buffer->flags&DWF_VALID && lister->cur_buffer->buf_Path[0] && !lister->cur_buffer->buf_CustomHandler[0]) { DirBuffer *buffer; BPTR lock; // Get current buffer buffer=lister->cur_buffer; // Return on a device list if (!(IsListEmpty((struct List *)&buffer->entry_list)) && ((DirEntry *)buffer->entry_list.mlh_Head)->de_Node.dn_Type==ENTRY_DEVICE) return; // Lock and examine directory if (lock=Lock(buffer->buf_Path,ACCESS_READ)) { // Examine and unlock Examine(lock,lister->fib); UnLock(lock); // Make sure it's a directory if (lister->fib->fib_DirEntryType>0) { // See if datestamp has changed if (CompareDates(&buffer->buf_DirectoryDate,&lister->fib->fib_Date)>0) reread=1; // Or, see if disk has changed else if (buffer->buf_VolumeLabel[0]) { char rootname[512]; // Get root of current directory if (get_path_root(buffer->buf_Path,rootname,0)) { // See if disk name is not the same if (strcmp(rootname,buffer->buf_VolumeLabel)!=0) reread=1; } } } } // Did we need to re-read? if (reread) { // Re-read directory read_directory( lister, buffer->buf_Path, GETDIRF_RESELECT); } } }
// Searches for an empty buffer, or one with the same name (preferred) // If a suitable buffer is not found, it uses the current buffer // Called from the LISTER PROCESS DirBuffer *lister_buffer_find_empty(Lister *lister,char *path,struct DateStamp *stamp) { DirBuffer *buffer,*first_empty=0,*first_unlocked=0; #ifdef DEBUG if (lister) check_call("lister_buffer_find_empty",lister); #endif // Check we're not showing special check_special_buffer(lister,1); // If current buffer is empty, use that one if (!(lister->cur_buffer->flags&DWF_VALID)) { // Lock buffer buffer_lock(lister->cur_buffer,TRUE); // Free buffer buffer_freedir(lister->cur_buffer,1); // Unlock it buffer_unlock(lister->cur_buffer); return lister->cur_buffer; } // Lock buffer list lock_listlock(&GUI->buffer_list,TRUE); // Go through buffers in this list (backwards) for (buffer=(DirBuffer *)GUI->buffer_list.list.lh_TailPred; buffer->node.ln_Pred; buffer=(DirBuffer *)buffer->node.ln_Pred) { // See if this directory is available and matches our path if (path && stricmp(buffer->buf_Path,path)==0 && (!stamp || CompareDates(&buffer->buf_VolumeDate,stamp)==0)) { // Not locked, or in use by this lister? if (!buffer->buf_CurrentLister || buffer->buf_CurrentLister==lister) { // Store pointer first_empty=buffer; break; } } // If directory is empty, store pointer (if the first one) if (!buffer->buf_CurrentLister && !(buffer->flags&DWF_VALID) && !first_empty) first_empty=buffer; // First unlocked buffer? if (!buffer->buf_CurrentLister && !first_unlocked) { // Because buffers are moved to the head of the list whenever // they are accessed, this will point to the unlocked buffer // that was accessed the longest time ago first_unlocked=buffer; } } // If we found an empty one, use that one if (!(buffer=first_empty)) { // Allocate a new buffer if we're allowed to if (GUI->buffer_count<environment->env->settings.max_buffer_count && !(environment->env->settings.dir_flags&DIRFLAGS_DISABLE_CACHING)) { // If this fails, use first unlocked buffer=lister_new_buffer(lister); } } // If nothing yet, use first unlocked buffer (if there is one) if (!buffer && !(buffer=first_unlocked)) { // If not, re-use current buffer buffer=lister->cur_buffer; } // Lock buffer buffer_lock(buffer,TRUE); // Free buffer buffer_freedir(buffer,1); // Unlock buffer buffer_unlock(buffer); // Show buffer in lister lister_show_buffer(lister,buffer,0,1); // Unlock buffer list unlock_listlock(&GUI->buffer_list); // Return current buffer return lister->cur_buffer; }
bool LoadGameForm::Init(FormMgr *pfrmm, IniReader *pini, word idf) { if (!ShellForm::Init(pfrmm, pini, idf)) return false; ListControl *plstc = (ListControl *)GetControlPtr(kidcGameList); Rect rc; plstc->GetSubRects(&rc); int cEntries = rc.Height() / (gapfnt[kifntDefault]->GetHeight() + gcxyBorder); Date dateLast; dateLast.nYear = 0; int nHours24Last = -1; int nMinutesLast = -1; int nSecondsLast = -1; int nGameLast = -1; int nGame; for (nGame = 0; nGame < cEntries; nGame++) { int nHours24; int nMinutes; int nSeconds; char szLevel[64]; char szT[64]; Date date; if (HostGetSaveGameName(nGame, szLevel, sizeof(szLevel), &date, &nHours24, &nMinutes, &nSeconds)) { sprintf(szT, "%02d:%02d %s", nHours24, nMinutes, szLevel); // Remember last saved game bool fGreater = false; switch (CompareDates(&dateLast, &date)) { case 1: fGreater = false; break; case -1: fGreater = true; break; case 0: if (nHours24 > nHours24Last) fGreater = true; if (nHours24 == nHours24Last && nMinutes > nMinutesLast) fGreater = true; if (nHours24 == nHours24Last && nMinutes == nMinutesLast && nSeconds >= nSecondsLast) fGreater = true; break; } if (fGreater) { nGameLast = nGame; dateLast = date; nHours24Last = nHours24; nMinutesLast = nMinutes; nSecondsLast = nSeconds; } } else { strcpy(szT, szLevel); } plstc->Add(szT, (void *)(nGame + 1)); } m_nGameLast = nGameLast; return true; }
LONG main(VOID) { struct DosLibrary *DOSBase; struct RDArgs *readargs; LONG rargs[5], vargs[5]; UBYTE *source, *target; ULONG buffersize = 0; UBYTE *sourcedir, *targetdir; UBYTE *textbuffer, *tmp, *tmp1, *tmp2; struct AnchorPath *anchorpath; struct FileInfoBlock *fib, *targetfib; struct Process *process; APTR wptr; BPTR dirlock, filelock; BOOL checkdatestamp, all; LONG date, error, rc = 0; /* Fail silently if < 37 */ if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37)) { rargs[0] = 0L; rargs[1] = 0L; rargs[2] = 0L; rargs[3] = 0L; rargs[4] = 0L; if (readargs = ReadArgs("SOURCE/A,TARGET/A,DATE/S,ALL/S,BUFFER/K/N", rargs, NULL)) { source = (UBYTE *) rargs[0]; target = (UBYTE *) rargs[1]; checkdatestamp = (BOOL) rargs[2]; all = (BOOL) rargs[3]; if (!(sourcedir = AllocMem(StrLen(source) + 129, MEMF_CLEAR))) error = ERROR_NO_FREE_STORE; else { /* 128 bytes to print informative text */ textbuffer = sourcedir + StrLen(source) + 1; /* use user specified buffersize if indicated */ if (rargs[4]) buffersize = *((LONG *) rargs[4]); if (buffersize < BUFFERSIZE || buffersize > 4096) buffersize = BUFFERSIZE; if (!(targetdir = AllocMem(buffersize, MEMF_CLEAR))) error = ERROR_NO_FREE_STORE; else { if (!(targetfib = AllocDosObject(DOS_FIB, NULL))) error = ERROR_NO_FREE_STORE; else { /* * Check if source and target are valid. * * Separate source path from pattern (if any). Use the source path figure * out what to append to the target. */ /* No requesters */ process = (struct Process *) FindTask(NULL); wptr = process->pr_WindowPtr; process->pr_WindowPtr = (APTR) - 1L; if ((error = GetPath(source, sourcedir, StrLen(source) + 1) == 0)) { if (!(dirlock = Lock(sourcedir, SHARED_LOCK))) error = IoErr(); else { UnLock(dirlock); if (!(dirlock = Lock(target, SHARED_LOCK))) error = IoErr(); else { UnLock(dirlock); if (anchorpath = AllocMem(sizeof(struct AnchorPath) + buffersize, MEMF_CLEAR)) { anchorpath->ap_Strlen = buffersize; /* Allow to break on CTRL-C */ anchorpath->ap_BreakBits = SIGBREAKF_CTRL_C; if ((error = MatchFirst(source, anchorpath)) == 0) { do { fib = &(anchorpath->ap_Info); /* * APF_DIDDIR indicates that we used returned from a * directory. In that case we clear both APF_DIDDIR and * APF_DODIR, so we can start afresh with the next one. */ if (anchorpath->ap_Flags & APF_DIDDIR) anchorpath->ap_Flags &= ~(APF_DODIR | APF_DIDDIR); else { /* * Make a filename for the target directory. First copy * targetname into buffer. */ targetdir[0] = '\0'; tmp = targetdir; tmp1 = target; while (*tmp++ = *tmp1++); /* Skip sourcename in ap_Buf */ tmp1 = sourcedir; tmp2 = anchorpath->ap_Buf; while (*tmp1++ == *tmp2++); /* Skip back 1 if not after a separator */ if (*(tmp2 - 1) != '/') tmp2--; /* * We hit the source itself, don't compare it, but enter * it. */ if (*tmp2 == 0) { anchorpath->ap_Flags |= APF_DODIR; continue; } /* Build it */ if (AddPart(targetdir, tmp2, buffersize - 1)) vargs[0] = (LONG) targetdir; else { PrintFault(ERROR_NO_FREE_STORE, NULL); break; } /* Lock it and check it out */ if (filelock = Lock(targetdir, SHARED_LOCK)) { if ((Examine(filelock, targetfib)) == DOSTRUE) { textbuffer[0] = '\0'; /* * To get nice output without work I use AddPart() to * add differences to the textbuffer. */ if (targetfib->fib_DirEntryType != fib->fib_DirEntryType) AddPart(textbuffer, "of different type", 128); else { if (targetfib->fib_Size < fib->fib_Size) AddPart(textbuffer, "smaller", 128); else if (targetfib->fib_Size > fib->fib_Size) AddPart(textbuffer, "larger", 128); if (checkdatestamp) { date = CompareDates((struct DateStamp *) & (fib->fib_Date), (struct DateStamp *) & (targetfib->fib_Date)); if (date < 0) AddPart(textbuffer, "older", 128); else if (date > 0) AddPart(textbuffer, "newer", 128); } } if (*textbuffer != NULL) { vargs[1] = (LONG) textbuffer; VFPrintf(Output(), "%s: object %s\n", vargs); } } else PrintFault(IoErr(), targetdir); UnLock(filelock); } else { PrintFault(IoErr(), targetdir); /* * If and error occured on a directory name, don't enter * it. */ if (fib->fib_DirEntryType > 0) continue; } /* * If the ALL keyword has been used and this is a directory * enter it by setting the APF_DODIR flag. */ if (fib->fib_DirEntryType > 0 && all != FALSE) anchorpath->ap_Flags |= APF_DODIR; } } while ((error = MatchNext(anchorpath)) == 0); } MatchEnd(anchorpath); if (error == ERROR_NO_MORE_ENTRIES) error = 0; FreeMem(anchorpath, sizeof(struct AnchorPath) + buffersize); } } } /* Reset windowpointer */ process->pr_WindowPtr = wptr; } else PrintFault(error, NULL); FreeDosObject(DOS_FIB, targetfib); } FreeMem(targetdir, buffersize); } FreeMem(sourcedir, StrLen(sourcedir) + 129); } FreeArgs(readargs); } else error = IoErr(); SetIoErr(error); if (error) { PrintFault(error, NULL); if (error = ERROR_BREAK) rc = RETURN_WARN; else error = RETURN_FAIL; } CloseLibrary((struct Library *) DOSBase); } return (rc); }