pls.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:4k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************
  2.  *
  3.  * This program is free software ; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7.  *
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program; if not, write to the Free Software
  15.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  16.  *
  17.  * $Id: pls.c 346 2005-11-21 22:20:40Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #include "../common.h"
  24. #include "pls.h"
  25. typedef struct pls
  26. {
  27. playlist Playlist;
  28. tchar_t File[MAXLINE];
  29. tchar_t Title[MAXLINE];
  30. int Length;
  31. } pls;
  32. static int UpdateStream(pls* p)
  33. {
  34. p->File[0] = 0;
  35. p->Title[0] = 0;
  36. p->Length = -1;
  37. return ERR_NONE;
  38. }
  39. static bool_t Fill(pls* p,tchar_t* Path,int PathLen,tchar_t* DispName,int DispNameLen,tick_t* Length)
  40. {
  41. if (p->Playlist.No >= 0 && p->File[0])
  42. {
  43. tcscpy_s(Path,PathLen,p->File);
  44. tcscpy_s(DispName,DispNameLen,p->Title);
  45. if (p->Length>=0) p->Length *= TICKSPERSEC;
  46. *Length = p->Length;
  47. p->File[0] = 0;
  48. p->Title[0] = 0;
  49. p->Length = -1;
  50. return 1;
  51. }
  52. return 0;
  53. }
  54. static int ReadList(pls* p,tchar_t* Path,int PathLen,tchar_t* DispName,int DispNameLen,tick_t* Length)
  55. {
  56. tchar_t s[MAXLINE];
  57. int No,Len;
  58. int Result = ERR_END_OF_FILE;
  59. while (Result==ERR_END_OF_FILE && ParserLine(&p->Playlist.Parser,s,MAXLINE))
  60. {
  61. tcsuprto(s,'=');
  62. if (stscanf(s,T("FILE%d ="),&No)==1)
  63. {
  64. if (No != p->Playlist.No && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
  65. Result = ERR_NONE;
  66. p->Playlist.No = No;
  67. tcscpy_s(p->File,TSIZEOF(p->File),tcschr(s,'=')+1);
  68. }
  69. else
  70. if (stscanf(s,T("TITLE%d ="),&No)==1)
  71. {
  72. if (No != p->Playlist.No && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
  73. Result = ERR_NONE;
  74. p->Playlist.No = No;
  75. tcscpy_s(p->Title,TSIZEOF(p->Title),tcschr(s,'=')+1);
  76. }
  77. else
  78. if (stscanf(s,T("LENGTH%d = %d"),&No,&Len)==2)
  79. {
  80. if (No != p->Playlist.No && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
  81. Result = ERR_NONE;
  82. p->Playlist.No = No;
  83. p->Length = Len;
  84. }
  85. }
  86. if (Result==ERR_END_OF_FILE && Fill(p,Path,PathLen,DispName,DispNameLen,Length))
  87. Result = ERR_NONE;
  88. return Result;
  89. }
  90. static int WriteList(pls* p, const tchar_t* Path,const tchar_t* DispName,tick_t Length)
  91. {
  92. if (p->Playlist.No<0)
  93. {
  94. p->Playlist.No=0;
  95. StreamPrintf(p->Playlist.Stream,T("[playlist]n"));
  96. }
  97. if (Path)
  98. {
  99. ++p->Playlist.No;
  100. StreamPrintf(p->Playlist.Stream,T("File%d=%sn"),p->Playlist.No,Path);
  101. if (DispName[0]) StreamPrintf(p->Playlist.Stream,T("Title%d=%sn"),p->Playlist.No,DispName);
  102. if (Length>=0) StreamPrintf(p->Playlist.Stream,T("Length%d=%dn"),p->Playlist.No,Length/TICKSPERSEC);
  103. }
  104. else
  105. {
  106. StreamPrintf(p->Playlist.Stream,T("NumberOfEntries=%dn"),p->Playlist.No);
  107. StreamPrintf(p->Playlist.Stream,T("Version=2n"));
  108. }
  109. return ERR_NONE;
  110. }
  111. static int Create(pls* p)
  112. {
  113. p->Playlist.UpdateStream = (nodefunc)UpdateStream;
  114. p->Playlist.ReadList = (playreadlist)ReadList;
  115. p->Playlist.WriteList = (playwritelist)WriteList;
  116. return ERR_NONE;
  117. }
  118. static const nodedef PLS =
  119. {
  120. sizeof(pls),
  121. PLS_ID,
  122. PLAYLIST_CLASS, 
  123. PRI_DEFAULT+1, //default playlist format (form saving)
  124. (nodecreate)Create,
  125. NULL,
  126. };
  127. void PLS_Init()
  128. {
  129. NodeRegisterClass(&PLS);
  130. }
  131. void PLS_Done()
  132. {
  133. NodeUnRegisterClass(PLS_ID);
  134. }