OSDN Git Service

add bbsmenuparser_item_t allocater for external bbs.
authorornse01 <ornse01@users.sourceforge.jp>
Tue, 17 Apr 2012 16:52:09 +0000 (16:52 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Tue, 17 Apr 2012 16:52:09 +0000 (16:52 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanl/trunk@446 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/bbsmenuparser.c
src/bbsmenuparser.h

index ef1c961..edac4d5 100644 (file)
@@ -415,6 +415,57 @@ EXPORT VOID bbsmnparser_clear(bbsmnparser_t *parser)
        bbsmnparser_item_clear(parser->itembuffer);
 }
 
+EXPORT bbsmnparser_item_t* bbsmnparser_newcategoryitem(bbsmnparser_t *parser, TC *category, W category_len)
+{
+       bbsmnparser_item_t *item;
+
+       item = bbsmnparser_item_new();
+       if (item == NULL) {
+               return NULL;
+       }
+       item->category = malloc(sizeof(TC)*(category_len+1));
+       if (item->category == NULL) {
+               bbsmnparser_item_delete(item);
+               return NULL;
+       }
+       memcpy(item->category, category, sizeof(TC)*category_len);
+       item->category[category_len] = TNULL;
+       item->category_len = category_len;
+
+       return item;
+}
+
+EXPORT bbsmnparser_item_t* bbsmnparser_newboarditem(bbsmnparser_t *parser, TC *title, W title_len, UB *url, W url_len)
+{
+       bbsmnparser_item_t *item;
+
+       item = bbsmnparser_item_new();
+       if (item == NULL) {
+               return NULL;
+       }
+
+       free(item->url);
+       item->url = malloc(sizeof(UB)*(url_len+1));
+       if (item->url == NULL) {
+               bbsmnparser_item_delete(item);
+               return NULL;
+       }
+       memcpy(item->url, url, sizeof(UB)*url_len);
+       item->url[url_len] = '\0';
+       item->url_len = url_len;
+
+       item->title = malloc(sizeof(TC)*(title_len+1));
+       if (item->title == NULL) {
+               bbsmnparser_item_delete(item);
+               return NULL;
+       }
+       memcpy(item->title, title, sizeof(TC)*title_len);
+       item->title[title_len] = TNULL;
+       item->title_len = title_len;
+
+       return item;
+}
+
 EXPORT bbsmnparser_t* bbsmnparser_new(bbsmncache_t *cache)
 {
        bbsmnparser_t *parser;
index 6bcce3b..0643fe1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * bbsmenuparser.h
  *
- * Copyright (c) 2009 project bchan
+ * Copyright (c) 2009-2012 project bchan
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any damages
@@ -49,5 +49,7 @@ IMPORT bbsmnparser_t* bbsmnparser_new(bbsmncache_t *cache);
 IMPORT VOID bbsmnparser_delete(bbsmnparser_t *parser);
 IMPORT W bbsmnparser_getnextitem(bbsmnparser_t *parser, bbsmnparser_item_t **item);
 IMPORT VOID bbsmnparser_clear(bbsmnparser_t *parser);
+IMPORT bbsmnparser_item_t* bbsmnparser_newcategoryitem(bbsmnparser_t *parser, TC *category, W category_len);
+IMPORT bbsmnparser_item_t* bbsmnparser_newboarditem(bbsmnparser_t *parser, TC *title, W title_len, UB *url, W url_len);
 
 #endif