Fossil SCM
In the "test-forumthread" command, if the thread-id argument is omitted show a list of all available threads.
Commit
98270ad6135e0fd7bbd15fabfdf66a7417bd756897b80f665d242562c267ab6d
Parent
2ee58cf546af64f…
1 file changed
+53
-4
+53
-4
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -199,17 +199,46 @@ | ||
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /* Return the result */ |
| 202 | 202 | return pThread; |
| 203 | 203 | } |
| 204 | + | |
| 205 | +/* | |
| 206 | +** List all forum threads to standard output. | |
| 207 | +*/ | |
| 208 | +static void forum_thread_list(void){ | |
| 209 | + Stmt q; | |
| 210 | + db_prepare(&q, | |
| 211 | + " SELECT" | |
| 212 | + " datetime(max(fmtime))," | |
| 213 | + " sum(fprev IS NULL)," | |
| 214 | + " froot" | |
| 215 | + " FROM forumpost" | |
| 216 | + " GROUP BY froot" | |
| 217 | + " ORDER BY 1;" | |
| 218 | + ); | |
| 219 | + fossil_print(" id cnt most recent post\n"); | |
| 220 | + fossil_print("------ ---- -------------------\n"); | |
| 221 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 222 | + fossil_print("%6d %4d %s\n", | |
| 223 | + db_column_int(&q, 2), | |
| 224 | + db_column_int(&q, 1), | |
| 225 | + db_column_text(&q, 0) | |
| 226 | + ); | |
| 227 | + } | |
| 228 | + db_finalize(&q); | |
| 229 | +} | |
| 204 | 230 | |
| 205 | 231 | /* |
| 206 | 232 | ** COMMAND: test-forumthread |
| 207 | 233 | ** |
| 208 | -** Usage: %fossil test-forumthread THREADID | |
| 234 | +** Usage: %fossil test-forumthread [THREADID] | |
| 235 | +** | |
| 236 | +** Display a summary of all messages on a thread THREADID. If the | |
| 237 | +** THREADID argument is omitted, then show a list of all threads. | |
| 209 | 238 | ** |
| 210 | -** Display a summary of all messages on a thread. | |
| 239 | +** This command is intended for testing an analysis only. | |
| 211 | 240 | */ |
| 212 | 241 | void forumthread_cmd(void){ |
| 213 | 242 | int fpid; |
| 214 | 243 | int froot; |
| 215 | 244 | const char *zName; |
| @@ -216,10 +245,14 @@ | ||
| 216 | 245 | ForumThread *pThread; |
| 217 | 246 | ForumEntry *p; |
| 218 | 247 | |
| 219 | 248 | db_find_and_open_repository(0,0); |
| 220 | 249 | verify_all_options(); |
| 250 | + if( g.argc==2 ){ | |
| 251 | + forum_thread_list(); | |
| 252 | + return; | |
| 253 | + } | |
| 221 | 254 | if( g.argc!=3 ) usage("THREADID"); |
| 222 | 255 | zName = g.argv[2]; |
| 223 | 256 | fpid = symbolic_name_to_rid(zName, "f"); |
| 224 | 257 | if( fpid<=0 ){ |
| 225 | 258 | fpid = db_int(0, "SELECT rid FROM blob WHERE rid=%d", atoi(zName)); |
| @@ -536,21 +569,37 @@ | ||
| 536 | 569 | /* |
| 537 | 570 | ** Add an appropriate style_header() to include title of the |
| 538 | 571 | ** given forum post. |
| 539 | 572 | */ |
| 540 | 573 | static int forumthread_page_header(int froot, int fpid){ |
| 541 | - char *zThreadTitle = 0; | |
| 574 | + Blob title; | |
| 575 | + int mxForumPostTitleLen = 50; | |
| 576 | + char *zThreadTitle = ""; | |
| 542 | 577 | |
| 543 | 578 | zThreadTitle = db_text("", |
| 544 | 579 | "SELECT" |
| 545 | 580 | " substr(event.comment,instr(event.comment,':')+2)" |
| 546 | 581 | " FROM forumpost, event" |
| 547 | 582 | " WHERE event.objid=forumpost.fpid" |
| 548 | 583 | " AND forumpost.fpid=%d;", |
| 549 | 584 | fpid |
| 550 | 585 | ); |
| 551 | - style_header("%s%s", zThreadTitle, zThreadTitle[0] ? "" : "Forum"); | |
| 586 | + blob_set(&title, zThreadTitle); | |
| 587 | + /* truncate the title when longer than max allowed; | |
| 588 | + * in case of UTF-8 make sure the truncated string remains valid, | |
| 589 | + * otherwise (different encoding?) pass as-is | |
| 590 | + */ | |
| 591 | + if( mxForumPostTitleLen>0 && blob_size(&title)>mxForumPostTitleLen ){ | |
| 592 | + int len; | |
| 593 | + len = utf8_codepoint_index(blob_str(&title), mxForumPostTitleLen); | |
| 594 | + if( len ){ | |
| 595 | + blob_truncate(&title, len); | |
| 596 | + blob_append(&title, "...", 3); | |
| 597 | + } | |
| 598 | + } | |
| 599 | + style_header("%s%s", blob_str(&title), blob_size(&title) ? " - Forum" : "Forum"); | |
| 600 | + blob_reset(&title); | |
| 552 | 601 | fossil_free(zThreadTitle); |
| 553 | 602 | return 0; |
| 554 | 603 | } |
| 555 | 604 | |
| 556 | 605 | /* |
| 557 | 606 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -199,17 +199,46 @@ | |
| 199 | } |
| 200 | |
| 201 | /* Return the result */ |
| 202 | return pThread; |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | ** COMMAND: test-forumthread |
| 207 | ** |
| 208 | ** Usage: %fossil test-forumthread THREADID |
| 209 | ** |
| 210 | ** Display a summary of all messages on a thread. |
| 211 | */ |
| 212 | void forumthread_cmd(void){ |
| 213 | int fpid; |
| 214 | int froot; |
| 215 | const char *zName; |
| @@ -216,10 +245,14 @@ | |
| 216 | ForumThread *pThread; |
| 217 | ForumEntry *p; |
| 218 | |
| 219 | db_find_and_open_repository(0,0); |
| 220 | verify_all_options(); |
| 221 | if( g.argc!=3 ) usage("THREADID"); |
| 222 | zName = g.argv[2]; |
| 223 | fpid = symbolic_name_to_rid(zName, "f"); |
| 224 | if( fpid<=0 ){ |
| 225 | fpid = db_int(0, "SELECT rid FROM blob WHERE rid=%d", atoi(zName)); |
| @@ -536,21 +569,37 @@ | |
| 536 | /* |
| 537 | ** Add an appropriate style_header() to include title of the |
| 538 | ** given forum post. |
| 539 | */ |
| 540 | static int forumthread_page_header(int froot, int fpid){ |
| 541 | char *zThreadTitle = 0; |
| 542 | |
| 543 | zThreadTitle = db_text("", |
| 544 | "SELECT" |
| 545 | " substr(event.comment,instr(event.comment,':')+2)" |
| 546 | " FROM forumpost, event" |
| 547 | " WHERE event.objid=forumpost.fpid" |
| 548 | " AND forumpost.fpid=%d;", |
| 549 | fpid |
| 550 | ); |
| 551 | style_header("%s%s", zThreadTitle, zThreadTitle[0] ? "" : "Forum"); |
| 552 | fossil_free(zThreadTitle); |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -199,17 +199,46 @@ | |
| 199 | } |
| 200 | |
| 201 | /* Return the result */ |
| 202 | return pThread; |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | ** List all forum threads to standard output. |
| 207 | */ |
| 208 | static void forum_thread_list(void){ |
| 209 | Stmt q; |
| 210 | db_prepare(&q, |
| 211 | " SELECT" |
| 212 | " datetime(max(fmtime))," |
| 213 | " sum(fprev IS NULL)," |
| 214 | " froot" |
| 215 | " FROM forumpost" |
| 216 | " GROUP BY froot" |
| 217 | " ORDER BY 1;" |
| 218 | ); |
| 219 | fossil_print(" id cnt most recent post\n"); |
| 220 | fossil_print("------ ---- -------------------\n"); |
| 221 | while( db_step(&q)==SQLITE_ROW ){ |
| 222 | fossil_print("%6d %4d %s\n", |
| 223 | db_column_int(&q, 2), |
| 224 | db_column_int(&q, 1), |
| 225 | db_column_text(&q, 0) |
| 226 | ); |
| 227 | } |
| 228 | db_finalize(&q); |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | ** COMMAND: test-forumthread |
| 233 | ** |
| 234 | ** Usage: %fossil test-forumthread [THREADID] |
| 235 | ** |
| 236 | ** Display a summary of all messages on a thread THREADID. If the |
| 237 | ** THREADID argument is omitted, then show a list of all threads. |
| 238 | ** |
| 239 | ** This command is intended for testing an analysis only. |
| 240 | */ |
| 241 | void forumthread_cmd(void){ |
| 242 | int fpid; |
| 243 | int froot; |
| 244 | const char *zName; |
| @@ -216,10 +245,14 @@ | |
| 245 | ForumThread *pThread; |
| 246 | ForumEntry *p; |
| 247 | |
| 248 | db_find_and_open_repository(0,0); |
| 249 | verify_all_options(); |
| 250 | if( g.argc==2 ){ |
| 251 | forum_thread_list(); |
| 252 | return; |
| 253 | } |
| 254 | if( g.argc!=3 ) usage("THREADID"); |
| 255 | zName = g.argv[2]; |
| 256 | fpid = symbolic_name_to_rid(zName, "f"); |
| 257 | if( fpid<=0 ){ |
| 258 | fpid = db_int(0, "SELECT rid FROM blob WHERE rid=%d", atoi(zName)); |
| @@ -536,21 +569,37 @@ | |
| 569 | /* |
| 570 | ** Add an appropriate style_header() to include title of the |
| 571 | ** given forum post. |
| 572 | */ |
| 573 | static int forumthread_page_header(int froot, int fpid){ |
| 574 | Blob title; |
| 575 | int mxForumPostTitleLen = 50; |
| 576 | char *zThreadTitle = ""; |
| 577 | |
| 578 | zThreadTitle = db_text("", |
| 579 | "SELECT" |
| 580 | " substr(event.comment,instr(event.comment,':')+2)" |
| 581 | " FROM forumpost, event" |
| 582 | " WHERE event.objid=forumpost.fpid" |
| 583 | " AND forumpost.fpid=%d;", |
| 584 | fpid |
| 585 | ); |
| 586 | blob_set(&title, zThreadTitle); |
| 587 | /* truncate the title when longer than max allowed; |
| 588 | * in case of UTF-8 make sure the truncated string remains valid, |
| 589 | * otherwise (different encoding?) pass as-is |
| 590 | */ |
| 591 | if( mxForumPostTitleLen>0 && blob_size(&title)>mxForumPostTitleLen ){ |
| 592 | int len; |
| 593 | len = utf8_codepoint_index(blob_str(&title), mxForumPostTitleLen); |
| 594 | if( len ){ |
| 595 | blob_truncate(&title, len); |
| 596 | blob_append(&title, "...", 3); |
| 597 | } |
| 598 | } |
| 599 | style_header("%s%s", blob_str(&title), blob_size(&title) ? " - Forum" : "Forum"); |
| 600 | blob_reset(&title); |
| 601 | fossil_free(zThreadTitle); |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 |