Re: [AD] ungetc

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2010-12-22, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
> On Tue, Dec 21, 2010 at 11:48 PM, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
> > Does it really make sense for every file interface to define their own
> > ungetc routine? Couldn't Allegro just handle a single universal one?
> ...
> > Or alternatively, only if the ungetc hook is left null, is the above
> > default implementation is used. Otherwise, drivers could fill it in
> > and do something non-standard.
> >
> Attached is a patch that does this. memfile and PhysicsFS no longer
> have their own implementation.
> 
...
> +   al_fputs(memfile, "legro rocks!");
> +   al_fseek(memfile, 0, ALLEGRO_SEEK_SET);
> +   al_fungetc(memfile, 'l');
> +   al_fungetc(memfile, 'A');
> +   al_fgets(memfile, buffer, 15);
> +   if (strcmp(buffer, "Allegro rocks!")) {
> +      printf("Expected to see 'Allegro Rocks!' but got '%s' instead.\n", buffer);

"Rocks" should be lowercase ;-)

> +      printf("(Maybe the ungetc buffer isn't big enough.)\n");
> +      goto Error;
> +   }   

I didn't study the patch in-depth but it seems fine.

Peter




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/