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

📄 pls.c

📁 betaplayer的源码 tcpmp的老版本
💻 C
字号:
/*****************************************************************************
 *
 * This program is free software ; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * $Id: pls.c 201 2005-01-15 08:42:20Z picard $
 *
 * BetaPlayer
 * Copyright (c) 2004 Gabor Kovacs
 *
 ****************************************************************************/

#include "../stdafx.h"
#include "pls.h"

typedef struct pls
{
	format p;
	stream* Input;
	merge Buffer;

	int No;
	tchar_t File[MAXLINE];
	tchar_t Title[MAXLINE];
	int Length;

} pls;

static int Enum( pls* p, int No, datadef* Param )
{
	return NodeEnumType(&No,Param,NodeParams,FormatParams,FormatPlayListParams,NULL);
}

static int Get( pls* p, int No, void* Data, int Size )
{
	int Result = ERR_INVALID_PARAM;
	switch (No)
	{
	case NODE_ID: GETVALUE(PLS_ID,int); break;
	case FORMAT_EXTS: GETSTRING(T("pls:P")); break;
	case FORMAT_INPUT: GETVALUE(p->Input,stream*); break;
	}
	return Result;
}

static int Init( pls* p )
{
	p->No = -1;
	p->File[0] = 0;
	p->Title[0] = 0;
	p->Length = -1;

	MergeDone(&p->Buffer);
	if (p->Input)
	{
		MergeInit(&p->Buffer);
		MergeAlloc(&p->Buffer,4096,1);
	}
	return ERR_NONE;
}

static int Set( pls* p, int No, const void* Data, int Size )
{
	int Result = ERR_INVALID_PARAM;
	switch (No)
	{
	case FORMAT_INPUT: SETVALUE(p->Input,stream*,Init(p)); break;
	}
	return Result;
}

static bool_t Fill( pls* p,tchar_t* Path,int PathLen,tchar_t* DispName,int DispNameLen,tick_t* Length)
{
	if (p->No >= 0 && p->File[0])
	{
		TcsNCpy(Path,p->File,PathLen);
		TcsNCpy(DispName,p->Title,DispNameLen);
		if (p->Length>=0) p->Length *= TICKSPERSEC;
		*Length = p->Length;

		p->File[0] = 0;
		p->Title[0] = 0;
		p->Length = -1;
		return 1;
	}
	return 0;
}

static int ReadList( pls* p,tchar_t* Path,int PathLen,tchar_t* DispName,int DispNameLen,tick_t* Length)
{
	tchar_t s[MAXLINE];
	int No,Len;
	int Result = ERR_END_OF_FILE;

	while (Result==ERR_END_OF_FILE && ReadLine(&p->Buffer,p->Input,s,sizeof(s)))
	{
		UpperUntil(s,'=');

		if (Scanf(s,T("FILE%d ="),&No)==1)
		{
			if (No != p->No && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
				Result = ERR_NONE;
			p->No = No;
			tcscpy(p->File,tcschr(s,'=')+1);
		}
		else
		if (Scanf(s,T("TITLE%d ="),&No)==1)
		{
			if (No != p->No && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
				Result = ERR_NONE;
			p->No = No;
			tcscpy(p->Title,tcschr(s,'=')+1);
		}
		else
		if (Scanf(s,T("LENGTH%d = %d"),&No,&Len)==2)
		{
			if (No != p->No && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
				Result = ERR_NONE;
			p->No = No;
			p->Length = Len;
		}
	}

	if (Result==ERR_END_OF_FILE && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
		Result = ERR_NONE;

	return Result;
}

static int WriteList( pls* p, const tchar_t* Path,const tchar_t* DispName,tick_t Length)
{
	if (p->No<0)
	{
		p->No=0;
		StreamPrintf(p->Input,T("[playlist]\n"));
	}

	if (Path)
	{
		++p->No;
		StreamPrintf(p->Input,T("File%d=%s\n"),p->No,Path);
		if (DispName[0]) StreamPrintf(p->Input,T("Title%d=%s\n"),p->No,DispName);
		if (Length>=0) StreamPrintf(p->Input,T("Length%d=%d\n"),p->No,Length/TICKSPERSEC);
	}
	else
	{
		StreamPrintf(p->Input,T("NumberOfEntries=%d\n"),p->No);
		StreamPrintf(p->Input,T("Version=2\n"));
	}
	return ERR_NONE;
}

static pls PLS;

void PLS_Init()
{
	NodeFill((node*)&PLS.p,sizeof(pls),(nodeenum)Enum,(nodeget)Get,(nodeset)Set);
	PLS.p.ReadList = (fmtreadlist)ReadList;
	PLS.p.WriteList = (fmtwritelist)WriteList;
	NodeRegister((node*)&PLS.p,PRI_DEFAULT);
}

void PLS_Done()
{
	NodeUnRegister((node*)&PLS.p);
}

⌨️ 快捷键说明

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