Re: Binary -> ASCII Converter (and bug i found)

From: Whitla, C. John (john.whitla@dat.com)
Date: 05/24/00


See below.

> -----Original Message-----
> 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)
> {

<snip>

>   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;
>   }

<snip>

> }
>
> 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

I don't have code for showplay.c, so I'm not sure what you're referring to
there, but I believe I see a few possible problems.

1) The fopen() call is using the mode "r+" on the file PLAYER_FILE.  This
should likely be "r+b" (as seen in db.c), because the player file you're
converting is a binary file.  What's more, since the intent is just to read
the binary player file and convert to an ascii file, the mode should
probably just be "rb" for read-only.

2) The fopen() call for /pfiles/plr_index used the mode "r+".  I don't know
whether it makes a difference or not (and haven't lit up test jigs to
verify), but the texts I have list "r+" as "opening for reading and writing"
and "w+" as "opening for writing and reading".  Whether this affects the
success of the fopen() call when/if the file does not already exist, I don't
know, but it may be worth a look.  Further note: do you really want the name
of the file to be fully-rooted?  Unless this machine is pretty much
dedicated to mudding, having a directory called "pfiles" off / seems like an
odd idea for packaging.

3) You could further isolate the cause of the problem by changing the
verbiage of your error message.  Something like "failure to open binary
file" and "failure to open index file" would let you know exactly which call
was failing.  At the moment, based on what you provided the cause of the
error is ambiguous.

Hope this helps.

J.


     +------------------------------------------------------------+
     | 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