Problems with a modified form of do_reboot

CAVNESS@utxvms.cc.utexas.edu
Date: 09/07/94


I have modifed do_reboot in teh following way:

struct reboot_data {
   char reboot_option[MAX_STRING_LENGTH];
   char reboot_file[MAX_STRING_LENGTH];
   char *whichfile;
 };

#define RB_OP(data) (data).reboot_option

#define RB_FILE(data) (data).reboot_file
#define RB_FILE_PTR(data) (data).whichfile

#define REREAD_FILE(file) file_to_string_alloc(RB_FILE((file)), \
                                               &RB_FILE_PTR((file)))

#define DO_ALL(str) ((is_abbrev((str), "all")) || *(str) == '*')
#define DO_LIST(str) ((is_abbrev((str), "list")) || *(str) == '?')
#define OK(ch)  send_to_char("Okay.\n\r", (ch))

#define STRING(var) char (var)[MAX_STRING_LENGTH]

ACMD(do_reboot)
{
   int  i;
   STRING(debug);

   struct reboot_data reboot_info[] =
   {
     {    "credits", CREDITS_FILE,    credits},
     {       "news", NULL_FILE,       '\0'},   
     {       "motd", MOTD_FILE,       motd},
     {    "kwdhelp", NULL_FILE,       '\0'},
     {   "pagehelp", HELP_PAGE_FILE,  help}, 
     {       "info", INFO_FILE,       info}, 
     {    "wizlist", WIZLIST_FILE,    wizlist},
     {      "poses", NULL_FILE,       '\0'},
     {      "imotd", IMOTD_FILE,      imotd},
     {   "policies", POLICIES_FILE,   policies},
     {   "handbook", HANDBOOK_FILE,   handbook},
     { "background", BACKGROUND_FILE, background},
     { "sacrifice",  NULL_FILE,       '\0'},
     {    "houses",  HOUSE_FILE,      houses},
     { "marriages",  MARRIAGES_FILE,  marriages},
     {   "qmanual",  QMANUAL_FILE,    qmanual},
     { "greetings",  GREETINGS_FILE,  GREETINGS},
     {        "\n",  NULL_FILE,       '\0'}
   };

   one_argument(argument, arg);
 
   if(!*arg)
   {
     send_to_char("Reboot what?\n\r",ch);
     return;
   }

   if(DO_LIST(arg))
   {
    send_to_char("The following reload options are available:\n\r", ch);
    for(i = 0;*RB_OP(reboot_info[i]) != TERM_ARRAY_CHAR; i++)
      {
        sprintf(buf,"%s\n\r", RB_OP(reboot_info[i]));
        send_to_char(buf, ch);
      }
    return;
  }
  else
    if(!DO_ALL(arg))
    {
        for(i = 0; *RB_OP(reboot_info[i]) != TERM_ARRAY_CHAR; i++)
          if(is_abbrev(arg, RB_OP(reboot_info[i]))) break;
    }
    else
    {
     for(i = 0; *RB_OP(reboot_info[i]) != TERM_ARRAY_CHAR; i++)  
       if(str_cmp(RB_FILE(reboot_info[i]), NULL_FILE))
       {
         sprintf(debug, "Rebooting_file: %s\n\r", RB_FILE(reboot_info[i]));
         send_to_char(debug, ch);
         if(REREAD_FILE(reboot_info[i]) < 0)
            send_to_char("ERROR! That file could not be reloaded!\n\r", ch);
    
       }
      OK(ch); 
      return;
     }
   
   /* if the two strings DON'T compare */
   if(str_cmp(RB_FILE(reboot_info[i]), NULL_FILE))
   {
       sprintf(debug, "Okay, rebooting file: %s\n\r", RB_FILE(reboot_info[i]));
       send_to_char(debug, ch);
       if(REREAD_FILE(reboot_info[i])< 0)
         send_to_char("Could not reboot the file!!", ch);
       OK(ch);
       return;
   }
   else
   {
     switch(i)
     {
       case 1:
             send_to_char("Reloading the news files\n\r", ch);
            file_to_string_alloc(NEWS_FILE, &news);
            file_to_string_alloc(NEWSVERSION, &nv);
            if(*news) newsversion = atoi(nv);
            OK(ch); 
            break;
       case 3: /* this is for the keyword file */
         send_to_char("Loading the help file again\n\r", ch);
         if (help_fl)
           fclose(help_fl);
         if (!(help_fl = fopen(HELP_KWRD_FILE, "r"))) return;
         else 
         { 
            for (i = 0; i < top_of_helpt; i++)
               free(help_index[i].keyword);
            free(help_index);
            help_index = build_help_index(help_fl, &top_of_helpt);
         }
         OK(ch);
        break;
       case 7: /* this is for the poses file */
        send_to_char("Loading the poses file =)\n\r", ch);
        boot_poses(); break;
      case 12: /* sacrifice messages */
        send_to_char("Rebooting sacrifice messages", ch);
        boot_sacrifices();
       }
      return;
   }

      /* If all of this fails, then you KNOW it didn't work. */

      send_to_char("Unknown reload option.\n\r", ch);
      send_to_char("Correct format: reload list | all | ? | * | <option>", ch);
      return;
}



For some reason, SOMETIMES it works, sometimes it doesn't!
For example, if I want to do a "reboot wizlist", first time it works like a
charm. Second time it works like a charm. Third time, and the pointers are all
fubared.

Can anyone at all see my error?

Thanks! :)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cavness@utxvms.cc.utexas.edu        |       The Great Holy Star Goat
Kenneth G. Cavness                  |          is with all of us,
"Supreme Diva"                      |         braised be Its name.
"I'm pro-choice--please don't       |
shoot me in the back."              |     Braise the name of Our Lard!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    



This archive was generated by hypermail 2b30 : 12/07/00 PST