Binary -> ASCII Converter (and bug i found)

From: Michael Gallagher (m_gally@HOTMAIL.COM)
Date: 05/23/00


I've just put in ASCII pfiles and thankfully it's working, I wrote a pfile
converter (i'll give you the shortened version of it):

ACMD(do_pfileconv)
{
  FILE *fl, *nfl, *ifl;
  struct char_file_u player;
  struct affected_type *aff, tmp_aff[MAX_AFFECT];
  char bits[127];
  int done = 0, i;

  if (!(fl = fopen(PLAYER_FILE, "r+"))) {
    perror("Can't open player file for converting");
    return;
  }
  if (!(ifl = fopen("/pfiles/plr_index", "r+"))) {
    perror("Can't open player file for converting");
    return;
  }
  while (!done) {
    fread(&player, sizeof(struct char_file_u), 1, fl);
    if (feof(fl)) {
      fclose(fl);
      done=TRUE;
    }
    if (!done) {
      sprintf(buf, "/pfiles/%s", player.name);
      if (!(nfl = fopen(buf, "w"))) {
        perror("Can't open converted player file");
        return;
      }
      fprintf(ifl, "%d %s %d 0 %d\n", player.char_specials_saved.idnum,
player.name, player.level, player.played);

      if(player.name)
        fprintf(nfl, "Name: %s\n", player.name);

      /* Obviously i got more than this saved to the file, but there's no
         point in spamming */

      fclose(nfl);
      sprintf(buf, "%s converted.\n", player.name);
      send_to_char(buf, ch);
    }
  }
  fprintf(ifl, "~\n");
  fclose(ifl);
  send_to_char("\r\nPfile Converted!\r\n", ch);
  return;
}

basically
ifl = the index file
nfl = ascii pfile
fl = binary pfile

and basically it can't open my binary pfile, since showplay.c can open
it and my mud is working, i assumed it must be something i've done wrong.

can anyone see anything wrong with that converter?
the error is

Can't open player file for converting: No such file or directory

Thanx
Subliminal

P.S. The bug i found was in the sprintbits() function in the ascii code,
one of the checks was:

if (vektor & 1)

and i think it should be

if (vektor & (1 << i))


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



This archive was generated by hypermail 2b30 : 04/10/01 PDT