void CookiePath::DebugWritePath(FILE* fp) { CookiePath* cp = (CookiePath*) Parent(); if (cp) { cp->DebugWritePath(fp); fprintf(fp, "/%s", PathPart()); } else fprintf(fp, "%s", PathPart()); }
CookiePath *CookiePath::GetNextPrefix() { OpStringC8 pth( PathPart()); if(pth.IsEmpty()) return NULL; CookiePath *cp = Pred(); int len1 = pth.Length(); int clen; int test = 1; while(cp && test!=0) { clen = cp->PathPart().Length(); if(clen < len1 && UriUnescape::isstrprefix(cp->PathPart().CStr(), pth.CStr(), UriUnescape::All)) test = 0; else test = UriUnescape::strcmp(cp->PathPart().CStr(), pth.CStr(), UriUnescape::Safe); if (test != 0) cp = cp->Pred(); } return (test == 0 ? cp : NULL); }
/************************************************************************** MUIM_Configdata_Save **************************************************************************/ IPTR Configdata__MUIM_Save(struct IClass *cl, Object * obj, struct MUIP_Configdata_Save *msg) { struct IFFHandle *iff; if ((iff = AllocIFF())) { if (!(iff->iff_Stream = (IPTR)Open(msg->filename,MODE_NEWFILE))) { /* Try to Create the directory where the file is located */ char *path = StrDup(msg->filename); if (path) { char *path_end = PathPart(path); if (path_end != path) { BPTR lock; *path_end = 0; if ((lock = CreateDir(path))) { UnLock(lock); iff->iff_Stream = (IPTR)Open(msg->filename,MODE_NEWFILE); } } FreeVec(path); } } if (iff->iff_Stream) { InitIFFasDOS(iff); if (!OpenIFF(iff, IFFF_WRITE)) { if (!PushChunk(iff, MAKE_ID('P','R','E','F'), ID_FORM, IFFSIZE_UNKNOWN)) { Configdata_SetWindowPos(cl, obj, (APTR)msg); if (SavePrefsHeader(iff)) { DoMethod(obj,MUIM_Dataspace_WriteIFF, (IPTR)iff, 0, MAKE_ID('M','U','I','C')); } PopChunk(iff); } CloseIFF(iff); } Close((BPTR)iff->iff_Stream); } FreeIFF(iff); } return 0; }
// Get font name from string void font_get_name(font_data *data,char *name) { short len; // .font suffix? if ((len=strlen(name))>5 && stricmp(name+len-5,".font")==0) { // Use name as given strcpy(data->font_name,name); } // Numeric name? else if ((len=atoi(FilePart(name)))) { // Strip filename *(PathPart(name))=0; // Store name strcpy(data->font_name,name); strcat(data->font_name,".font"); // Store size data->font_size=len; data->first=TRUE; } // Name specified without .font else { // Store name strcpy(data->font_name,name); strcat(data->font_name,".font"); } }
char *uilib_select_file_autostart(const char *title, unsigned int filterlist, unsigned int type, int style, int *autostart, char *resource_readonly) { char *name = NULL; char *initialdir = NULL; char *initialfile = NULL; // char *filter = NULL; // unsigned int filterindex; // OPENFILENAME ofn; // int result; char *ret = NULL; if (styles[style].initialdir_resource != NULL) resources_get_value(styles[style].initialdir_resource, (void *)&initialdir); initialfile = ui_file_selector_initialfile[style]; if (styles[style].file_resource != NULL) resources_get_value(styles[style].file_resource, (void *)&initialfile); #if 0 if (fontfile == NULL) { fontfile = util_concat(archdep_boot_path(), "\\fonts\\cbm-directory-charset.fon", NULL); font_loaded = 0; EnumFontFamilies(GetDC(NULL), "cbm-directory-charset/ck!", (FONTENUMPROC)EnumFontProc, (LPARAM)&font_loaded); if (font_loaded == 0) { font_loaded = AddFontResource(fontfile); } } filter = set_filter(filterlist, &filterindex); memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.hInstance = winmain_instance; ofn.lpstrFilter = filter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = filterindex; ofn.lpstrFile = st_name; ofn.nMaxFile = sizeof(st_name); ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = initialdir; ofn.lpstrTitle = title; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOTESTFILECREATE | OFN_SHAREAWARE | OFN_ENABLESIZING; if (styles[style].TemplateID != 0) { ofn.Flags |= OFN_ENABLEHOOK | OFN_ENABLETEMPLATE; ofn.lpfnHook = styles[style].hook_proc; ofn.lpTemplateName = MAKEINTRESOURCE(styles[style].TemplateID); } else { ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; } if (type == UILIB_SELECTOR_TYPE_FILE_LOAD) ofn.Flags |= OFN_FILEMUSTEXIST; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = NULL; read_content_func = styles[style].content_read_function; autostart_result = autostart; res_readonly = resource_readonly; vsync_suspend_speed_eval(); if (type == UILIB_SELECTOR_TYPE_FILE_SAVE) result = GetSaveFileName(&ofn); else result = GetOpenFileName(&ofn); update_filter_history(ofn.nFilterIndex); #endif name = ui_filereq(title, styles[style].TemplateID, initialdir, initialfile, styles[style].content_read_function, autostart, resource_readonly); if (name != NULL) { char newdir[1024], *ptr = PathPart(name); memcpy(newdir, name, (int)(ptr - name)); newdir[(int)(ptr - name)] = '\0'; if (ui_file_selector_initialfile[style] != NULL) lib_free(ui_file_selector_initialfile[style]); if (styles[style].file_resource != NULL) resources_set_value(styles[style].file_resource, FilePart(name)); ui_file_selector_initialfile[style] = lib_stralloc(FilePart(name)); resources_set_value(styles[style].initialdir_resource, newdir); ret = lib_stralloc(name); } // lib_free(filter); return ret; }
static int findFirstMatch( char * pFileName, char * wpName ) { static BOOL isfirst=TRUE; BPTR dirlock; struct Node * newnode; /* char * onefname; */ char * point; unsigned len; /* printf("Called findFirstMatch: %s %s\n", pFileName, wpName); */ if(isfirst) { isfirst=FALSE; NewListPPC(&filelist); fib = AllocDosObject(DOS_FIB, NULL); strcpy(filepart, FilePart(pFileName)); if((point=PathPart(pFileName)) == pFileName) /* Current directory */ { dirlock=DupLock(((struct Process *)FindTask(NULL))->pr_CurrentDir); *pathpart=0; } else { len =(unsigned) (point-pFileName); strncpy(pathpart, pFileName, len); pathpart[len]=0; dirlock=Lock(pathpart, ACCESS_READ); } if(dirlock) { if(Examine(dirlock, fib)) { while(ExNext(dirlock, fib)) { if(fib->fib_DirEntryType == ST_FILE || fib->fib_DirEntryType == ST_LINKFILE) { /* printf("%s\n", fib->fib_FileName); */ newnode=malloc(sizeof(struct Node)); newnode->ln_Type = NT_USER; newnode->ln_Name=malloc(strlen(fib->fib_FileName)+1); strcpy(newnode->ln_Name, fib->fib_FileName); AddTailPPC(&filelist, newnode); } } } UnLock(dirlock); FreeDosObject(DOS_FIB, fib); } else return FALSE; } if(ParsePatternNoCase(filepart, parsebuf, PARSEBUFLEN)) { for(currentnode = filelist.lh_Head; currentnode->ln_Succ; currentnode = currentnode->ln_Succ) { /* printf("Match %s %s\n", parsebuf, currentnode->ln_Name); */ if(MatchPatternNoCase(parsebuf, currentnode->ln_Name)) { /* printf("Trovato %s\n", currentnode->ln_Name); */ strcpy(wpName, pathpart); AddPart(wpName, currentnode->ln_Name, MAX_NAMELEN); currentnode = currentnode->ln_Succ; return TRUE; } } /* return FALSE; */ } return FALSE; }
bool PathStartsWith(const string &Path, const string &Start) { string PathPart(Start); DeleteEndSlash(PathPart, true); return Path.IsSubStrAt(0, PathPart) && (Path.GetLength() == PathPart.GetLength() || IsSlash(Path[PathPart.GetLength()])); }
LONG GetPath(UBYTE * path, UBYTE * buffer, LONG buffersize) { UBYTE *pathpart, *filepart; UBYTE *tmp1, *tmp2; BPTR lock; struct FileInfoBlock *fib; LONG error = 0; /* * If there seems to be no path, the pathpart will point to the filepart too, so we * need to check for that. */ filepart = FilePart(path); pathpart = PathPart(path); /* * This also handles cases where there is only a volume/device name, only a * directory name or a combo of those. */ if (pathpart == path) { /* * There seems to be only one component. Copy it if it is not wild. Caller will * have to check whether if it exists and if it is a file or directory. */ if (!(ItsWild(pathpart))) pathpart = NULL; } if (pathpart != path) { /* * If pathpart equals filepart (pointer wise) then there is only one component * (possible preceeded by a volume name). */ if (pathpart == filepart) { if (!(ItsWild(pathpart))) pathpart = NULL; } else { /* Try to lock it to determine if the last component is a directory. */ if (lock = Lock(path, SHARED_LOCK)) { if (fib = AllocVec(sizeof(struct FileInfoBlock), MEMF_CLEAR)) { if ((Examine(lock, fib)) == DOSTRUE) { /* Hey it's a directory after all */ if (fib->fib_DirEntryType > 0) pathpart = NULL; } FreeVec(fib); } UnLock(lock); } /* else treat it as a filename */ } /* Copy the pathpart in the buffer */ tmp1 = buffer; tmp2 = path; while ((*tmp1++ = *tmp2++) && (tmp2 != pathpart)) { if (tmp1 == (buffer + buffersize)) { error = ERROR_NO_FREE_STORE; break; } } *tmp1 = '\0'; /* NULL terminate. */ } return (error); }
// Set an environment variable permanently void LIBFUNC L_SetEnv( REG(a0, char *name), REG(a1, char *data), REG(d0, BOOL save)) { #ifdef __AROS__ // same as below. we really need a recursive mkdir function... char path[256] = "ENV:"; char *ptr; BPTR pathlock; strncat(path, name, sizeof(path)); *PathPart(path) = '\0'; for (ptr = path + 1; *ptr; ptr++) { if(*ptr == '/') { *ptr = '\0'; if ((pathlock = Lock(path, ACCESS_READ)) || (pathlock = CreateDir(path))) UnLock(pathlock); *ptr = '/'; } } if ((pathlock = Lock(path, ACCESS_READ)) || (pathlock = CreateDir(path))) UnLock(pathlock); #endif // Set variable if ((SetVar(name,data,-1,GVF_GLOBAL_ONLY)) && save) { BPTR old,dir; // Switch to ENVARC: if ((dir=Lock("envarc:",ACCESS_READ))) { char *ptr,*start,*tmp; BPTR file; // Change CD old=CurrentDir(dir); // Create temporary copy of 'name' if ((tmp = AllocVec(strlen(name) + 1, MEMF_ANY))) { strcpy(tmp, name); name = tmp; // Go through string for (ptr=name,start=name;*ptr;ptr++) { // Directory separator? if (*ptr=='/') { // Null it out temporarily *ptr=0; // Try to lock or create directory if ((dir=Lock(start,ACCESS_READ)) || (dir=CreateDir(start))) { // CD into directory UnLock(CurrentDir(dir)); // Restore character we destroyed *ptr='/'; // Bump start pointer start=ptr+1; } else // Failed break; } } // Open file if ((file=Open(start,MODE_NEWFILE))) { // Write data Write(file,data,strlen(data)); Close(file); } FreeVec(tmp); } // Restore CD UnLock(CurrentDir(old)); } } }