[liblouis-liblouisxml] Re: The use of inlen output

  • From: "John J. Boyer" <john.boyer@xxxxxxxxxxxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Wed, 5 Mar 2008 14:21:27 -0600

Eitan,

One confusing factor is that the en-us-g2.ctb table has pass2 and 
correct opcodes. These cause additional passes over the input and 
probably make giving an accurate value of inlen impossible. When I 
removed these inlen came out as 18. This is still inaccurate. It looks 
like it is for the last word tried. The fix should be simple. I'll also 
fix the problem with compBrlATCursor and send you the revised 
lou_translateString.c . That will also be available on 
www.jjb-software.com .

John

On Tue, Mar 04, 2008 at 07:47:31PM -0800, Eitan Isaacson wrote:
> Hi John.
> 
> I ran a quick experiment with to see if the output received is correct.
> I used the grade 2 american english table.
> The string I used for input is: "running away from the world".
> inlen was set to 27, and the ouput buffer was set to a size of 12.
> After translation we get: "runn+ away".
> Both inlen and outlen equal 10, the size of the string after
> translation. From your explanation below, shouldn't the the value of
> inlen be 12, because we translated up to the 12th character ("running
> away")?.
> 
> Attached is the code I use for the test.
> 
> Cheers,
>       Eitan.
> 
> On Mon, 2008-03-03 at 17:25 -0600, John J. Boyer wrote:
> > eitan,
> > 
> > It can happen that the output buffer is not large enough to hold the 
> > translation of the entire input buffer. If this happens, inlen is set to 
> > the number of characters actually translated. As you know, liblouis
> > is based on the translation module in brltty. When brltty calls it, it 
> > passes the line length of the braille display in outlen. The function 
> > translates 
> > as many whole words as will fit on a line (or as many characters if the 
> > "word" is longer than the line). It then sets *inlen to the number of 
> > characters in the input buffer actually used. Brljty then calls the 
> > function again starting from this point.
> > 
> > John
> > 
> > On Mon, Mar 03, 2008 at 01:50:44PM -0800, Eitan Isaacson wrote:
> > > Hi,
> > > 
> > > I asked John this question before, but I didn't understand his answer,
> > > so here it is again. *smile*
> > > 
> > > When calling translate() or translateString() in liblouis the outlen
> > > variable's reference is passed, and it is re-assigned to the newly
> > > translated string's length. inlen also seems to be modified, but I am
> > > not sure what it's new value means, or how it is useful. Shouldn't inlen
> > > remain equal to the length of the input buffer?
> > > 
> > > Cheers,
> > >   Eitan.
> > > 
> > > For a description of the software and to download it go to
> > > http://www.jjb-software.com
> > 

> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
> #include "liblouis.h"
> 
> #define OUTBUF_SIZE 12
> 
> int main(int argc, char **argv)
> {
>               const char *str = "running away from the world";
>               int inlen, outlen, i;
>               widechar *inbuf, *outbuf;
> 
>               inlen = strlen(str);
>               outlen = OUTBUF_SIZE;
>               inbuf = malloc(sizeof(widechar)*inlen);
>               outbuf = malloc(sizeof(widechar)*outlen);
>               printf("inlen=%d outlen=%d\n", inlen, outlen);
>               for (i=0;i<inlen;i++)
>                               inbuf[i] = str[i];
>               lou_translateString(argv[1], inbuf, &inlen, outbuf, &outlen, 
>                                               NULL, NULL, 0);
>               printf("'");
>               for (i=0;i<outlen;i++)
>                               printf("%c", (char)outbuf[i]);
>               printf("'\n");
>               printf("inlen=%d outlen=%d\n", inlen, outlen);
> }


-- 
John J. boyer; President, Chief Software Developer
JJB Software, Inc.
http://www.jjb-software.com
Madison, WI USA
Developing software for people with disabilities

For a description of the software and to download it go to
http://www.jjb-software.com

Other related posts: