[m-dev.] for review: io__read_line_as_string (round 2)

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 9 01:10:46 AEST 1998


On 08-Sep-1998, Andrew Bromage <bromage at cs.mu.OZ.AU> wrote:
> G'day all.
> 
> As before, Fergus' fixes are all incorporated in this diff.
> 
> Cheers,
> Andrew Bromage
> 
> Estimated hours taken: 10
> 
> library/io.m:
> library/io.nu.nl:
> 	Implement io__read_line_as_string/{3,4}.
> 	
> 	Also sneaked in here are some trivial whitespace fixes in some
> 	of the pragma c_code which did not comply with our coding
> 	standards (to do with type casting).
> 
> samples/cat.m:
> samples/sort.m:
> 	Use io__read_line_as_string.
> 
> tests/general/Mmakefile:
> tests/general/read_line_as_string.exp:
> tests/general/read_line_as_string.m:
> 	Test case for io__read_line_as_string.
> 
> NEWS:
> 	Mention the above change.

io.m:
> +:- pred io__read_line_as_string_2(io__input_stream, int, string,
> +                io__state, io__state).
> +:- mode io__read_line_as_string_2(in, out, out, di, uo) is det.
> +
> +:- pragma c_code(io__read_line_as_string_2(File::in, Res :: out,
> +                        RetString::out, IO0::di, IO::uo),
> +                [will_not_call_mercury, thread_safe],
> +"
> +#define READ_LINE_GROW(n)       ((n) * 3 / 2)
> +#define BYTES_TO_WORDS(n)       (((n) + sizeof(Word) - 1) / sizeof(Word))
> +#define READ_LINE_START         1024

With intermodule inlining, these macro names could invade the user's
namespace.  Please prefix them with `ML_IO_'.

> +        Char initial_read_buffer[READ_LINE_START];
> +        Char *read_buffer = initial_read_buffer;
> +        size_t read_buf_size = READ_LINE_START;
> +        size_t i;
> +        int char_code = '\\0';
> +
> +        Res = 0;
> +        for (i = 0; char_code != '\\n'; ) {
> +                char_code = mercury_getc((MercuryFile *) File);
> +                if (char_code == -1) {

I suggest s/-1/EOF/

Otherwise that change looks fine.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list