/* replaces the chars with special meaning with the associated data from the player info struct */ static char *generatetextfromlabel(widget *item) { char *text = malloc(MAX_LABELSIZE); char tmp[MAX_LABELSIZE]; if(!item) { free(text); return NULL; } strcpy(text, item->label); if(item->type == tySlabel) return text; stringreplace(text, "$1", "%.2i:%.2i:%.2i", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); stringreplace(text, "$2", "%.4i:%.2i", guiInfo.ElapsedTime / 60, guiInfo.ElapsedTime % 60); stringreplace(text, "$3", "%.2i", guiInfo.ElapsedTime / 3600); stringreplace(text, "$4", "%.2i", (guiInfo.ElapsedTime / 60) % 60); stringreplace(text, "$5", "%.2i", guiInfo.ElapsedTime % 60); stringreplace(text, "$6", "%.2i:%.2i:%.2i", guiInfo.RunningTime / 3600, (guiInfo.RunningTime / 60) % 60, guiInfo.RunningTime % 60); stringreplace(text, "$7", "%.4i:%.2i", guiInfo.RunningTime / 60, guiInfo.RunningTime % 60); stringreplace(text, "$8", "%i:%.2i:%.2i", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); stringreplace(text, "$v", "%3.2f%%", guiInfo.Volume); stringreplace(text, "$V", "%3.1f", guiInfo.Volume); stringreplace(text, "$U", "%3.0f", guiInfo.Volume); stringreplace(text, "$b", "%3.2f%%", guiInfo.Balance); stringreplace(text, "$B", "%3.1f", guiInfo.Balance); stringreplace(text, "$D", "%3.0f", guiInfo.Balance); stringreplace(text, "$t", "%.2i", guiInfo.Track); stringreplace(text, "$o", "%s", acp(TranslateFilename(0, tmp, sizeof(tmp)))); stringreplace(text, "$O", "%s", acp(TranslateFilename(4, tmp, sizeof(tmp)))); stringreplace(text, "$x", "%i", guiInfo.VideoWidth); stringreplace(text, "$y", "%i", guiInfo.VideoHeight); stringreplace(text, "$C", "%s", guiInfo.sh_video ? codecname : ""); stringreplace(text, "$$", "$"); if(guiInfo.Playing == GUI_STOP) { stringreplace(text, "$P", "s"); stringreplace(text, "$s", "s"); } else if(guiInfo.Playing == GUI_PLAY) { stringreplace(text, "$P", "p"); stringreplace(text, "$p", "p"); } else if(guiInfo.Playing == GUI_PAUSE) { stringreplace(text, "$P", "e"); stringreplace(text, "$e", "e"); } if(guiInfo.AudioChannels == 0) stringreplace(text, "$a", "n"); else if(guiInfo.AudioChannels == 1) stringreplace(text, "$a", "m"); else if(guiInfo.AudioChannels == 2) stringreplace(text, "$a", (guiInfo.AudioPassthrough ? "r" : "t")); else stringreplace(text, "$a", "r"); if(guiInfo.StreamType == STREAMTYPE_FILE) stringreplace(text, "$T", "f"); else if(guiInfo.StreamType == STREAMTYPE_DVD || guiInfo.StreamType == STREAMTYPE_DVDNAV) stringreplace(text, "$T", "d"); else if(guiInfo.StreamType == STREAMTYPE_STREAM) stringreplace(text, "$T", "u"); else stringreplace(text, "$T", " "); stringreplace(text, "$f", acp(TranslateFilename(1, tmp, sizeof(tmp)))); stringreplace(text, "$F", acp(TranslateFilename(2, tmp, sizeof(tmp)))); return text; }
/* Unsafe! Pass only null-terminated strings as (char *)str. */ char * Translate( char * str ) { mixer_t *mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); static char trbuf[512]; char tmp[512]; int i,c; int t; int strsize = 0; memset( trbuf,0,512 ); memset( tmp,0,128 ); strsize = strlen(str); for ( c=0,i=0;i < strsize;i++ ) { if ( str[i] != '$' ) { trbuf[c++]=str[i]; trbuf[c]=0; } else { switch ( str[++i] ) { case 't': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.Track ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'o': TranslateFilename( 0,tmp,sizeof( tmp ) ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'f': TranslateFilename( 1,tmp,sizeof( tmp ) ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'F': TranslateFilename( 2,tmp,sizeof( tmp ) ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case '6': t=guiIntfStruct.LengthInSec; goto calclengthhhmmss; case '1': t=guiIntfStruct.TimeSec; calclengthhhmmss: snprintf( tmp,sizeof( tmp ),"%02d:%02d:%02d",t/3600,t/60%60,t%60 ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case '7': t=guiIntfStruct.LengthInSec; goto calclengthmmmmss; case '2': t=guiIntfStruct.TimeSec; calclengthmmmmss: snprintf( tmp,sizeof( tmp ),"%04d:%02d",t/60,t%60 ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case '3': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec / 3600 ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case '4': snprintf( tmp,sizeof( tmp ),"%02d",( ( guiIntfStruct.TimeSec / 60 ) % 60 ) ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case '5': snprintf( tmp,sizeof( tmp ),"%02d",guiIntfStruct.TimeSec % 60 ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case '8': snprintf( tmp,sizeof( tmp ),"%01d:%02d:%02d",guiIntfStruct.TimeSec / 3600,( guiIntfStruct.TimeSec / 60 ) % 60,guiIntfStruct.TimeSec % 60 ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'v': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Volume ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'V': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Volume ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'b': snprintf( tmp,sizeof( tmp ),"%3.2f%%",guiIntfStruct.Balance ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'B': snprintf( tmp,sizeof( tmp ),"%3.1f",guiIntfStruct.Balance ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'd': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.FrameDrop ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'x': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieWidth ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'y': snprintf( tmp,sizeof( tmp ),"%d",guiIntfStruct.MovieHeight ); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 'C': snprintf( tmp,sizeof( tmp ),"%s", guiIntfStruct.sh_video? ((sh_video_t *)guiIntfStruct.sh_video)->codec->name : ""); av_strlcat( trbuf,tmp,sizeof( trbuf ) ); break; case 's': if ( guiIntfStruct.Playing == 0 ) av_strlcat( trbuf,"s",sizeof( trbuf ) ); break; case 'l': if ( guiIntfStruct.Playing == 1 ) av_strlcat( trbuf,"p",sizeof( trbuf ) ); break; case 'e': if ( guiIntfStruct.Playing == 2 ) av_strlcat( trbuf,"e",sizeof( trbuf ) ); break; case 'a': if ( mixer->muted ) { av_strlcat( trbuf,"n",sizeof( trbuf ) ); break; } switch ( guiIntfStruct.AudioType ) { case 0: av_strlcat( trbuf,"n",sizeof( trbuf ) ); break; case 1: av_strlcat( trbuf,"m",sizeof( trbuf ) ); break; case 2: av_strlcat( trbuf,"t",sizeof( trbuf ) ); break; } break; case 'T': switch ( guiIntfStruct.StreamType ) { case STREAMTYPE_FILE: av_strlcat( trbuf,"f",sizeof( trbuf ) ); break; #ifdef CONFIG_VCD case STREAMTYPE_VCD: av_strlcat( trbuf,"v",sizeof( trbuf ) ); break; #endif case STREAMTYPE_STREAM: av_strlcat( trbuf,"u",sizeof( trbuf ) ); break; #ifdef CONFIG_DVDREAD case STREAMTYPE_DVD: av_strlcat( trbuf,"d",sizeof( trbuf ) ); break; #endif default: av_strlcat( trbuf," ",sizeof( trbuf ) ); break; } break; case '$': av_strlcat( trbuf,"$",sizeof( trbuf ) ); break; default: continue; } c=strlen( trbuf ); } } return trbuf; }
/** * @brief Translate all variables in the @a text. * * @param text text containing variables * * @return new text with all variables translated */ static char *TranslateVariables(const char *text) { static char translation[512]; char trans[512]; unsigned int i, c; int t; *translation = 0; for (c = 0, i = 0; i < strlen(text); i++) { if (text[i] != '$') { if (c + 1 < sizeof(translation)) { translation[c++] = text[i]; translation[c] = 0; } } else { switch (text[++i]) { case '1': t = guiInfo.ElapsedTime; HH_MM_SS: snprintf(trans, sizeof(trans), "%02d:%02d:%02d", t / 3600, t / 60 % 60, t % 60); av_strlcat(translation, trans, sizeof(translation)); break; case '2': t = guiInfo.ElapsedTime; MMMM_SS: snprintf(trans, sizeof(trans), "%04d:%02d", t / 60, t % 60); av_strlcat(translation, trans, sizeof(translation)); break; case '3': snprintf(trans, sizeof(trans), "%02d", guiInfo.ElapsedTime / 3600); av_strlcat(translation, trans, sizeof(translation)); break; case '4': snprintf(trans, sizeof(trans), "%02d", guiInfo.ElapsedTime / 60 % 60); av_strlcat(translation, trans, sizeof(translation)); break; case '5': snprintf(trans, sizeof(trans), "%02d", guiInfo.ElapsedTime % 60); av_strlcat(translation, trans, sizeof(translation)); break; case '6': t = guiInfo.RunningTime; goto HH_MM_SS; case '7': t = guiInfo.RunningTime; goto MMMM_SS; case '8': snprintf(trans, sizeof(trans), "%01d:%02d:%02d", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); av_strlcat(translation, trans, sizeof(translation)); break; case 'a': switch (guiInfo.AudioChannels) { case 0: av_strlcat(translation, "n", sizeof(translation)); break; case 1: av_strlcat(translation, "m", sizeof(translation)); break; case 2: av_strlcat(translation, guiInfo.AudioPassthrough ? "r" : "t", sizeof(translation)); break; default: av_strlcat(translation, "r", sizeof(translation)); break; } break; case 'b': snprintf(trans, sizeof(trans), "%3.2f%%", guiInfo.Balance); av_strlcat(translation, trans, sizeof(translation)); break; case 'B': snprintf(trans, sizeof(trans), "%3.1f", guiInfo.Balance); av_strlcat(translation, trans, sizeof(translation)); break; case 'C': snprintf(trans, sizeof(trans), "%s", guiInfo.CodecName ? guiInfo.CodecName : ""); av_strlcat(translation, trans, sizeof(translation)); break; case 'D': snprintf(trans, sizeof(trans), "%3.0f", guiInfo.Balance); av_strlcat(translation, trans, sizeof(translation)); break; case 'e': if (guiInfo.Playing == GUI_PAUSE) av_strlcat(translation, "e", sizeof(translation)); break; case 'f': TranslateFilename(1, trans, sizeof(trans)); av_strlcat(translation, trans, sizeof(translation)); break; case 'F': TranslateFilename(2, trans, sizeof(trans)); av_strlcat(translation, trans, sizeof(translation)); break; case 'o': TranslateFilename(0, trans, sizeof(trans)); av_strlcat(translation, trans, sizeof(translation)); break; case 'O': TranslateFilename(4, trans, sizeof(trans)); av_strlcat(translation, trans, sizeof(translation)); break; case 'l': // legacy case 'p': if (guiInfo.Playing == GUI_PLAY) av_strlcat(translation, "p", sizeof(translation)); break; case 'P': switch (guiInfo.Playing) { case GUI_STOP: av_strlcat(translation, "s", sizeof(translation)); break; case GUI_PLAY: av_strlcat(translation, "p", sizeof(translation)); break; case GUI_PAUSE: av_strlcat(translation, "e", sizeof(translation)); break; } break; case 's': if (guiInfo.Playing == GUI_STOP) av_strlcat(translation, "s", sizeof(translation)); break; case 't': snprintf(trans, sizeof(trans), "%02d", guiInfo.Track); av_strlcat(translation, trans, sizeof(translation)); break; case 'T': switch (guiInfo.StreamType) { case STREAMTYPE_FILE: av_strlcat(translation, "f", sizeof(translation)); break; case STREAMTYPE_STREAM: av_strlcat(translation, "u", sizeof(translation)); break; case STREAMTYPE_CDDA: av_strlcat(translation, "a", sizeof(translation)); break; case STREAMTYPE_VCD: av_strlcat(translation, "v", sizeof(translation)); break; case STREAMTYPE_DVD: av_strlcat(translation, "d", sizeof(translation)); break; case STREAMTYPE_TV: case STREAMTYPE_DVB: av_strlcat(translation, "b", sizeof(translation)); break; case STREAMTYPE_BINCUE: av_strlcat(translation, "c", sizeof(translation)); break; default: av_strlcat(translation, " ", sizeof(translation)); break; } break; case 'U': snprintf(trans, sizeof(trans), "%3.0f", guiInfo.Volume); av_strlcat(translation, trans, sizeof(translation)); break; case 'v': snprintf(trans, sizeof(trans), "%3.2f%%", guiInfo.Volume); av_strlcat(translation, trans, sizeof(translation)); break; case 'V': snprintf(trans, sizeof(trans), "%3.1f", guiInfo.Volume); av_strlcat(translation, trans, sizeof(translation)); break; case 'x': snprintf(trans, sizeof(trans), "%d", guiInfo.VideoWidth); av_strlcat(translation, trans, sizeof(translation)); break; case 'y': snprintf(trans, sizeof(trans), "%d", guiInfo.VideoHeight); av_strlcat(translation, trans, sizeof(translation)); break; case '$': av_strlcat(translation, "$", sizeof(translation)); break; default: continue; } c = strlen(translation); } } return translation; }
static char *Translate(char *str) { static char trbuf[512]; char tmp[512]; unsigned int i, c; int t; mixer_t *mixer; *trbuf = 0; for (c = 0, i = 0; i < strlen(str); i++) { if (str[i] != '$') { if (c + 1 < sizeof(trbuf)) { trbuf[c++] = str[i]; trbuf[c] = 0; } } else { switch (str[++i]) { case 't': snprintf(tmp, sizeof(tmp), "%02d", guiInfo.Track); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'o': TranslateFilename(0, tmp, sizeof(tmp)); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'f': TranslateFilename(1, tmp, sizeof(tmp)); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'F': TranslateFilename(2, tmp, sizeof(tmp)); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case '6': t = guiInfo.RunningTime; goto calclengthhhmmss; case '1': t = guiInfo.ElapsedTime; calclengthhhmmss: snprintf(tmp, sizeof(tmp), "%02d:%02d:%02d", t / 3600, t / 60 % 60, t % 60); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case '7': t = guiInfo.RunningTime; goto calclengthmmmmss; case '2': t = guiInfo.ElapsedTime; calclengthmmmmss: snprintf(tmp, sizeof(tmp), "%04d:%02d", t / 60, t % 60); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case '3': snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime / 3600); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case '4': snprintf(tmp, sizeof(tmp), "%02d", (guiInfo.ElapsedTime / 60) % 60); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case '5': snprintf(tmp, sizeof(tmp), "%02d", guiInfo.ElapsedTime % 60); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case '8': snprintf(tmp, sizeof(tmp), "%01d:%02d:%02d", guiInfo.ElapsedTime / 3600, (guiInfo.ElapsedTime / 60) % 60, guiInfo.ElapsedTime % 60); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'v': snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Volume); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'V': snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Volume); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'b': snprintf(tmp, sizeof(tmp), "%3.2f%%", guiInfo.Balance); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'B': snprintf(tmp, sizeof(tmp), "%3.1f", guiInfo.Balance); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'x': snprintf(tmp, sizeof(tmp), "%d", guiInfo.VideoWidth); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'y': snprintf(tmp, sizeof(tmp), "%d", guiInfo.VideoHeight); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 'C': snprintf(tmp, sizeof(tmp), "%s", guiInfo.sh_video ? guiInfo.sh_video->codec->name : ""); av_strlcat(trbuf, tmp, sizeof(trbuf)); break; case 's': if (guiInfo.Playing == GUI_STOP) av_strlcat(trbuf, "s", sizeof(trbuf)); break; case 'l': // legacy case 'p': if (guiInfo.Playing == GUI_PLAY) av_strlcat(trbuf, "p", sizeof(trbuf)); break; case 'e': if (guiInfo.Playing == GUI_PAUSE) av_strlcat(trbuf, "e", sizeof(trbuf)); break; case 'a': mixer = mpctx_get_mixer(guiInfo.mpcontext); if (mixer->muted) { av_strlcat(trbuf, "n", sizeof(trbuf)); break; } switch (guiInfo.AudioChannels) { case 0: av_strlcat(trbuf, "n", sizeof(trbuf)); break; case 1: av_strlcat(trbuf, "m", sizeof(trbuf)); break; case 2: av_strlcat(trbuf, "t", sizeof(trbuf)); break; } break; case 'T': switch (guiInfo.StreamType) { case STREAMTYPE_FILE: av_strlcat(trbuf, "f", sizeof(trbuf)); break; case STREAMTYPE_STREAM: av_strlcat(trbuf, "u", sizeof(trbuf)); break; case STREAMTYPE_CDDA: av_strlcat(trbuf, "a", sizeof(trbuf)); break; case STREAMTYPE_VCD: av_strlcat(trbuf, "v", sizeof(trbuf)); break; case STREAMTYPE_DVD: av_strlcat(trbuf, "d", sizeof(trbuf)); break; default: av_strlcat(trbuf, " ", sizeof(trbuf)); break; } break; case '$': av_strlcat(trbuf, "$", sizeof(trbuf)); break; default: continue; } c = strlen(trbuf); } } return trbuf; }