Commit 155ef08e authored by Jan Koester's avatar Jan Koester
Browse files

now uses std again

parent 1062e3db
Loading
Loading
Loading
Loading
+0 −7
Changes for CMakeLists.txt: 0 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -9,13 +9,6 @@ find_package(systempp REQUIRED)
set(LIBV "1.0.0")
set(Upstream_VERSION 1.0.0)

CHECK_INCLUDE_FILE_CXX("${systempp_INCLUDE_DIR}/config.h" GLIBSUPPORT)

if(GLIBSUPPORT MATCHES OFF)
    SET(CMAKE_CXX_FLAGS "-nolibc -nostdlib") #goal -nolibc
endif()


configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
+4 −4
Changes for src/exception.cpp: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ const char* libhtmlpp::HTMLException::what(){
    delete[] _printBuffer;
    _printBuffer = new char[bufsize+1];
    for(Message *curmsg=_firstMessage; curmsg; curmsg=curmsg->_nextMessage){
        libsystempp::scopy(curmsg->_Buffer,curmsg->_Buffer+curmsg->_BufferSize,_printBuffer+written);
        sys::scopy(curmsg->_Buffer,curmsg->_Buffer+curmsg->_BufferSize,_printBuffer+written);
        written+=curmsg->_BufferSize;
    }
    _printBuffer[bufsize]='\0';
@@ -99,9 +99,9 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::asign(const char *src){
        _lastMessage=_lastMessage->_nextMessage;
    }
    _lastMessage->_CType=_curCType;
    _lastMessage->_BufferSize=libsystempp::getlen(src);
    _lastMessage->_BufferSize=sys::getlen(src);
    _lastMessage->_Buffer=new char[_lastMessage->_BufferSize+1];
    libsystempp::scopy(src,src+_lastMessage->_BufferSize+1,_lastMessage->_Buffer);
    sys::scopy(src,src+_lastMessage->_BufferSize+1,_lastMessage->_Buffer);
    return *this;   
}

