static const XML_Char * resolveSystemId(const XML_Char *base, const XML_Char *systemId, XML_Char **toFree) { XML_Char *s; *toFree = 0; if (!base || *systemId == T('/') #if (defined(WIN32) || defined(__WATCOMC__)) || *systemId == T('\\') || (isAsciiLetter(systemId[0]) && systemId[1] == T(':')) #endif ) return systemId; *toFree = (XML_Char *)malloc((tcslen(base) + tcslen(systemId) + 2) * sizeof(XML_Char)); if (!*toFree) return systemId; tcscpy(*toFree, base); s = *toFree; if (tcsrchr(s, T('/'))) s = tcsrchr(s, T('/')) + 1; #if (defined(WIN32) || defined(__WATCOMC__)) if (tcsrchr(s, T('\\'))) s = tcsrchr(s, T('\\')) + 1; #endif tcscpy(s, systemId); return *toFree; }
bool_t SetFileExt(tchar_t* URL, size_t URLLen, const tchar_t* Ext) { tchar_t *p,*q,*p2; bool_t HasHost; p = (tchar_t*) GetProtocol(URL,NULL,0,&HasHost); q = p; p = tcsrchr(q,'\\'); p2 = tcsrchr(q,'/'); if (!p || (p2 && p2>p)) p=p2; if (p) q = p+1; else if (HasHost) // only hostname return 0; if (!q[0]) // no filename at all? return 0; p = tcsrchr(q,'.'); if (p) *p = 0; tcscat_s(URL,URLLen,T(".")); tcscat_s(URL,URLLen,Ext); return 1; }
bool_t UpperPath(tchar_t* Path, tchar_t* Last, size_t LastLen) { tchar_t *a,*b,*c; bool_t HasHost; tchar_t Mime[32]; if (!*Path) return 0; RemovePathDelimiter(Path); c = (tchar_t*)GetProtocol(Path,Mime,TSIZEOF(Mime),&HasHost); a = tcsrchr(c,'\\'); b = tcsrchr(c,'/'); if (!a || (b && b>a)) a=b; #ifdef TARGET_PS2SDK if (!a && (a = tcschr(c,':'))!=NULL) if (a[1]==0) a = NULL; #endif if (!a) { if (tcsicmp(Mime, T("smb")) == 0) { *c = 0; tcscpy_s(Last, LastLen, Path); return 1; } if (HasHost && tcsicmp(Mime, T("upnp"))!=0) return 0; a=c; if (!a[0]) // only mime left a=c=Path; } else ++a; if (Last) tcscpy_s(Last,LastLen,a); if (a==c) *a = 0; #ifdef TARGET_PS2SDK if (a>c && a[-1]==':') *a = 0; #endif while (--a>=c && (*a=='\\' || *a=='/')) *a = 0; return 1; }
static err_t Open(urlpart* p, const tchar_t* URL, int Flags) { err_t Result; const tchar_t *String, *Equal; tchar_t Value[MAXPATHFULL]; datetime_t Date = INVALID_DATETIME_T; String = tcsrchr(URL,URLPART_SEP_CHAR); if (!String) return ERR_INVALID_DATA; Clear(p); Node_SetData((node*)p,STREAM_URL,TYPE_STRING,URL); Equal = GetProtocol(URL,NULL,0,NULL); tcsncpy_s(Value,TSIZEOF(Value),Equal,String-Equal); tcsreplace(Value,TSIZEOF(Value),URLPART_SEP_ESCAPE,URLPART_SEPARATOR); Node_SetData((node*)p,URLPART_URL,TYPE_STRING,Value); while (String++ && *String) { Equal = tcschr(String,T('=')); if (Equal) { tchar_t *Sep = tcschr(Equal,T('#')); if (Sep) tcsncpy_s(Value,TSIZEOF(Value),Equal+1,Sep-Equal-1); else tcscpy_s(Value,TSIZEOF(Value),Equal+1); if (tcsncmp(String,T("ofs"),Equal-String)==0) p->Pos = StringToInt(Value,0); else if (tcsncmp(String,T("len"),Equal-String)==0) p->Length = StringToInt(Value,0); else if (tcsncmp(String,T("mime"),Equal-String)==0) Node_SetData((node*)p,URLPART_MIME,TYPE_STRING,Value); else if (tcsncmp(String,T("date"),Equal-String)==0) Date = StringToInt(Value,0); } String = tcschr(String,'#'); } if (Date!=INVALID_DATETIME_T && Date != FileDateTime(Node_Context(p),Node_GetDataStr((node*)p,URLPART_URL))) return ERR_INVALID_DATA; p->Input = GetStream(p,Node_GetDataStr((node*)p,URLPART_URL),Flags); if (!p->Input) return ERR_NOT_SUPPORTED; Stream_Blocking(p->Input,p->Blocking); Result = Stream_Open(p->Input,Node_GetDataStr((node*)p,URLPART_URL),Flags); if (Result == ERR_NONE && p->Pos!=INVALID_FILEPOS_T) // TODO: support asynchronous stream opening { if (Stream_Seek(p->Input,p->Pos,SEEK_SET)!=p->Pos) return ERR_INVALID_DATA; } return Result; }
static HANDLE Load(const tchar_t* Name) { HANDLE Module; tchar_t Path[MAXPATH]; tchar_t *s; GetModuleFileName(NULL,Path,MAXPATH); s = tcsrchr(Path,'\\'); if (s) s[1]=0; tcscpy_s(Path+tcslen(Path),TSIZEOF(Path)-tcslen(Path),Name); Module = LoadLibrary(Path); if (!Module) Module = LoadLibrary(Name); return Module; }
void get_mame_root(TCHAR *buffer, int buflen) { GetModuleFileName(NULL, buffer, buflen); tcsrchr(buffer, '\\')[0] = '\0'; }
void SplitPath(const tchar_t* URL, tchar_t* Dir, int DirLen, tchar_t* Name, int NameLen, tchar_t* Ext, int ExtLen) { const tchar_t *p,*p2,*p3; bool_t HasHost; tchar_t LocalURL[MAXPATH]; tchar_t Protocol[MAXPATH]; // mime p = GetProtocol(URL,Protocol,TSIZEOF(Protocol),&HasHost); // dir p2 = tcsrchr(p,'\\'); p3 = tcsrchr(p,'/'); if (!p2 || (p3 && p3>p2)) p2 = p3; #ifdef TARGET_PS2SDK // "host:test.elf" -> "host:" // "host:/test.elf" -> "host:/" (keeping end delimiter) if ((p2 && p2>p && p2[-1]==':') || (!p2 && (p2 = tcschr(p,':'))!=NULL)) { if (Dir) tcsncpy_s(Dir,DirLen,URL,p2-URL+1); URL = p2+1; } else #endif if (p2) { if (Dir) tcsncpy_s(Dir,DirLen,URL,p2-URL); URL = p2+1; } else if (HasHost) // no filename, only host { if (Dir) tcscpy_s(Dir,DirLen,URL); URL += tcslen(URL); } else // no directory { if (Dir) tcsncpy_s(Dir,DirLen,URL,p-URL); URL = p; } // name if (tcsicmp(Protocol,T("http"))==0 && tcsrchr(URL,T('#'))) { tchar_t *NulChar; tcscpy_s(LocalURL,TSIZEOF(LocalURL),URL); URL = LocalURL; NulChar = tcsrchr(LocalURL,T('#')); *NulChar = 0; } if (Name && Name == Ext) tcscpy_s(Name,NameLen,URL); else { p = tcsrchr(URL,'.'); if (p) { if (Name) tcsncpy_s(Name,NameLen,URL,p-URL); if (Ext) { if (p[1]) ++p; // remove '.', but only if there is a real extension tcscpy_s(Ext,ExtLen,p); } } else { if (Name) tcscpy_s(Name,NameLen,URL); if (Ext) Ext[0] = 0; } } }