refactored code and ported project to cmake

This commit is contained in:
2017-08-08 20:04:47 +02:00
parent 17da357871
commit 640a5edee2
10 changed files with 563 additions and 348 deletions

54
inc/attribute.h Normal file
View File

@@ -0,0 +1,54 @@
/*
* attribute.h
*
* Created on: 08.08.2017
* Author: julian
*/
#ifndef ATTRIBUTE_H_
#define ATTRIBUTE_H_
#include <errno.h>
#include "nhtml_string.h"
typedef struct {
string_t name, value;
} attr_t;
/**
* \brief copy the give attribute
* \return a copy of attr
*/
attr_t attr_copy(attr_t * attr);
/**
* \brief reset the attribute
* Deletes all strings
*/
void attr_destroy(attr_t * attr);
typedef struct {
attr_t * arr;
size_t len;
} attr_set_t;
/**
* \brief search in attribute set for key
* \param set The Attribute set
* \param key The Key to search
* \return the pointer to the attribute in the set mathching the key
* \return NULL if there is no matching attribute
*/
attr_t * attr_set_find(attr_set_t *set, const char * key);
// Append new Attribute to set
/**
* \brief Append new attribute pair to set
* \return 0 on success
* \return -1 on failure (error can be found to errno)
*/
int attr_set_append(attr_set_t * set, attr_t *new_entry);
#endif /* ATTRIBUTE_H_ */

37
inc/html.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* html.h
*
* Created on: 07.08.2017
* Author: julian
*/
#ifndef HTML_H_
#define HTML_H_
#include <stdio.h> // needs FILE
#include "nhtml_string.h"
#include "attribute.h"
extern int html_escape(int c, FILE* output);
typedef struct node {
string_t name;
attr_set_t attributes;
} node_t;
/**
* \brief emit html opening tag for \node
* \param node the Node to create the opening tag for
* \param output the File to write to
*/
void open_node(node_t * node, FILE * output);
/**
* \brief emit html closing tag for \node
* \param node the Node to create the closing tag for
* \param output the File to write to
*/
void close_node(node_t * node, FILE * output);
#endif /* HTML_H_ */

40
inc/nhtml_string.h Normal file
View File

@@ -0,0 +1,40 @@
/*
* nhtml_string.h
*
* Created on: 08.08.2017
* Author: julian
*/
#ifndef NHTML_STRING_H_
#define NHTML_STRING_H_
#include <stddef.h> // size_t
#include <errno.h> // errno
typedef struct {
char * c_str;
size_t len;
} string_t;
/**\brief append the char @c to @str
* \param str to the String to append to
* \param c the char to append
* \return -1 on error, errno will be set to errorcode
* \return 0 on success
*/
int string_append(string_t *str, char c);
/**
* \brief Erase the String from memory
*/
void string_destroy(string_t s);
/**
* \brief copy the contents of a string
* \param old The String to copy
* \return returns the new string
*/
string_t string_copy(string_t old);
#endif /* NHTML_STRING_H_ */