@@ -116,7 +116,7 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(const char *src){

libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(int src){
    char *buf=new char[sizeof(int)+1];
    libsystempp::itoa(src,buf);
    sys::itoa(src,buf);
    asign(buf);
    delete[] buf;
    return *this;
+96 −120
Changes for src/html.cpp: 96 added lines, 120 removed lines.
Original line number Diff line number Diff line
@@ -25,9 +25,10 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include <systempp/sysfile.h>
#include <iostream>
#include <fstream>

#include <systempp/sysutils.h>
#include <systempp/sysconsole.h>
#include <systempp/sysexception.h>

#include "utils.h"
@@ -50,8 +51,8 @@ libhtmlpp::HtmlString::HtmlString(){

libhtmlpp::HtmlString::HtmlString(char *header){
    _InitString();
    _HtmlHeader=new char[libsystempp::getlen(header)+1];
    libsystempp::scopy(header,header+libsystempp::getlen(header)+1,_HtmlHeader);
    _HtmlHeader=new char[sys::getlen(header)+1];
    sys::scopy(header,header+sys::getlen(header)+1,_HtmlHeader);
}

libhtmlpp::HtmlString::~HtmlString(){
@@ -60,50 +61,27 @@ libhtmlpp::HtmlString::~HtmlString(){
}

void libhtmlpp::HtmlString::assign(const char* src, size_t srcsize){
    size_t nsize=_DataSize+srcsize;
    char *buf=new char [nsize+1];
    size_t i=0;
    libsystempp::scopy(_Data,_Data+_DataSize,buf);
    libsystempp::scopy(src,src+srcsize,buf+_DataSize);
    _DataSize=nsize;
    delete[] _Data;
    buf[nsize]='\0';
    _Data=buf;
    _Data.assign(src,srcsize);
}

void libhtmlpp::HtmlString::push_back(const char src){
    size_t nsize=_DataSize+1;
    char *buf=new char [nsize+2];
    size_t i;
    for(i = 0; i<_DataSize; ++i){
        buf[i]=_Data[i];
    }
    buf[i]=src;
    buf[nsize]='\0';
    _DataSize=nsize;
    delete[] _Data;
    _Data=buf;
    _Data.push_back(src);
}

void libhtmlpp::HtmlString::assign(const char* src) {
    assign(src,libsystempp::getlen(src));
    assign(src,sys::getlen(src));
}

void libhtmlpp::HtmlString::insert(size_t pos, char src){
    HTMLException excp;
    if(pos < _DataSize){
        excp[HTMLException::Critical] << "HtmlString: out of String";
        throw excp;
    }
    _Data[pos]=src;
    _Data.insert(pos,&src);
}

void libhtmlpp::HtmlString::clear(){
    _Data.clear();
    for(size_t i=0; i<_HTableSize; ++i){
        delete[] _HTable[i];
    }
    delete[]   _HTable;
    delete[]   _Data;
    delete     _HtmlRootNode;
    _InitString();
}
@@ -120,16 +98,11 @@ libhtmlpp::HtmlString & libhtmlpp::HtmlString::operator+=(libhtmlpp::HtmlString&


libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator=(const char *src){
    clear();
    _DataSize=libsystempp::getlen(src);
    _Data = new char[_DataSize];
    for(size_t i = 0; i<_DataSize; ++i){
        _Data[i]=src[i];
    } 
    _Data=src;
    return *this;
}

char &libhtmlpp::HtmlString::operator[](size_t pos){
const char libhtmlpp::HtmlString::operator[](size_t pos){
    return _Data[pos];
}

@@ -140,7 +113,7 @@ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(const char* src){

libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(int src){
    char *buf=new char[sizeof(int)+1];
    libsystempp::itoa(src,buf);
    sys::itoa(src,buf);
    assign(buf);
    delete[] buf;
    return *this;
@@ -148,7 +121,7 @@ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(int src){

libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(unsigned long src){
    char *buf=new char[sizeof(int)+1];
    libsystempp::ultoa(src,buf);
    sys::ultoa(src,buf);
    assign(buf);
    delete[] buf;
    return *this;
@@ -162,16 +135,16 @@ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(char src){
const char *libhtmlpp::HtmlString::c_str() {
    size_t level=0;
    _printHtml(_HtmlRootNode,level);
    return _Data;
    return _Data.c_str();
}

void libhtmlpp::HtmlString::_printHtml(libhtmlpp::HtmlElement* node,size_t &level){
    if(node){
            for(size_t i=0; i<level; ++i){
                libsystempp::Console[SYSOUT] << " ";
                std::cout << " ";
            }
            libsystempp::Console[SYSOUT] << "<" << node->_Tag << ">"
                                         << libsystempp::Console[SYSOUT].endl;
            std::cout << "<" << node->_Tag << ">"
                                         << std::endl;
            
            if(node->_Child){
                size_t lvl=level+2;
@@ -179,10 +152,10 @@ void libhtmlpp::HtmlString::_printHtml(libhtmlpp::HtmlElement* node,size_t &leve
            }
            
            for(size_t i=0; i<level; ++i){
                libsystempp::Console[SYSOUT] << " ";
                std::cout << " ";
            }
            libsystempp::Console[SYSOUT] << "</" << node->_Tag << ">" 
                                         << libsystempp::Console[SYSOUT].endl;
            std::cout << "</" << node->_Tag << ">" 
                                         << std::endl;
            if(node->_nextElement)
                _printHtml(node->_nextElement,level);
    }           
@@ -190,13 +163,13 @@ void libhtmlpp::HtmlString::_printHtml(libhtmlpp::HtmlElement* node,size_t &leve


size_t libhtmlpp::HtmlString::size(){
    return _DataSize;
    return _Data.size();
}
  
bool libhtmlpp::HtmlString::validate(){
    _HTableSize=0;
    size_t opentag=0,closetag=0;
    for(size_t i=0; i<_DataSize; ++i){
    for(size_t i=0; i<_Data.size(); ++i){
        switch(_Data[i]){
            case HTMLTAG_OPEN:
                ++opentag;
@@ -247,7 +220,7 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_serialzeElements(HtmlElement *pr
            if(_HtmlHeader)
                throw excp[HTMLException::Error] << "Htmlheader exist too often: "<< tag;
            _HtmlHeader = new char[tagsize+1];
            libsystempp::scopy(tag,tag+(tagsize+1),_HtmlHeader);
            sys::scopy(tag,tag+(tagsize+1),_HtmlHeader);
            return _serialzeElements(prevnode,++pos);
        }else if(ret==HTMLELEMENT){
            if(prevnode){
@@ -280,12 +253,12 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(HtmlElement *node,Html
        int ret=_serialzeTags(_HTable[pos][0],_HTable[pos][2],&tag,tagsize);
        if(node){
            if(ret==HTMLELEMENT){
                if(libsystempp::ncompare(node->_Tag,libsystempp::getlen(node->_Tag),
                if(sys::ncompare(node->_Tag,sys::getlen(node->_Tag),
                                         tag,tagsize)==0){
                    node->_nextElement=parent;
                }
            }else if(ret==HTMLTERMELEMENT){
                if(!node->_Child && libsystempp::ncompare(node->_Tag,libsystempp::getlen(node->_Tag),
                if(!node->_Child && sys::ncompare(node->_Tag,sys::getlen(node->_Tag),
                                                          tag,tagsize)==0){
                    parent=node->_nextElement;
                    node->_nextElement=nullptr;
@@ -305,7 +278,6 @@ libhtmlpp::HtmlElement *libhtmlpp::HtmlString::_buildTree(HtmlElement *node,Html

void libhtmlpp::HtmlString::_InitString(){
    _Data=nullptr;
    _DataSize=0;
    _HTable=nullptr;
    _HTableSize=0;
    _HtmlRootNode=nullptr;
@@ -330,7 +302,7 @@ void libhtmlpp::HtmlString::_parseTree(){
    
    bool open=false;
    size_t ip=0;
    for(size_t ii=0; ii<_DataSize; ++ii){
    for(size_t ii=0; ii<_Data.length(); ++ii){
        switch(_Data[ii]){
            case HTMLTAG_OPEN:
                open=true;
@@ -357,57 +329,58 @@ void libhtmlpp::HtmlString::_parseTree(){
int libhtmlpp::HtmlString::_serialzeTags(size_t spos, size_t epos, char **value,size_t &valuesize){
    size_t anpos=0,enpos=0,i=spos;
    int term=-1;
    while(i<epos){
        switch(_Data[i]){
            case('!'):
                if(_Data[i+1]=='-' && _Data[i+2]=='-'){ 
                    i+=2;
                    goto FINDCOMMENTEND;
                }else if(libsystempp::ncompare(_Data+i,7,"DOCTYPE",7)==0){
                    ++i;
                    goto FINDHTMLHEADER;
                }
            case('/'):
                term=i;
                ++i;
                anpos=i;
                continue;
            case '"':
                for(; _Data[i]!='"'; ++i);
                continue;
            case('<'):
                anpos=++i;
                enpos=i;
                continue;
            default:
                goto FINDTAGNAMEPOS;
        }
    }
FINDHTMLHEADER:
    if(enpos < epos && _Data[++enpos]!='>')
        goto FINDHTMLHEADER;
    valuesize=libsystempp::substr(_Data,value,anpos,(enpos-anpos));
    return HTMLHEADER;
FINDCOMMENTEND:
    if(enpos < epos && !(_Data[enpos]=='!' && _Data[++enpos]=='-' &&
        _Data[++enpos]=='-' && _Data[++enpos]=='>')
    ){
        ++enpos;
        goto FINDCOMMENTEND;
    }
    valuesize=libsystempp::substr(_Data,value,anpos,(enpos-anpos));
    return HTMLCOMMENT;
FINDTAGNAMEPOS:
    if(enpos < epos && !(_Data[enpos]==' ' || _Data[enpos]=='>')){
        ++enpos;
        if(enpos > 0 && _Data[enpos]!='/'){
            goto FINDTAGNAMEPOS;
        }
    }
    valuesize=libsystempp::substr(_Data,value,anpos,(enpos-anpos));
    if(term >0 && term<enpos)
        return HTMLTERMELEMENT;
    return HTMLELEMENT;
    std::string Doctype;
//     while(i<epos){
//         switch(_Data[i]){
//             case('!'):
//                 if(_Data[i+1]=='-' && _Data[i+2]=='-'){ 
//                     i+=2;
//                     goto FINDCOMMENTEND;
//                 }else if(libsystempp::ncompare(_Data+i,7,"DOCTYPE",7)==0){
//                     ++i;
//                     goto FINDHTMLHEADER;
//                 }
//             case('/'):
//                 term=i;
//                 ++i;
//                 anpos=i;
//                 continue;
//             case '"':
//                 for(; _Data[i]!='"'; ++i);
//                 continue;
//             case('<'):
//                 anpos=++i;
//                 enpos=i;
//                 continue;
//             default:
//                 goto FINDTAGNAMEPOS;
//         }
//     }
// FINDHTMLHEADER:
//     if(enpos < epos && _Data[++enpos]!='>')
//         goto FINDHTMLHEADER;
//     valuesize=libsystempp::substr(_Data,value,anpos,(enpos-anpos));
//     return HTMLHEADER;
// FINDCOMMENTEND:
//     if(enpos < epos && !(_Data[enpos]=='!' && _Data[++enpos]=='-' &&
//         _Data[++enpos]=='-' && _Data[++enpos]=='>')
//     ){
//         ++enpos;
//         goto FINDCOMMENTEND;
//     }
//     valuesize=libsystempp::substr(_Data,value,anpos,(enpos-anpos));
//     return HTMLCOMMENT;
// FINDTAGNAMEPOS:
//     if(enpos < epos && !(_Data[enpos]==' ' || _Data[enpos]=='>')){
//         ++enpos;
//         if(enpos > 0 && _Data[enpos]!='/'){
//             goto FINDTAGNAMEPOS;
//         }
//     }
//     valuesize=libsystempp::substr(_Data,value,anpos,(enpos-anpos));
//     if(term >0 && term<enpos)
//         return HTMLTERMELEMENT;
//     return HTMLELEMENT;
}

libhtmlpp::HtmlElement::HtmlElement(){
@@ -451,29 +424,32 @@ const char *libhtmlpp::HtmlPage::printHtml(){
void libhtmlpp::HtmlPage::loadFile(const char* path){
    delete _HtmlDocument;
    _HtmlDocument= new HtmlString();
    libsystempp::FileDescriptor fd;
    std::fstream fs;
    try{
        fd.open(path,O_RDONLY);
    }catch(libsystempp::SystemException &e){
        fs.open(path,std::ios::in);
    }catch(sys::SystemException &e){
        HTMLException excp;
        throw excp[HTMLException::Critical] << e.what();
    }
    char buf[HTML_BLOCKSIZE];
READFILE:
    ssize_t rdd=fd.read(buf,HTML_BLOCKSIZE);
    if(rdd>0){
    fs.seekg (0, fs.end);
    int length = fs.tellg();
    fs.seekg (0, fs.beg);
    
    char *buf=new char[length];
    if(fs.read(buf,HTML_BLOCKSIZE)){
        char *dest;
        size_t cdd=libsystempp::cleannewline(buf,rdd,&dest);
        size_t cdd=sys::cleannewline(buf,length,&dest);
        _HtmlDocument->assign(dest,cdd);
        delete[] dest;
        goto READFILE;
    }
        _HtmlDocument->parse();
    }
    HTMLException excp;
    throw excp[HTMLException::Critical] << "Could not read file";
}

void libhtmlpp::HtmlElement::setID(const char *id){
    HTMLException excp;
    if(!setter(id,libsystempp::getlen(id),&_ID)){
    if(!setter(id,sys::getlen(id),&_ID)){
        excp[HTMLException::Error] << "HtmlElement can't id: " << id;
        throw excp;        
    }
@@ -481,7 +457,7 @@ void libhtmlpp::HtmlElement::setID(const char *id){

void libhtmlpp::HtmlElement::setClass(const char *cname){
    HTMLException excp;
    if(!setter(cname,libsystempp::getlen(cname),&_Class)){
    if(!setter(cname,sys::getlen(cname),&_Class)){
        excp[HTMLException::Error] << "HtmlElement can't class name: " << cname;
        throw excp;          
    }
@@ -489,7 +465,7 @@ void libhtmlpp::HtmlElement::setClass(const char *cname){

void libhtmlpp::HtmlElement::setStyle(const char *css){
    HTMLException excp;
    if(!setter(css,libsystempp::getlen(css),&_Style,":;(),+~'")){
    if(!setter(css,sys::getlen(css),&_Style,":;(),+~'")){
        excp[HTMLException::Error] << "HtmlElement can't set Style: " << css;
        throw excp;          
    }
@@ -497,7 +473,7 @@ void libhtmlpp::HtmlElement::setStyle(const char *css){

void libhtmlpp::HtmlElement::setComment(const char* comment){
    HTMLException excp;
    if(!setter(comment,libsystempp::getlen(comment),&_Style,":;(),+~'")){
    if(!setter(comment,sys::getlen(comment),&_Style,":;(),+~'")){
        excp[HTMLException::Error] << "HtmlElement can't set Comment: " << comment;
        throw excp;          
    }    
+4 −3
Changes for src/html.h: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include <string>

#include <sys/types.h>

#pragma once
@@ -78,7 +80,7 @@ namespace libhtmlpp {
        HtmlString &operator+=(const char *src);
        HtmlString &operator+=(HtmlString &hstring);
        HtmlString &operator=(const char *src);
        char &operator[](size_t pos);
        const char operator[](size_t pos);
        
        HtmlString &operator<<(const char *src);
        HtmlString &operator<<(int src);
@@ -97,8 +99,7 @@ namespace libhtmlpp {
        HtmlElement      *_serialzeElements(HtmlElement *prevnode,ssize_t &pos);
        int               _serialzeTags(size_t spos,size_t epos,char **value,size_t &valuesize);
        void              _printHtml(HtmlElement *node,size_t &level);
        char             *_Data;
        size_t            _DataSize;
        std::string             _Data;
        ssize_t               **_HTable;
        size_t                  _HTableSize;
        char                   *_HtmlHeader;
+2 −2
Changes for src/utils.h: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ namespace libhtmlpp {
        int i, j;
        char c;
        
        for (i = 0, j = libsystempp::getlen(s)-1; i<j; i++, j--) {
        for (i = 0, j = sys::getlen(s)-1; i<j; i++, j--) {
            c = s[i];
            s[i] = s[j];
            s[j] = c;
@@ -72,7 +72,7 @@ namespace libhtmlpp {
        for(int i=0; i<srcsize; ++i){
            if(!isdigit(src[i]) || !isalpha(src[i]) || ssigns){
                nallowd=true;
                for(size_t pos=0; pos<libsystempp::getlen(ssigns); ++pos){
                for(size_t pos=0; pos<sys::getlen(ssigns); ++pos){
                    if(ssigns[pos]==src[i]){
                        nallowd=false;
                    }
Loading