static NOINLINE void AddFieldInt(pin* Pin,int Id,int Value) { tchar_t s[40]; GetFrameName(Id,s,TSIZEOF(s)); IntToString(s+tcslen(s),TSIZEOF(s)-tcslen(s),Value,0); AddField(Pin,Id,s); }
static bool_t FindRunning(const tchar_t* CmdLine) { HWND Wnd; tchar_t ClassName[32]; int n = tcslen(ProgramName); tcscpy_s(ClassName,TSIZEOF(ClassName),ProgramName); tcscpy_s(ClassName+n,TSIZEOF(ClassName)-n,T("_Win")); Wnd = FindWindow(ClassName, NULL); if (Wnd) { HWND WndMain = Wnd; while (!IsWindowEnabled(Wnd)) { HWND Last = Wnd; EnumWindows(EnumWindowsProc,(LPARAM)&Wnd); if (Wnd == Last) break; } SetForegroundWindow(Wnd); if (CmdLine && CmdLine[0]) { COPYDATASTRUCT Data; Data.dwData = 0; Data.cbData = (tcslen(CmdLine)+1)*sizeof(tchar_t); Data.lpData = (PVOID)CmdLine; SendMessage(WndMain,WM_COPYDATA,(WPARAM)WndMain,(LPARAM)&Data); } return 1; } return 0; }
static int wince_mess_vprintf(char *fmt, va_list arg) { int length; int old_length; LPTSTR new_messages; LPCTSTR tbuffer; char buffer[256]; /* get into a buffer */ length = vsnprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), fmt, arg); tbuffer = A2T(buffer); /* output to debugger */ OutputDebugString(tbuffer); /* append the buffer to the rest of the messages */ old_length = messages ? tcslen(messages) : 0; new_messages = realloc(messages, (old_length + tcslen(tbuffer) + 1) * sizeof(TCHAR)); if (new_messages) { messages = new_messages; tcscpy(messages + old_length, tbuffer); } return length; }
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; }
int tcsncmp(const tchar_t* a,const tchar_t* b,size_t n) { int i = CompareString(LOCALE_USER_DEFAULT,0,a,min(tcslen(a),n),b,min(tcslen(b),n)); if (i) return i-CSTR_EQUAL; // fallback #ifdef UNICODE return wcsncmp(a,b,n); #else return strncmp(a,b,n); #endif }
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 AbsPathNormalize(tchar_t* Abs,size_t AbsLen) { if (GetProtocol(Abs,NULL,0,NULL)!=Abs) { tchar_t *i; for (i=Abs;*i;++i) if (*i == '\\') *i = '/'; } else { #if defined(TARGET_WIN) || defined(TARGET_SYMBIAN) tchar_t *i; for (i=Abs;*i;++i) if (*i == '/') *i = '\\'; #if defined(TARGET_WINCE) if (Abs[0]!='\\') { size_t n = tcslen(Abs)+1; if (n>=AbsLen) { n=AbsLen-1; Abs[n-1]=0; } memmove(Abs+1,Abs,n*sizeof(tchar_t)); Abs[0]='\\'; } #endif #endif } }
static NOINLINE void AddField(pin* Pin,int Id,tchar_t* Value) { tchar_t* p; if (Id == COMMENT_GENRE) { int Genre; p = tcschr(Value,'='); if (p && stscanf(p,T("=(%d)"),&Genre)==1 && Genre<GENRE_COUNT) { tchar_t* q=++p; while (*q && *q!=')') ++q; if (q[0]==')' && q[1]) // custom name while ((*(p++)=*(++q))!=0); else { AddGenre(Pin,Genre); return; } } } if (Id != COMMENT_COMMENT) for (p=Value;*p;++p) if (*p==10) *p=' '; Pin->Node->Set(Pin->Node,Pin->No,Value,(tcslen(Value)+1)*sizeof(tchar_t)); }
int tcsnicmp(const tchar_t* a,const tchar_t* b,size_t n) { #ifndef WINDOWS_DESKTOP int i = CompareStringEx(LOCALE_NAME_USER_DEFAULT, NORM_IGNORECASE, a, min(tcslen(a), n), b, min(tcslen(b), n), NULL, NULL, 0); #else int i = CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,a,min(tcslen(a),n),b,min(tcslen(b),n)); #endif if (i) return i-CSTR_EQUAL; // fallback #ifdef UNICODE return wcsnicmp(a,b,n); #else return strnicmp(a,b,n); #endif }
void tcscat_s(tchar_t *Out, size_t OutLen, const tchar_t *In) { if (OutLen > 0) { size_t n = tcslen(Out); tcscpy_s(Out + n, OutLen - n, In); } }
void tcscpy_s(tchar_t *Out, size_t OutLen, const tchar_t *In) { if (OutLen > 0) { size_t n = min(tcslen(In), OutLen - 1); memcpy(Out, In, n *sizeof(tchar_t)); Out[n] = 0; } }
static void tcscpy_s(tchar_t* Out,int OutLen,const tchar_t* In) { if (OutLen>0) { int n = min((int)tcslen(In),OutLen-1); memcpy(Out,In,n*sizeof(tchar_t)); Out[n] = 0; } }
static void AddCol(openfile* p, int Index, const tchar_t* Name, int Width, int Format ) { LVCOLUMN Col; Col.mask=LVCF_TEXT | LVCF_WIDTH | LVCF_FMT; Col.cx=WinUnitToPixelX(&p->Win,Width); Col.pszText=(tchar_t*)Name; Col.cchTextMax=tcslen(Name)+1; Col.fmt=Format; ListView_InsertColumn(p->WndList,Index,&Col); }
/** * @brief duplicate a string and return it */ tchar * tcsdup(const tchar *s) { size_t len; tchar *copy; len = tcslen(s) + 1; copy = xmalloc(len * sizeof *copy); tmemcpy(copy, s, len); return copy; }
static void SetURLText(openfile* p,const tchar_t* s) { int Len = tcslen(s); ++p->InUpdate; SetWindowText(p->WndURL,s); if (p->Win.Smartphone) SendMessage(p->WndURL,EM_SETSEL,Len,Len); else SendMessage(p->WndURL,CB_SETEDITSEL,0,MAKEWORD(-1,-1)); --p->InUpdate; }
int CfgQueryStringExamples(int verbose, struct cfg *cfg, char *args[]) { unsigned char buf[1024], *row[10]; FILE *in; int ret; if ((in = fopen(args[0], "r")) == NULL) { PMNO(errno); return -1; } while ((ret = csv_row_fread(in, buf, 1024, row, 10, ',', CSV_QUOTES | CSV_TRIM)) > 0) { int success = atoi(row[0]); tcase_printf(verbose, "%s:\n", row[1]); cfg_clear(cfg); if (cfg_load_cgi_query_string(cfg, row[1], row[1] + tcslen(row[1])) == -1) { if (success) { ret = -1; AMSG(""); goto out; } } else if (!success) { ret = -1; AMSG("Supposed to fail"); goto out; } if (verbose) { iter_t iter; const tchar *name; tchar dst[512]; cfg_iterate(cfg, &iter); while ((name = cfg_next(cfg, &iter))) { if (cfg_get_str(cfg, dst, 512, NULL, name) == -1) { errno = ENOENT; PMNO(errno); return -1; } tcase_printf(verbose, "\t%s=%s\n", name, dst); } } } out: fclose(in); return ret; }
void RemovePathDelimiter(tchar_t* Path) { size_t n = tcslen(Path); const tchar_t* s = GetProtocol(Path,NULL,0,NULL); #if defined(TARGET_WIN) || defined(TARGET_SYMBIAN) bool_t HasProtocol = s==Path; if (s[0] && n>0 && ((HasProtocol && Path[n-1] == '\\') || (!HasProtocol && Path[n-1] == '/'))) #else if (s[0] && n>0 && Path[n-1] == '/' && n > 1) #endif Path[n-1] = 0; }
void SplitURL(const tchar_t* URL, tchar_t* Protocol, int ProtocolLen, tchar_t* Host, int HostLen, int* Port, tchar_t* Path, int PathLen) { bool_t HasHost; URL = GetProtocol(URL,Protocol,ProtocolLen,&HasHost); if (HasHost) { const tchar_t* p; const tchar_t* p2; p = tcschr(URL,'\\'); p2 = tcschr(URL,'/'); if (!p || (p2 && p2>p)) p=p2; if (!p) p = URL+tcslen(URL); p2 = tcschr(URL,':'); if (p2 && p2<p) { if (Port) stscanf(p2+1,T("%d"),Port); } else p2 = p; if (Host) tcsncpy_s(Host,HostLen,URL,p2-URL); URL = p; } else { if (Host && HostLen>0) *Host = 0; } if (Path) { if (URL[0]) { tchar_t* p; tcscpy_s(Path,PathLen,URL); for (p=Path;*p;++p) if (*p == '\\') *p = '/'; } else tcscpy_s(Path,PathLen,T("/")); } }
void RelPath(tchar_t* Rel, int RelLen, const tchar_t* Path, const tchar_t* Base) { size_t n; bool_t HasHost; const tchar_t* p = GetProtocol(Base,NULL,0,&HasHost); if (p != Base) { if (HasHost) { // include host name too tchar_t *a,*b; a = tcschr(p,'\\'); b = tcschr(p,'/'); if (!a || (b && b<a)) a=b; if (a) p=a; else p+=tcslen(p); } // check if mime and host is the same n = p-Base; if (n>0 && n<tcslen(Path) && (Path[n]=='\\' || Path[n]=='/') && tcsnicmp(Path,Base,n)==0) { Base += n; Path += n; } } n = tcslen(Base); if (n>0 && n<tcslen(Path) && (Path[n]=='\\' || Path[n]=='/') && tcsnicmp(Path,Base,n)==0) Path += n+1; tcscpy_s(Rel,RelLen,Path); }
bool_t ParserIsToken(parser* p, const tchar_t* Token) { size_t n = tcslen(Token); tchar_t* Tmp = alloca(sizeof(tchar_t)*(n+1)); const char* i; SkipSpace(p); if ((i=(const char*)ParserPeek(p,n))!=NULL) { GetAsciiToken(Tmp,n+1,i,n); if (tcsicmp(Tmp,Token)==0) { p->Buffer.ReadPos += n; return 1; } } return 0; }
void AddPathDelimiter(tchar_t* Path,size_t PathLen) { size_t n = tcslen(Path); #if defined(TARGET_WIN) || defined(TARGET_SYMBIAN) bool_t HasProtocol = GetProtocol(Path,NULL,0,NULL)==Path; if (!n || (n>0 && (HasProtocol || Path[n-1] != '/') && (!HasProtocol || Path[n-1] != '\\'))) { if (HasProtocol) tcscat_s(Path,PathLen,T("\\")); else tcscat_s(Path,PathLen,T("/")); } #elif defined(TARGET_PS2SDK) if (!n || (n>0 && Path[n-1] != '/' && Path[n-1] != '\\' && Path[n-1] != ':')) tcscat_s(Path,PathLen,T("/")); #else if (!n || (n>0 && Path[n-1] != '/')) tcscat_s(Path,PathLen,T("/")); #endif }
int CheckExts(const tchar_t* URL, const tchar_t* Exts) { tchar_t Ext[MAXPATH]; tchar_t* Tail; intptr_t ExtLen; SplitPath(URL,NULL,0,NULL,0,Ext,TSIZEOF(Ext)); Tail = tcschr(Ext,'?'); if (Tail) *Tail = 0; ExtLen = tcslen(Ext); while (Exts) { const tchar_t* p = tcschr(Exts,':'); if (p && (ExtLen == p-Exts) && tcsnicmp(Ext,Exts,p-Exts)==0) return p[1]; // return type char Exts = tcschr(Exts,';'); if (Exts) ++Exts; } return 0; }
bool_t SplitAddr(const tchar_t* URL, tchar_t* Peer, int PeerLen, tchar_t* Local, int LocalLen) { const tchar_t* p = NULL; const tchar_t* p2; const tchar_t* Addr; bool_t HasHost; bool_t Result = 0; Addr = GetProtocol(URL,NULL,0,&HasHost); if (HasHost) { p = tcschr(Addr,'\\'); p2 = tcschr(Addr,'/'); if (!p || (p2 && p2>p)) p=p2; } if (!p) p = Addr+tcslen(Addr); p2 = tcschr(Addr,'@'); if (!p2 || p2>p) p2 = p; else Result = 1; if (Peer) tcsncpy_s(Peer,PeerLen,URL,p2-URL); if (Local) { if (p2<p) ++p2; tcsncpy_s(Local,LocalLen,URL,Addr-URL); tcsncat_s(Local,LocalLen,p2,p-p2); } return Result; }
int vsprintf(tchar_t *s0, const tchar_t *fmt, va_list args) { tchar_t Num[80]; tchar_t *s; for (s=s0;*fmt;++fmt) { if (fmt[0]=='%' && fmt[1]) { const tchar_t *str; bool_t Left = 0; bool_t Sign = 0; bool_t Large = 0; bool_t ZeroPad = 0; int Width = -1; int Type = -1; int Base = 10; tchar_t ch,cs; int Len; long n; for (;;) { switch (*(++fmt)) { case '-': Left = 1; continue; case '0': ZeroPad = 1; continue; default: break; } break; } if (*fmt>='0' && *fmt<='9') { Width = 0; for (;*fmt>='0' && *fmt<='9';++fmt) Width = Width*10 + (*fmt-'0'); } else if (*fmt == '*') { ++fmt; Width = va_arg(args, int); if (Width < 0) { Left = 1; Width = -Width; } } if (*fmt == 'h' || *fmt == 'L' || *fmt == 'l') Type = *(fmt++); switch (*fmt) { case 'c': for (;!Left && Width>1;--Width) *(s++) = ' '; *(s++) = (char)va_arg(args,int); for (;Width>1;--Width) *(s++) = ' '; continue; case 's': str = va_arg(args,const tchar_t*); if (!s) str = T("<NULL>"); Len = tcslen(str); for (;!Left && Width>Len;--Width) *(s++) = ' '; for (;Len>0;--Len,--Width) *(s++) = *(str++); for (;Width>0;--Width) *(s++) = ' '; continue; case 'o': Base = 8; break; case 'X': Large = 1; case 'x': Base = 16; break; case 'i': case 'd': Sign = 1; case 'u': break; default: if (*fmt != '%') *(s++) = '%'; *(s++) = *fmt; continue; } if (Type == 'l') n = va_arg(args,unsigned long); else if (Type == 'h') if (Sign) n = (short)va_arg(args,int); else
static void tcscat_s(tchar_t* Out,int OutLen,const tchar_t* In) { int n = tcslen(Out); tcscpy_s(Out+n,OutLen-n,In); }
static void UpdateList(openfile* p, bool_t Silent, int ListMode) { streamdir DirItem; stream* Stream; int Result; openitem New; LVITEM Item; int No=0; int Pos=0; int State = LVIS_FOCUSED; int Len; const tchar_t* s; bool_t HasHost; if (!p->Multiple || (p->Flags & OPENFLAG_SINGLE)) State |= LVIS_SELECTED; Len = tcslen(p->Path); if (Len && (p->Path[Len-1] == '\\' || p->Path[Len-1] == '/')) p->Path[--Len] = 0; tcscpy_s(p->Base,TSIZEOF(p->Base),p->Path); s = p->Path[0] ? p->Path : T("\\"); AddHistory(p,s); if (!ListMode) return; ++p->InUpdate; WaitBegin(); ShowWindow(p->WndList,SW_HIDE); ClearList(p); Item.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM; Item.pszText=T(""); Item.cchTextMax=1; Item.iSubItem=0; Stream = GetStream(p->Path,Silent); if (Stream) { s = GetMime(p->Path,NULL,0,&HasHost); if (*s) { Item.iImage=IMG_DIRUP; Item.iItem = No; Item.lParam = 0; ListView_InsertItem(p->WndList,&Item); ListView_SetItemText(p->WndList,No,0,T("..")); ListView_SetItemText(p->WndList,No,1,(tchar_t*)LangStr(OPENFILE_ID,OPENFILE_UP)); ++No; } Result = Stream->EnumDir(Stream,p->Path,p->Exts,*p->CurrentFileType!=-1,&DirItem); if (ListMode==2 && Result == ERR_FILE_NOT_FOUND && UpperPath(p->Path,p->Last,TSIZEOF(p->Last))) { WaitEnd(); --p->InUpdate; p->LastClick = -1; UpdateList(p,Silent,ListMode); return; } if (Result == ERR_NOT_DIRECTORY && !Silent) { New.FileName[0] = 0; New.Ext[0] = 0; New.Image = IMG_FILE; New.Size = 0; Item.lParam = (DWORD)malloc(sizeof(openitem)); if (Item.lParam) { p->Last[0] = 0; Pos = No; State = LVIS_SELECTED; PostMessage(p->Win.Wnd,WM_COMMAND,PLATFORM_OK,0); *(openitem*)Item.lParam = New; Item.iItem = No; Item.iImage = New.Image; ListView_InsertItem(p->WndList,&Item); ++No; } } if (Result == ERR_NONE) Stream->Get(Stream,STREAM_BASE,p->Base,sizeof(p->Base)); while (Result == ERR_NONE) { tchar_t Size[32]; tchar_t Date[32]; int i; for (i=0;i<No;++i) { LVITEM Item; Item.iItem=i; Item.iSubItem = 0; Item.mask=LVIF_PARAM; ListView_GetItem(p->WndList,&Item); if (Item.lParam && tcscmp(((openitem*)Item.lParam)->FileName,DirItem.FileName)==0) break; } if (i==No) { tchar_t DisplayName[MAXPATH]; tcscpy_s(New.FileName,TSIZEOF(New.FileName),DirItem.FileName); New.DisplayName = DirItem.DisplayName[0] != 0; tcscpy_s(DisplayName,TSIZEOF(DisplayName),New.DisplayName?DirItem.DisplayName:DirItem.FileName); Size[0] = 0; Date[0] = 0; if (DirItem.Size < 0) { New.Image = IMG_DIR; New.Size = 0; New.Date = 0; tcscpy_s(New.Ext,TSIZEOF(New.Ext),LangStr(OPENFILE_ID,OPENFILE_DIR)); tcscpy_s(New.Name,TSIZEOF(New.Name),DisplayName); //keep extension } else { switch (DirItem.Type) { case FTYPE_AUDIO: New.Image = IMG_AUDIO; break; case FTYPE_PLAYLIST: New.Image = IMG_PLAYLIST; break; case FTYPE_VIDEO: New.Image = IMG_VIDEO; break; default: New.Image = IMG_FILE; break; } New.Size = DirItem.Size; New.Date = DirItem.Date; SplitURL(DisplayName,NULL,0,NULL,0,New.Name,TSIZEOF(New.Name),New.Ext,TSIZEOF(New.Ext)); tcsupr(New.Ext); if (New.Size >= 0) { if (New.Size < 10000*1024) stprintf_s(Size,TSIZEOF(Size),T("%d KB"),New.Size/1024); else stprintf_s(Size,TSIZEOF(Size),T("%d MB"),New.Size/(1024*1024)); } if (New.Date >= 0) { FILETIME Time; SYSTEMTIME SysTime; Time.dwHighDateTime = (DWORD)(New.Date >> 32); Time.dwLowDateTime = (DWORD)(New.Date); if (FileTimeToSystemTime(&Time,&SysTime)) GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&SysTime,NULL,Date,TSIZEOF(Date)); } } Item.lParam = (DWORD)malloc(sizeof(openitem)); if (Item.lParam) { *(openitem*)Item.lParam = New; Item.iItem = No; Item.iImage = New.Image; ListView_InsertItem(p->WndList,&Item); ListView_SetItemText(p->WndList,No,0,New.Name); ListView_SetItemText(p->WndList,No,1,New.Ext); ListView_SetItemText(p->WndList,No,2,Size); ListView_SetItemText(p->WndList,No,3,Date); ++No; } } Result = Stream->EnumDir(Stream,NULL,NULL,0,&DirItem); }
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; } } }
static int Init(win* p) { tchar_t s[256]; packetformat Format; int No; node* VOutput = NULL; node* Reader = NULL; node* Input = NULL; node* Player = Context()->Player; winunit y; Player->Get(Player,PLAYER_FORMAT,&Reader,sizeof(Reader)); Player->Get(Player,PLAYER_INPUT,&Input,sizeof(Input)); Player->Get(Player,PLAYER_VOUTPUT,&VOutput,sizeof(VOutput)); y = 4; if (Input) Info(p,Input,&y,0); if (Reader) { pin Pin; Info(p,Reader,&y,MEDIAINFO_FORMAT); Comment(p,(player*)Player,&y,-1); for (No=0;Reader->Get(Reader,FORMAT_STREAM+No,&Pin,sizeof(Pin))==ERR_NONE;++No) if (PlayerGetStream((player*)Player,No,&Format,NULL,0,NULL)) { y += 6; if (Format.Type != PACKET_NONE) { if (!PacketFormatName(&Format,s,TSIZEOF(s))) s[0] =0; WinPropLabel(p,&y,LangStr(PLAYER_ID,STREAM_NAME+Format.Type),s); } switch (Format.Type) { case PACKET_NONE: break; case PACKET_VIDEO: if (Pin.Node && Compressed(&Format.Format.Video.Pixel)) Info(p,Pin.Node,&y,MEDIAINFO_CODEC); if (Format.Format.Video.Width && Format.Format.Video.Height) { stprintf_s(s,TSIZEOF(s),T("%d x %d"),Format.Format.Video.Width,Format.Format.Video.Height); WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_SIZE),s); } if (Format.PacketRate.Num) { FractionToString(s,TSIZEOF(s),&Format.PacketRate,0,3); WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_FPS),s); } if (Format.ByteRate) { IntToString(s,TSIZEOF(s),(Format.ByteRate+62)/125,0); tcscat_s(s,TSIZEOF(s),T(" kbit/s")); // 1000byte/sec WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_BITRATE),s); } break; case PACKET_AUDIO: if (Pin.Node && Format.Format.Audio.Format != AUDIOFMT_PCM) Info(p,Pin.Node,&y,MEDIAINFO_CODEC); s[0] = 0; if (Format.Format.Audio.SampleRate) { IntToString(s+tcslen(s),TSIZEOF(s)-tcslen(s),Format.Format.Audio.SampleRate,0); tcscat_s(s,TSIZEOF(s),T(" Hz ")); } switch (Format.Format.Audio.Channels) { case 0: break; case 1: tcscat_s(s,TSIZEOF(s),LangStr(MEDIAINFO_ID,MEDIAINFO_AUDIO_MONO)); break; case 2: tcscat_s(s,TSIZEOF(s),LangStr(MEDIAINFO_ID,MEDIAINFO_AUDIO_STEREO)); break; default: stcatprintf_s(s,TSIZEOF(s),T("%d Ch"),Format.Format.Audio.Channels); break; } if (s[0]) WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_FORMAT),s); if (Format.ByteRate) { IntToString(s,TSIZEOF(s),(Format.ByteRate+62)/125,0); tcscat_s(s,TSIZEOF(s),T(" kbit/s")); // 1000bit/sec WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_BITRATE),s); } break; case PACKET_SUBTITLE: if (Pin.Node) Info(p,Pin.Node,&y,MEDIAINFO_CODEC); break; } Comment(p,(player*)Player,&y,No); } if (VOutput) { int Total = 0; int Dropped = 0; VOutput->Get(VOutput,OUT_TOTAL,&Total,sizeof(int)); VOutput->Get(VOutput,OUT_DROPPED,&Dropped,sizeof(int)); Total += Dropped; if (Total) { y += 6; IntToString(s,TSIZEOF(s),Total,0); WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_VIDEO_TOTAL),s); IntToString(s,TSIZEOF(s),Dropped,0); WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_VIDEO_DROPPED),s); Player->Get(Player,PLAYER_VSTREAM,&No,sizeof(No)); if (No>=0 && Reader->Get(Reader,(FORMAT_STREAM+No)|PIN_FORMAT,&Format,sizeof(Format))==ERR_NONE && Format.Type == PACKET_VIDEO && Format.PacketRate.Num) { Simplify(&Format.PacketRate,(1<<30)/Total,(1<<30)/Total); Format.PacketRate.Num *= Total - Dropped; Format.PacketRate.Den *= Total; FractionToString(s,TSIZEOF(s),&Format.PacketRate,0,3); WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_AVG_FPS),s); } } } } return ERR_NONE; }
/* print a brief resume of the input ("filename:line:car: " or ""str":car: ") */ tchar * escm_input_prefix(escm_input *f) { tchar *buf, *p; size_t len, all, rest, n; assert(f != NULL); if (f->type == INPUT_FILE) { len = strlen(f->d.file.name); all = len + 50; /* enough for "name:LONG_MAX:LONG_MAX: " */ buf = xmalloc(all * sizeof *buf); n = sntprintf(buf, len + 1, T("%s"), f->d.file.name); /* XXX: n == -1? */ p = buf + n; *p++ = T(':'); rest = all - n - 1; if (f->d.file.line != -1) { n = sntprintf(p, rest, T("%ld"), f->d.file.line); while (n >= rest) { all += 50; rest += 50; buf = xrealloc(buf, all * sizeof *buf); p = buf + all - rest; n = sntprintf(p, rest, T("%ld"), f->d.file.line); } p += n; rest -= n; } if (f->d.file.car != -1) { n = sntprintf(p, rest, T(":%ld: "), f->d.file.car); while (n >= rest) { all += 50; rest += 50; buf = xrealloc(buf, all * sizeof *buf); p = buf + all - rest; n = sntprintf(p, rest, T(":%ld: "), f->d.file.car); } p += n; rest -= n; } else { if (rest <= 4) { all += 5; rest += 5; buf = xrealloc(buf, all * sizeof *buf); p = buf + all - rest; sntprintf(p, rest, T(":: ")); } p += n; rest -= n; } } else { len = tcslen(f->d.str.str) * sizeof(tchar); all = len + 50; /* well enough for "name":LONG_MAX: " */ buf = xmalloc(all * sizeof *buf); n = sntprintf(buf, all, T("\"%") TFMT T("s\":%td: "), f->d.str.str, f->d.str.cur - f->d.str.str); while (n >= all) { all += 50; buf = xrealloc(buf, all * sizeof *buf); n = sntprintf(buf, all, T("\"%") TFMT T("s\":%td: "), f->d.str.str, f->d.str.cur - f->d.str.str); } } return buf; }
void ID3v2_Parse(const void* Ptr,size_t Len,pin* Pin,filepos_t Offset) { const uint8_t* Data = (const uint8_t*)Ptr; size_t Size = ID3v2_Query(Ptr,Len); uint8_t* Data_org=(const uint8_t*)Ptr; Data_org+=Size; // RETAILMSG(1, (TEXT(" ^^^^11111111111111111111^^^^^^^^ID3v2_Parse = %x , %x, %x \r\n"), Size,&Size,Data)); if (Size>0 && Pin) { int HeadFlag = Data[5]; int Ver = Data[3]; if (Ver >= 2 && Ver <= 4 && Size<=Len) { uint8_t* Tmp = NULL; // jump after header Data += 10; Size -= 10; if (Ver<4 && (HeadFlag & FLAG_UNSYNC)) { // undo unsync coding Tmp = malloc(Size); if (Tmp) { Size = UnSync(Tmp,Data,Size); Data = Tmp; } else return; } if ((HeadFlag & FLAG_EXTENDED) && Size>=4) { // skip extended header size_t n = (Ver>=4)?Read7Bit(Data,4):Read8Bit(Data,4); Data += 4+n; Size -= 4+n; } while (Data_org > Data ) { // parse frame uint8_t* Tmp = NULL; uint8_t* Tmp2 = NULL; const uint8_t* p; bool_t NeedDecompress = 0; bool_t NeedUnSync = 0; int Id = 0; int Len = 0; int Len2 = 0; int Flag = 0; const int* Info; if( Size <= 0 || Data[0]==0) break; switch (Ver) { case 2: if (Size >= 6) { Id = FOURCC(Data[0],Data[1],Data[2],' '); Len = Read8Bit(Data+3,3); Data += 6; Size -= 6; } break; case 3: if (Size >= 10) { Id = FOURCC(Data[0],Data[1],Data[2],Data[3]); Len = Read8Bit(Data+4,4); Flag = Read8Bit(Data+8,2); Data += 10; Size -= 10; if (Flag & FLAG3_UNKNOWN) Id = 0; if ((Flag & FLAG3_COMPRESSION) && Size>=4) { NeedDecompress = 1; Len2 = Read8Bit(Data,4); Data += 4; Size -= 4; } if ((Flag & FLAG3_GROUPID) && Size>=1) { Data++; Size--; } } break; case 4: if (Size >= 10) { Id = FOURCC(Data[0],Data[1],Data[2],Data[3]); Len = Read8Bit(Data+4,4); Flag = Read8Bit(Data+8,2); Data += 10; Size -= 10; if (Flag & FLAG4_UNKNOWN) Id = 0; if ((Flag & FLAG4_GROUPID) && Size>=1) { Data++; Size--; } if ((Flag & FLAG4_DATALENGTH) && Size>=4) { Len2 = Read8Bit(Data,4); Data += 4; Size -= 4; } if (Flag & FLAG4_COMPRESSION) NeedDecompress = 1; if (Flag & FLAG4_UNSYNC) NeedUnSync = 1; } break; } p = Data; Data += Len; Size -= Len; if (Id && Size>=0) for (Info=FrameInfo;Info[0];Info+=3) if (Info[0]==Id) { int n; tchar_t Value[512]; if (NeedUnSync) { Tmp = malloc(Len); if (!Tmp) break; Len = UnSync(Tmp,p,Len); p = Tmp; } if (NeedDecompress && Len2>0) { unsigned long n = Len2; Tmp2 = malloc(Len2); if (!Tmp2 || uncompress(Tmp2,&n,p,Len)!=Z_OK) break; Len = n; p = Tmp2; } switch (Info[2]) { case FIELD_STRING: if (Len>1) { ReadStrEncode(p+1,Len-1,p[0],Value,TSIZEOF(Value)); AddFieldStr(Pin,Info[1],Value); } break; case FIELD_COMMENT: if (Len>5) for (n=4;n<Len;++n) if (p[n]==0) { ReadStrEncode(p+n+1,Len-n-1,p[0],Value,TSIZEOF(Value)); AddFieldStr(Pin,Info[1],Value); break; } break; case FIELD_APIC: if (Len>5) { int Encode = *(p++); --Len; if (Ver==2) { tcscpy_s(Value,TSIZEOF(Value),T("image/")); GetAsciiToken(Value+tcslen(Value),TSIZEOF(Value)-tcslen(Value),(const char*)p,3); Len -= 3; p += 3; if (tcsicmp(Value,T("image/jpg"))==0) tcscpy_s(Value,TSIZEOF(Value),T("image/jpeg")); } else { n = ReadStrEncode(p,Len,Encode,Value,TSIZEOF(Value)); Len -= n; p += n; } ++p; --Len; n = ReadStrEncode(p,Len,Encode,NULL,0); // skip description Len -= n; p += n; AddFieldAttachment(Pin,COMMENT_COVER,(p-(const uint8_t*)Ptr)+Offset,Len,Value); } break; } break; } free(Tmp); free(Tmp2); } free(Tmp); } } }