2016-10-07 20:47:31 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2016 Alexander Borisov
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Author: lex.borisov@gmail.com (Alexander Borisov)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "modest/modest.h"
|
2016-10-23 16:09:32 +03:00
|
|
|
#include "modest/style/sheet.h"
|
|
|
|
#include "modest/style/raw.h"
|
|
|
|
#include "modest/node/node.h"
|
2016-10-07 20:47:31 +03:00
|
|
|
|
|
|
|
modest_t * modest_create(void)
|
|
|
|
{
|
2017-03-03 09:20:23 +03:00
|
|
|
return (modest_t*)mycore_calloc(1, sizeof(modest_t));
|
2016-10-07 20:47:31 +03:00
|
|
|
}
|
|
|
|
|
2017-03-03 09:20:23 +03:00
|
|
|
mystatus_t modest_init(modest_t* modest)
|
2016-10-07 20:47:31 +03:00
|
|
|
{
|
|
|
|
/* Modest nodes */
|
|
|
|
modest->mnode_obj = mcobject_async_create();
|
|
|
|
if(modest->mnode_obj == NULL)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_MNODE_CREATE;
|
2016-10-07 20:47:31 +03:00
|
|
|
|
|
|
|
mcobject_async_status_t mcstatus = mcobject_async_init(modest->mnode_obj, 128, 1024, sizeof(modest_node_t));
|
|
|
|
if(mcstatus)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_MNODE_INIT;
|
2016-10-07 20:47:31 +03:00
|
|
|
|
|
|
|
/* base object node for all modest node objects */
|
|
|
|
modest->mnode_node_id = mcobject_async_node_add(modest->mnode_obj, &mcstatus);
|
|
|
|
if(mcstatus)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_MNODE_NODE_ADD;
|
2016-10-07 20:47:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* Modest stylesheet */
|
|
|
|
modest->mstylesheet_obj = mcobject_async_create();
|
|
|
|
if(modest->mstylesheet_obj == NULL)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_STYLESHEET_CREATE;
|
2016-10-07 20:47:31 +03:00
|
|
|
|
|
|
|
mcstatus = mcobject_async_init(modest->mstylesheet_obj, 128, 1024, sizeof(modest_style_sheet_t));
|
|
|
|
if(mcstatus)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_STYLESHEET_INIT;
|
2016-10-07 20:47:31 +03:00
|
|
|
|
|
|
|
/* base object node for all modest stylesheet objects */
|
|
|
|
modest->mstylesheet_node_id = mcobject_async_node_add(modest->mstylesheet_obj, &mcstatus);
|
|
|
|
if(mcstatus)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_STYLESHEET_NODE_ADD;
|
2016-10-07 20:47:31 +03:00
|
|
|
|
2016-10-23 16:09:32 +03:00
|
|
|
|
|
|
|
/* Modest style type */
|
|
|
|
modest->mstyle_type_obj = mchar_async_create(12, (4096 * 5));
|
|
|
|
if(modest->mstyle_type_obj == NULL)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_STYLE_TYPE_CREATE;
|
2016-10-23 16:09:32 +03:00
|
|
|
|
|
|
|
modest->mstyle_type_node_id = mchar_async_node_add(modest->mstyle_type_obj);
|
|
|
|
|
|
|
|
|
|
|
|
/* for raw declaration style */
|
|
|
|
modest->mraw_style_declaration_obj = mcobject_create();
|
|
|
|
if(modest->mraw_style_declaration_obj == NULL)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_STYLE_DECLARATION_CREATE;
|
2016-10-23 16:09:32 +03:00
|
|
|
|
2017-03-03 09:20:23 +03:00
|
|
|
mystatus_t myhtml_status = mcobject_init(modest->mraw_style_declaration_obj, 256, sizeof(modest_style_raw_declaration_t));
|
2016-10-23 16:09:32 +03:00
|
|
|
if(myhtml_status)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_STYLE_DECLARATION_INIT;
|
|
|
|
|
2016-10-23 16:09:32 +03:00
|
|
|
|
2016-12-14 23:21:35 +03:00
|
|
|
/* styles tree */
|
2017-03-03 09:20:23 +03:00
|
|
|
modest->style_avl_tree = mycore_utils_avl_tree_create();
|
2016-11-21 02:12:38 +03:00
|
|
|
if(modest->style_avl_tree == NULL)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_AVL_TREE_CREATE;
|
2016-11-21 02:12:38 +03:00
|
|
|
|
2017-03-03 09:20:23 +03:00
|
|
|
myhtml_status = mycore_utils_avl_tree_init(modest->style_avl_tree);
|
2016-11-21 02:12:38 +03:00
|
|
|
if(myhtml_status)
|
2016-12-22 16:46:43 +03:00
|
|
|
return MODEST_STATUS_ERROR_AVL_TREE_INIT;
|
2016-11-21 02:12:38 +03:00
|
|
|
|
2016-10-07 20:47:31 +03:00
|
|
|
return MODEST_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void modest_clean(modest_t* modest)
|
|
|
|
{
|
|
|
|
mcobject_async_clean(modest->mnode_obj);
|
|
|
|
mcobject_async_clean(modest->mstylesheet_obj);
|
2017-03-03 09:20:23 +03:00
|
|
|
mycore_utils_avl_tree_clean(modest->style_avl_tree);
|
2016-10-07 20:47:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
modest_t * modest_destroy(modest_t* modest, bool self_destroy)
|
|
|
|
{
|
|
|
|
if(modest == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
modest->mnode_obj = mcobject_async_destroy(modest->mnode_obj, true);
|
|
|
|
modest->mstylesheet_obj = mcobject_async_destroy(modest->mstylesheet_obj, true);
|
2017-03-03 09:20:23 +03:00
|
|
|
modest->style_avl_tree = mycore_utils_avl_tree_destroy(modest->style_avl_tree, true);
|
2016-10-07 20:47:31 +03:00
|
|
|
|
|
|
|
if(self_destroy) {
|
2017-03-03 09:20:23 +03:00
|
|
|
mycore_free(modest);
|
2016-10-07 20:47:31 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return modest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|