sobota, 28 grudnia 2019

Save from text file to html (c++ function)

#define max_Size 256
void Save_to_HTML(char *text_File, char *new_html_File)
{

    int i,j,line=0;
    fstream file_Text;
    string buff[max_Size];
    file_Text.open(text_File,ios::in);
    while(!file_Text.eof())
    {
        getline(file_Text,buff[line]);
        ++line;
    }
    file_Text.close();
    int sum_Count=line;
    string begin_Page[6]={"<HTML>","<HEAD>","<TITLE>","</TITLE","</HEAD>","<BODY>"};
    string end_Page[2]={"</BODY>","</HTML>"};
    int size_html_Page=sum_Count+6+2;
    string *page_HTML=new string[size_html_Page];
    for(i=0;i<6;i++)
   {
    page_HTML[i]=begin_Page[i];
   }
   for(i=0,j=6;i<sum_Count;i++,j++)
   {
    page_HTML[j]=buff[i]+" <br> ";
   }
   for(i=0,j=6+sum_Count;i<2;i++,j++)
   {
    page_HTML[j]=end_Page[i];
   }
   fstream file_HTML;
   file_HTML.open(new_html_File, ios::out | ios::app);
   if(file_HTML.good() == true)
   {
       for(i=0;i<size_html_Page;i++)
       {
           file_HTML<<page_HTML[i]<<"\n";
       }
       file_HTML.close();
   }
   delete [] page_HTML;

}


int main()
{
 Save_to_HTML("readme.txt","READ2.html");
    return 0;
}

czwartek, 26 grudnia 2019

utsname values (html) gcc (linux)

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/utsname.h>

struct uts_Values
{
char* sysname;
char* release;
char* machine;
char* version;
};

int main(int argc, char **argv)
{
size_t length_Table;
int file_HTML;
char *filename="Version.html";
struct utsname sys_Utsname;
struct uts_Values m_Values;
uname(&sys_Utsname);
m_Values.sysname=sys_Utsname.sysname;
m_Values.release=sys_Utsname.release;
m_Values.machine=sys_Utsname.machine;
m_Values.version=sys_Utsname.version;
static char* html_page=
"<html>\n"
"<body>\n"
"<table>\n"
"<thead>\n"
"<tr>\n"
"<th>m_Values.sysname</th>\n"
"<th>m_Values.release</th>\n"
"<th>m_Values.machine</th>\n"
"<th>m_Values.version</th>\n"
"</tr>\n"
"</thead>\n"
"</table>\n"
"</body>\n"
"</thml>\n";
length_Table=strlen(html_page);
file_HTML=open(filename,O_WRONLY);
write(file_HTML,html_page,length_Table);
close(file_HTML);


return 0;
}