⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playlist.c

📁 本程序为ST公司开发的源代码
💻 C
字号:
/************************************************** * * playlist.c * * CVS ID:   $Id: playlist.c,v 1.28 2007/11/09 13:38:31 trubac Exp $ * Author:   Emanuela Zaccaria [EZ] - STM * Date:     $Date: 2007/11/09 13:38:31 $ * Revision: $Revision: 1.28 $ *  * Description: *  *   Main entry point for the playlist parsing. * *************************************************** *  * COPYRIGHT (C) ST Microelectronics  2005 *            All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: playlist.c,v $ * Revision 1.28  2007/11/09 13:38:31  trubac * Added checking of playlist item limit into PL_AddFile * * Revision 1.27  2007/09/26 08:09:36  trubac * PL_CompareStrings updated to use different weighting factors for OEM characters * * Revision 1.26  2007/03/19 17:57:18  belardi * Removed compiler warning * * Revision 1.25  2007/02/26 13:41:27  trubac * warning removed * * Revision 1.24  2007/02/26 13:24:39  trubac * String comparison compares alse extension string with file type * * Revision 1.23  2007/02/22 18:38:17  belardi * Removed unused variable * * Revision 1.22  2007/02/21 10:12:45  trubac * Playlist compares file names stored without extension * * Revision 1.21  2006/12/07 13:19:16  trubac * relative indexing of playlist items, pls processing improved "..\" * * Revision 1.20  2006/12/01 17:38:36  trubac * fixed line parsing error * * Revision 1.19  2006/12/01 16:04:46  trubac * Improved parsing for various text encodings * * Revision 1.18  2006/11/20 13:23:46  sedmik * var containing amount of playlist files moved to global, to be able to init it * * Revision 1.17  2006/11/07 18:57:41  sedmik * alignment to playlist field to X_array (uin8 array changed to uint16) * * Revision 1.16  2006/10/18 12:36:57  belardi * Changed usage of #define, PLS_SHRINKING becomes already-available HAVE_FSHRINK * * Revision 1.15  2006/09/29 15:10:24  zaccaria * Fixed bug in playlist function * * Revision 1.14  2006/09/28 11:48:46  zaccaria * Fixed bug in shrink function * * Revision 1.13  2006/09/25 13:23:04  zaccaria * shrink filename function modified * * Revision 1.12  2006/09/18 09:55:21  belardi * Corrected CVS keyword usage * * Revision 1.11  2006/09/18 09:22:36  belardi * Added Log CVS keyword into file header * * Revision 1.10  2006/09/15 19:34:58  belardi * Fix line endings * * Revision 1.9  2006/09/15 19:33:24  belardi * Merged the m8_cav2_cm80506_cs3563. * - name change X_LAST_ITEM * * ***************************************************/#include "configuration.h"#if (HAVE_PLAYLIST==1)#include "xfile.h"#include "filesys.h"#include "playlist.h"#include <string.h>t_player_playlist  player_playlist;t_pl_parser PL_parser; int PL_GetChar(int *pos, uint8* buffer, int read_stop, int encoding){int ch,ch2;int p = *pos;	if(p>=read_stop)		return E_EOF; 			switch(encoding)	{		case SIG_BE:			ch = *(buffer+p);					p++;			ch <<= 8;			ch |= *(buffer+p);			p++;						break; 				case SIG_LE:		    ch = *(buffer+p);					p++;			ch |= (*(buffer+p))<<8;			p++;						break;				case SIG_UTF8:			ch =  *(buffer+p);			p++;						if(ch<0x80)			{			   break;			}						if((ch>=0x80)&&(ch<=0xC0))			    return E_WRONG_FORMAT;						if((ch&0xE0) == 0xC0)			{			    ch &= 0x1F;			    ch <<= 6;			    ch2 = *(buffer+p);			    p++;			    if((ch2&0xC0)!=0x80)			        return E_WRONG_FORMAT;			    ch |= (ch2&0x3F);			    break;    			}						if((ch&0xF0) == 0xE0)			{			    ch &= 0x0F;			    ch <<= 12;			    ch2 = *(buffer+p);			    p++;			    if((ch2&0xC0)!=0x80)			        return E_WRONG_FORMAT;			    ch |= ((ch2&0x3F)<<6);			    ch2 = *(buffer+p);			    p++;			    if((ch2&0xC0)!=0x80)			        return E_WRONG_FORMAT;			    ch |= (ch2&0x3F);			    break;    			}						return E_WRONG_FORMAT;					case SIG_SINGB:			ch = *(buffer+p);			p++;			if((ch>=0)&&(ch<=0x1f))			{ // non-displayed characters			    if((ch==0x0D)||(ch==0x0A))			        break;			 			    return E_WRONG_FORMAT;			}						if((ch>=0x80)&&(ch<=0x9F))			{ // non-displayed characters			    return E_WRONG_FORMAT;			}						break;								case SIG_UNKNOWN:		default:			ch = *(buffer+p);			p++;			break;	}		if(p>read_stop)		return E_EOF;		*pos = p;		return ch;}int PL_CheckEncoding(uint8* buffer, int read_pos, uint8* read_stop){int enc = 0x0C;int ch=-1,ch2;int utf8=0,utf8cnt=0;uint8 *ptr = buffer+read_pos;	while(ptr < read_stop)	{		ch2 = ch;		ch = *ptr;							    if(enc&0x04)  // check UTF8 if still allowed	    {	    	if(!ch)	            enc &= ~0x4 ;  // clear UTF-8 flag	        else	        {		        switch(utf8)		        {		        	case 0:		        	    if(ch<0x80)		        	    {		        	        if((ch<=0x1F)&&(ch!=0x0A)&&(ch!=0x0D))		        	        {		        	        // not allowed ASCII range						       enc &= ~0x4 ;  // clear UTF-8 flag						    }		        	    }		        	    else		        	    {		        	        if((ch&0xC0)==0x80)  // succeeding bytes not allowed		        	        	enc &= ~0x4 ;  // clear UTF-8 flag		        	        else		        	        {		        	        	if((ch&0xE0)==0xC0)		        	        	{		        	        		utf8cnt++;		        	        	    if(ch&0x1F)		        	        		    utf8 = 1;		        	        		else		        	        			enc &= ~0x4 ;  // clear UTF-8 flag		        	        	}		        	        	else		        	        	{		        	        		if((ch&0xF0)==0xE0)									{										utf8cnt += 2;										if(ch&0x0F)											utf8=2;										else									    	enc &= ~0x4 ;									}									enc &= ~0x4 ;											        	        	}		        	        }		        	    }		        	    break;		        	case 1:		        	case 2:		        		if((ch&0xC0)!=0x80)  // succeeding bytes not allowed		        	        enc &= ~0x4 ;  // clear UTF-8 flag		        	    else		        	    	utf8--;		        	    break;		        			        	default:		        		break;		        }			}	    }	    	    if(enc&0x08)	// check single byte if still allowed	    {	    	if(((ch>=0x80)&&(ch<=0x9F))||((ch<=0x1F)&&(ch!=0x0A)&&(ch!=0x0D)))	        {	        // not allowed ASCII range			    enc &= ~0x8 ;  // clear SB encoding flag			}	    } 	    	    if(read_pos&1)	    {		    if((ch==0xD)||(ch==0xA))		    {		    	if(!ch2)		    		enc |= 2;  // big endian UTF16		    }		    else		    	if(!ch)		    	{		    		if((ch2==0xD)||(ch2==0xA))				    {				    	enc |= 1;  // little endian UTF16				    }		    			    	}		}				ptr++;	    read_pos++;   	}			//if((enc&0x4)&&(utf8cnt)&&(!utf8))	if((enc&0x4)&&(!utf8))		return SIG_UTF8;			if((enc&2)&&(!(enc&1)))		return SIG_BE;			if((enc&1)&&(!(enc&2)))		return SIG_LE;		if(enc&8)		return SIG_SINGB;			return SIG_UNKNOWN;}// Searches string in parser buffer till ps->eol_pos position (one line)int PL_FindString(uint8* nstr, t_pl_parser *ps,int* pos, int stop_after){uint8 *cptr;int   pt,pt2,pt1=*pos;int ch;int ok=0;int stop;	cptr = nstr;		pt = *pos;		stop = ps->nonchar_pos;	if(!stop)	    stop = ps->eol_pos;		if(!stop)	    stop = ps->read_stop;		    	while(1)	{		pt2 = pt;		ch = PL_GetChar( &pt, ps->buffer, stop, ps->encoding);		if(ch == E_EOF)		{			return ch;			}		if(*cptr == ch)		{			if(!ok)				pt1 = pt2;	// remember first same character position			cptr++;			ok = 1;		}		else		{			cptr = nstr;			ok = 0;		}				if(*cptr == '\0')		{			if(stop_after)				*pos = pt;			else				*pos = pt1;			return S_OK;		}			}}// PL_CompareStrings// compares char by char from current position till stop// returns number of non-matching characters// modified to process file names without extensionint PL_CompareStrings(t_pl_parser *ps,int stop,t_XItem xitem, t_XNodeType item_type  ){uint8 *utf;int utflen;int p,p1,ch,ch1,cnt,cnt1,cnt2,cnt3;int err=0,i;	utflen = filesys_name_length(xitem);   //filesys_get_name	utf = filesys_get_name(xitem);	if((utf==NULL)||(!utflen))		return E_INVALID_PARAMETER;		    	cnt = -1;	p = ps->pos;	do 	// count characters of compared string	{		cnt++;		ch = PL_GetChar( &p, ps->buffer, stop, ps->encoding);		if(ch==E_WRONG_FORMAT)			return ch;	}while(ch!=E_EOF);		cnt2 = -1;	p = 0;	do	// count characters in UTF8 name	{		cnt2++;		ch = PL_GetChar(&p,utf,utflen,SIG_UTF8);	}while(ch!=E_EOF);		// cnt = number of chars in parsed playlist line	// cnt2 = number of chars in name from X_array    if(item_type==DIRECTORY)    {        cnt3 = 0;       // cnt3 = number of extension chars    }    else    {        cnt3 = 4;    }    	if(cnt2+cnt3>cnt)		return 0xFFFF; // compared string is too short	#if(HAVE_FSHRINK==1)	cnt1 = cnt-cnt3-cnt2;	// cnt1 = how many characters should be skipped#else  // not HAVE_FSHRINK    cnt1 = 0;    if(cnt2+cnt3<cnt)    	return 0xFFFF;	// strings has different length	#endif // HAVE_FSHRINK       	if(cnt2&1)	{		cnt = 1 + cnt2>>1;		cnt2 >>= 1;		}	else	{		cnt = cnt2>>1;		cnt2 >>= 1;	}	// cnt - how many chars must be checked from beginning of parsed line	// cnt2 - how many chars must be checked right before extension	/*	if(test_file)	{		cnt3 = cnt + cnt1+ cnt2 - 4;			// cnt3 is number of positions where difference is acceptable		// for files extension should match absolutely	}	else	{		cnt3 = 0xffff;	}*/		p = ps->pos;	p1 = 0;	for(i=0;i<cnt;i++)	{		ch = PL_GetChar( &p, ps->buffer, stop, ps->encoding);		ch = UPPER_CASE(ch);		ch1 = PL_GetChar( &p1, utf, utflen, SIG_UTF8);		ch1 = UPPER_CASE(ch1);		if(ch != ch1 )		{			err++;					if( !((ch>127)&&(ch>256)||(ch1>127)&&(ch1>256)) )			    err++;			    						}		//cnt3--;	}		for(i=0;i<cnt1;i++)	{		ch = PL_GetChar( &p, ps->buffer, stop, ps->encoding);		//cnt3--;	}		for(i=0;i<cnt2;i++)	{		ch = PL_GetChar( &p, ps->buffer, stop, ps->encoding);		ch = UPPER_CASE(ch);		ch1 = PL_GetChar( &p1, utf, utflen, SIG_UTF8);		ch1 = UPPER_CASE(ch1);		if(ch != ch1)		{			err++;						if( !((ch>127)&&(ch>256)||(ch1>127)&&(ch1>256)) )			    err++;		}		//cnt3--;			}    if(cnt3)    {        ch = PL_GetChar( &p, ps->buffer, stop, ps->encoding);        if(ch!='.')            return 0xFFFF;                       if(item_type!=XAR_FileType((char *)ps->buffer+p))        {            err =0xFFFF;                }    }     	if(err >= cnt)		return 0xFFFF;			return err;}int PL_IsDigit(int wch){	if((wch>=0x30)&&(wch<=0x39))		return S_TRUE;	return S_FALSE;}GRESULT PL_AddFile(int xfile){// TODO    if(player_playlist.array_items<MAX_PLAYLIST_ITEMS)    {    	player_playlist.array[player_playlist.array_items] = xfile - player_playlist.first_volume_node;    	player_playlist.array_items++;    	return S_OK;    }        return E_FAIL;}#endif //HAVE_PLAYLIST

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -