Changeset 1157
- Timestamp:
- 11/22/07 12:42:08 (9 months ago)
- Files:
-
- 1.8.3/branches/devel/CHANGES.183 (modified) (1 diff)
- 1.8.3/branches/devel/hdrs/parse.h (modified) (1 diff)
- 1.8.3/branches/devel/src/funlist.c (modified) (1 diff)
- 1.8.3/branches/devel/src/help.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/devel/CHANGES.183
r1156 r1157 32 32 and/or socket timeouts instead. (The main event loop still uses 33 33 select() for now.) 34 * A wildcard help topic search (help foo*) that only matches one 35 entry will display that entry. Suggested by Cheetah. 34 36 35 37 Flags and powers: 1.8.3/branches/devel/hdrs/parse.h
r905 r1157 83 83 84 84 /* Split a sep-delimited string into individual elements */ 85 externint list2arr(char *r[], int max, char *list, char sep);85 int list2arr(char *r[], int max, char *list, char sep); 86 86 /* The reverse */ 87 extern void arr2list(char *r[], int max, char *list, char **lp,char *sep);87 void arr2list(char *r[], int max, char *list, char **lp, const char *sep); 88 88 /* Split a sep-delimited string into individual elements. 89 89 * Uses mush_strdup, so freearr() is required on all 90 90 * list2arr_ansi()'d arrays (r) */ 91 externint list2arr_ansi(char *r[], int max, char *list, char sep);91 int list2arr_ansi(char *r[], int max, char *list, char sep); 92 92 /* Free an array generated by list2arr_ansi */ 93 externvoid freearr(char *r[], int size);93 void freearr(char *r[], int size); 94 94 95 95 /* All function declarations follow the format: */ 1.8.3/branches/devel/src/funlist.c
r1151 r1157 139 139 */ 140 140 void 141 arr2list(char *r[], int max, char *list, char **lp, c har *sep)141 arr2list(char *r[], int max, char *list, char **lp, const char *sep) 142 142 { 143 143 int i; 1.8.3/branches/devel/src/help.c
r1051 r1157 32 32 static const char *string_spitfile(help_file * help_dat, char *arg1); 33 33 static help_indx *help_find_entry(help_file * help_dat, const char *the_topic); 34 static const char *list_matching_entries(char *pattern, help_file * help_dat, 35 const char *sep); 36 static const char *normalize_entry(help_file * help_dat, char *arg1); 34 static char** list_matching_entries(const char *pattern, 35 help_file *help_dat, int *len); 36 static void free_entry_list(char **); 37 static const char *normalize_entry(help_file * help_dat, const char *arg1); 37 38 38 39 static void help_build_index(help_file * h, int restricted); … … 68 69 } 69 70 70 if (wildcard(arg_left)) 71 notify_format(player, T("Here are the entries which match '%s':\n%s"), 72 arg_left, list_matching_entries(arg_left, h, ", ")); 73 else 71 if (wildcard(arg_left)) { 72 int len = 0; 73 char **entries; 74 75 entries = list_matching_entries(arg_left, h, &len); 76 if (len == 0) 77 notify_format(player, T("No entries matching '%s' were found."), 78 arg_left); 79 else if (len == 1) 80 do_new_spitfile(player, *entries, h); 81 else { 82 char buff[BUFFER_LEN]; 83 char *bp; 84 85 bp = buff; 86 arr2list(entries, len, buff, &bp, ", "); 87 *bp = '\0'; 88 notify_format(player, T("Here are the entries which match '%s':\n%s"), 89 arg_left, buff); 90 } 91 free_entry_list(entries); 92 } else 74 93 do_new_spitfile(player, arg_left, h); 75 94 } 76 95 77 /** Initialize the helpfile hashtable, which contains the names of the 96 /** Initialize the helpfile hashtable, which contains the names of thes 78 97 * help files. 79 98 */ … … 453 472 454 473 if (wildcard(args[1])) { 455 const char *entries = list_matching_entries(args[1], h, ", "); 456 if (*entries) 457 safe_str(entries, buff, bp); 474 char **entries; 475 int len = 0; 476 entries = list_matching_entries(args[1], h, &len); 477 if (len == 0) 478 safe_str(T("No matching help topics."), buff, bp); 458 479 else 459 safe_str(T("No matching help topics."), buff, bp); 480 arr2list(entries, len, buff, bp, ", "); 481 free_entry_list(entries); 460 482 } else 461 483 safe_str(string_spitfile(h, args[1]), buff, bp); … … 466 488 { 467 489 help_file *h; 490 char **entries; 491 int len = 0; 468 492 const char *sep = " "; 469 493 … … 479 503 if (nargs > 2) 480 504 sep = args[2]; 481 safe_str(list_matching_entries(args[1], h, sep), buff, bp); 505 506 entries = list_matching_entries(args[1], h, &len); 507 if (entries) { 508 arr2list(entries, len, buff, bp, sep); 509 free_entry_list(entries); 510 } 482 511 } 483 512 484 513 static const char * 485 normalize_entry(help_file * help_dat, c har *arg1)514 normalize_entry(help_file * help_dat, const char *arg1) 486 515 { 487 516 static char the_topic[LINE_SIZE + 2]; … … 491 520 else if (*arg1 == '&') 492 521 return T("#-1 INVALID ENTRY"); 493 if (strlen(arg1) > LINE_SIZE)494 *(arg1 + LINE_SIZE) = '\0';495 496 522 if (help_dat->admin) 497 s printf(the_topic, "&%s", arg1);523 snprintf(the_topic, LINE_SIZE, "&%s", arg1); 498 524 else 499 strcpy(the_topic, arg1);525 mush_strncpy(the_topic, arg1, LINE_SIZE); 500 526 return the_topic; 501 527 } … … 542 568 543 569 /** Return a string with all help entries that match a pattern */ 544 static c onst char*545 list_matching_entries(c har *pattern, help_file * help_dat, const char *sep)546 { 547 static char buff[BUFFER_LEN];570 static char ** 571 list_matching_entries(const char *pattern, help_file *help_dat, int *len) 572 { 573 char **buff; 548 574 int offset; 549 char *bp;550 575 size_t n; 551 int len = 0;552 576 553 577 if (help_dat->admin) … … 561 585 help_indx *entry = NULL; 562 586 strcpy(the_topic, normalize_entry(help_dat, pattern)); 563 if (!help_dat->indx || help_dat->entries == 0) 564 return T("#-1 NO INDEX FOR FILE"); 587 if (!help_dat->indx || help_dat->entries == 0) { 588 *len = 0; 589 return NULL; 590 } 565 591 entry = help_find_entry(help_dat, the_topic); 566 if (!entry) 567 return (char *) ""; 568 return (char *) (entry->topic + offset); 569 } 570 571 bp = buff; 572 573 if (sep) 574 len = strlen(sep); 592 if (!entry) { 593 *len = 0; 594 return NULL; 595 } else { 596 *len = 1; 597 buff = mush_malloc(sizeof(char**), "help.search"); 598 *buff = entry->topic + offset; 599 return buff; 600 } 601 } 602 603 buff = mush_calloc(help_dat->entries, sizeof(char*), "help.search"); 604 *len = 0; 575 605 576 606 for (n = 0; n < help_dat->entries; n++) 577 607 if (quick_wild(pattern, help_dat->indx[n].topic + offset)) { 578 safe_str(help_dat->indx[n].topic + offset, buff, &bp); 579 if (sep) 580 safe_strl(sep, len, buff, &bp); 581 } 582 583 if (bp > buff) 584 *(bp - len) = '\0'; 585 else { 586 *bp = '\0'; 587 } 608 buff[*len] = help_dat->indx[n].topic + offset; 609 *len += 1; 610 } 588 611 589 612 return buff; 590 613 } 614 615 static void 616 free_entry_list(char **entries) 617 { 618 if (entries) 619 mush_free(entries, "help.search"); 620 }
