Index: apps/plugins/viewers.config
===================================================================
--- apps/plugins/viewers.config	(revision 13196)
+++ apps/plugins/viewers.config	(working copy)
@@ -1,3 +1,4 @@
+m3u,viewers/m3u2pla,5
 ch8,viewers/chip8,0
 txt,viewers/viewer,1
 nfo,viewers/viewer,1
Index: apps/plugins/m3u2pla.c
===================================================================
--- apps/plugins/m3u2pla.c	(revision 0)
+++ apps/plugins/m3u2pla.c	(revision 0)
@@ -0,0 +1,405 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: m3u2pla $
+ *
+ * Copyright (C) 2007 Gerritt Gonzales
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/* pla2m3u does not work yet just an empty named.m3u file */
+/* so far unable to read in more than the first character */
+/* each char is followed by a null byte "\0" */
+/* anybody know how I can read this file type, worked in Perl */
+/* there is a null byte "\0" between each character */
+/* and each line ends with a "\r\n" */
+
+#include "plugin.h"
+
+/* welcome to the example rockbox plugin */
+
+/* This macros must always be included. Should be placed at the top by
+   convention, although the actual position doesn't matter */
+PLUGIN_HEADER
+
+/* here is a global api struct pointer. while not strictly necessary,
+   it's nice not to have to pass the api pointer in all function calls
+   in the plugin */
+static struct plugin_api* rb;
+#define plug_QUIT BUTTON_POWER
+#define plug_DISPLAY_YES BUTTON_UP
+#define plug_DISPLAY_NO BUTTON_DOWN
+#define EXT_UNKNOWN -1
+#define EXT_8 0
+#define EXT_u 1
+#define EXT_a 2
+
+
+void cleanup(void *parameter)
+{
+    (void)parameter;
+    rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
+}
+
+static int getExt(char *filename)
+{   switch (filename[rb->strlen(filename)-1])
+    {
+        /*m3u8*/
+        case '8': return EXT_8;
+        /*m3u*/
+        case 'u': return EXT_u;
+        /*pla*/
+        case 'a': return EXT_a;
+        /*anything else*/
+        default: return EXT_UNKNOWN;
+    }
+    return EXT_UNKNOWN; /*error*/
+}
+
+
+int pla2m3u(char *param, char *newparam)
+{
+
+    /* pla2m3u does not work yet just an empty named.m3u file */
+    /* so far unable to read in more than the first character */
+    /* each char is followed by a null byte "\0" */
+
+    int f;
+    int fd1;
+    int len;
+    int len2;
+    int button;
+    int count= 0;
+    int j, q;
+    bool conf=false;
+    char buff[256];
+    char buffer[256];
+    char buffertwin[256];
+
+    f = rb->open(param, O_RDONLY);
+
+    if(f < 0) 
+    {
+        rb->splash(HZ*2, "Can't open file");
+        rb->splash(HZ*2, "%s", param);
+    } else {
+        /*rb->splash(HZ*1, "      File opened  ");*/
+        
+        button = rb->button_get(false);
+
+        switch(button)
+        {
+            case(plug_QUIT):
+                cleanup(NULL);
+                rb->close(f);
+                rb->lcd_clear_display();
+                return PLUGIN_OK;
+                break;
+                
+            default:
+                if (rb->default_event_handler_ex(button, cleanup, NULL)
+                    == SYS_USB_CONNECTED)
+                    return PLUGIN_USB_CONNECTED;
+                break;
+        }
+        
+        fd1 = rb->open(newparam, O_CREAT|O_WRONLY|O_TRUNC); 
+        /*rb->splash(HZ*2, " fd1 opened");*/
+        
+    if(fd1 < 0) 
+    {
+        rb->splash(HZ*2, "Can't open file");
+        rb->splash(HZ*2, "%s", newparam);
+    }
+
+
+        /*rb->splash(HZ*2, "inside if fd1 is opened");*/
+        /* this will skip the leading header in the pla file 3 lines*/
+        int hardcodecount=0; 
+        while(rb->read_line(f, buffer, 256))
+        {
+        /*rb->splash(HZ*2, "inside while read");*/
+        /*rb->splash(HZ*2, buffer);*/
+            hardcodecount++; 
+            button = rb->button_get(false);
+            switch(button)
+            {
+                case (plug_DISPLAY_NO):
+                    conf=false;
+                    rb->splash(HZ*1, "Display off");
+                    break;
+                case (plug_DISPLAY_YES):
+                    conf=true;
+                    rb->splash(HZ*1, "Display on");
+                    break;
+            }
+
+            if (hardcodecount >3)
+            {
+                /* rb->splash(HZ*2, "inside hard code count greater than 3");*/
+                /* the "/0" null bytes are stopping the read write etc.." */
+                /* anybody know how I can read this file type, worked in Perl */
+                if (conf==true)
+                {
+                    rb->splash(HZ*1, buffer);
+                }
+                len2=(rb->strlen(buffer));
+                /*
+                for( y=0; y< len2-1; y++ )
+                {
+                */
+                /*change sansa \ to rockbox / */ 
+                /*
+                if( buffer[y] == '\\')
+                    {buffer[y] = '/';}
+                }*/
+                rb->snprintf(buffertwin, len2+2, "%s\n", buffer);
+                len=rb->strlen(buffertwin);
+
+                /*rb->splash(HZ*2, buffertwin);*/
+
+                /* skip leading "HARP, " need plus 6 after nulls removed */
+                /* will need to add in a check when SD card is functional */
+                for(q=6; q< len && q<256; q++ )
+                {
+                    buff[q-6] = buffertwin[q];
+                }
+                /*buff[q-6]='\n';*/
+                /*rb->splash(HZ*2, buff);*/
+
+                len=rb->strlen(buff);
+                for( j=0; j< len; j++ )
+                {
+                /* could just write out a sting here */
+                rb->write(fd1, &buff[j], 1);
+                }
+                ++count;
+            }
+        }
+    }
+    rb->close(f);
+    rb->close(fd1);
+    rb->lcd_clear_display();
+    if(fd1<0)
+    {
+    rb->splash(HZ*2, "Unable to write file!");
+    } else {
+   
+    rb->splash(HZ*3, "%d songs in playlist, %s", count, newparam);
+    }
+
+    return 1;
+
+}
+
+
+int m3u2pla(char *param, char *newparam)
+{
+
+    int f;
+    int fd1;
+    int len;
+    int len2;
+    int button;
+    int count= 0;
+    int y, j, k, t, q;
+    bool conf=false;
+    char buff[256];
+    char buffprx[9];
+    char buffer[256];
+    char buffheader[31];
+    char buffertwin[256];
+    /*changed for generic character encoding*/
+    const char tempy[]={NULL};
+
+    f = rb->open(param, O_RDONLY);
+
+    if(f < 0) 
+    {
+        rb->splash(HZ*2, "Can't open file");
+        rb->splash(HZ*2, "%s", param);
+    } else {
+        rb->splash(HZ*1, "      File opened  ");
+        
+        button = rb->button_get(false);
+
+        switch(button)
+        {
+            case(plug_QUIT):
+                cleanup(NULL);
+                rb->close(f);
+                rb->lcd_clear_display();
+                return PLUGIN_OK;
+                break;
+                
+            default:
+                if (rb->default_event_handler_ex(button, cleanup, NULL)
+                    == SYS_USB_CONNECTED)
+                    return PLUGIN_USB_CONNECTED;
+                break;
+        }
+        
+        fd1 = rb->open(newparam, O_CREAT|O_WRONLY|O_TRUNC); 
+        
+        /* build header and prefix */
+        rb->snprintf(buffprx, 9, "HARP, \r\n" );
+        rb->snprintf(buffheader, 31, "PLP PLAYLIST\r\nVERSION 1.20\r\n\r\n");
+        
+        /* time waster need for this*/
+        /*rb->splash(HZ*1, "Header being output...");*/
+        for( t=0; t< 30; t++ )
+        {
+            rb->write(fd1, &buffheader[t], 1);
+            rb->write(fd1, tempy, sizeof(tempy));
+
+        }
+        /* time waster need for this*/
+        /*rb->splash(HZ*1, "Processing Music files.");*/
+        while(rb->read_line(f, buffer, 256))
+        {
+
+        button = rb->button_get(false);
+        switch(button)
+        {
+            case (plug_DISPLAY_NO):
+                conf=false;
+                rb->splash(HZ*1, "Display off");
+                break;
+            case (plug_DISPLAY_YES):
+                conf=true;
+                rb->splash(HZ*1, "Display on");
+                break;
+        }
+            /* only really neader to convert real m3u files with tag info in them */
+            if( buffer[0] != '#')
+            {
+                if (conf==true)
+                {
+                    rb->splash(HZ*2, buffer);
+                }
+                len2=(rb->strlen(buffer));
+                for( y=0; y< len2-1; y++ )
+                {
+                /* change unix / to sansa \    */
+                    if( buffer[y] == '/')
+                    {buffer[y] = '\\';}
+                }
+                rb->snprintf(buffertwin, len2+3, "%s\r\n", buffer);
+                len=rb->strlen(buffertwin);
+                /* skip leading slash */
+                for(q=1; q< len && q<256; q++ )
+                {
+                    buff[q-1] = buffertwin[q];
+                }
+                buff[q-1]='\0';
+                /* prefix to file 'HARP,' */
+                for( k=0; k< 6; k++ )
+                {
+                rb->write(fd1, &buffprx[k], 1);
+                rb->write(fd1, tempy, sizeof(tempy));
+                }
+                len=rb->strlen(buff);
+                for( j=0; j< len; j++ )
+                {
+                rb->write(fd1, &buff[j], 1);
+                rb->write(fd1, tempy, sizeof(tempy));
+                }
+                ++count;
+            }
+        }
+    }
+    rb->close(f);
+    rb->close(fd1);
+    rb->lcd_clear_display();
+    rb->show_logo();
+    if(fd1<0)
+    {
+    rb->splash(HZ*2, "Unable to write file!");
+    } else {
+   
+    rb->splash(HZ*3, "%d songs in playlist, %s", count, newparam);
+    }
+
+    return 1;
+}
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
+{
+    /* if you don't use the parameter, you can do like
+       this to avoid the compiler warning about it */
+    /* (void)parameter; */
+
+    /* if you are using a global api pointer, don't forget to copy it!
+       otherwise you will get lovely "I04: IllInstr" errors... :-) */
+    rb = api;
+    /* now go ahead and have fun! */
+
+    const char tempy[]={NULL};
+    char newparameter[256];
+    int length;
+
+    rb->splash(HZ*4, "Use: UP Display ON, DOWN display OFF"); 
+    length=rb->strlen((char*)parameter);
+    rb->snprintf(newparameter, length+1, "%s", (char*)parameter);
+            
+    rb->show_logo();
+    if (!parameter) 
+    {  
+        rb->splash(HZ*2, "Use open with... to select a file to convert"); 
+    }else{
+        switch (getExt(parameter))
+        {
+            case EXT_8:rb->splash(HZ*1, "m3u8 file");
+            /* change ext to .pla */
+            newparameter[rb->strlen(newparameter)-4]='p';
+            newparameter[rb->strlen(newparameter)-3]='l';
+            newparameter[rb->strlen(newparameter)-2]='a';
+            newparameter[rb->strlen(newparameter)-1]=(char)*tempy;
+            /* function call here for conversion */
+            m3u2pla(parameter, newparameter);
+            break;
+
+            case EXT_u:rb->splash(HZ*1, "m3u file"); 
+            /* chnage ext to .pla */
+            newparameter[rb->strlen(newparameter)-3]='p';
+            newparameter[rb->strlen(newparameter)-2]='l';
+            newparameter[rb->strlen(newparameter)-1]='a';
+            newparameter[rb->strlen(newparameter)-0]=(char)*tempy;
+            /* function call here for conversion */
+            m3u2pla(parameter, newparameter);
+            break;
+
+            case EXT_a:rb->splash(HZ*1, "pla file"); 
+            /* chnage ext to .m3u */
+            newparameter[rb->strlen(newparameter)-3]='m';
+            newparameter[rb->strlen(newparameter)-2]='3';
+            newparameter[rb->strlen(newparameter)-1]='u';
+            newparameter[rb->strlen(newparameter)-0]=(char)*tempy;
+            /* function call here for conversion */
+            pla2m3u(parameter, newparameter);
+            break;
+
+            case EXT_UNKNOWN:rb->splash(HZ*2, "You must select a .m3u, .m3u8 or a .pla file to convert"); 
+            return PLUGIN_OK;
+        }
+    }
+
+    rb->lcd_clear_display();
+    rb->show_logo();
+    rb->splash(HZ*1, "Conversion - By GRaTT"); 
+    rb->splash(HZ*1, "Good Bye"); 
+    cleanup(NULL);
+
+    return PLUGIN_OK;
+}
Index: apps/plugins/SOURCES
===================================================================
--- apps/plugins/SOURCES	(revision 13196)
+++ apps/plugins/SOURCES	(working copy)
@@ -24,6 +24,10 @@
 metronome.c
 #endif
 
+#if defined(SANSA_E200)
+m3u2pla.c
+#endif
+
 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)) && !defined(SIMULATOR)
 wavplay.c
 #endif
