[alt.sources] Elvis1.3, 3 fixes

joep@tnosoes.izf.tno.nl (Joep Mathijssen) (08/31/90)

Here are three fixes for problems I found while using Elvis1.3. 
Now I'm testing Elvis on a Sun3, but I'll use it on an Atari soon.

[1] Elvis had a problem with the substitute and find functions when
ignorecase was TRUE. I found that the problem was caused by the
"ustrncmp" function. When ignorecase is TRUE, the 'tolower' was
performed on every character. Even on lowercase characters.
From the man-page 'tolower':

     tolower(c)          converts c to its lower-case equivalent.
			 Note:  this  only works where c is known to be
			 a upper-case  character  to  start with
			 (presumably checked using isupper).

This probably differs between compilers, but I think you should add the
'isupper'-test.


========================================================================
	    These functions should go to REGEXP.C
========================================================================
 
/* Here is a function which performs string comparisons.  Uses o_ignorecase */
int ustrncmp(str1, str2, len)
        register char   *str1, *str2;   /* the strings to compare */
        register int    len;            /* max # of chars we care about */
{
    char ch1, ch2;
     
    if (*o_ignorecase) {
        while (--len >= 0) {
            ch1 = (isupper(*str1)) ? tolower(*str1) : *str1;
            ch2 = (isupper(*str2)) ? tolower(*str2) : *str2;
            if (ch1 != ch2)
                return ch2 - ch1;
            str1++;
            str2++;
        }
        return 0;
    }
    else {
        while (--len >= 0 && *str1++ == *str2++);
        if (len < 0)
            return 0;
        str1--;
        str2--;
        return *str2 - *str1;
    }
}

/* Here is a function which looks for a character in a string. */
char *ustrchr(str, ch)
register char   *str;   /* the string to look in */
register char   ch;     /* the character to look for */
{
    char tmpch;
    
    if (*o_ignorecase) {
        if (isupper(ch))
            ch = tolower(ch);
        for (; *str && *str != '\n'; str++) {
            tmpch = (isupper(*str)) ? tolower(*str) : *str;
            if (tmpch == ch)
                return str;
        }
    }
    else
        for (; *str && *str != '\n'; str++)
            if (*str == ch)
                return str;
    return (char *)0;
}    

========================================================================


[2] Small bug. While debugging elvis I found a small error. A temporary
file ('/usr/tmp/elvta000ffff8208') was not removed, because I aborted
the program. Starting elvis again the following message was displayed:

	"" is busy

This msg comes from 'tmp.c'. But instead of printing the name of the
tmpfile (variable 'tmpname') the variable 'filename' is printed, so an
empty string is shown. Line 134 in tmp.c should be

	FAIL("\"%s\" is busy", tmpname);

BTW: it's not possible to run elvis twice, because a fixed temporary
file is used! 



[3] The ESC is incorrect handled in INPUT_MODE.  After escaping from
the 'append'-operation (a) the cursor should move to the last typed
character.  The problem with elvis was that the screen is not updated
for some reason. So when you press 'x' after doing an append, the
'wrong' character is removed ( not the character the cursor was on, but
the previous one -> yes the last character that was typed).  This
problem is caused by the function 'getkey' in tio.c. When I press 'ESC'
this function checks all mapped keys and will find some matches (our
cursorkeys also start with an escape). Then the routine 'ttyread' is
called again because more than one mapped key matched. When I press 'x'
after the ESC no mapped will match anymore and ESC and 'x' are
processed, resulting in a late screen-update.

If I remove my mapped cursorkeys, the problem is solved and my cursor
will move to the last character I added. Another better (?) solution is
to skip the check for mapped keys, because you're not in CMD_MODE. I
don't know if this solution is correct, but it works fine for me:

Line 427 from TIO.C

for (i=j=0, k=-1, km=mapped; when & WHEN_VICMD && i < MAXMAPS; i++, km++)
			     ^^^^^^^^^^^^^^^^^
			     are we in CMD-mode?



===============================================================================
Joep Mathijssen
TNO Institute for Perception    Phone : +31 34 63 562 11
P.O. Box 23          		Fax   : +31 34 63 539 77
3769 ZG  Soesterberg    	E-mail: uunet!hp4nl.nluug.nl!tnosoes!joep
The Netherlands         	    or: joep@izf.tno.nl
===============================================================================

dan@hrc.UUCP (Dan Troxel) (09/07/90)

In article <B5P5504@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>In article <1358@tnosoes.izf.tno.nl> joep@tnosoes.izf.tno.nl (Joep Mathijssen) writes:

This is alt.sources. Please move this discussion to alt.sources.d for 
	*discussion*.

(Peter, you should know better). :->

-- 
Dan Troxel @ Handwriting Research Corporation                  WK 1-602-957-8870
Camelback Corporate Center  2821 E. Camelback Road  Suite 600  Phoenix, AZ 85016
ncar!noao!asuvax!hrc!dan          zardoz!hrc!dan      hrc!dan@asuvax.eas.asu.edu