[OLC] A problem with hedit

From: Jason Yarber (JasonYarber@hotmail.com)
Date: 06/06/02


Ok, I've been having a problem with another mud I work on, that deals with the help files.
It seems that extra lines are being added to the beginning and end of every help file entry.
I've narrowed it down to either when it saves, or when it loads, which it does both everytime
I do a copyover to update my code.  This bug has been persistant for a very long time, and
as you can probably imagine, we're having to cycle through about 5 blank screens before we
get to the actual help file.  I do know that the blank lines are being saved to disk.  But whether
they are being added when the file is loaded or when it's saved, is beyond me.  I've looked at
the code for both the saving and the loading, but can't see any apparent problems myself.
So I'm reluctantly asking you for help.  I've placed a copy of each suspect function below.
Please look through those functions and tell me what you think is wrong.  As usual, your
help is greatly appreciated.


void load_help(FILE *fl)
{
  char key[READ_SIZE+1], entry[32384];
  char line[READ_SIZE+1];
  struct help_index_element el;

  /* get the keyword line */
  get_one_line(fl, key);
  while (*key != '$') {
    /* read in the corresponding help entry */
    strcpy(entry, strcat(key, "\r\n"));
    get_one_line(fl, line);
    *entry = '\0';
    while (*line != '#') {
      strcat(entry, strcat(line, "\r\n"));
      get_one_line(fl, line);
    }

    el.min_level = 0;
    if ((*line == '#') && (*(line + 1) != 0))
      el.min_level = atoi((line + 1));

    el.min_level = MAX(0, MIN(el.min_level, LVL_IMPL));
    
    /* now, add the entry to the index with each keyword on the keyword line */
    el.entry = str_dup(entry);
    el.keywords = str_dup(key);

    help_table[top_of_helpt] = el;
    top_of_helpt++;

    /* get next keyword line (or $) */
    get_one_line(fl, key);
  }
}

void hedit_save_to_disk(void)
{
  int i;
  FILE *fp;
  struct help_index_element *help;

  sprintf(buf, "%s/%s.new", HLP_PREFIX, HELP_FILE);
  if (!(fp = fopen(buf, "w+"))) {
    mudlog("SYSERR: OLC: Cannot open help file!", BRF, LVL_BUILDER, TRUE);
    return;
  }
  for (i = 0; i <= top_of_helpt; i++) {
    help = (help_table + i);

#if defined(HEDIT_LIST)
    sprintf(buf1, "OLC: Saving help entry %d.", i);
    log(buf1);
#endif

    /*
     * Remove the '\r\n' sequences from description.
     */
    strcpy(buf1, help->entry ? help->entry : "Empty");

    /*
     * Forget making a buffer, lets just write the thing now.
     */
    kill_ems(buf1);
    fprintf(fp, "%s\n%s\n#%d\n",
      help->keywords ? help->keywords : "UNDEFINED", buf1,
      help->min_level);
  }

  /*
   * Write final line and close.
   */
  fprintf(fp, "$~\n");
  fclose(fp);
  sprintf(buf2, "%s/%s", HLP_PREFIX, HELP_FILE);
  /*
   * We're fubar'd if we crash between the two lines below.
   */
  remove(buf2);
  rename(buf, buf2);

}

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT