int lib_dos_f_MatchEnd_2(emumsg_syscall_t *msg) { /* Make real syscall */ MatchEnd((struct AnchorPath *)msg->arg[0]._aptr); return HOOK_DONE; }
static boolean createTagsForAmigaWildcard (const char *const pattern) { boolean resize = FALSE; struct AnchorPath *const anchor = (struct AnchorPath *) eMalloc ((size_t) ANCHOR_SIZE); LONG result; memset (anchor, 0, (size_t) ANCHOR_SIZE); anchor->ap_Strlen = ANCHOR_BUF_SIZE; /* Allow '.' for current directory */ #ifdef APF_DODOT anchor->ap_Flags = APF_DODOT | APF_DOWILD; #else anchor->ap_Flags = APF_DoDot | APF_DoWild; #endif result = MatchFirst ((UBYTE *) pattern, anchor); while (result == 0) { resize |= createTagsForEntry ((char *) anchor->ap_Buf); result = MatchNext (anchor); } MatchEnd (anchor); eFree (anchor); return resize; }
char * wildcard_expansion (char *wc, char *o) { # define PATH_SIZE 1024 struct AnchorPath * apath; if ( (apath = AllocMem (sizeof (struct AnchorPath) + PATH_SIZE, MEMF_CLEAR)) ) { apath->ap_Strlen = PATH_SIZE; if (MatchFirst (wc, apath) == 0) { do { o = variable_buffer_output (o, apath->ap_Buf, strlen (apath->ap_Buf)); o = variable_buffer_output (o, " ",1); } while (MatchNext (apath) == 0); } MatchEnd (apath); FreeMem (apath, sizeof (struct AnchorPath) + PATH_SIZE); } return o; }
void Q_FindClose (void) { if (apath == NULL) return; MatchEnd(apath); FreeVec(apath); UnLock(CurrentDir(oldcurrentdir)); oldcurrentdir = 0; apath = NULL; free (pattern_str); pattern_str = NULL; }
// Build theme list Att_List *theme_build_list(char *path) { Att_List *list; // Create list if ((list=Att_NewList(LISTF_POOL))) { long err; char buf[280]; #ifdef __amigaos4__ struct AnchorPath *anchor; if (!(anchor = AllocDosObjectTags( DOS_ANCHORPATH, ADO_Strlen, 0, ADO_Flags, APF_DOWILD, ADO_Mask, 0, TAG_DONE))) { return NULL; } #else D_S(struct AnchorPath,anchor) anchor->ap_BreakBits=0; anchor->ap_Flags=APF_DOWILD; anchor->ap_Strlen=0; #endif strcpy(buf,path); AddPart(buf,"#?.theme",280); err=MatchFirst(buf,anchor); while (!err) { char *ptr; if (anchor->ap_Info.fib_DirEntryType>0) { anchor->ap_Flags&=~APF_DODIR; continue; } anchor->ap_Info.fib_FileName[strlen(anchor->ap_Info.fib_FileName)-6]=0; for (ptr=anchor->ap_Info.fib_FileName;*ptr;ptr++) if (*ptr=='_') *ptr=' '; Att_NewNode(list,anchor->ap_Info.fib_FileName,0,ADDNODE_SORT); err=MatchNext(anchor); } MatchEnd(anchor); #ifdef __amigaos4__ FreeDosObject(DOS_ANCHORPATH,anchor); #endif }
// Read filetype list void filetype_read_list( APTR memory, struct List *main_list) { Cfg_FiletypeList *list; #ifdef __amigaos4__ struct AnchorPathOld *anchor; #else struct AnchorPath *anchor; #endif long error; // Allocate anchor path #ifdef __amigaos4__ if (!(anchor=AllocMemH(memory,sizeof(struct AnchorPathOld)+256))) return; #else if (!(anchor=AllocMemH(memory,sizeof(struct AnchorPath)+256))) return; #endif // Initialise anchor path anchor->ap_Strlen=256; anchor->ap_BreakBits=IPCSIG_QUIT; anchor->ap_Flags=APF_DOWILD; // Search for filetypes error=MatchFirst("dopus5:filetypes/~(#?.info)",anchor); // Continue while there's files while (!error) { // Read new filetype list if ((list=ReadFiletypes(anchor->ap_Buf,memory))) { // Add to list AddTail(main_list,&list->node); } // Find next file in directory error=MatchNext(anchor); } // Clean up match stuff MatchEnd(anchor); FreeMemH(anchor); }
// 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)); } }
void visainfo(void) { struct AnchorPath *anchor; char filnamn[100],pattern[100]; if(!argument[0]) { sendfile("NiKom:Texter/Info.txt"); return; } if(anchor = AllocMem(sizeof(struct AnchorPath),MEMF_CLEAR)) { sprintf(pattern,"NiKom:Texter/%s#?.txt",argument); if(MatchFirst(pattern,anchor)) { puttekn("\r\n\nFinns ingen sådan fil!\r\n",-1); return; } sprintf(filnamn,"NiKom:Texter/%s",anchor->ap_Info.fib_FileName); MatchEnd(anchor); FreeMem(anchor,sizeof(struct AnchorPath)); sendfile(filnamn); } else puttekn("\n\n\rKunde inte allokera en Anchorpath\n\r",-1); }
/* * matchwild - pushes filenames which match the given pattern. * it also returns a count of the matches found. */ int matchwild(char *pattern) { static char *special = "#?*%([|"; /* )] */ struct AnchorPath *APath; int matches = 0; LONG error; /* Check if correct OS */ if (isOldDOS()) return; /* Check if pattern is special */ if (!(strpbrk(pattern, special))) return; APath = AllocMem(sizeof(struct AnchorPath) + BLKSIZE, MEMF_CLEAR); if (!(APath)) return; APath->ap_Strlen = BLKSIZE; APath->ap_BreakBits = SIGBREAKF_CTRL_C; if ((error = MatchFirst((UBYTE *) pattern, APath)) == 0) { do { ++matches; push(strdup((char *) APath->ap_Buf)); } while ((error = MatchNext(APath)) == 0); } MatchEnd(APath); if (error != ERROR_NO_MORE_ENTRIES) { PrintFault(error, NULL); } FreeMem(APath, sizeof(struct AnchorPath) + BLKSIZE); return matches; }
int main(void) { struct AnchorPath aPath; struct RDArgs *rda; IPTR args[5] = { NULL, NULL, NULL, NULL, FALSE }; struct DateTime dt; LONG error = 0; BPTR oldCurDir; LONG retval = RETURN_OK; BOOL timeError = FALSE; /* Error in time/date specification? */ rda = ReadArgs("FILE/A,WEEKDAY,DATE,TIME,ALL/S", args, NULL); if(rda == NULL) { PrintFault(IoErr(), "SetDate"); return RETURN_FAIL; } /* Use the current time as default (if no DATE, TIME or WEEKDAY is defined) */ DateStamp(&dt.dat_Stamp); dt.dat_Flags = DTF_FUTURE; dt.dat_Format = FORMAT_DOS; dt.dat_StrDate = (TEXT *)args[ARG_DATE]; dt.dat_StrTime = (TEXT *)args[ARG_TIME]; /* Change the defaults according to the user's specifications */ if(StrToDate(&dt)) { dt.dat_StrDate = (TEXT *)args[ARG_WEEKDAY]; if(!StrToDate(&dt)) timeError = TRUE; } else timeError = TRUE; if(timeError) { PutStr("SetDate: Illegal DATE or TIME string\n"); return RETURN_FAIL; } aPath.ap_Flags = (BOOL)args[ARG_ALL] ? APF_DOWILD : 0; aPath.ap_BreakBits = SIGBREAKF_CTRL_C; aPath.ap_Strlen = 0; /* Save the current dir */ oldCurDir = CurrentDir(NULL); CurrentDir(oldCurDir); error = MatchFirst((STRPTR)args[ARG_FILE], &aPath); while(error == 0) { CurrentDir(aPath.ap_Current->an_Lock); // VPrintf("%s", (IPTR *)&aPath.ap_Info.fib_FileName); SetFileDate(aPath.ap_Info.fib_FileName, &dt.dat_Stamp); error = MatchNext(&aPath); } MatchEnd(&aPath); /* Restore the current dir */ CurrentDir(oldCurDir); FreeArgs(rda); if(error != ERROR_NO_MORE_ENTRIES) { if(error == ERROR_BREAK) retval = RETURN_WARN; else retval = RETURN_FAIL; PrintFault(IoErr(), "SetDate"); } return retval; }
// Read program groups (icon list must be locked) void backdrop_read_groups(BackdropInfo *info) { BPTR lock; struct FileInfoBlock __aligned fib; struct AnchorPath *anchor; short error; // Allocate anchor if (!(anchor=AllocVec(sizeof(struct AnchorPath)+256,MEMF_CLEAR))) return; // Initialise anchor anchor->ap_Strlen=256; // Search for icons error=MatchFirst("dopus5:groups/#?.info",anchor); // Continue while there's files while (!error) { char *ptr; // Strip .info suffix if (ptr=sufcmp(anchor->ap_Buf,".info")) *ptr=0; // See if directory exists to go with it if (lock=Lock(anchor->ap_Buf,ACCESS_READ)) { // Examine file Examine(lock,&fib); UnLock(lock); // Is it a directory? if (fib.fib_DirEntryType>0) { BackdropObject *object; struct List *search; // Lock icon list lock_listlock(&info->objects,FALSE); // See if group already exists search=&info->objects.list; while (object=(BackdropObject *)FindNameI(search,fib.fib_FileName)) { // Is it a group? if (object->type==BDO_GROUP) break; // Continue search search=(struct List *)object; } // Unlock icon list unlock_listlock(&info->objects); // Didn't have it already? if (!object) { // Create a new icon for this if (object=backdrop_leftout_new(info,anchor->ap_Buf,0,0)) { // Change type to group object->type=BDO_GROUP; // Get icon backdrop_get_icon(info,object,GETICON_CD); } } } } // Get next entry error=MatchNext(anchor); } // Clean up MatchEnd(anchor); FreeVec(anchor); }
LONG main(VOID) { struct RDArgs *readargs; LONG rargs[5]; UBYTE *source; ULONG buffersize = 0; UBYTE *sourcedir; UBYTE *textbuffer; struct AnchorPath *anchorpath; struct FileInfoBlock *fib; BPTR dirlock, filelock; LONG error, rc = 0; rargs[0] = 0L; if (readargs = ReadArgs("SOURCE/A", rargs, NULL)) { source = (UBYTE *) rargs[0]; if (!(sourcedir = AllocVec(strlen(source) + 129, MEMF_CLEAR))) error = ERROR_NO_FREE_STORE; else { /* 128 bytes to print informative text */ textbuffer = sourcedir + strlen(source) + 1; buffersize = BUFFERSIZE; if ((error = GetPath(source, sourcedir, strlen(source) + 1) == 0)) { if (!(dirlock = Lock(sourcedir, SHARED_LOCK))) error = IoErr(); else { UnLock(dirlock); if (anchorpath = AllocVec(sizeof(struct AnchorPath) + buffersize,MEMF_CLEAR)) { anchorpath->ap_Strlen = buffersize; if ((error = MatchFirst(source, anchorpath)) == 0) { do { char *path; fib = &(anchorpath->ap_Info); path=anchorpath->ap_Buf; /* * 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. */ printf("path %s - %lx ",anchorpath->ap_Buf,anchorpath->ap_Flags); if (anchorpath->ap_Flags & APF_DIDDIR) { anchorpath->ap_Flags &= ~(APF_DODIR | APF_DIDDIR); //printf(" Returned --- SKIP\n"); } else { if (fib->fib_DirEntryType > 0 ) { anchorpath->ap_Flags |= APF_DODIR; printf("============================="); } else { // Trim .info if needed if (strlen(path) >= 5 && !stricmp( path + strlen(path) - 5, ".info" )) { printf("ICON "); } else printf("NOT ICON"); } } printf("\n"); } while ((error = MatchNext(anchorpath)) == 0); } MatchEnd(anchorpath); if (error == ERROR_NO_MORE_ENTRIES) error = 0; FreeVec(anchorpath); } } } FreeVec(sourcedir); } FreeArgs(readargs); } return (rc); }
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); }