jcs
/subtext
/amendments
/117
board: Fix thread indentation, check for session ending in loops
jcs made amendment 117 over 2 years ago
--- board.c Fri Jun 3 14:01:37 2022
+++ board.c Fri Jun 3 21:52:08 2022
@@ -158,7 +158,7 @@ board_show(struct session *s, short id)
show_help = false;
done = false;
- while (!done) {
+ while (!done && !s->ending) {
if (find_post_ids) {
nall_post_ids = board_find_post_ids(board, &npost_ids,
&post_ids, page * POSTS_PER_PAGE, POSTS_PER_PAGE);
@@ -311,15 +311,18 @@ board_list_posts(struct session *s, struct board *boar
indent_parent_ids[j] == 0) {
indent = j;
indent_parent_ids[j] = post.parent_post_id;
- for (k = j + 1; k < nitems(indent_parent_ids); k++)
+ for (k = j + 1; k < nitems(indent_parent_ids); k++) {
+ if (indent_parent_ids[k] == 0)
+ break;
indent_parent_ids[k] = 0;
+ }
break;
}
}
if (indent == -1)
indent = nitems(indent_parent_ids) - 1;
- for (j = 0; j < indent - 1; j++) {
+ for (j = 0; j < indent; j++) {
indent_s[j] = ' ';
}
indent_s[j] = '`';
@@ -557,7 +560,7 @@ board_post_read(struct session *s, struct board *board
snprintf(prompt, sizeof(prompt), "%s:%ld", board->name, post.id);
- while (!done) {
+ while (!done && !s->ending) {
c = session_menu(s, thread.subject, prompt, opts,
nitems(opts), show_help);
show_help = false;
@@ -736,14 +739,14 @@ board_post_create(struct board *board, struct board_th
insert = thread->nposts - 1;
for (n = 0; n < thread->nposts - 1; n++) {
- if (thread->parent_post_ids[n] != post->parent_post_id)
+ if (thread->post_ids[n] != post->parent_post_id)
continue;
- for (j = thread->nposts - 2; j >= n; j--) {
+ for (j = thread->nposts - 2; j > n; j--) {
thread->post_ids[j + 1] = thread->post_ids[j];
thread->parent_post_ids[j + 1] = thread->parent_post_ids[j];
}
- insert = n;
+ insert = n + 1;
break;
}
thread->post_ids[insert] = post->id;