| 434 |
return -1; |
return -1; |
| 435 |
} |
} |
| 436 |
|
|
| 437 |
|
if (p_section->article_count >= BBS_article_limit_per_section) |
| 438 |
|
{ |
| 439 |
|
log_error("section_list_append_article() error: article_count reach limit in section %d\n", p_section->sid); |
| 440 |
|
return -2; |
| 441 |
|
} |
| 442 |
|
|
| 443 |
if (p_article_block_pool->block_count == 0 || |
if (p_article_block_pool->block_count == 0 || |
| 444 |
p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count >= ARTICLE_PER_BLOCK) |
p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count >= ARTICLE_PER_BLOCK) |
| 445 |
{ |
{ |
| 536 |
p_section->page_count++; |
p_section->page_count++; |
| 537 |
p_section->last_page_visible_article_count = 0; |
p_section->last_page_visible_article_count = 0; |
| 538 |
} |
} |
| 539 |
p_section->last_page_visible_article_count++; |
|
| 540 |
|
if (p_article->visible) |
| 541 |
|
{ |
| 542 |
|
p_section->last_page_visible_article_count++; |
| 543 |
|
} |
| 544 |
|
|
| 545 |
return 0; |
return 0; |
| 546 |
} |
} |
| 663 |
p_article = p_section->p_page_first_article[*p_page]; |
p_article = p_section->p_page_first_article[*p_page]; |
| 664 |
|
|
| 665 |
// p_section->p_page_first_article[*p_page]->aid <= aid < p_section->p_page_first_article[*p_page + 1]->aid |
// p_section->p_page_first_article[*p_page]->aid <= aid < p_section->p_page_first_article[*p_page + 1]->aid |
| 666 |
right = (*p_page == p_section->page_count - 1 ? INT32_MAX : p_section->p_page_first_article[*p_page + 1]->aid); |
right = (*p_page == MAX(1, p_section->page_count) - 1 ? INT32_MAX : p_section->p_page_first_article[*p_page + 1]->aid); |
| 667 |
|
|
| 668 |
// left will be the offset of article found or offset to insert |
// left will be the offset of article found or offset to insert |
| 669 |
left = 0; |
left = 0; |
| 670 |
|
|
| 671 |
while (1) |
while (aid > p_article->aid) |
| 672 |
{ |
{ |
|
if (aid == p_article->aid) // found |
|
|
{ |
|
|
break; |
|
|
} |
|
|
else if (aid < p_article->aid) // not exist |
|
|
{ |
|
|
p_article = NULL; |
|
|
break; |
|
|
} |
|
|
|
|
| 673 |
// aid > p_article->aid |
// aid > p_article->aid |
| 674 |
p_article = p_article->p_next; |
p_article = p_article->p_next; |
| 675 |
left++; |
left++; |
| 677 |
// over last article in the page |
// over last article in the page |
| 678 |
if (p_article == p_section->p_article_head || p_article->aid >= right) |
if (p_article == p_section->p_article_head || p_article->aid >= right) |
| 679 |
{ |
{ |
|
p_article = NULL; |
|
| 680 |
break; |
break; |
| 681 |
} |
} |
| 682 |
} |
} |
| 683 |
|
|
| 684 |
|
if (aid != p_article->aid) // not exist |
| 685 |
|
{ |
| 686 |
|
p_article = NULL; |
| 687 |
|
} |
| 688 |
|
|
| 689 |
*p_offset = left; |
*p_offset = left; |
| 690 |
|
|
| 691 |
return p_article; |
return p_article; |
| 693 |
|
|
| 694 |
int section_list_calculate_page(SECTION_LIST *p_section, int32_t start_aid) |
int section_list_calculate_page(SECTION_LIST *p_section, int32_t start_aid) |
| 695 |
{ |
{ |
| 696 |
// ARTICLE *p_article; |
ARTICLE *p_article; |
| 697 |
|
int32_t page; |
| 698 |
|
int32_t offset; |
| 699 |
|
int visible_article_count; |
| 700 |
|
int page_head_set; |
| 701 |
|
|
| 702 |
if (p_section == NULL) |
if (p_section == NULL) |
| 703 |
{ |
{ |
| 705 |
return -1; |
return -1; |
| 706 |
} |
} |
| 707 |
|
|
| 708 |
|
p_article = section_list_find_article_with_offset(p_section, start_aid, &page, &offset); |
| 709 |
|
if (p_article == NULL) |
| 710 |
|
{ |
| 711 |
|
if (page < 0) |
| 712 |
|
{ |
| 713 |
|
return 0; |
| 714 |
|
} |
| 715 |
|
|
| 716 |
|
log_error("section_list_calculate_page() aid = %d not found in section sid = %d\n", start_aid, p_section->sid); |
| 717 |
|
} |
| 718 |
|
|
| 719 |
|
if (offset > 0) |
| 720 |
|
{ |
| 721 |
|
p_article = p_section->p_page_first_article[page]; |
| 722 |
|
} |
| 723 |
|
|
| 724 |
|
visible_article_count = 0; |
| 725 |
|
page_head_set = 0; |
| 726 |
|
|
| 727 |
|
do |
| 728 |
|
{ |
| 729 |
|
if (!page_head_set && visible_article_count == 0) |
| 730 |
|
{ |
| 731 |
|
p_section->p_page_first_article[page] = p_article; |
| 732 |
|
page_head_set = 1; |
| 733 |
|
} |
| 734 |
|
|
| 735 |
|
if (p_article->visible) |
| 736 |
|
{ |
| 737 |
|
visible_article_count++; |
| 738 |
|
} |
| 739 |
|
|
| 740 |
|
p_article = p_article->p_next; |
| 741 |
|
|
| 742 |
|
// skip remaining invisible articles |
| 743 |
|
while (p_article->visible == 0 && p_article != p_section->p_article_head) |
| 744 |
|
{ |
| 745 |
|
p_article = p_article->p_next; |
| 746 |
|
} |
| 747 |
|
|
| 748 |
|
if (visible_article_count >= BBS_article_limit_per_page && p_article != p_section->p_article_head) |
| 749 |
|
{ |
| 750 |
|
page++; |
| 751 |
|
visible_article_count = 0; |
| 752 |
|
page_head_set = 0; |
| 753 |
|
|
| 754 |
|
if (page >= BBS_article_limit_per_section / BBS_article_limit_per_page && p_article != p_section->p_article_head) |
| 755 |
|
{ |
| 756 |
|
log_error("Count of page exceed limit in section %d\n", p_section->sid); |
| 757 |
|
break; |
| 758 |
|
} |
| 759 |
|
} |
| 760 |
|
} while (p_article != p_section->p_article_head); |
| 761 |
|
|
| 762 |
|
p_section->page_count = page + (visible_article_count > 0 ? 1 : 0); |
| 763 |
|
p_section->last_page_visible_article_count = visible_article_count; |
| 764 |
|
|
| 765 |
return 0; |
return 0; |
| 766 |
} |
} |