Browse Source

Initial commit

master
mort 9 years ago
commit
4f88f9624b
6 changed files with 92 additions and 0 deletions
  1. 2
    0
      Makefile
  2. BIN
      cms
  3. 21
    0
      src/cms_page.h
  4. 49
    0
      src/cms_post.c
  5. 16
    0
      src/cms_post.h
  6. 4
    0
      src/main.c

+ 2
- 0
Makefile View File

@@ -0,0 +1,2 @@
build:
gcc -o cms src/*.c -std=c99

BIN
cms View File


+ 21
- 0
src/cms_page.h View File

@@ -0,0 +1,21 @@
#ifndef CMS_PAGE_H
#define CMS_PAGE_H

#include "cms_post.h"

typedef struct cms_page
{
char* _str;
char* title;
char* slug;
cms_post* posts;
size_t numposts;
} cms_page;

cms_page* cms_page_create();

void cms_page_parse(cms_page* page, char* str);

void cms_page_add_post(cms_page* page, cms_post* post);

#endif

+ 49
- 0
src/cms_post.c View File

@@ -0,0 +1,49 @@
#include "cms_post.h"
#include <stdlib.h>
#include <stddef.h>
#include <string.h>

cms_post* cms_post_create()
{
cms_post* post = malloc(sizeof(cms_post));
return post;
}

int cms_post_parse(cms_post* post, char* str)
{
//Adding 1 because strlen() returns the length without \0
size_t len = strlen(str) + 1;

post->_str = malloc(len * sizeof(char));
memcpy(post->_str, str, len * sizeof(char));

post->title = post->_str;

size_t line = 0;
for (size_t i = 0; i < len; ++i)
{
char c = str[i];

switch (c)
{
case '\n':
line += 1;
if (line == 1)
post->slug = (post->_str + i + 1);
else if (line == 2)
post->markdown = (post->_str + i + 1);

case '\r':
post->_str[i] = '\0';
break;
}

if (line == 3)
break;
}

if (line == 3)
return 0;
else
return 1;
}

+ 16
- 0
src/cms_post.h View File

@@ -0,0 +1,16 @@
#ifndef CMS_POST_H
#define CMS_POST_H

typedef struct cms_post
{
char* _str;
char* title;
char* slug;
char* markdown;
} cms_post;

cms_post* cms_post_create();

int cms_post_parse(cms_post* post, char* str);

#endif

+ 4
- 0
src/main.c View File

@@ -0,0 +1,4 @@
int main(int argv, char** argc)
{

}

Loading…
Cancel
Save