Index: apps/plugins/viewers.config
===================================================================
--- apps/plugins/viewers.config	(revision 13344)
+++ apps/plugins/viewers.config	(working copy)
@@ -1,3 +1,5 @@
+html,viewers/HTML_Parser,7
+htm,viewers/HTML_Parser,7
 ch8,viewers/chip8,0
 txt,viewers/viewer,1
 nfo,viewers/viewer,1
Index: apps/plugins/SOURCES
===================================================================
--- apps/plugins/SOURCES	(revision 13344)
+++ apps/plugins/SOURCES	(working copy)
@@ -1,4 +1,5 @@
 /* plugins common to all models */
+HTML_Parser.c
 battery_bench.c
 chessclock.c
 credits.c
Index: apps/plugins/HTML_Parser.c
===================================================================
--- apps/plugins/HTML_Parser.c	(revision 0)
+++ apps/plugins/HTML_Parser.c	(revision 0)
@@ -0,0 +1,235 @@
+/*****************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: HTML_Parser $ 
+ *
+ * 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.
+ *
+ * This program will parse html and htm files, suitable for reading
+ * in the text viewer.
+ * More formatting to come.
+ * Usage: Select a html or htm file, then select the txt file created 
+ *        for viewing.
+ ****************************************************************************/
+
+#include "plugin.h"
+
+/* 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 EXT_UNKNOWN -1
+#define EXT_l 0
+#define EXT_m 1
+
+void cleanup(void *parameter){
+    (void)parameter;
+    rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
+}
+
+static int getExt(char *filename){   
+    /* requires additional extention checking here */
+    switch (filename[rb->strlen(filename)-1]){
+        /*html*/
+        case 'l': return EXT_l;
+        /*htm*/
+        case 'm': return EXT_m;
+        /*anything else*/
+        default: return EXT_UNKNOWN;
+    }
+    return EXT_UNKNOWN; /*error*/
+}
+
+int tag(int IN, int OUT){
+    int inc=0;
+    int dec=0;
+    int size_of=1;
+    int writechar=0;
+    char buff[1];
+
+    dec=rb->read(IN, &buff[0], size_of);
+    inc=inc+dec;
+    if(dec==0){
+        return 0;
+    }
+    /* add in tag formatting here */
+    /* need to look for <br> and <p> tags */
+
+    while (buff[0]!='>'){
+        dec=rb->read(IN, &buff[0], size_of);
+        inc=inc+dec;
+        if(dec==0){
+            return 0;
+        }
+        if(writechar){
+            rb->write(OUT, &buff[0], 1);
+        }
+    }
+    return inc;
+} 
+
+int html_parse(char *param, char *newparam){
+    int t;
+    int f=0;
+    int fd1=0;
+    int dec=0;
+    int inc=0;
+    int skipit=0;
+    int button;
+    int size_of=1; 
+    int size_of_file=0; 
+    char buffheader[26];
+    char buff[1];
+
+    f = rb->open(param, O_RDONLY);
+    if(f < 0){
+        rb->splash(HZ*2, "Can't open file %s", param);
+    }else{
+        size_of_file=rb->filesize(f);
+        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->lcd_puts(0,6," * FILE Name:");
+        rb->lcd_puts_scroll(0,7, newparam);
+        rb->lcd_update();
+        /* build header */
+        rb->snprintf(buffheader, 26, " <HTML Parser by GRaTT>\n\n");
+        for(t=0; t< 26; t++){
+            rb->write(fd1, &buffheader[t], 1);
+        }
+        while(inc<size_of_file){/* keep reading file */
+            dec=rb->read(f, &buff[0], size_of);
+            if(dec>0){
+                inc=inc+dec;
+                /* if a tag is found */
+                /* add in formatting in function tag */
+                if(buff[0]=='<'){
+                inc=inc+tag(f, fd1);
+                }else{ 
+                    /* skip extra blank spaces */
+                    if(skipit>0 &&  buff[0]==' '){
+                        /* skipit */
+                    }else{
+                        /* limit blank lines */
+                        if(skipit>1 &&  buff[0]=='\n'){
+                            /* skipit */
+                        }else{
+                            if(buff[0]=='\r'){
+                            /* skipit */
+                            }else{
+                                rb->write(fd1, &buff[0], 1);
+                                skipit=0;
+                            }
+                        }
+                        if(buff[0]==' ' || buff[0]=='\n'){
+                        skipit++; 
+                        }
+                    }
+                }
+            }
+        }
+    }
+    rb->snprintf(buffheader, 26, "\n\n <HTML Parser by GRaTT>");
+    for(t=0; t< 26; t++){
+        rb->write(fd1, &buffheader[t], 1);
+    }
+    rb->close(f);
+    rb->close(fd1);
+    if(fd1<0){
+        rb->splash(HZ*2, "Unable to write file!");
+    }
+
+    rb->button_get_w_tmo(250);
+    return 1;
+}
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
+    rb = api;
+    const char tempy[]={NULL};
+    char newparameter[256];
+    int length, button, w, h;
+    bool prev_show_statusbar;
+
+    prev_show_statusbar = rb->global_settings->statusbar;
+    rb->global_settings->statusbar = false;
+    if (!parameter){  
+        rb->splash(HZ*2, "Select a file to convert and use Open With..."); 
+    }else{
+        rb->lcd_getstringsize("A",&w,&h);
+        length=rb->strlen((char*)parameter);
+        rb->snprintf(newparameter, length+1, "%s", (char*)parameter);
+        rb->lcd_puts(4,0," * HTML Parser *");
+        rb->lcd_drawline(0,h+5,LCD_WIDTH-1,h+5);
+        rb->lcd_drawline(0,LCD_HEIGHT-h-7,LCD_WIDTH-1,LCD_HEIGHT-h-7);
+        rb->lcd_update();
+
+        button = rb->button_get(false);
+        switch(button){
+            case(plug_QUIT):
+                cleanup(NULL);
+                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;
+        }
+        switch (getExt(parameter)){
+            case EXT_l:rb->lcd_putsxy(0,(LCD_HEIGHT-h-5), "* Converting html to txt *");
+            /* change ext to .pla */
+            newparameter[rb->strlen(newparameter)-4]='t';
+            newparameter[rb->strlen(newparameter)-3]='x';
+            newparameter[rb->strlen(newparameter)-2]='t';
+            newparameter[rb->strlen(newparameter)-1]=(char)*tempy;
+            /* function call here for conversion */
+            html_parse(parameter, newparameter);
+            break;
+            case EXT_m:rb->lcd_putsxy(0,(LCD_HEIGHT-h-5), "* Converting htm to txt *");
+            /* chnage ext to .pla */
+            newparameter[rb->strlen(newparameter)-3]='t';
+            newparameter[rb->strlen(newparameter)-2]='x';
+            newparameter[rb->strlen(newparameter)-1]='t';
+            newparameter[rb->strlen(newparameter)-0]=(char)*tempy;
+            /* function call here for conversion */
+            html_parse(parameter, newparameter);
+            break;
+            case EXT_UNKNOWN:rb->splash(HZ*2, "Select a (.htm) or (.html) file"); 
+            return PLUGIN_OK;
+        }
+    }
+    rb->lcd_putsxy(0,(LCD_HEIGHT-h-5), " * Convertion * By GRaTT");
+    rb->lcd_update();
+    rb->global_settings->statusbar = prev_show_statusbar;
+    rb->button_get_w_tmo(150);
+    return PLUGIN_OK;
+}
