replace fixed-sized buffers in OSD code trunk
authornathan
Wed, 04 Feb 2009 19:34:25 +0800
branchtrunk
changeset 240598c933ccae
parent 23 3b14b8aacaa0
child 25 887faebaba0a
replace fixed-sized buffers in OSD code
mp3.c
mplayer.c
     1.1 --- a/mp3.c	Wed Feb 04 12:30:14 2009 +0800
     1.2 +++ b/mp3.c	Wed Feb 04 19:34:25 2009 +0800
     1.3 @@ -442,15 +442,11 @@
     1.4      cMP3PlayInfo *mode=new cMP3PlayInfo;
     1.5      bool valid=mgr->Info(-1,mode);
     1.6      bool changed=(!lastMode || mode->Hash!=lastMode->Hash);
     1.7 -    char buf[256];
     1.8      if(changed) { d(printf("mp3-ctrl: mode change detected\n")) }
     1.9  
    1.10      if(valid) { // send progress to status monitor
    1.11 -      if(changed || mode->Loop!=lastMode->Loop || mode->Shuffle!=lastMode->Shuffle) {
    1.12 -        snprintf(buf,sizeof(buf),"[%c%c] (%d/%d) %s",
    1.13 -                  mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,*TitleArtist(mode->Title,mode->Artist));
    1.14 -        cStatus::MsgReplaying(this,buf,mode->Filename[0]?mode->Filename:0,true);
    1.15 -        }
    1.16 +      if(changed || mode->Loop!=lastMode->Loop || mode->Shuffle!=lastMode->Shuffle)
    1.17 +        cStatus::MsgReplaying(this,cString::sprintf("[%c%c] (%d/%d) %s",mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,*TitleArtist(mode->Title,mode->Artist)),mode->Filename[0]?mode->Filename:0,true);
    1.18        }
    1.19  
    1.20      if(visible) { // refresh the OSD progress display
    1.21 @@ -470,8 +466,7 @@
    1.22          }
    1.23        else {
    1.24          if(!selecting && changed && !statusActive) {
    1.25 -          snprintf(buf,sizeof(buf),"(%d/%d)",mode->Num,mode->MaxNum);
    1.26 -          Write(0,-2,CTAB,buf);
    1.27 +          Write(0,-2,CTAB,cString::sprintf("(%d/%d)",mode->Num,mode->MaxNum));
    1.28            flush=true;
    1.29            }
    1.30  
    1.31 @@ -492,8 +487,7 @@
    1.32              cProgressBar ProgressBar(bw-(CTAB+CTAB2)*fw,fh,index,total);
    1.33              osd->DrawBitmap(CTAB*fw,bh-fh,ProgressBar);
    1.34              }
    1.35 -          snprintf(buf,sizeof(buf),total?"%02d:%02d/%02d:%02d":"%02d:%02d",index/60,index%60,total/60,total%60);
    1.36 -          Write(0,-1,11,buf);
    1.37 +          Write(0,-1,11,cString::sprintf(total?"%02d:%02d/%02d:%02d":"%02d:%02d",index/60,index%60,total/60,total%60));
    1.38            flush=true;
    1.39            }
    1.40          }
    1.41 @@ -512,45 +506,41 @@
    1.42            doflip=true;
    1.43  	  }
    1.44          if(doflip) {
    1.45 -          buf[0]=0;
    1.46 +          cString buff;
    1.47            switch(flip) {
    1.48  	    default:
    1.49  	      flip=0;
    1.50  	      // fall through
    1.51  	    case 0:
    1.52 -	      snprintf(buf,sizeof(buf),"%s",*TitleArtist(mode->Title,mode->Artist));
    1.53 +	      buff=TitleArtist(mode->Title,mode->Artist);
    1.54  	      flipint=6;
    1.55  	      break;
    1.56  	    case 1:
    1.57                if(mode->Album[0]) {
    1.58 -      	        snprintf(buf,sizeof(buf),mode->Year>0?"from: %s (%d)":"from: %s",mode->Album,mode->Year);
    1.59 +      	        buff=cString::sprintf(mode->Year>0?"from: %s (%d)":"from: %s",mode->Album,mode->Year);
    1.60  	        flipint=4;
    1.61 +	        break;
    1.62  	        }
    1.63 -              else fliptime=0;
    1.64 -              break;
    1.65 +              flip++;
    1.66 +              // fall through
    1.67  	    case 2:
    1.68                if(mode->MaxBitrate>0)
    1.69 -                snprintf(buf,sizeof(buf),"%.1f kHz, %d-%d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->MaxBitrate/1000,mode->SMode);
    1.70 +                buff=cString::sprintf("%.1f kHz, %d-%d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->MaxBitrate/1000,mode->SMode);
    1.71                else
    1.72 -                snprintf(buf,sizeof(buf),"%.1f kHz, %d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->SMode);
    1.73 +                buff=cString::sprintf("%.1f kHz, %d kbps, %s",mode->SampleFreq/1000.0,mode->Bitrate/1000,mode->SMode);
    1.74  	      flipint=3;
    1.75  	      break;
    1.76  	    }
    1.77 -          if(buf[0]) {
    1.78 -            if(MP3Setup.ReplayDisplay) {
    1.79 -              char buf2[256];
    1.80 -              snprintf(buf2,sizeof(buf2),"[%c%c] (%d/%d) %s",
    1.81 -                       mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,buf);
    1.82 -              disp->SetTitle(buf2);
    1.83 +          if(MP3Setup.ReplayDisplay) {
    1.84 +            disp->SetTitle(cString::sprintf("[%c%c] (%d/%d) %s",mode->Loop?'L':'.',mode->Shuffle?'S':'.',mode->Num,mode->MaxNum,*buff));
    1.85 +            flush=true;
    1.86 +            }
    1.87 +          else {
    1.88 +            if(!statusActive) {
    1.89 +              DisplayInfo(buff);
    1.90                flush=true;
    1.91                }
    1.92 -            else {
    1.93 -              if(!statusActive) {
    1.94 -                DisplayInfo(buf);
    1.95 -                flush=true;
    1.96 -                }
    1.97 -              else { d(printf("mp3-ctrl: display info skip due to status active\n")) }
    1.98 -              }
    1.99 +            else { d(printf("mp3-ctrl: display info skip due to status active\n")) }
   1.100              }
   1.101            }
   1.102          }
   1.103 @@ -565,19 +555,19 @@
   1.104            for(int i=0 ; i<rows && i<MAXROWS && num<=mode->MaxNum ; i++,num++) {
   1.105              cMP3PlayInfo pi;
   1.106              mgr->Info(num,&pi); if(!pi.Title[0]) break;
   1.107 -            snprintf(buf,sizeof(buf),"%d.\t%s",num,*TitleArtist(pi.Title,pi.Artist));
   1.108 +            cString buff=cString::sprintf("%d.\t%s",num,*TitleArtist(pi.Title,pi.Artist));
   1.109              int fg=clrWhite, bg=clrGray50;
   1.110 -            int hash=MakeHash(buf);
   1.111 +            int hash=MakeHash(buff);
   1.112              if(num==mode->Num) { fg=clrBlack; bg=clrCyan; hash=(hash^77) + 23; }
   1.113              if(all || hash!=hashlist[i]) {
   1.114 -              char *s=rindex(buf,'\t');
   1.115 +              char *s=rindex(buff,'\t');
   1.116                if(s) {
   1.117                  *s++=0;
   1.118 -                Write(0,i,5,buf,fg,bg);
   1.119 +                Write(0,i,5,buff,fg,bg);
   1.120                  Write(5,i,bwc-5,s,fg,bg);
   1.121                  }
   1.122                else
   1.123 -                Write(0,i,bwc,buf,fg,bg);
   1.124 +                Write(0,i,bwc,buff,fg,bg);
   1.125                flush=true;
   1.126                hashlist[i]=hash;
   1.127                }
     2.1 --- a/mplayer.c	Wed Feb 04 12:30:14 2009 +0800
     2.2 +++ b/mplayer.c	Wed Feb 04 19:34:25 2009 +0800
     2.3 @@ -103,7 +103,7 @@
     2.4    static bool rewind;
     2.5    cMPlayerPlayer *player;
     2.6    cSkinDisplayReplay *display;
     2.7 -  bool visible, modeOnly, haveBeauty;
     2.8 +  bool visible, modeOnly;
     2.9    time_t timeoutShow;
    2.10    int lastCurrent, lastTotal;
    2.11    char *lastReplayMsg;
    2.12 @@ -134,7 +134,7 @@
    2.13  cMPlayerControl::cMPlayerControl(void)
    2.14  :cControl(player=new cMPlayerPlayer(file,rewind))
    2.15  {
    2.16 -  visible=modeOnly=jumpactive=haveBeauty=false;
    2.17 +  visible=modeOnly=jumpactive=false;
    2.18    lastReplayMsg=0;
    2.19    display=0;
    2.20    ShowTitle();