DG Trigger index fix

From: Del Minturn (caminturn@EARTHLINK.NET)
Date: 08/27/98


Here is a fix for the triger index fix, I didn't make a diff cause
of all the power hits I keep getting.. just to get this out.. so I can
turn off my machine.. All I did was mimic the zedit index save!
in DG_OLC.C:


near top add:

  void trigedit_disp_menu(struct descriptor_data *d);
  void trigedit_save(struct descriptor_data *d);
+ void trigedit_create_index(int znum, char *type);

  /* copy an entire script from one holder (mob/obj/room) to another */

----------
at the end of "void trigedit_save(struct descriptor_data *d)"
add/change:

  sprintf(buf, "%s/%d.trg", TRG_PREFIX, zone);
  rename(fname, buf);

+  send_to_char("Saving Index file\r\n", d->character);
+  trigedit_create_index(zone, "trg");

}

--------------------
add this in right after the above:

void trigedit_create_index(int znum, char *type)
{
  FILE *newfile, *oldfile;
  char new_name[32], old_name[32], *prefix;
  int num, found = FALSE;

    prefix = TRG_PREFIX;

  sprintf(old_name, "%s/index", prefix);
  sprintf(new_name, "%s/newindex", prefix);

  if (!(oldfile = fopen(old_name, "r"))) {
    sprintf(buf, "SYSERR: DG_OLC: Failed to open %s", buf);
    mudlog(buf, BRF, LVL_IMPL, TRUE);
    return;
  } else if (!(newfile = fopen(new_name, "w"))) {
    sprintf(buf, "SYSERR: DG_OLC: Failed to open %s", buf);
    mudlog(buf, BRF, LVL_IMPL, TRUE);
    return;
  }

  /*
   * Index contents must be in order: search through the old file for
the
   * right place, insert the new file, then copy the rest over.
   */
  sprintf(buf1, "%d.%s", znum, type);
 while (get_line(oldfile, buf)) {
    if (*buf == '$') {
      fprintf(newfile, "%s\n$\n", (!found ? buf1 : ""));
      break;
    } else if (!found) {
      sscanf(buf, "%d", &num);
      if (num > znum) {
        found = TRUE;
        fprintf(newfile, "%s\n", buf1);
      }
    }
    fprintf(newfile, "%s\n", buf);
  }

  fclose(newfile);
  fclose(oldfile);
  /*
   * Out with the old, in with the new.
   */
  remove(old_name);
  rename(new_name, old_name);
}


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



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