void SplitFilePathName(const CString& FilePathName, CString& FilePath, CString& FileName, CString& FileExt) { CString name_ext; int pos = std::max(LastCharPos(FilePathName,'/'),LastCharPos(FilePathName,'\\')); if (pos >= 1) { FilePath = LeftStr(FilePathName,pos-1); name_ext = RightStr(FilePathName,pos+1); } else { FilePath.Clear(); name_ext = FilePathName; } pos = LastCharPos(name_ext,'.'); if (pos >= 0) { if (pos >= 1) { FileName = LeftStr(name_ext,pos-1); } else { FileName.Clear(); } FileExt = RightStr(name_ext,pos+1); } else { FileName = name_ext; FileExt.Clear(); } }
/* ------------------------------------------------------------------------------ function ChompPathDelim(const Path: string): string; ------------------------------------------------------------------------------ */ wxString ChompPathDelim(wxString const & Path) { if ((Path.Length() != 0) && (Path.Last() == PathDelim)) return LeftStr(Path, Length(Path) - 1); else return Path; }
CString ExtractFilePath(const CString& FilePathName) { CString result; int pos = std::max(LastCharPos(FilePathName,'/'),LastCharPos(FilePathName,'\\')); if (pos >= 1) { result = LeftStr(FilePathName,pos-1); } return result; }
/* ------------------------------------------------------------------------------ function FileIsInPath(const Filename, Path: string): boolean; ------------------------------------------------------------------------------ */ bool FileIsInDirectory(wxString const & Filename, wxString const & Directory) { bool result; wxString ExpFile; wxString ExpDir; int LenFile; int LenDir; long p; ExpFile = CleanAndExpandFilename(Filename); ExpDir = CleanAndExpandDirectory(Directory); LenFile = Length(ExpFile); LenDir = Length(ExpDir); p = LenFile; while ((p > 0) && (ExpFile[(unsigned int)p] != PathDelim)) --p; result = (p == LenDir) && (p < LenFile) && (CompareFilenames(ExpDir, LeftStr(ExpFile, p)) == 0); return result; }
/* HTDir_headLine ** -------------- ** Puts out the header line of the list itself ** Returns YES if OK, else NO */ PRIVATE BOOL HTDir_headLine (HTDir *dir) { if (dir) { char *tp; HTStructured *target = dir->target; START(HTML_PRE); if (dir->show & HT_DS_ICON) { HTIconNode * icon = HTIcon_find(HT_IS_BLANK, NULL, NULL); if (icon) { char * alt = HTIcon_alternative(icon, NO); HTMLPutImg(target, HTIcon_url(icon), alt, NULL); HT_FREE(alt); PUTC(' '); } } tp = dir->fnbuf; LeftStr(&tp, "Name", dir->curfw); LeftStr(&tp, " ", HT_DLEN_SPACE); *tp = '\0'; PUTS(dir->fnbuf); tp = dir->lnbuf; if (dir->show & HT_DS_DATE) { LeftStr(&tp, "Last Modified", HT_DLEN_DATE); LeftStr(&tp, " ", HT_DLEN_SPACE); } if (dir->show & HT_DS_SIZE) { RightStr(&tp, "Size", HT_DLEN_SIZE); LeftStr(&tp, " ", HT_DLEN_SPACE); } if (dir->show & HT_DS_DES) { LeftStr(&tp, "Description", HT_DLEN_DATE); LeftStr(&tp, " ", HT_DLEN_SPACE); } *tp = '\0'; PUTS(dir->lnbuf); END(HTML_PRE); START(HTML_HR); START(HTML_PRE); return YES; } return NO; }
/* ** Output an element in HTML ** Returns YES if OK, else NO */ PRIVATE BOOL HTDirNode_print (HTDir *dir, HTDirNode *node) { char *tp = NULL; HTStructured *target = dir->target; if (dir->show & HT_DS_ICON) { HTFormat format = NULL; HTEncoding encoding = NULL; double q=1.0; HTIconNode * icon; if (node->mode == HT_IS_FILE) HTBind_getFormat(node->fname, &format, &encoding, NULL, NULL, &q); icon = HTIcon_find(node->mode, format, encoding); /* Are we having a hot or a cold icon? */ if (!(dir->show & HT_DS_HOTI)) { if (icon) { char * alt = HTIcon_alternative(icon, YES); HTMLPutImg(target, HTIcon_url(icon), alt, NULL); HT_FREE(alt); PUTC(' '); } } /* Start the anchor element */ if (dir->base) { char *escaped = expand_name(node->fname, node->mode); char *full; if ((full = (char *) HT_MALLOC(strlen(escaped)+strlen(dir->base)+1)) == NULL) HT_OUTOFMEM("HTDirNode_print"); strcpy(full, dir->base); strcat(full, escaped); HTStartAnchor(target, NULL, full); HT_FREE(escaped); HT_FREE(full); } else { char *escaped = expand_name(node->fname, node->mode); HTStartAnchor(target, NULL, escaped); HT_FREE(escaped); } if (dir->show & HT_DS_HOTI) { char * alt = HTIcon_alternative(icon, YES); HTMLPutImg(target, HTIcon_url(icon), alt, NULL); PUTC(' '); } } else { if (dir->base) { char *escaped = expand_name(node->fname, node->mode); char *full; if ((full = (char *) HT_MALLOC(strlen(escaped)+strlen(dir->base)+1)) == NULL) HT_OUTOFMEM("HTDirNode_print"); strcpy(full, dir->base); strcat(full, escaped); HTStartAnchor(target, NULL, escaped); HT_FREE(escaped); HT_FREE(full); } else { char *escaped = HTEscape(node->fname, URL_XPALPHAS); HTStartAnchor(target, NULL, escaped); HT_FREE(escaped); } } /* Insert the anchor text and end anchor */ { char *in = node->fname; char *out = dir->fnbuf; int l = dir->curfw; while (l-- > 0 && *in && (*out++ = *in++)); if (*in) *(out-1) = '>'; else if (node->mode == HT_IS_DIR) { *out++ = '/'; l--; } *out = '\0'; PUTS(dir->fnbuf); END(HTML_A); out = dir->fnbuf; while (l-- >= 0) *out++ = ' '; LeftStr(&out, " ", HT_DLEN_SPACE); *out = '\0'; PUTS(dir->fnbuf); } /* Print the rest of it */ tp = dir->lnbuf; if (node->date) { RightStr(&tp, node->date, HT_DLEN_DATE); LeftStr(&tp, " ", HT_DLEN_SPACE); } if (node->size) { RightStr(&tp, node->size, HT_DLEN_SIZE); LeftStr(&tp, " ", HT_DLEN_SPACE); } if (node->note) { LeftStr(&tp, node->note, HT_DLEN_DES); LeftStr(&tp, " ", HT_DLEN_SPACE); } *tp = '\0'; PUTS(dir->lnbuf); PUTC('\n'); return YES; }