• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂446 (tree)
時間2012-04-18 01:52:09
作者ornse01

Log Message

add bbsmenuparser_item_t allocater for external bbs.

Change Summary

差異

--- bchanl/trunk/src/bbsmenuparser.c (revision 445)
+++ bchanl/trunk/src/bbsmenuparser.c (revision 446)
@@ -415,6 +415,57 @@
415415 bbsmnparser_item_clear(parser->itembuffer);
416416 }
417417
418+EXPORT bbsmnparser_item_t* bbsmnparser_newcategoryitem(bbsmnparser_t *parser, TC *category, W category_len)
419+{
420+ bbsmnparser_item_t *item;
421+
422+ item = bbsmnparser_item_new();
423+ if (item == NULL) {
424+ return NULL;
425+ }
426+ item->category = malloc(sizeof(TC)*(category_len+1));
427+ if (item->category == NULL) {
428+ bbsmnparser_item_delete(item);
429+ return NULL;
430+ }
431+ memcpy(item->category, category, sizeof(TC)*category_len);
432+ item->category[category_len] = TNULL;
433+ item->category_len = category_len;
434+
435+ return item;
436+}
437+
438+EXPORT bbsmnparser_item_t* bbsmnparser_newboarditem(bbsmnparser_t *parser, TC *title, W title_len, UB *url, W url_len)
439+{
440+ bbsmnparser_item_t *item;
441+
442+ item = bbsmnparser_item_new();
443+ if (item == NULL) {
444+ return NULL;
445+ }
446+
447+ free(item->url);
448+ item->url = malloc(sizeof(UB)*(url_len+1));
449+ if (item->url == NULL) {
450+ bbsmnparser_item_delete(item);
451+ return NULL;
452+ }
453+ memcpy(item->url, url, sizeof(UB)*url_len);
454+ item->url[url_len] = '\0';
455+ item->url_len = url_len;
456+
457+ item->title = malloc(sizeof(TC)*(title_len+1));
458+ if (item->title == NULL) {
459+ bbsmnparser_item_delete(item);
460+ return NULL;
461+ }
462+ memcpy(item->title, title, sizeof(TC)*title_len);
463+ item->title[title_len] = TNULL;
464+ item->title_len = title_len;
465+
466+ return item;
467+}
468+
418469 EXPORT bbsmnparser_t* bbsmnparser_new(bbsmncache_t *cache)
419470 {
420471 bbsmnparser_t *parser;
--- bchanl/trunk/src/bbsmenuparser.h (revision 445)
+++ bchanl/trunk/src/bbsmenuparser.h (revision 446)
@@ -1,7 +1,7 @@
11 /*
22 * bbsmenuparser.h
33 *
4- * Copyright (c) 2009 project bchan
4+ * Copyright (c) 2009-2012 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -49,5 +49,7 @@
4949 IMPORT VOID bbsmnparser_delete(bbsmnparser_t *parser);
5050 IMPORT W bbsmnparser_getnextitem(bbsmnparser_t *parser, bbsmnparser_item_t **item);
5151 IMPORT VOID bbsmnparser_clear(bbsmnparser_t *parser);
52+IMPORT bbsmnparser_item_t* bbsmnparser_newcategoryitem(bbsmnparser_t *parser, TC *category, W category_len);
53+IMPORT bbsmnparser_item_t* bbsmnparser_newboarditem(bbsmnparser_t *parser, TC *title, W title_len, UB *url, W url_len);
5254
5355 #endif
Show on old repository browser