Sort the chelp index after loading - ensures that all topics are reachable.
Use correct define for PUBLIC_ACCESS. Some cleanups - separate out help index freeing, change get_help_topic() to return void. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@127 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -41,7 +41,7 @@ struct chelp_index {
|
||||
struct chelp_index bitchx_help;
|
||||
struct chelp_index script_help;
|
||||
|
||||
char *get_help_topic(const char *args, int helpfunc)
|
||||
void get_help_topic(const char *args, int helpfunc)
|
||||
{
|
||||
int found = 0, i;
|
||||
char *others = NULL;
|
||||
@@ -90,64 +90,66 @@ char *get_help_topic(const char *args, int helpfunc)
|
||||
put_it("Other %d subjects: %s", found - 1, others);
|
||||
}
|
||||
new_free(&others);
|
||||
if (helpfunc)
|
||||
return m_strdup(empty_string);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BUILT_IN_COMMAND(chelp)
|
||||
{
|
||||
static int first_time = 1;
|
||||
int reload = 0;
|
||||
|
||||
reset_display_target();
|
||||
if (args && *args == '-' && !my_strnicmp(args, "-dump", 4))
|
||||
|
||||
if (args && !my_strnicmp(args, "-dump", 4))
|
||||
{
|
||||
int i, j;
|
||||
next_arg(args, &args);
|
||||
first_time = 1;
|
||||
if (bitchx_help.entries)
|
||||
{
|
||||
for (i = 0; i < bitchx_help.size; i++)
|
||||
{
|
||||
if (bitchx_help.entries[i].contents)
|
||||
{
|
||||
for (j =0; bitchx_help.entries[i].contents[j]; j++)
|
||||
new_free(&bitchx_help.entries[i].contents[j]);
|
||||
reload = 1;
|
||||
}
|
||||
new_free(&bitchx_help.entries[i].contents);
|
||||
new_free(&bitchx_help.entries[i].title);
|
||||
new_free(&bitchx_help.entries[i].relates);
|
||||
}
|
||||
new_free(&bitchx_help.entries);
|
||||
bitchx_help.size = 0;
|
||||
}
|
||||
}
|
||||
if (first_time)
|
||||
|
||||
if (reload || !bitchx_help.size)
|
||||
{
|
||||
char *help_dir = NULL;
|
||||
FILE *help_file;
|
||||
#ifdef PUBLIC_SYSTEM
|
||||
malloc_sprintf(&help_dir, "%s", DEFAULT_BITCHX_HELP_FILE);
|
||||
#ifdef PUBLIC_ACCESS
|
||||
malloc_strcpy(&help_dir, DEFAULT_BITCHX_HELP_FILE);
|
||||
#else
|
||||
malloc_sprintf(&help_dir, "%s", get_string_var(BITCHX_HELP_VAR));
|
||||
malloc_strcpy(&help_dir, get_string_var(BITCHX_HELP_VAR));
|
||||
#endif
|
||||
if (!(help_file = uzfopen(&help_dir, get_string_var(LOAD_PATH_VAR), 1)))
|
||||
{
|
||||
help_file = uzfopen(&help_dir, get_string_var(LOAD_PATH_VAR), 1);
|
||||
new_free(&help_dir);
|
||||
if (!help_file)
|
||||
return;
|
||||
}
|
||||
new_free(&help_dir);
|
||||
first_time = 0;
|
||||
|
||||
read_file(help_file, 0);
|
||||
fclose(help_file);
|
||||
}
|
||||
|
||||
if (!args || !*args)
|
||||
{
|
||||
userage(command, helparg);
|
||||
return;
|
||||
}
|
||||
else
|
||||
get_help_topic(args, 0);
|
||||
}
|
||||
|
||||
static void free_index(struct chelp_index *index)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < index->size; i++)
|
||||
{
|
||||
for (j = 0; index->entries[i].contents[j]; j++)
|
||||
new_free(&index->entries[i].contents[j]);
|
||||
new_free(&index->entries[i].contents);
|
||||
new_free(&index->entries[i].title);
|
||||
new_free(&index->entries[i].relates);
|
||||
}
|
||||
new_free(&index->entries);
|
||||
index->size = 0;
|
||||
}
|
||||
|
||||
static int compare_chelp(const void *va, const void *vb)
|
||||
{
|
||||
const struct chelp_entry *a = va, *b = vb;
|
||||
return my_stricmp(a->title, b->title);
|
||||
}
|
||||
|
||||
int read_file(FILE *help_file, int helpfunc)
|
||||
{
|
||||
char line[BIG_BUFFER_SIZE + 1];
|
||||
@@ -155,6 +157,8 @@ int read_file(FILE *help_file, int helpfunc)
|
||||
int topic = -1;
|
||||
struct chelp_index *index = helpfunc ? &script_help : &bitchx_help;
|
||||
|
||||
free_index(index);
|
||||
|
||||
while (fgets(line, sizeof line, help_file))
|
||||
{
|
||||
size_t len = strlen(line);
|
||||
@@ -197,6 +201,8 @@ int read_file(FILE *help_file, int helpfunc)
|
||||
|
||||
index->size = topic + 1;
|
||||
|
||||
qsort(index->entries, index->size, sizeof index->entries[0], compare_chelp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4770,19 +4770,16 @@ BUILT_IN_FUNCTION(function_umask, words)
|
||||
RETURN_INT(umask(new_umask));
|
||||
}
|
||||
|
||||
|
||||
extern char *get_help_topic (const char *, int);
|
||||
extern int read_file (FILE *, int);
|
||||
|
||||
BUILT_IN_FUNCTION(function_help, words)
|
||||
{
|
||||
#ifdef PUBLIC_ACCESS
|
||||
RETURN_INT(0);
|
||||
#else
|
||||
#ifdef WANT_CHELP
|
||||
#if defined(WANT_CHELP) && !defined(PUBLIC_ACCESS)
|
||||
extern void get_help_topic(const char *, int);
|
||||
extern int read_file(FILE *, int);
|
||||
|
||||
char *filename = NULL, *subject = NULL;
|
||||
static int first_time = 1;
|
||||
FILE *help_file;
|
||||
|
||||
GET_STR_ARG(subject, words);
|
||||
if (words && *words)
|
||||
words = next_arg(filename, &words);
|
||||
@@ -4802,11 +4799,9 @@ FILE *help_file;
|
||||
read_file(help_file, 1);
|
||||
fclose(help_file);
|
||||
} else if (first_time) RETURN_EMPTY;
|
||||
return get_help_topic(subject, (filename) ? 1 : 0);
|
||||
#else
|
||||
get_help_topic(subject, (filename) ? 1 : 0);
|
||||
#endif
|
||||
RETURN_EMPTY;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
BUILT_IN_FUNCTION(function_isuser, words)
|
||||
|
||||
Reference in New Issue
Block a user