#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void help(void){
int i;
char *hlp[]={
"playlist.exe: Decodes a .pls playlist from winamp3.",
"Prints the playlist titles on stdout, ready to copy",
"with the mouse into a jewelcase maker.",
"Example: playlist \"c:\\My Documents\\chocolat.pls\"",
0
};
for(i=0;hlp[i]!=0;++i)
  fprintf(stderr,"%s\n",hlp[i]);
}
int main(int argc,char **argv){
char s[256];
char *p;
FILE *fp;
  if(argc > 1 && argv[1][0]=='-'){
    help(); exit(0);
  }
  if(argc < 2) {
    help();
    fgets(s,255,stdin);
    fprintf(stderr,"Enter the .pls file name: ");
    fgets(s,255,stdin);
    if((p=strchr(s,'\r'))!=0) p[0]=0;
    if((p=strchr(s,'\n'))!=0) p[0]=0;
  } else strcpy(s,argv[1]);
top:
  fp=fopen(s,"r"); 
  if(fp==0) {printf("Can't find file %s\n",s); goto quit;}
  while(1){
    if(fgets(s,255,fp) == (char *)0) break;
    if(strncmp(s,"Title",5)==0){
      p=strchr(s,'='); 
      if(p!=(char *)0) printf("%2d. %s",atoi(s+5),p+1);
    }
  }
quit:
return 0;
}
