[SlashMUD-commits] slashmudx/src help_manager.c, 1.6, 1.7 magic_numbers.h, 1.7, 1.8
Status: Alpha
Brought to you by:
koryn
From: Neil T. <nt...@us...> - 2006-06-15 02:17:01
|
Update of /cvsroot/slashmud/slashmudx/src In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv29283/src Modified Files: help_manager.c magic_numbers.h Log Message: Basic help working. Index: help_manager.c =================================================================== RCS file: /cvsroot/slashmud/slashmudx/src/help_manager.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** help_manager.c 14 Jun 2006 11:08:13 -0000 1.6 --- help_manager.c 15 Jun 2006 02:16:56 -0000 1.7 *************** *** 3,11 **** /* SlashMUD headers. */ ! #include "virtuals.h" #include "utility_procedures.h" /* libkoryn headers. */ #include "kg_directory_iterator.h" #include "kg_logging.h" #include "kg_std_text.h" --- 3,14 ---- /* SlashMUD headers. */ ! #include "magic_numbers.h" #include "utility_procedures.h" + #include "virtuals.h" /* libkoryn headers. */ + #include "kg_list.h" #include "kg_directory_iterator.h" + #include "kg_disposal.h" #include "kg_logging.h" #include "kg_std_text.h" *************** *** 13,21 **** #include "kg_text_file.h" - /* CVS Header. */ const char* const kHelpManagerCvsHeader = "$Header$"; static void help_file_processor(const char* const filepath, Ptr user_data); typedef struct HelpManagerHeader HelpManagerHeader; --- 16,34 ---- #include "kg_text_file.h" /* CVS Header. */ const char* const kHelpManagerCvsHeader = "$Header$"; + /* Internal routines. */ static void help_file_processor(const char* const filepath, Ptr user_data); + static void help_entry_disposer(Ptr data); + + typedef struct HelpManagerEntry HelpManagerEntry; + typedef HelpManagerEntry* HelpManagerEntryPtr; + + struct HelpManagerEntry + { + char * helpTitle; + StandardTextPtr helpText; + }; typedef struct HelpManagerHeader HelpManagerHeader; *************** *** 24,33 **** struct HelpManagerHeader { ! ! unsigned int mFIXME; }; ! HelpManagerHeaderPtr uHelpManager = NULL; --- 37,54 ---- struct HelpManagerHeader { ! magic_number_t mMagicNumber; ! ListPtr helpList; }; ! static HelpManagerHeaderPtr uHelpManager = NULL; ! ! ! static void help_entry_disposer(Ptr data) ! { ! kg_dispose_ptr( ((HelpManagerEntryPtr)data)->helpTitle); ! kg_std_text_dispose( ((HelpManagerEntryPtr)data)->helpText); ! kg_dispose_ptr( data ); ! } *************** *** 35,42 **** initialise_help_manager(void) { LogPtr log = kg_log_init("Logs/load_help_topics", NULL, 10 * 1024 * 1024); ! KGLOG_INFO(log, "Loading Help Topics"); ! /* when init'ed get a list of file names and start array */ kg_iterate_directory("Help", kg_text_file_filter, cvs_directory_filter, help_file_processor, (Ptr) log); } --- 56,68 ---- initialise_help_manager(void) { + uHelpManager = (HelpManagerHeaderPtr) KG_XALLOCATE(sizeof(HelpManagerHeader)); + memset(uHelpManager, 0, sizeof(HelpManagerHeader)); + uHelpManager->mMagicNumber = kHelpListMagicNumber; + uHelpManager->helpList = kg_list_init(kListInterfacePlain, kListRepresentationDynamic, (DisposeRoutine) help_entry_disposer); + LogPtr log = kg_log_init("Logs/load_help_topics", NULL, 10 * 1024 * 1024); ! KGLOG_INFO(log, "Loading Help Topics"); ! kg_iterate_directory("Help", kg_text_file_filter, cvs_directory_filter, help_file_processor, (Ptr) log); } *************** *** 53,69 **** help_manager_do_command(const char* remainder, LivingPtr living) { if (remainder == NULL) { ! /* default to 'help' */ ! virtual_catch_tell((BasePtr) living, (BasePtr) living, "Welcome to the SlashMUD help system."); ! virtual_catch_tell((BasePtr) living, (BasePtr) living, "===================================="); ! virtual_catch_tell((BasePtr) living, (BasePtr) living, "To get help for a specific topic: help <topic>"); ! virtual_catch_tell((BasePtr) living, (BasePtr) living, "To get help about the help system: help help"); ! virtual_catch_tell((BasePtr) living, (BasePtr) living, "To get a list of topics: help topics"); ! virtual_catch_tell((BasePtr) living, (BasePtr) living, "For an explanation of how help information is presented: help template"); return 1; } ! /* keep array of help files loaded */ ! /* when requested for the first time, load it */ return 0; } --- 79,108 ---- help_manager_do_command(const char* remainder, LivingPtr living) { + int i; + char * text_line; + if (remainder == NULL) { ! ! for (i = 1; i <= kg_list_items(uHelpManager->helpList); i++) ! { ! HelpManagerEntryPtr the_help_entry = (HelpManagerEntryPtr) kg_list_get_indexed_item(uHelpManager->helpList, i); ! /* FIXME remove "Help/" from strcmp */ ! if (strcmp( "Help/help", the_help_entry->helpTitle) == 0) ! { ! kg_std_text_first(the_help_entry->helpText); ! text_line = kg_std_text_get_line(the_help_entry->helpText); ! while (text_line != NULL) ! { ! virtual_catch_tell((BasePtr) living, (BasePtr) living, text_line); ! kg_std_text_advance(the_help_entry->helpText); ! text_line = kg_std_text_get_line(the_help_entry->helpText); ! } ! } ! } return 1; } ! ! /* TODO convert remainder to all lower case */ return 0; } *************** *** 81,85 **** char tokbuffer[LINE_MAX]; char logbuf[kLogBufferBytes]; ! if (!file_stream) { --- 120,125 ---- char tokbuffer[LINE_MAX]; char logbuf[kLogBufferBytes]; ! HelpManagerEntryPtr new_help_entry; ! if (!file_stream) { *************** *** 89,123 **** } while (fgets(buffer, LINE_MAX, file_stream) != NULL) { unsigned int length = strlen(buffer) - 1; ! if ((length != 0) && (buffer[0] != '#')) { buffer[length] = '\0'; /* Replace newline character by null-terminator. */ snprintf(logbuf, kLogBufferBytes, "buffer: %s", buffer); KGLOG_INFO(log, logbuf); - - strncpy(tokbuffer, buffer, LINE_MAX); - - token = strtok(tokbuffer, " \t\n"); - remainder = strtok(NULL, "\n"); - - snprintf(logbuf, kLogBufferBytes, "token: '%s', remainder: '%s'", token, remainder); - KGLOG_INFO(log, logbuf); - - if (token == NULL) - { - snprintf(logbuf, kLogBufferBytes, "no token found, moving on to next line"); - KGLOG_INFO(log, logbuf); - } - else - { - /* TODO the bulk of the work here.*/ - } } } ! fclose(file_stream); --- 129,160 ---- } + new_help_entry = (HelpManagerEntryPtr) KG_XALLOCATE(sizeof(HelpManagerEntry)); + memset(new_help_entry, 0, sizeof(HelpManagerEntry)); + + /* FIXME parse "Help/" out of filepath text */ + new_help_entry->helpTitle = KG_XALLOCATE_CSTRING(filepath); + new_help_entry->helpText = kg_std_text_init(); + + KGLOG_INFO(log, " "); + snprintf(logbuf, kLogBufferBytes, "Processing File: %s", filepath); + KGLOG_INFO(log, logbuf); + while (fgets(buffer, LINE_MAX, file_stream) != NULL) { unsigned int length = strlen(buffer) - 1; ! if ((length != 0) && (buffer[0] != '#')) { buffer[length] = '\0'; /* Replace newline character by null-terminator. */ + kg_std_text_add_line(new_help_entry->helpText, buffer); + snprintf(logbuf, kLogBufferBytes, "buffer: %s", buffer); KGLOG_INFO(log, logbuf); } } ! ! kg_list_add_last(uHelpManager->helpList, new_help_entry); ! fclose(file_stream); Index: magic_numbers.h =================================================================== RCS file: /cvsroot/slashmud/slashmudx/src/magic_numbers.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** magic_numbers.h 13 Dec 2003 04:29:31 -0000 1.7 --- magic_numbers.h 15 Jun 2006 02:16:56 -0000 1.8 *************** *** 23,26 **** --- 23,27 ---- kFilterMagicNumber, kGroupMagicNumber, + kHelpListMagicNumber, kLivingStateMagicNumber, kMoodMagicNumber, |