On Sun, Jul 17, 2016 at 03:23:14PM -0300, Henrique N. Lengler wrote:

> On Sun, Jul 17, 2016 at 07:20:48PM +0200, Otto Moerbeek wrote:
> > On Sun, Jul 17, 2016 at 12:51:03PM -0300, Henrique N. Lengler wrote:
> > 
> > > Hi,
> > > 
> > > I'm new on bc, I'm writing a library with some math functions I intend to 
> > > use
> > > on calculations.
> > > I would like to use long names for variables and functions on my library
> > > but also use functions from the main math library, which I do by calling 
> > > bc
> > > with '-l' flag. But once I start bc with '-l' I can't use any long name, 
> > > why?
> > > 
> > > Is there a way to change this behaviour?
> > > Why it works like this?
> > > 
> > > Regards,
> > > 
> > > Henrique N. Lengler
> > 
> > This is a bug introduced by not execing dc anymore, but calling the
> > dc code as a function.
> > 
> > In that case getopt is called a second time for a new set of
> > parameters and it has to be reinitialized,
> > 
> > The code below should fix it. Recompile both dc and bc after patching.
> > 
> >     -Otto
> > 
> > Index: dc.c
> > ===================================================================
> > RCS file: /cvs/src/usr.bin/dc/dc.c,v
> > retrieving revision 1.17
> > diff -u -p -r1.17 dc.c
> > --- dc.c    3 Nov 2015 04:58:58 -0000       1.17
> > +++ dc.c    17 Jul 2016 17:20:19 -0000
> > @@ -50,6 +50,8 @@ dc_main(int argc, char *argv[])
> >     if ((buf = strdup("")) == NULL)
> >             err(1, NULL);
> >     /* accept and ignore a single dash to be 4.4BSD dc(1) compatible */
> > +   optind = 1;
> > +   optreset = 1;
> >     while ((ch = getopt(argc, argv, "e:x-")) != -1) {
> >             switch (ch) {
> >             case 'e':
> 
> Will try it, shouldn't this patch go to the repository?
> 
> Regards,
> 
> Henrique N. Lengler

Yes, in the meantime I committed it in the -current tree.

        -Otto

Reply via email to