Updated hedit to Rhade's cleaner version. --Rumble

This commit is contained in:
Rumble 2007-06-25 23:29:21 +00:00
parent 62f74102af
commit e7683af387
8 changed files with 307 additions and 238 deletions

View file

@ -7,6 +7,8 @@ builderacademy.net 9091
tbaMUD 3.53 tbaMUD 3.53
[Jun 28 2007] [Jun 28 2007]
Updated World and files for 3.53 release. Updated World and files for 3.53 release.
[Jun 26 2007] - Rumble
Updated hedit to Rhade's cleaner version. (thanks Rhade)
[Jun 25 2007] - Rumble [Jun 25 2007] - Rumble
Added questpoints to load_char and set autoexit on by default. (thanks Trulight) Added questpoints to load_char and set autoexit on by default. (thanks Trulight)
[Jun 20 2007] [Jun 20 2007]

View file

@ -22,7 +22,7 @@
#include "dg_scripts.h" #include "dg_scripts.h"
/* extern variables */ /* extern variables */
extern int top_of_h_table; extern int top_of_helpt;
extern struct help_index_element *help_table; extern struct help_index_element *help_table;
extern char *help; extern char *help;
extern char *ihelp; extern char *ihelp;
@ -996,7 +996,7 @@ int search_help(char *argument, int level)
int chk, bot, top, mid, minlen; int chk, bot, top, mid, minlen;
bot = 0; bot = 0;
top = top_of_h_table; top = top_of_helpt;
minlen = strlen(argument); minlen = strlen(argument);
while (bot <= top) { while (bot <= top) {
@ -1052,7 +1052,7 @@ ACMD(do_help)
mudlog(NRM, MAX(LVL_IMPL, GET_INVIS_LEV(ch)), TRUE, mudlog(NRM, MAX(LVL_IMPL, GET_INVIS_LEV(ch)), TRUE,
"%s tried to get help on %s", GET_NAME(ch), argument); "%s tried to get help on %s", GET_NAME(ch), argument);
int i, found = 0; int i, found = 0;
for (i = 0; i <= top_of_h_table; i++) { for (i = 0; i <= top_of_helpt; i++) {
if (help_table[i].min_level > GET_LEVEL(ch)) if (help_table[i].min_level > GET_LEVEL(ch))
continue; continue;
/* To help narrow down results, if they don't start with the same letters, move on. */ /* To help narrow down results, if they don't start with the same letters, move on. */

View file

@ -195,7 +195,7 @@ void aedit_save_internally(struct descriptor_data *d) {
create_command_list(); create_command_list();
sort_commands(); sort_commands();
add_to_save_list(AEDIT_PERMISSION, SL_ACTION); add_to_save_list(AEDIT_PERMISSION, SL_ACT);
aedit_save_to_disk(d); /* autosave by Rumble */ aedit_save_to_disk(d); /* autosave by Rumble */
} }
@ -238,7 +238,7 @@ void aedit_save_to_disk(struct descriptor_data *d) {
fprintf(fp, "$\n"); fprintf(fp, "$\n");
fclose(fp); fclose(fp);
remove_from_save_list(AEDIT_PERMISSION, SL_ACTION); remove_from_save_list(AEDIT_PERMISSION, SL_ACT);
} }
/* The Main Menu. */ /* The Main Menu. */

105
src/db.c
View file

@ -80,9 +80,8 @@ char *background = NULL; /* background story */
char *handbook = NULL; /* handbook for new immortals */ char *handbook = NULL; /* handbook for new immortals */
char *policies = NULL; /* policies page */ char *policies = NULL; /* policies page */
int top_of_helpt = 0;
struct help_index_element *help_table = NULL; struct help_index_element *help_table = NULL;
void load_help(FILE *fl, char *name);
extern int top_of_h_table;
struct social_messg *soc_mess_list = NULL; /* list of socials */ struct social_messg *soc_mess_list = NULL; /* list of socials */
int top_of_socialt = -1; /* number of socials */ int top_of_socialt = -1; /* number of socials */
@ -1028,10 +1027,10 @@ void index_boot(int mode)
} }
fclose(db_index); fclose(db_index);
/* sort the help index */ /* Sort the help index. */
if (mode == DB_BOOT_HLP) { if (mode == DB_BOOT_HLP) {
qsort(help_table, top_of_h_table, sizeof(struct help_index_element), hsort); qsort(help_table, top_of_helpt, sizeof(struct help_index_element), hsort);
top_of_h_table--; top_of_helpt--;
} }
} }
@ -2081,6 +2080,102 @@ void get_one_line(FILE *fl, char *buf)
buf[strlen(buf) - 1] = '\0'; /* take off the trailing \n */ buf[strlen(buf) - 1] = '\0'; /* take off the trailing \n */
} }
void free_help(struct help_index_element *help) {
if (help->keywords)
free(help->keywords);
if (help->entry && !help->duplicate)
free(help->entry);
free(help);
}
void free_help_table(void)
{
if (help_table) {
int hp;
for (hp = 0; hp <= top_of_helpt; hp++) {
if (help_table[hp].keywords)
free(help_table[hp].keywords);
if (help_table[hp].entry && !help_table[hp].duplicate)
free(help_table[hp].entry);
}
free(help_table);
help_table = NULL;
}
top_of_helpt = 0;
}
void load_help(FILE * fl, char *name)
{
char key[READ_SIZE + 1], next_key[READ_SIZE + 1], entry[32384];
size_t entrylen;
char line[READ_SIZE + 1], hname[READ_SIZE + 1], *scan;
struct help_index_element el;
strlcpy(hname, name, sizeof(hname));
get_one_line(fl, key);
while (*key != '$') {
strcat(key, "\r\n"); /* strcat: OK (READ_SIZE - "\n" "\r\n" == READ_SIZE 1) */
entrylen = strlcpy(entry, key, sizeof(entry));
/* Read in the corresponding help entry. */
get_one_line(fl, line);
while (*line != '#' && entrylen < sizeof(entry) - 1) {
entrylen += strlcpy(entry + entrylen, line, sizeof(entry) - entrylen);
if (entrylen + 2 < sizeof(entry) - 1) {
strcpy(entry + entrylen, "\r\n"); /* strcpy: OK (size checked above) */
entrylen += 2;
}
get_one_line(fl, line);
}
if (entrylen >= sizeof(entry) - 1) {
int keysize;
const char *truncmsg = "\r\n*TRUNCATED*\r\n";
strcpy(entry + sizeof(entry) - strlen(truncmsg) - 1, truncmsg); /* strcpy: OK (assuming sane 'entry' size) */
keysize = strlen(key) - 2;
log("SYSERR: Help entry exceeded buffer space: %.*s", keysize, key);
/* If we ran out of buffer space, eat the rest of the entry. */
while (*line != '#')
get_one_line(fl, line);
}
if (*line == '#') {
if (sscanf(line, "#%d", &el.min_level) != 1) {
log("SYSERR: Help entry does not have a min level. %s", key);
el.min_level = 0;
}
}
el.duplicate = 0;
el.entry = strdup(entry);
scan = one_word(key, next_key);
while (*next_key) {
el.keywords = strdup(next_key);
help_table[top_of_helpt++] = el;
el.duplicate++;
scan = one_word(scan, next_key);
}
get_one_line(fl, key);
}
}
int hsort(const void *a, const void *b)
{
const struct help_index_element *a1, *b1;
a1 = (const struct help_index_element *) a;
b1 = (const struct help_index_element *) b;
return (str_cmp(a1->keywords, b1->keywords));
}
int vnum_mobile(char *searchname, struct char_data *ch) int vnum_mobile(char *searchname, struct char_data *ch)
{ {
int nr, found = 0; int nr, found = 0;

View file

@ -44,7 +44,8 @@ struct {
{ SL_WLD, save_rooms, "room" }, { SL_WLD, save_rooms, "room" },
{ SL_ZON, save_zone, "zone" }, { SL_ZON, save_zone, "zone" },
{ SL_CFG, save_config, "config" }, { SL_CFG, save_config, "config" },
{ SL_ACTION, NULL, "social" }, { SL_ACT, NULL, "social" },
{ SL_HLP, NULL, "help" },
{ -1, NULL, NULL }, { -1, NULL, NULL },
}; };
@ -64,16 +65,23 @@ int save_all(void)
{ {
while (save_list) { while (save_list) {
if (save_list->type < 0 || save_list->type > SL_MAX) { if (save_list->type < 0 || save_list->type > SL_MAX) {
if (save_list->type == SL_ACTION) { switch (save_list->type) {
log("Actions not saved - cannot autosave. Use 'aedit save'."); case SL_ACT:
save_list = save_list->next; /* Fatal error, skip this one. */ log("Actions not saved - can not autosave. Use 'aedit save'.");
} else save_list = save_list->next; /* Fatal error, skip this one. */
log("SYSERR: GenOLC: Invalid save type %d in save list.\n", save_list->type); break;
} else if ((*save_types[save_list->type].func)(real_zone(save_list->zone)) < 0) case SL_HLP:
save_list = save_list->next; /* Fatal error, skip this one. */ log("Help not saved - can not autosave. Use 'hedit save'.");
} save_list = save_list->next; /* Fatal error, skip this one. */
break;
return TRUE; default:
log("SYSERR: GenOLC: Invalid save type %d in save list.\n", save_list->type);
break;
}
} else if ((*save_types[save_list->type].func) (real_zone(save_list->zone)) < 0)
save_list = save_list->next; /* Fatal error, skip this one. */
}
return TRUE;
} }
/* NOTE: This changes the buffer passed in. */ /* NOTE: This changes the buffer passed in. */

View file

@ -37,12 +37,9 @@ extern int top_shop_offset;
#define SL_WLD 3 #define SL_WLD 3
#define SL_ZON 4 #define SL_ZON 4
#define SL_CFG 5 #define SL_CFG 5
#define SL_ACT 6 #define SL_MAX 5
#define SL_MAX 6 #define SL_ACT SL_MAX + 1 /* must be above MAX */
#define SL_HLP SL_MAX + 2
#ifndef STOCK_CIRCLE
#define SL_ACTION 100 /* must be above MAX */
#endif
#define ZCMD(zon, cmds) zone_table[(zon)].cmd[(cmds)] #define ZCMD(zon, cmds) zone_table[(zon)].cmd[(cmds)]

View file

@ -1,8 +1,13 @@
/************************************************************************** /**************************************************************************
* File: hedit.c Part of tbaMUD * * File: hedit.c Part of tbaMUD *
* Usage: Help Editor. * * Usage: Oasis OLC Help Editor. *
* Author: Steve Wolfe, Scott Meisenholder, Rhade *
* * * *
* By Steve Wolfe. Updated by Scott Meisenholder. * * All rights reserved. See license.doc for complete information. *
* *
* Copyright (C) 2007 by Rhade *
* InfoTechMUD is based on CircleMUD, Copyright (C) 1993, 1994. *
* CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. *
**************************************************************************/ **************************************************************************/
#include "conf.h" #include "conf.h"
@ -19,98 +24,30 @@
#include "handler.h" #include "handler.h"
#include "improved-edit.h" #include "improved-edit.h"
/* external data structures */
extern struct descriptor_data *descriptor_list;
void hedit_disp_menu(struct descriptor_data *d);
/* external variables */ /* external variables */
extern int top_of_helpt;
extern struct help_index_element *help_table; extern struct help_index_element *help_table;
void get_one_line(FILE *fl, char *buf);
int search_help(char *argument, int level);
ACMD(do_reboot);
/* local variables */ /* external functions */
int top_of_h_table = 0; /* ref to top of help table */ int search_help(char *argument, int level);
void index_boot(int mode);
/* local functions */ /* local functions */
void hedit_save_internally(struct descriptor_data *d); ACMD(do_oasis_hedit);
void hedit_save_to_disk(struct descriptor_data *d); void hedit_disp_menu(struct descriptor_data *);
void hedit_setup_new(struct descriptor_data *d, char *new_key); void hedit_parse(struct descriptor_data *, char *);
void hedit_setup_existing(struct descriptor_data *d, int rnum); void hedit_setup_new(struct descriptor_data *);
void hedit_setup_existing(struct descriptor_data *, int);
void load_help(FILE *fl, char *name) void hedit_save_to_disk(struct descriptor_data *);
{ void hedit_save_internally(struct descriptor_data *);
char key[READ_SIZE + 1], next_key[READ_SIZE + 1], entry[32384]; void hedit_string_cleanup(struct descriptor_data *, int);
size_t entrylen; ACMD(do_helpcheck);
char line[READ_SIZE + 1], hname[READ_SIZE + 1], *scan; ACMD(do_hindex);
struct help_index_element el;
strlcpy(hname, name, sizeof(hname));
/* get the first keyword line */
get_one_line(fl, key);
while (*key != '$') {
strcat(key, "\r\n"); /* strcat: OK (READ_SIZE - "\n" "\r\n" == READ_SIZE 1) */
entrylen = strlcpy(entry, key, sizeof(entry));
/* read in the corresponding help entry */
get_one_line(fl, line);
while (*line != '#' && entrylen < sizeof(entry) - 1) {
entrylen += strlcpy(entry + entrylen, line, sizeof(entry) - entrylen);
if (entrylen + 2 < sizeof(entry) - 1) {
strcpy(entry + entrylen, "\r\n"); /* strcpy: OK (size checked above) */
entrylen += 2;
}
get_one_line(fl, line);
}
if (entrylen >= sizeof(entry) - 1) {
int keysize;
const char *truncmsg = "\r\n*TRUNCATED*\r\n";
strcpy(entry + sizeof(entry) - strlen(truncmsg) - 1, truncmsg); /* strcpy: OK (assuming sane 'entry' size) */
keysize = strlen(key) - 2;
log("SYSERR: Help entry exceeded buffer space: %.*s", keysize, key);
/* If we ran out of buffer space, eat the rest of the entry. */
while (*line != '#')
get_one_line(fl, line);
}
if (*line == '#') {
if (sscanf(line, "#%d", &el.min_level) != 1){
log("SYSERR: Help entry does not have a min level. %s", key);
el.min_level = 0;
}
}
el.duplicate = 0;
el.entry = strdup(entry);
scan = one_word(key, next_key);
while (*next_key) {
el.keywords = strdup(next_key);
help_table[top_of_h_table++] = el;
el.duplicate++;
scan = one_word(scan, next_key);
}
/* get next keyword line (or $) */
get_one_line(fl, key);
}
}
int hsort(const void *a, const void *b)
{
const struct help_index_element *a1, *b1;
a1 = (const struct help_index_element *) a;
b1 = (const struct help_index_element *) b;
return (str_cmp(a1->keywords, b1->keywords));
}
ACMD(do_oasis_hedit) ACMD(do_oasis_hedit)
{ {
char arg[MAX_INPUT_LENGTH];
struct descriptor_data *d; struct descriptor_data *d;
int i;
/* No building as a mob or while being forced. */ /* No building as a mob or while being forced. */
if (IS_NPC(ch) || !ch->desc || STATE(ch->desc) != CON_PLAYING) if (IS_NPC(ch) || !ch->desc || STATE(ch->desc) != CON_PLAYING)
@ -121,15 +58,16 @@ ACMD(do_oasis_hedit)
return; return;
} }
for (d = descriptor_list; d; d = d->next) for (d = descriptor_list; d; d = d->next) {
if (STATE(d) == CON_HEDIT) { if (STATE(d) == CON_HEDIT) {
send_to_char(ch, "Sorry, only one can person can edit help files at a time.\r\n"); send_to_char(ch, "Sorry, only one can person can edit help files at a time.\r\n");
return; return;
} }
}
skip_spaces(&argument); one_argument(argument, arg);
if (!*argument) { if (!*arg) {
send_to_char(ch, "Please specify a help entry to edit.\r\n"); send_to_char(ch, "Please specify a help entry to edit.\r\n");
return; return;
} }
@ -137,10 +75,10 @@ ACMD(do_oasis_hedit)
d = ch->desc; d = ch->desc;
if (!str_cmp("save", argument)) { if (!str_cmp("save", argument)) {
mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(ch)), TRUE, "OLC: %s saves help files.", GET_NAME(ch)); mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(ch)), TRUE, "OLC: %s saves help files.",
send_to_char(ch, "Writing help file..\r\n"); GET_NAME(ch));
hedit_save_to_disk(d); hedit_save_to_disk(d);
send_to_char(ch, "Done.\r\n"); send_to_char(ch, "Saving help files.\r\n");
return; return;
} }
@ -152,17 +90,16 @@ ACMD(do_oasis_hedit)
CREATE(d->olc, struct oasis_olc_data, 1); CREATE(d->olc, struct oasis_olc_data, 1);
OLC_NUM(d) = 0; OLC_NUM(d) = 0;
OLC_STORAGE(d) = strdup(argument); OLC_STORAGE(d) = strdup(arg);
OLC_ZNUM(d) = search_help(OLC_STORAGE(d), LVL_IMPL); OLC_ZNUM(d) = search_help(OLC_STORAGE(d), LVL_IMPL);
for(i = 0; i < (int)strlen(argument); i++) if (OLC_ZNUM(d) == NOWHERE) {
argument[i] = toupper(argument[i]); send_to_char(ch, "Do you wish to add the '%s' help file? ", OLC_STORAGE(d));
OLC_MODE(d) = HEDIT_CONFIRM_ADD;
if (OLC_ZNUM(d) == NOWHERE) } else {
hedit_setup_new(d, OLC_STORAGE(d)); send_to_char(ch, "Do you wish to edit the '%s' help file? ", help_table[OLC_ZNUM(d)].keywords);
else OLC_MODE(d) = HEDIT_CONFIRM_EDIT;
hedit_setup_existing(d, OLC_ZNUM(d)); }
STATE(d) = CON_HEDIT; STATE(d) = CON_HEDIT;
act("$n starts using OLC.", TRUE, d->character, 0, 0, TO_ROOM); act("$n starts using OLC.", TRUE, d->character, 0, 0, TO_ROOM);
@ -170,57 +107,56 @@ ACMD(do_oasis_hedit)
mudlog(CMP, LVL_IMMORT, TRUE, "OLC: %s starts editing help files.", GET_NAME(d->character)); mudlog(CMP, LVL_IMMORT, TRUE, "OLC: %s starts editing help files.", GET_NAME(d->character));
} }
/* Utils and exported functions. */ void hedit_setup_new(struct descriptor_data *d)
void hedit_setup_new(struct descriptor_data *d, char *new_key)
{ {
CREATE(OLC_HELP(d), struct help_index_element, 1); CREATE(OLC_HELP(d), struct help_index_element, 1);
OLC_HELP(d)->keywords = strdup(new_key); OLC_HELP(d)->keywords = strdup(OLC_STORAGE(d));
OLC_HELP(d)->entry = strdup("This is an unfinished help entry.\r\n"); OLC_HELP(d)->entry = strdup("This help file is unfinished.\r\n");
OLC_HELP(d)->min_level = 0; OLC_HELP(d)->min_level = 0;
hedit_disp_menu(d); OLC_HELP(d)->duplicate = 0;
OLC_VAL(d) = 0; OLC_VAL(d) = 0;
hedit_disp_menu(d);
} }
void hedit_setup_existing(struct descriptor_data *d, int rnum) void hedit_setup_existing(struct descriptor_data *d, int rnum)
{ {
/* Build a copy of the help entry for editing.*/
CREATE(OLC_HELP(d), struct help_index_element, 1); CREATE(OLC_HELP(d), struct help_index_element, 1);
/* Allocate space for all strings. */
OLC_HELP(d)->keywords = strdup(help_table[rnum].keywords ?
help_table[rnum].keywords : "UNDEFINED\r\n");
OLC_HELP(d)->entry = strdup(help_table[rnum].entry ?
help_table[rnum].entry : "undefined\r\n");
OLC_HELP(d)->min_level = help_table[rnum].min_level;
/* Attach copy of help entry to player's descriptor. */ OLC_HELP(d)->keywords = str_udup(help_table[rnum].keywords);
OLC_HELP(d)->entry = str_udup(help_table[rnum].entry);
OLC_HELP(d)->duplicate = help_table[rnum].duplicate;
OLC_HELP(d)->min_level = help_table[rnum].min_level;
OLC_VAL(d) = 0; OLC_VAL(d) = 0;
hedit_disp_menu(d); hedit_disp_menu(d);
} }
void hedit_save_internally(struct descriptor_data *d) void hedit_save_internally(struct descriptor_data *d)
{ {
struct help_index_element *new_help_table = NULL; struct help_index_element *new_help_table = NULL;
int i;
if (OLC_ZNUM(d) > top_of_h_table) { if (OLC_ZNUM(d) > top_of_helpt) {
CREATE(new_help_table, struct help_index_element, top_of_h_table + 2); CREATE(new_help_table, struct help_index_element, top_of_helpt + 2);
new_help_table[0] = *OLC_HELP(d);
for (i = 0; i <= top_of_h_table; i++) int i;
new_help_table[i + 1] = help_table[i]; for (i = 0; i <= top_of_helpt; i++)
new_help_table[i] = help_table[i];
new_help_table[++top_of_helpt] = *OLC_HELP(d);
free(help_table); free(help_table);
help_table = new_help_table; help_table = new_help_table;
top_of_h_table ++;
} else } else
help_table[OLC_ZNUM(d)] = *OLC_HELP(d); help_table[OLC_ZNUM(d)] = *OLC_HELP(d);
hedit_save_to_disk(d);
add_to_save_list(HEDIT_PERMISSION, SL_HLP);
hedit_save_to_disk(d);
} }
void hedit_save_to_disk(struct descriptor_data *d) void hedit_save_to_disk(struct descriptor_data *d)
{ {
FILE *fp; FILE *fp;
char buf1[MAX_STRING_LENGTH], index_name[READ_SIZE], buf[READ_SIZE]; char buf1[MAX_STRING_LENGTH], index_name[READ_SIZE];
int i;
snprintf(index_name, sizeof(index_name), "%s%s", HLP_PREFIX, HELP_FILE); snprintf(index_name, sizeof(index_name), "%s%s", HLP_PREFIX, HELP_FILE);
if (!(fp = fopen(index_name, "w"))) { if (!(fp = fopen(index_name, "w"))) {
@ -228,43 +164,48 @@ void hedit_save_to_disk(struct descriptor_data *d)
return; return;
} }
for (i = 0; i <= top_of_h_table; i++){ int i;
if (help_table[i].entry && help_table[i].duplicate) for (i = 0; i <= top_of_helpt; i++) {
if (help_table[i].duplicate)
continue; continue;
strncpy(buf1, help_table[i].entry ? help_table[i].entry : "Empty\n\r", sizeof(buf1) - 1); strncpy(buf1, help_table[i].entry ? help_table[i].entry : "Empty\r\n", sizeof(buf1) - 1);
strip_cr(buf1); strip_cr(buf1);
/* Forget making a buffer, lets just write the thing now. */ /* Forget making a buffer, lets just write the thing now. */
fprintf(fp, "%s" "#%d\n", buf1, help_table[i].min_level); fprintf(fp, "%s#%d\n", buf1, help_table[i].min_level);
} }
/* Write final line and close. */ /* Write final line and close. */
fprintf(fp, "$~\n"); fprintf(fp, "$~\n");
fclose(fp); fclose(fp);
do_reboot(d->character, strcpy(buf, "xhelp"), 0, 0);
remove_from_save_list(HEDIT_PERMISSION, SL_HLP);
/* Reboot the help files. */
free_help_table();
index_boot(DB_BOOT_HLP);
} }
/* Menu functions */
/* The main menu. */ /* The main menu. */
void hedit_disp_menu(struct descriptor_data *d) void hedit_disp_menu(struct descriptor_data *d)
{ {
clear_screen(d); get_char_colors(d->character);
write_to_output(d, write_to_output(d,
"%s-- Help file editor\r\n"
"-- Help file editor\r\n" "%s1%s) Keywords : %s%s\r\n"
"@g1@n) Keywords : @y%s@n\r\n" "%s2%s) Entry :\r\n%s%s"
"@g2@n) Entry :\r\n@y%s@n" "%s3%s) Min Level : %s%d\r\n"
"@g3@n) Min Level : @c%d@n\r\n" "%sQ%s) Quit\r\n"
"@gQ@n) Quit\r\n" "Enter choice : ",
"Enter choice : ", nrm,
grn, nrm, yel, OLC_HELP(d)->keywords,
OLC_HELP(d)->keywords, grn, nrm, yel, OLC_HELP(d)->entry,
OLC_HELP(d)->entry, grn, nrm, yel, OLC_HELP(d)->min_level,
OLC_HELP(d)->min_level grn, nrm
); );
OLC_MODE(d) = HEDIT_MAIN_MENU; OLC_MODE(d) = HEDIT_MAIN_MENU;
} }
/* The main loop */
void hedit_parse(struct descriptor_data *d, char *arg) void hedit_parse(struct descriptor_data *d, char *arg)
{ {
char buf[MAX_STRING_LENGTH]; char buf[MAX_STRING_LENGTH];
@ -276,11 +217,13 @@ void hedit_parse(struct descriptor_data *d, char *arg)
switch (*arg) { switch (*arg) {
case 'y': case 'y':
case 'Y': case 'Y':
snprintf(buf, sizeof(buf), "OLC: %s edits help for %s.", GET_NAME(d->character), OLC_HELP(d)->keywords); snprintf(buf, sizeof(buf), "OLC: %s edits help for %s.", GET_NAME(d->character),
OLC_HELP(d)->keywords);
mudlog(TRUE, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), CMP, buf); mudlog(TRUE, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), CMP, buf);
write_to_output(d, "Help files saved to disk.\r\n"); write_to_output(d, "Help saved to disk.\r\n");
hedit_save_internally(d); hedit_save_internally(d);
/* Do NOT free strings! Just the help structure. */
/* Do not free strings, just the help structure. */
cleanup_olc(d, CLEANUP_STRUCTS); cleanup_olc(d, CLEANUP_STRUCTS);
break; break;
case 'n': case 'n':
@ -294,17 +237,67 @@ void hedit_parse(struct descriptor_data *d, char *arg)
} }
return; return;
case HEDIT_CONFIRM_EDIT:
switch (*arg) {
case 'y': case 'Y':
hedit_setup_existing(d, OLC_ZNUM(d));
break;
case 'q': case 'Q':
cleanup_olc(d, CLEANUP_ALL);
break;
case 'n': case 'N':
OLC_ZNUM(d)++;
for (; OLC_ZNUM(d) <= top_of_helpt; OLC_ZNUM(d)++)
if (is_abbrev(OLC_STORAGE(d), help_table[OLC_ZNUM(d)].keywords))
break;
else
OLC_ZNUM(d) = top_of_helpt + 1;
if (OLC_ZNUM(d) > top_of_helpt) {
write_to_output(d, "Do you wish to add the '%s' help file? ",
OLC_STORAGE(d));
OLC_MODE(d) = HEDIT_CONFIRM_ADD;
} else {
write_to_output(d, "Do you wish to edit the '%s' help file? ",
help_table[OLC_ZNUM(d)].keywords);
OLC_MODE(d) = HEDIT_CONFIRM_EDIT;
}
break;
default:
write_to_output(d, "Invalid choice!\r\n"
"Do you wish to edit the '%s' help file? ",
help_table[OLC_ZNUM(d)].keywords);
break;
}
return;
case HEDIT_CONFIRM_ADD:
switch (*arg) {
case 'y': case 'Y':
hedit_setup_new(d);
break;
case 'n': case 'N': case 'q': case 'Q':
cleanup_olc(d, CLEANUP_ALL);
break;
default:
write_to_output(d, "Invalid choice!\r\n"
"Do you wish to add the '%s' help file? ",
OLC_STORAGE(d));
break;
}
return;
case HEDIT_MAIN_MENU: case HEDIT_MAIN_MENU:
switch (*arg) { switch (*arg) {
case 'q': case 'q':
case 'Q': case 'Q':
if (OLC_VAL(d)) { /* Something has been modified. */ if (OLC_VAL(d)) {
write_to_output(d, "Do you wish to save your changes? : "); /* Something has been modified. */
OLC_MODE(d) = HEDIT_CONFIRM_SAVESTRING; write_to_output(d, "Do you wish to save your changes? : ");
OLC_MODE(d) = HEDIT_CONFIRM_SAVESTRING;
} else { } else {
log("this is a test of quit out of hedit"); write_to_output(d, "No changes made.\r\n");
write_to_output(d, "No changes made.\r\n"); cleanup_olc(d, CLEANUP_ALL);
cleanup_olc(d, CLEANUP_ALL);
} }
break; break;
case '1': case '1':
@ -317,14 +310,14 @@ void hedit_parse(struct descriptor_data *d, char *arg)
send_editor_help(d); send_editor_help(d);
write_to_output(d, "Enter help entry: (/s saves /h for help)\r\n"); write_to_output(d, "Enter help entry: (/s saves /h for help)\r\n");
if (OLC_HELP(d)->entry) { if (OLC_HELP(d)->entry) {
write_to_output(d, "%s", OLC_HELP(d)->entry); write_to_output(d, "%s", OLC_HELP(d)->entry);
oldtext = strdup(OLC_HELP(d)->entry); oldtext = strdup(OLC_HELP(d)->entry);
} }
string_write(d, &OLC_HELP(d)->entry, 8052, 0, oldtext); string_write(d, &OLC_HELP(d)->entry, MAX_MESSAGE_LENGTH, 0, oldtext);
OLC_VAL(d) = 1; OLC_VAL(d) = 1;
break; break;
case '3': case '3':
write_to_output(d, "Enter min level:-\r\n] "); write_to_output(d, "Enter min level : ");
OLC_MODE(d) = HEDIT_MIN_LEVEL; OLC_MODE(d) = HEDIT_MIN_LEVEL;
break; break;
default: default:
@ -340,7 +333,7 @@ void hedit_parse(struct descriptor_data *d, char *arg)
if (strlen(arg) > MAX_HELP_KEYWORDS) if (strlen(arg) > MAX_HELP_KEYWORDS)
arg[MAX_HELP_KEYWORDS - 1] = '\0'; arg[MAX_HELP_KEYWORDS - 1] = '\0';
strip_cr(arg); strip_cr(arg);
OLC_HELP(d)->keywords = strdup((arg && *arg) ? arg : "UNDEFINED"); OLC_HELP(d)->keywords = str_udup(arg);
break; break;
case HEDIT_ENTRY: case HEDIT_ENTRY:
@ -363,6 +356,7 @@ void hedit_parse(struct descriptor_data *d, char *arg)
mudlog(TRUE, LVL_BUILDER, BRF, "SYSERR: Reached default case in parse_hedit"); mudlog(TRUE, LVL_BUILDER, BRF, "SYSERR: Reached default case in parse_hedit");
break; break;
} }
/* If we get this far, something has been changed. */ /* If we get this far, something has been changed. */
OLC_VAL(d) = 1; OLC_VAL(d) = 1;
hedit_disp_menu(d); hedit_disp_menu(d);
@ -371,10 +365,9 @@ void hedit_parse(struct descriptor_data *d, char *arg)
void hedit_string_cleanup(struct descriptor_data *d, int terminator) void hedit_string_cleanup(struct descriptor_data *d, int terminator)
{ {
switch (OLC_MODE(d)) { switch (OLC_MODE(d)) {
case HEDIT_ENTRY: case HEDIT_ENTRY:
default: hedit_disp_menu(d);
hedit_disp_menu(d); break;
break;
} }
} }
@ -387,14 +380,13 @@ ACMD(do_helpcheck)
size_t len = 0, nlen; size_t len = 0, nlen;
send_to_char(ch, "Commands without help entries:\r\n"); send_to_char(ch, "Commands without help entries:\r\n");
send_to_char(ch, "-------------------------------------------------------------------\r\n");
for (i = 1; *(complete_cmd_info[i].command) != '\n'; i++) { for (i = 1; *(complete_cmd_info[i].command) != '\n'; i++) {
if (complete_cmd_info[i].command_pointer != do_action) { if (complete_cmd_info[i].command_pointer != do_action && complete_cmd_info[i].minimum_level >= 0) {
if (search_help((char *) complete_cmd_info[i].command, LVL_IMPL) == NOWHERE) { if (search_help((char *)(complete_cmd_info[i].command), LVL_IMPL) == NOWHERE) {
nlen = snprintf(buf + len, sizeof(buf) - len, " %-20.20s%s", nlen = snprintf(buf + len, sizeof(buf) - len, "%-20.20s%s", complete_cmd_info[i].command,
complete_cmd_info[i].command, (++count % 3 ? "|":"\r\n")); (++count % 3 ? "" : "\r\n"));
if (len + nlen >= sizeof(buf) || nlen < 0) if (len + nlen >= sizeof(buf))
break; break;
len += nlen; len += nlen;
} }
@ -422,43 +414,18 @@ ACMD(do_hindex)
} }
len = sprintf(buf, "Help index entries based on '%s':\r\n", argument); len = sprintf(buf, "Help index entries based on '%s':\r\n", argument);
for (i = 0; i <= top_of_h_table; i++) for (i = 0; i <= top_of_helpt; i++)
if (is_abbrev(argument, help_table[i].keywords) && (GET_LEVEL(ch) >= help_table[i].min_level)) if (is_abbrev(argument, help_table[i].keywords)
len += snprintf(buf + len, sizeof(buf) - len, "%-20.20s%s", && (GET_LEVEL(ch) >= help_table[i].min_level))
help_table[i].keywords, (++count % 3 ? "" : "\r\n")); len +=
snprintf(buf + len, sizeof(buf) - len, "%-20.20s%s", help_table[i].keywords,
(++count % 3 ? "" : "\r\n"));
if (count % 3) if (count % 3)
len += snprintf(buf + len, sizeof(buf) - len, "\r\n"); len += snprintf(buf + len, sizeof(buf) - len, "\r\n");
if (!count) if (!count)
len += snprintf(buf + len, sizeof(buf) - len, " None.\r\n"); len += snprintf(buf + len, sizeof(buf) - len, " None.\r\n");
page_string(ch->desc, buf, TRUE); page_string(ch->desc, buf, TRUE);
} }
void free_help(struct help_index_element *help)
{
if (help->keywords)
free(help->keywords);
if (help_table->entry && !help_table->duplicate)
free(help->entry);
free(help);
}
void free_help_table(void)
{
int i;
if (help_table) {
for (i = 0; i <= top_of_h_table; i++) {
if (help_table[i].keywords)
free(help_table[i].keywords);
if (help_table[i].entry && !help_table[i].duplicate)
free(help_table[i].entry);
}
free(help_table);
}
top_of_h_table = 0;
}

View file

@ -354,13 +354,13 @@ extern const char *nrm, *grn, *cyn, *yel;
#define CEDIT_MIN_WIZLIST_LEV 53 #define CEDIT_MIN_WIZLIST_LEV 53
/* Hedit Submodes of connectedness. */ /* Hedit Submodes of connectedness. */
#define HEDIT_MAIN_MENU 0 #define HEDIT_CONFIRM_SAVESTRING 0
#define HEDIT_ENTRY 1 #define HEDIT_CONFIRM_EDIT 1
#define HEDIT_MIN_LEVEL 2 #define HEDIT_CONFIRM_ADD 2
#define HEDIT_KEYWORDS 3 #define HEDIT_MAIN_MENU 3
#define HEDIT_CONFIRM_SAVESTRING 4 #define HEDIT_ENTRY 4
#define HEDIT_KEYWORDS 5
#define HEDIT_LIST 0 /* Define True, for logging help - FUTURE USE */ #define HEDIT_MIN_LEVEL 6
#ifndef __GENOLC_C__ #ifndef __GENOLC_C__