html version for mbed os V5.2

Dependents:   scooter_mbed_correction_mbed_os

Fork of html by philippe laurent

Committer:
superphil06
Date:
Tue Aug 11 15:00:40 2015 +0000
Revision:
0:539b0fc9d536
Child:
1:ba608856b208
version beta1 html patch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
superphil06 0:539b0fc9d536 1 /****************************************************************************
superphil06 0:539b0fc9d536 2 *
superphil06 0:539b0fc9d536 3 * (C) 2000 by BECK IPC GmbH
superphil06 0:539b0fc9d536 4 *
superphil06 0:539b0fc9d536 5 * BECK IPC GmbH
superphil06 0:539b0fc9d536 6 * Garbenheimerstr. 38
superphil06 0:539b0fc9d536 7 * D-35578 Wetzlar
superphil06 0:539b0fc9d536 8 *
superphil06 0:539b0fc9d536 9 * Phone : (49)-6441-905-240
superphil06 0:539b0fc9d536 10 * Fax : (49)-6441-905-245
superphil06 0:539b0fc9d536 11 *
superphil06 0:539b0fc9d536 12 * ---------------------------------------------------------------------------
superphil06 0:539b0fc9d536 13 * Module : HTML.C
superphil06 0:539b0fc9d536 14 * Function : contains functions to operate between HTML files and SC12
superphil06 0:539b0fc9d536 15 * Cgi Interface. It read Html files, copy it into memory
superphil06 0:539b0fc9d536 16 * block and save positions of '^VARDEF[x]' entry in var_field
superphil06 0:539b0fc9d536 17 * struct to insert dynamtic code int the static file.
superphil06 0:539b0fc9d536 18
superphil06 0:539b0fc9d536 19 By Example:
superphil06 0:539b0fc9d536 20 On the flash exists the following htm file (a:\exp.htm):
superphil06 0:539b0fc9d536 21 _______________________________________________________
superphil06 0:539b0fc9d536 22
superphil06 0:539b0fc9d536 23 <HTML><HEAD><TITLE>Example Page</TITLE></HEAD>
superphil06 0:539b0fc9d536 24 <BODY>
superphil06 0:539b0fc9d536 25 The first Dynamic code/text ^VARDEF[0] = 32 <BR>
superphil06 0:539b0fc9d536 26 And now the Dynamic code/text ^VARDEF[1] = 3 <BR>
superphil06 0:539b0fc9d536 27 </BODY>
superphil06 0:539b0fc9d536 28 </HTML>
superphil06 0:539b0fc9d536 29 _______________________________________________________
superphil06 0:539b0fc9d536 30
superphil06 0:539b0fc9d536 31 now you have to call the function in the following way:
superphil06 0:539b0fc9d536 32
superphil06 0:539b0fc9d536 33
superphil06 0:539b0fc9d536 34
superphil06 0:539b0fc9d536 35
superphil06 0:539b0fc9d536 36
superphil06 0:539b0fc9d536 37
superphil06 0:539b0fc9d536 38 #include "html.h"
superphil06 0:539b0fc9d536 39
superphil06 0:539b0fc9d536 40 vard_field_t exp_vardef[2]; // size "2": 2 var defs in htm file
superphil06 0:539b0fc9d536 41 char exp_page[1024]; // html code buffer (1024 bytes)
superphil06 0:539b0fc9d536 42
superphil06 0:539b0fc9d536 43 ....
superphil06 0:539b0fc9d536 44 ....
superphil06 0:539b0fc9d536 45 ..
superphil06 0:539b0fc9d536 46
superphil06 0:539b0fc9d536 47 int main(void)
superphil06 0:539b0fc9d536 48 {
superphil06 0:539b0fc9d536 49 char tmpBuffer[1024];
superphil06 0:539b0fc9d536 50 ...
superphil06 0:539b0fc9d536 51
superphil06 0:539b0fc9d536 52
superphil06 0:539b0fc9d536 53
superphil06 0:539b0fc9d536 54
superphil06 0:539b0fc9d536 55 exp_page = Gen_HtmlCode_From_File( "a:\exp.htm", &exp_vardef, 2 );
superphil06 0:539b0fc9d536 56
superphil06 0:539b0fc9d536 57 // know, if exp != Null the page is in the memory block.
superphil06 0:539b0fc9d536 58 // the Vardef field are filled with blank spaces (ASCII 32).
superphil06 0:539b0fc9d536 59 // The exp_vardef struct points to this vardefs fields.
superphil06 0:539b0fc9d536 60 // So you can access to this empty fields in the
superphil06 0:539b0fc9d536 61 // following way (normaly the filling of the Vardefs will
superphil06 0:539b0fc9d536 62 // be done in the CGI function):
superphil06 0:539b0fc9d536 63
superphil06 0:539b0fc9d536 64 // 1. text:
superphil06 0:539b0fc9d536 65 strcpy( tmpBuffer, "I am the First text" );
superphil06 0:539b0fc9d536 66 FILL_STR( tmpBuffer, exp_vardef[0].length ); // this will
superphil06 0:539b0fc9d536 67 // to fill the not used characters of
superphil06 0:539b0fc9d536 68 // the string with blank spaces
superphil06 0:539b0fc9d536 69 memcpy( exp_vardef[0].ptr, tmpBufferm, exp_vardef[0].length );
superphil06 0:539b0fc9d536 70
superphil06 0:539b0fc9d536 71
superphil06 0:539b0fc9d536 72 // 2. text:
superphil06 0:539b0fc9d536 73 strcpy( tmpBuffer, "I am the First text" );
superphil06 0:539b0fc9d536 74 FILL_STR( tmpBuffer, exp_vardef[0].length ); // this will
superphil06 0:539b0fc9d536 75 // to fill the not used characters of
superphil06 0:539b0fc9d536 76 // the string with blank spaces
superphil06 0:539b0fc9d536 77 memcpy( exp_vardef[0].ptr, tmpBufferm, exp_vardef[0].length );
superphil06 0:539b0fc9d536 78
superphil06 0:539b0fc9d536 79 .....
superphil06 0:539b0fc9d536 80 ..
superphil06 0:539b0fc9d536 81 return;
superphil06 0:539b0fc9d536 82
superphil06 0:539b0fc9d536 83 }
superphil06 0:539b0fc9d536 84
superphil06 0:539b0fc9d536 85 *
superphil06 0:539b0fc9d536 86 * Author : Stoidner
superphil06 0:539b0fc9d536 87 * Date : 30.08.00
superphil06 0:539b0fc9d536 88 * Version : V1.00
superphil06 0:539b0fc9d536 89 * ---------------------------------------------------------------------------
superphil06 0:539b0fc9d536 90 * History :
superphil06 0:539b0fc9d536 91 *
superphil06 0:539b0fc9d536 92 * Vx.yy Author Changes
superphil06 0:539b0fc9d536 93 *
superphil06 0:539b0fc9d536 94 * V1.00 cs Create
superphil06 0:539b0fc9d536 95 **************************************************************/
superphil06 0:539b0fc9d536 96
superphil06 0:539b0fc9d536 97
superphil06 0:539b0fc9d536 98 //*******************
superphil06 0:539b0fc9d536 99 //* standard includes
superphil06 0:539b0fc9d536 100
superphil06 0:539b0fc9d536 101 #include "mbed.h"
superphil06 0:539b0fc9d536 102 #include <stdio.h>
superphil06 0:539b0fc9d536 103 #include <stdlib.h>
superphil06 0:539b0fc9d536 104 #include <string.h>
superphil06 0:539b0fc9d536 105
superphil06 0:539b0fc9d536 106 //********************
superphil06 0:539b0fc9d536 107 //* specified includes
superphil06 0:539b0fc9d536 108 #include "html.h"
superphil06 0:539b0fc9d536 109 #include <stdlib.h>
superphil06 0:539b0fc9d536 110
superphil06 0:539b0fc9d536 111
superphil06 0:539b0fc9d536 112 #define HTML_DEBUG
superphil06 0:539b0fc9d536 113
superphil06 0:539b0fc9d536 114
superphil06 0:539b0fc9d536 115
superphil06 0:539b0fc9d536 116
superphil06 0:539b0fc9d536 117
superphil06 0:539b0fc9d536 118
superphil06 0:539b0fc9d536 119
superphil06 0:539b0fc9d536 120
superphil06 0:539b0fc9d536 121 char *Gen_HtmlCode_From_File( char *Path, var_field_t *var_field, int max_vardef )
superphil06 0:539b0fc9d536 122 {LocalFileSystem local("local");
superphil06 0:539b0fc9d536 123 FILE *in; // File Handle
superphil06 0:539b0fc9d536 124 //fpos_t filepos; // file position counter
superphil06 0:539b0fc9d536 125 long filepos; // file position counter
superphil06 0:539b0fc9d536 126 int data; // read data from file
superphil06 0:539b0fc9d536 127 char value_str[40]; // to search for '^VARDEF[x]' entrys
superphil06 0:539b0fc9d536 128 int i=0; // VarDef Counter ( '^VARDEF[i]' )
superphil06 0:539b0fc9d536 129 long mem_pos = -1; // actually mem offset
superphil06 0:539b0fc9d536 130 char *html_page; // pointer to memory area of Html Page
superphil06 0:539b0fc9d536 131
superphil06 0:539b0fc9d536 132 if ((in = fopen(Path, "rt")) == NULL)
superphil06 0:539b0fc9d536 133 {
superphil06 0:539b0fc9d536 134 printf("\r\nError Open File: -%s-", Path);
superphil06 0:539b0fc9d536 135 return(NULL);
superphil06 0:539b0fc9d536 136 }
superphil06 0:539b0fc9d536 137
superphil06 0:539b0fc9d536 138 #ifdef HTML_DEBUG
superphil06 0:539b0fc9d536 139 printf("\r\nOpen File.. \"%s\"", Path);
superphil06 0:539b0fc9d536 140 #endif
superphil06 0:539b0fc9d536 141
superphil06 0:539b0fc9d536 142 // checking Html Page size and filling var_field struct
superphil06 0:539b0fc9d536 143 while (!feof(in))
superphil06 0:539b0fc9d536 144 {
superphil06 0:539b0fc9d536 145 // serach for Commands
superphil06 0:539b0fc9d536 146 mem_pos++;
superphil06 0:539b0fc9d536 147
superphil06 0:539b0fc9d536 148 // check for unexpected page size
superphil06 0:539b0fc9d536 149 if (mem_pos >= 0xFFFF)
superphil06 0:539b0fc9d536 150 {
superphil06 0:539b0fc9d536 151 fclose(in);
superphil06 0:539b0fc9d536 152 return(NULL);
superphil06 0:539b0fc9d536 153 }
superphil06 0:539b0fc9d536 154
superphil06 0:539b0fc9d536 155 if ( fgetc(in) == CMD_HTML_SIGN )
superphil06 0:539b0fc9d536 156 {
superphil06 0:539b0fc9d536 157 //fgetpos(in, &filepos);
superphil06 0:539b0fc9d536 158 filepos= ftell ( in );// replace fgetpos call
superphil06 0:539b0fc9d536 159
superphil06 0:539b0fc9d536 160
superphil06 0:539b0fc9d536 161 if ( fscanf(in , "VARDEF[ %d ] = %s", &i, &value_str ) )
superphil06 0:539b0fc9d536 162 {
superphil06 0:539b0fc9d536 163 #ifdef HTML_DEBUG
superphil06 0:539b0fc9d536 164 printf("\r\nFound and save entry..");
superphil06 0:539b0fc9d536 165 #endif
superphil06 0:539b0fc9d536 166 mem_pos += atoi(value_str)-1;
superphil06 0:539b0fc9d536 167 }
superphil06 0:539b0fc9d536 168 else fseek( in, filepos, SEEK_SET );
superphil06 0:539b0fc9d536 169 }
superphil06 0:539b0fc9d536 170
superphil06 0:539b0fc9d536 171 } // while (!feof
superphil06 0:539b0fc9d536 172
superphil06 0:539b0fc9d536 173 // allocate memory
superphil06 0:539b0fc9d536 174 html_page = (char *) malloc( (int) mem_pos+1 );
superphil06 0:539b0fc9d536 175
superphil06 0:539b0fc9d536 176 // check if alloc was successful
superphil06 0:539b0fc9d536 177 if (html_page == NULL) return(NULL);
superphil06 0:539b0fc9d536 178
superphil06 0:539b0fc9d536 179 // jump to beginning of html file
superphil06 0:539b0fc9d536 180 fseek( in, 0, SEEK_SET);
superphil06 0:539b0fc9d536 181
superphil06 0:539b0fc9d536 182 // now loading website into memory
superphil06 0:539b0fc9d536 183 mem_pos = 0;
superphil06 0:539b0fc9d536 184 #ifdef HTML_DEBUG
superphil06 0:539b0fc9d536 185 printf("\r\nReading Page");
superphil06 0:539b0fc9d536 186 #endif
superphil06 0:539b0fc9d536 187 while (!feof(in))
superphil06 0:539b0fc9d536 188 {
superphil06 0:539b0fc9d536 189 data = fgetc(in);
superphil06 0:539b0fc9d536 190
superphil06 0:539b0fc9d536 191 // serach for Commands
superphil06 0:539b0fc9d536 192 if ( data == CMD_HTML_SIGN )
superphil06 0:539b0fc9d536 193 {
superphil06 0:539b0fc9d536 194 // fgetpos(in, &filepos);
superphil06 0:539b0fc9d536 195 filepos =ftell ( in );// replace fgetpos call
superphil06 0:539b0fc9d536 196
superphil06 0:539b0fc9d536 197 if ( fscanf(in , "VARDEF[ %d ] = %s", &i, &value_str ) )
superphil06 0:539b0fc9d536 198 {
superphil06 0:539b0fc9d536 199 if (var_field)
superphil06 0:539b0fc9d536 200 {
superphil06 0:539b0fc9d536 201 // save VarDef
superphil06 0:539b0fc9d536 202
superphil06 0:539b0fc9d536 203 // check if vardef index is valid
superphil06 0:539b0fc9d536 204 if ( i>max_vardef ) { free(html_page); return(NULL); };
superphil06 0:539b0fc9d536 205 //var_field[i].length = atoi(value_str);
superphil06 0:539b0fc9d536 206 var_field[i].length=strlen(value_str);
superphil06 0:539b0fc9d536 207 var_field[i].ptr = &html_page[(int)mem_pos];
superphil06 0:539b0fc9d536 208 }
superphil06 0:539b0fc9d536 209
superphil06 0:539b0fc9d536 210 // insert free characters
superphil06 0:539b0fc9d536 211 // for (i=0; i<=atoi(value_str)-1; i++)
superphil06 0:539b0fc9d536 212 for(i=0;i<=strlen(value_str);i++)
superphil06 0:539b0fc9d536 213 {
superphil06 0:539b0fc9d536 214 html_page[(int)mem_pos] = (char) 32;
superphil06 0:539b0fc9d536 215 mem_pos++;
superphil06 0:539b0fc9d536 216 }
superphil06 0:539b0fc9d536 217
superphil06 0:539b0fc9d536 218 }
superphil06 0:539b0fc9d536 219 else
superphil06 0:539b0fc9d536 220 {
superphil06 0:539b0fc9d536 221 // set data pointer back
superphil06 0:539b0fc9d536 222 fseek( in, (long) filepos, SEEK_SET);
superphil06 0:539b0fc9d536 223
superphil06 0:539b0fc9d536 224 // copy data into memory
superphil06 0:539b0fc9d536 225 html_page[(int)mem_pos] = (char)data;
superphil06 0:539b0fc9d536 226 mem_pos++;
superphil06 0:539b0fc9d536 227 }
superphil06 0:539b0fc9d536 228
superphil06 0:539b0fc9d536 229 }
superphil06 0:539b0fc9d536 230 else
superphil06 0:539b0fc9d536 231 {
superphil06 0:539b0fc9d536 232 // copy data into memory
superphil06 0:539b0fc9d536 233 html_page[(int)mem_pos] = (char)data;
superphil06 0:539b0fc9d536 234 mem_pos++;
superphil06 0:539b0fc9d536 235 }
superphil06 0:539b0fc9d536 236
superphil06 0:539b0fc9d536 237 } // while (!feof
superphil06 0:539b0fc9d536 238
superphil06 0:539b0fc9d536 239 // terminate string
superphil06 0:539b0fc9d536 240 html_page[(int)mem_pos-1] = (char)'\0';
superphil06 0:539b0fc9d536 241
superphil06 0:539b0fc9d536 242
superphil06 0:539b0fc9d536 243
superphil06 0:539b0fc9d536 244 // close HTML Page
superphil06 0:539b0fc9d536 245 fclose(in);
superphil06 0:539b0fc9d536 246
superphil06 0:539b0fc9d536 247 #ifdef HTML_DEBUG
superphil06 0:539b0fc9d536 248 printf("\r\nDone.");
superphil06 0:539b0fc9d536 249 #endif
superphil06 0:539b0fc9d536 250
superphil06 0:539b0fc9d536 251
superphil06 0:539b0fc9d536 252 return(html_page);
superphil06 0:539b0fc9d536 253 }
superphil06 0:539b0fc9d536 254 //simple function thatr load file from disk and return pointer
superphil06 0:539b0fc9d536 255
superphil06 0:539b0fc9d536 256 char *load_HtmlCode_From_File( char *Path,long * size)
superphil06 0:539b0fc9d536 257 {LocalFileSystem local("local");
superphil06 0:539b0fc9d536 258 FILE *in; // File Handle
superphil06 0:539b0fc9d536 259 int data; // read data from file
superphil06 0:539b0fc9d536 260 long mem_pos = -1; // actually mem offset
superphil06 0:539b0fc9d536 261 char *html_page; // pointer to memory area of Html Page
superphil06 0:539b0fc9d536 262 if ((in = fopen(Path, "rt")) == NULL)
superphil06 0:539b0fc9d536 263 { printf("\r\nError Open File: -%s-", Path); //open file from disk
superphil06 0:539b0fc9d536 264 return(NULL);
superphil06 0:539b0fc9d536 265 }
superphil06 0:539b0fc9d536 266
superphil06 0:539b0fc9d536 267 while (!feof(in)) // checking Html Page size
superphil06 0:539b0fc9d536 268 {
superphil06 0:539b0fc9d536 269 mem_pos++;
superphil06 0:539b0fc9d536 270 if ( (fgetc(in) == EOF)||(mem_pos==0xFFFF) )
superphil06 0:539b0fc9d536 271 {break;}
superphil06 0:539b0fc9d536 272 }// while (!feof )
superphil06 0:539b0fc9d536 273 html_page = (char *) malloc( (int) mem_pos+1 );// allocate memory
superphil06 0:539b0fc9d536 274
superphil06 0:539b0fc9d536 275 // check if alloc was successful
superphil06 0:539b0fc9d536 276 if (html_page == NULL) return(NULL);
superphil06 0:539b0fc9d536 277 fseek( in, 0, SEEK_SET);// jump to beginning of html file
superphil06 0:539b0fc9d536 278
superphil06 0:539b0fc9d536 279 mem_pos = 0; // now loading website into memory
superphil06 0:539b0fc9d536 280 while (!feof(in))
superphil06 0:539b0fc9d536 281 { data = fgetc(in);
superphil06 0:539b0fc9d536 282 html_page[(int)mem_pos] = (char)data;
superphil06 0:539b0fc9d536 283 mem_pos++;
superphil06 0:539b0fc9d536 284 } // while (!feof
superphil06 0:539b0fc9d536 285
superphil06 0:539b0fc9d536 286 html_page[(int)mem_pos-1] = (char)'\0'; // terminate string
superphil06 0:539b0fc9d536 287 *size=mem_pos-1; //return size of file
superphil06 0:539b0fc9d536 288 fclose(in); // close HTML Page
superphil06 0:539b0fc9d536 289 return(html_page);
superphil06 0:539b0fc9d536 290 }
superphil06 0:539b0fc9d536 291
superphil06 0:539b0fc9d536 292 void Html_Patch ( var_field_t *pTab_Balise,int index, char * pChaine ){
superphil06 0:539b0fc9d536 293
superphil06 0:539b0fc9d536 294 FILL_STR( pChaine,pTab_Balise[index].length );
superphil06 0:539b0fc9d536 295 memcpy( pTab_Balise[index].ptr, pChaine, pTab_Balise[index].length );
superphil06 0:539b0fc9d536 296 }