summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-11-09 16:36:20 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-11-09 16:36:20 +0800
commit4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4 (patch)
tree2bba662907b8eeb90227562ee88eeee5acdc1c4f
parentce9a187e3802d8408a6e2f39b7b0816df61a0179 (diff)
downloadpttbbs-4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4.tar
pttbbs-4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4.tar.gz
pttbbs-4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4.tar.bz2
pttbbs-4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4.tar.lz
pttbbs-4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4.tar.xz
pttbbs-4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4.tar.zst
pttbbs-4a00eb5c0ad8c64c91e70eabcc3bed4bce1628b4.zip
fix sort problem and improve it
git-svn-id: http://opensvn.csie.org/pttbbs/branches/victor.fav4.bak@1310 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/include/proto.h1
-rw-r--r--pttbbs/mbbsd/board.c6
-rw-r--r--pttbbs/mbbsd/fav.c54
3 files changed, 33 insertions, 28 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h
index c3e830fe..3b06fa7d 100644
--- a/pttbbs/include/proto.h
+++ b/pttbbs/include/proto.h
@@ -216,6 +216,7 @@ int fav_load(void);
int fav_save(void);
void fav_remove_current(void);
void fav_remove_board_from_whole(int bid);
+fav_type_t *getboard(short bid);
char getbrdattr(short bid);
time_t getbrdtime(short bid);
void setbrdtime(short bid, time_t t);
diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c
index faa0b8a1..247fb8bf 100644
--- a/pttbbs/mbbsd/board.c
+++ b/pttbbs/mbbsd/board.c
@@ -733,7 +733,7 @@ show_brdlist(int head, int clsflag, int newflag)
prints("%5d %c %sMyFavFolder\033[m ¥Ø¿ý ¡¼%-34s\033[m",
head,
ptr->myattr & BRD_TAG ? 'D' : ' ',
- (cuser.uflag2 & FAVNOHILIGHT)? "" : "\033[1;36m",
+ !(cuser.uflag2 & FAVNOHILIGHT) ? "\033[1;36m" : "",
title);
continue;
}
@@ -759,8 +759,8 @@ show_brdlist(int head, int clsflag, int newflag)
if (class_bid != 1) {
prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m"
"%-34.34s",
- ((ptr->myattr & BRD_FAV) &&
- !(cuser.uflag2 & FAVNOHILIGHT))? "\033[1;36m" : "",
+ ((!(cuser.uflag2 & FAVNOHILIGHT) &&
+ getboard(ptr->bid) != NULL))? "\033[1;36m" : "",
B_BH(ptr)->brdname,
color[(unsigned int)
(B_BH(ptr)->title[1] + B_BH(ptr)->title[2] +
diff --git a/pttbbs/mbbsd/fav.c b/pttbbs/mbbsd/fav.c
index c31230be..a0097b02 100644
--- a/pttbbs/mbbsd/fav.c
+++ b/pttbbs/mbbsd/fav.c
@@ -206,6 +206,15 @@ inline static fav_t *get_fav_root(void){
return fav_stack[0];
}
+/* cursor never on an unvisable entry */
+inline int is_visible_item(fav_type_t *ft){
+ if (!(ft->attr & FAVH_FAV))
+ return 0;
+ if (get_item_type(ft) != FAVT_BOARD)
+ return 1;
+ return Ben_Perm(&bcache[cast_board(ft)->bid - 1]);
+}
+
/* return: the exact number after cleaning
* reset the line number, board number, folder number, and total number (number)
*/
@@ -215,8 +224,8 @@ static void rebuild_fav(fav_t *fp)
fav_type_t *ft;
fav_number = 0;
fp->nLines = fp->nBoards = fp->nFolders = 0;
- for (i = 0, j = 0; i < fp->nAllocs; i++){
- if (!is_set_attr(&fp->favh[i], FAVH_FAV))
+ for (i = 0, j = 0; i < fp->DataTail; i++){
+ if (!is_visible_item(&fp->favh[i]))
continue;
ft = &fp->favh[i];
switch (get_item_type(ft)){
@@ -257,7 +266,7 @@ static int favcmp_by_name(const void *a, const void *b)
void fav_sort_by_name(void)
{
rebuild_fav(get_current_fav());
- qsort(get_current_fav(), get_data_number(get_current_fav()), sizeof(fav_type_t), favcmp_by_name);
+ qsort(get_current_fav()->favh, get_data_number(get_current_fav()), sizeof(fav_type_t), favcmp_by_name);
}
static int favcmp_by_class(const void *a, const void *b)
@@ -267,10 +276,14 @@ static int favcmp_by_class(const void *a, const void *b)
f1 = (fav_type_t *)a;
f2 = (fav_type_t *)b;
- if (get_item_type(f1) == FAVT_FOLDER || get_item_type(f2) == FAVT_FOLDER)
+ if (get_item_type(f1) == FAVT_FOLDER)
return -1;
- if (get_item_type(f1) == FAVT_LINE || get_item_type(f2) == FAVT_LINE)
+ if (get_item_type(f2) == FAVT_FOLDER)
return 1;
+ if (get_item_type(f1) == FAVT_LINE)
+ return 1;
+ if (get_item_type(f2) == FAVT_LINE)
+ return -1;
cmp = strncasecmp(get_item_class(f1), get_item_class(f2), 4);
if (cmp)
@@ -281,7 +294,7 @@ static int favcmp_by_class(const void *a, const void *b)
void fav_sort_by_class(void)
{
rebuild_fav(get_current_fav());
- qsort(get_current_fav(), get_data_number(get_current_fav()), sizeof(fav_type_t), favcmp_by_class);
+ qsort(get_current_fav()->favh, get_data_number(get_current_fav()), sizeof(fav_type_t), favcmp_by_class);
}
/* --- */
@@ -327,15 +340,6 @@ void fav_folder_out(void)
fav_stack_pop();
}
-/* cursor never on an unvisable entry */
-inline int is_visible_item(fav_type_t *ft){
- if (!(ft->attr & FAVH_FAV))
- return 0;
- if (get_item_type(ft) != FAVT_BOARD)
- return 1;
- return Ben_Perm(&bcache[cast_board(ft)->bid - 1]);
-}
-
void fav_cursor_up(void)
{
fav_t *ft = get_current_fav();
@@ -343,7 +347,7 @@ void fav_cursor_up(void)
return;
do{
if (fav_place == 0)
- fav_place = ft->nAllocs - 1;
+ fav_place = ft->DataTail - 1;
else
fav_place--;
}while(!is_visible_item(&ft->favh[fav_place]));
@@ -355,7 +359,7 @@ void fav_cursor_down(void)
if (get_data_number(ft) <= 0)
return;
do{
- if (fav_place == ft->nAllocs - 1)
+ if (fav_place == ft->DataTail - 1)
fav_place = 0;
else
fav_place++;
@@ -376,7 +380,7 @@ void fav_cursor_down_step(short int step)
{
int i;
for(i = 0; i < step; i++){
- if (fav_place >= get_current_fav()->nAllocs - 1)
+ if (fav_place >= get_current_fav()->DataTail - 1)
break;
fav_cursor_down();
}
@@ -519,7 +523,7 @@ static void fav_free_branch(fav_t *fp)
fav_type_t *ft;
if (fp == NULL)
return;
- for(i = 0; i < fp->nAllocs; i++){
+ for(i = 0; i < fp->DataTail; i++){
ft = &fp->favh[i];
fav_remove(fp, ft);
}
@@ -544,9 +548,9 @@ static fav_type_t *get_fav_item(short id, int type)
fav_type_t *ft;
fav_t *fp = get_current_fav();
- for(i = 0; i < fp->nAllocs; i++){
+ for(i = 0; i < fp->DataTail; i++){
ft = &fp->favh[i];
- if (!is_set_attr(ft, FAVH_FAV) || get_item_type(ft) != type)
+ if (!is_visible_item(ft) || get_item_type(ft) != type)
continue;
if (fav_getid(ft) == id)
return ft;
@@ -554,7 +558,7 @@ static fav_type_t *get_fav_item(short id, int type)
return NULL;
}
-static fav_type_t *getboard(short bid)
+fav_type_t *getboard(short bid)
{
return get_fav_item(bid, FAVT_BOARD);
}
@@ -732,7 +736,7 @@ inline void fav_tag_current(int bool) {
static void fav_dosomething_tagged_item(fav_t *fp, int (*act)(fav_t *, fav_type_t *))
{
int i;
- for(i = 0; i < fp->nAllocs; i++){
+ for(i = 0; i < fp->DataTail; i++){
if (is_set_attr(&fp->favh[i], FAVH_FAV) && is_set_attr(&fp->favh[i], FAVH_TAG))
if ((*act)(fp, &fp->favh[i]) < 0)
break;
@@ -776,9 +780,9 @@ static void fav_do_recursively(fav_t *fp, int (*act)(fav_t *))
{
int i;
fav_type_t *ft;
- for(i = 0; i < fp->nAllocs; i++){
+ for(i = 0; i < fp->DataTail; i++){
ft = &fp->favh[i];
- if (!is_set_attr(ft, FAVH_FAV))
+ if (!is_visible_item(ft))
continue;
if (get_item_type(ft) == FAVT_FOLDER && get_fav_folder(ft) != NULL){
fav_do_recursively(get_fav_folder(ft), act);